-
Notifications
You must be signed in to change notification settings - Fork 0
180 lines (174 loc) · 6.54 KB
/
publish_version_merging.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# Workflow triggered when we have a new release candidate
# This action is adapted from https://github.com/t4d-gmbh/stubbed_versioning
name: Publish a version
on:
pull_request:
types:
- closed
env:
LABEL_PUBLISHED: 'release::published'
BUILD_LOC: "./build"
DOC_LOC: "./docs"
jobs:
associated_pr:
if: ${{ github.event.pull_request.merged && startsWith(github.head_ref, 'release-') }}
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
permissions:
pull-requests: read
repository-projects: read
outputs:
published: ${{ steps.published.outputs.labeled }}
event: ${{ github.event.number }}
steps:
- name: Check if the pull request is labeled with ${{ env.LABEL_PUBLISHED }}
id: published
run: |
if $( gh pr view ${{ github.event.number }} --repo ${{ env.OWNER }}/${{ env.REPO }} --json "labels" --jq ".[].[].name" | grep --quiet ${{ env.LABEL_PUBLISHED }}); then
echo "LABELED=true" >> $GITHUB_OUTPUT
else
echo "LABELED=false" >> $GITHUB_OUTPUT
fi
# NOTE: creating a step to check if the label is in the list of labels rather than failing below step
- name: Attempt to create label ${{ env.LABEL_PUBLISHED }}
if: ${{ steps.published.outputs.labeled == 'false' }}
run: |
gh label create ${{ env.LABEL_PUBLISHED }} --repo ${{ env.OWNER }}/${{ env.REPO }}
continue-on-error: true # make sure the next steps run also on failure
build-release-content:
if: ${{ (needs.associated_pr.outputs.published == 'false') }}
needs:
- associated_pr
runs-on: ubuntu-latest
container:
image: ${{ vars.CONTAINER_SOURCE }}/debian/gcc/release/abn:latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Create build location
run: |
mkdir ${{ env.BUILD_LOC }}
shell: bash
- name: Disable renv
run: |
renv::deactivate()
shell: Rscript {0}
- name: Change permissions of configure
run: |
chmod +x configure
shell: bash
- name: Build the package
run: |
devtools::build(pkg = '.', path = '${{ env.BUILD_LOC }}/abn.tar.gz')
shell: Rscript {0}
- name: Upload the built package as artifact
uses: actions/upload-artifact@v4
with:
name: package
path: ${{ env.BUILD_LOC }}/abn.tar.gz
build-pkgdown-content:
if: ${{ (needs.associated_pr.outputs.published == 'false') }}
needs:
- associated_pr
runs-on: ubuntu-latest
# Only restrict concurrency for non-PR jobs
concurrency:
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
id-token: write
pages: write
steps:
- uses: actions/checkout@v4
- uses: r-lib/actions/setup-pandoc@v2
- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::pkgdown, local::.
needs: website
- name: Build site
run: |
pkgdown::build_site_github_pages(dest_dir= "${{ env.DOC_LOC }}", new_process = FALSE, install = FALSE)
shell: Rscript {0}
- name: Setup Pages
uses: actions/configure-pages@v3
- name: Upload pkgdown artifact
uses: actions/upload-pages-artifact@v2
with:
path: ${{ env.DOC_LOC }}/
release-version:
needs:
- associated_pr
- build-release-content
- build-pkgdown-content
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
permissions:
contents: write
pull-requests: write
repository-projects: write
pages: write
id-token: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Get the version to release
id: release_version
run: |
git fetch --filter=tree:0 origin +refs/tags/*:refs/tags/*
echo "VERSION=$(echo ${{ github.head_ref }}|grep -Eo '[0-9]+.[0-9]+.[0-9]+')" >> $GITHUB_OUTPUT
echo "PREVIOUS_VERSION=`echo $(git tag --list --sort=version:refname | grep -E '^[0-9]+.[0-9]+.[0-9]+$' | tail -n1)`" >> $GITHUB_OUTPUT
- name: Remove previous releases of the target tag, if existing
if: ${{ steps.published.outputs.labeled == 'false' }}
run: |
if script -q -e -c "gh release view ${{ steps.release_version.outputs.version }} --repo ${{ env.OWNER }}/${{ env.REPO }}"; then
# removing previous release along with associated tag
gh release delete ${{ steps.release_version.outputs.version }} \
--cleanup-tag -y \
--repo ${{ env.OWNER }}/${{ env.REPO }}
else
# non-exist
echo "No trace of a previous release."
fi
- name: Prepare Release note
# this gets the first the changes to the previous clean tag (including manual edits)
run: |
awk '/# abn ${{ steps.release_version.outputs.version }}*/{a=1};a;/# abn ${{ steps.release_version.outputs.previous_version }}*/{exit}' NEWS.md | head -n -1 >> body.md
- name: Create tag and release
run: |
gh release create ${{ steps.release_version.outputs.version }} \
--target ${{ github.event.pull_request.head.sha }} \
--latest \
--title "${{ steps.release_version.outputs.version }}" \
--notes-file body.md \
--repo ${{ env.OWNER }}/${{ env.REPO }}
- name: Get the built package
uses: actions/download-artifact@v4
with:
name:
package
- name: Upload additional artifacts to the release
run: |
gh release upload ${{ steps.release_version.outputs.version }} \
./abn.tar.gz \
--clobber \
--repo ${{ env.OWNER }}/${{ env.REPO }}
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
- name: Adding the label ${{ env.LABEL_PUBLISHED }}
run: |
gh pr edit ${{ needs.associated_pr.outputs.event }} --add-label ${{ env.LABEL_PUBLISHED }} --repo ${{ env.OWNER }}/${{ env.REPO }}
shell: bash