-
Notifications
You must be signed in to change notification settings - Fork 1
261 lines (237 loc) · 10.6 KB
/
build-test-release.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
name: CI/CD
on:
push:
branches:
- main
- '*\@[0-9]+.[0-9]+.[0-9]+*' # package development branch
jobs:
build:
if: ${{ !contains(github.event.head_commit.message, '[no ci]') }}
runs-on: ubuntu-latest
outputs:
branch: ${{ steps.get_pkg_info.outputs.branch }}
pkg_name: ${{ steps.get_pkg_info.outputs.pkg_name }}
pkg_ver: ${{ steps.get_pkg_info.outputs.pkg_ver }}
docker_file: ${{ steps.get_pkg_info.outputs.docker_file }}
repo_lowercase: ${{ steps.repo_lowercase.outputs.lowercase }}
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
architecture: "x64"
env:
AGENT_TOOLSDIRECTORY: /opt/hostedtoolcache
- name: Extract package name and version from branch name
id: get_pkg_info
shell: bash
run: |
echo "::set-output name=branch::$(echo ${GITHUB_REF#refs/heads/})"
PKG_NAME=$(echo ${GITHUB_REF#refs/heads/} | awk -F'@' '{print $1}')
PKG_VER=$(echo ${GITHUB_REF#refs/heads/} | awk -F'@' '{print $2}')
echo "::set-output name=pkg_name::$(echo $PKG_NAME)"
echo "::set-output name=pkg_ver::$(echo $PKG_VER)"
if [[ -f "./$PKG_NAME/Dockerfile" ]]; then
echo "::set-output name=docker_file::$(echo ./$PKG_NAME/Dockerfile)"
else
echo "::set-output name=docker_file::"
fi
- name: Login to GitHub Container Registry
if: ${{ steps.get_pkg_info.outputs.branch != 'main' && steps.get_pkg_info.outputs.docker_file != ''}}
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}
- id: repo_lowercase
uses: ASzc/change-string-case-action@v1
with:
string: ${{ github.repository }}
- name: Build image
if: ${{ steps.get_pkg_info.outputs.branch != 'main' && steps.get_pkg_info.outputs.docker_file != ''}}
uses: docker/build-push-action@v2
with:
context: "./${{steps.get_pkg_info.outputs.pkg_name}}"
file: "${{steps.get_pkg_info.outputs.docker_file}}"
platforms: linux/amd64
load: true
tags: |
ghcr.io/${{ steps.repo_lowercase.outputs.lowercase }}.${{ steps.get_pkg_info.outputs.pkg_name }}:${{ steps.get_pkg_info.outputs.pkg_ver }}
- name: Push image to ghcr.io
id: push_to_ghcr
if: ${{ steps.get_pkg_info.outputs.branch != 'main' && steps.get_pkg_info.outputs.docker_file != ''}}
shell: bash
run: |
docker push ghcr.io/${{ steps.repo_lowercase.outputs.lowercase }}.${{ steps.get_pkg_info.outputs.pkg_name }}:${{ steps.get_pkg_info.outputs.pkg_ver }} | tee ./ghcr.io.stdout
IMAGE_SHA=$(cat ./ghcr.io.stdout | tr ' ' '\n' | grep 'sha256:' | awk -F':' '{print $2}')
echo "::set-output name=image_sha256::$(echo ${IMAGE_SHA})"
echo "::set-output name=created_at::$(date -u +%FT%TZ)"
test-and-release:
runs-on: ubuntu-latest
needs: [build]
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
architecture: "x64"
env:
AGENT_TOOLSDIRECTORY: /opt/hostedtoolcache
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install wfpm
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f requirements-test.txt ]; then pip install -r requirements-test.txt; fi
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
- name: Install Nextflow
run: |
wget --tries=10 -qO- https://get.nextflow.io | bash
sudo chmod 755 nextflow
sudo mv nextflow /usr/local/bin/
- name: "Login to GitHub Container Registry" # normally shouldn't need to login, but new image when just created is private
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}
- name: Run tests for all packages
if: ${{ needs.build.outputs.branch == 'main' }}
run: |
wfpm test
- name: Run tests for the current package only
if: ${{ needs.build.outputs.branch != 'main' }}
run: |
cd ./${{needs.build.outputs.pkg_name}}
wfpm test
- name: Check whether to proceed with release
id: to_release
run: |
if [[ \
"${{ github.event.head_commit.message }}" = "Merge"[[:space:]]"pull"[[:space:]]"request"* && \
"${{ github.event.head_commit.message }}" = *"@"* && \
"${{ github.event.head_commit.message }}" = *"[release]"* && \
"${{ needs.build.outputs.branch }}" = 'main'
]]; then
echo "::set-output name=release::$(echo Y)"
else
echo "::set-output name=release::$(echo N)"
fi
- name: Extract package name and version from commit message
if: ${{ steps.to_release.outputs.release == 'Y' }}
id: get_pkg_info
shell: bash
run: |
MERGED_BR=$(echo -e '${{ github.event.head_commit.message }}' | \
{ grep '^Merge pull request'||:; } | tr ' ' '\n' |{ grep '@'||:; } | awk -F'/' '{print $2}')
PKG_NAME=$(echo $MERGED_BR | awk -F'@' '{print $1}')
PKG_VER=$(echo $MERGED_BR | awk -F'@' '{print $2}')
echo "::set-output name=pkg_name::$(echo ${PKG_NAME})"
echo "::set-output name=pkg_ver::$(echo ${PKG_VER})"
if [[ -f "./$PKG_NAME/Dockerfile" ]]; then
echo "::set-output name=docker_file::$(echo ./$PKG_NAME/Dockerfile)"
echo "::set-output name=docker_image::$(echo ghcr.io/${{ needs.build.outputs.repo_lowercase }}.$PKG_NAME:$PKG_VER)"
else
echo "::set-output name=docker_file::"
echo "::set-output name=docker_image::"
fi
- name: Prepare package release tarball
id: prep_assets
if: ${{ steps.to_release.outputs.release == 'Y' }}
shell: bash
run: |
./scripts/cleanup_temp_files.sh # just in case
PKG_TAR=${{ steps.get_pkg_info.outputs.pkg_name }}.v${{ steps.get_pkg_info.outputs.pkg_ver }}.tar.gz
pushd ${{ steps.get_pkg_info.outputs.pkg_name }}
tar --exclude=wfpr_modules --dereference -czvf ../$PKG_TAR .
popd
echo "::set-output name=pkg_tar::$(echo ${PKG_TAR})"
echo "::set-output name=pkg_tar_sha::$(sha256sum ${PKG_TAR} |awk '{print $1}')"
echo "::set-output name=pkg_tar_size::$(ls -l ${PKG_TAR} |awk '{print $5}')"
echo "::set-output name=created_at::$(date -u +%FT%TZ)"
- name: Create release
id: create_release
if: ${{ steps.to_release.outputs.release == 'Y' }}
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_pkg_info.outputs.pkg_name }}.v${{ steps.get_pkg_info.outputs.pkg_ver }}
release_name: ${{ steps.get_pkg_info.outputs.pkg_name }}.v${{ steps.get_pkg_info.outputs.pkg_ver }}
body: |
* Release `${{ steps.get_pkg_info.outputs.pkg_name }}.v${{ steps.get_pkg_info.outputs.pkg_ver }}` (${{ github.sha }})
* Package `${{ steps.prep_assets.outputs.pkg_tar }}` (sha256: `${{ steps.prep_assets.outputs.pkg_tar_sha }}`)
* Package URI `github.com/${{ needs.build.outputs.repo_lowercase }}/${{ steps.get_pkg_info.outputs.pkg_name }}@${{ steps.get_pkg_info.outputs.pkg_ver }}`
* Run the package: `nextflow run ${{ needs.build.outputs.repo_lowercase }}/${{ steps.get_pkg_info.outputs.pkg_name }}/main.nf -r ${{ steps.get_pkg_info.outputs.pkg_name }}.v${{ steps.get_pkg_info.outputs.pkg_ver }} -params-file <params-json-file>`
draft: false
prerelease: false
- name: Prepare in pkg-release.json
if: ${{ steps.to_release.outputs.release == 'Y' }}
shell: bash
run: |
WFPM_VER=$(wfpm -v | cut -d ' ' -f 2)
if [[ '${{ steps.get_pkg_info.outputs.docker_file }}' != '' ]]; then
docker pull ${{ steps.get_pkg_info.outputs.docker_image }} | tee image.info
IMAGE_SHA=$(cat ./image.info | tr ' ' '\n' | grep 'sha256:' | awk -F':' '{print $2}')
else
IMAGE_SHA=$(echo)
fi
# temporary solution
TAG="${{ steps.get_pkg_info.outputs.pkg_name }}.v${{ steps.get_pkg_info.outputs.pkg_ver }}"
./scripts/prepare_package_release_json.py -p ${{ steps.get_pkg_info.outputs.pkg_name }}/pkg.json -d \
"
{
\"_release\": {
\"created\": \"${{ steps.prep_assets.outputs.created_at }}\",
\"hash\": {
\"checksum_type\": \"sha1\",
\"checksume\": \"${{ github.sha }}\"
},
\"tag\": \"$TAG\",
\"assets\": [
{
\"filename\": \"$TAG.tar.gz\",
\"download_url\": \"https://github.com/${{ github.repository }}/releases/download/$TAG/$TAG.tar.gz\",
\"checksum\": \"${{ steps.prep_assets.outputs.pkg_tar_sha }}\",
\"checksum_type\": \"sha256\",
\"size\": ${{ steps.prep_assets.outputs.pkg_tar_size }}
},
{
\"_NOTE_\": \"this file\",
\"filename\": \"pkg-release.json\",
\"download_url\": \"https://github.com/${{ github.repository }}/releases/download/$TAG/pkg-release.json\",
\"checksum\": null,
\"checksum_type\": null,
\"size\": null
}
]
},
\"_image_digest\": {
\"checksum\": \"$IMAGE_SHA\",
\"checksum_type\": \"sha256\"
},
\"_wfpm_ver\": \"$WFPM_VER\"
}
" > pkg-release.json
- name: Upload package release tarball
if: ${{ steps.to_release.outputs.release == 'Y' }}
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./${{ steps.prep_assets.outputs.pkg_tar }}
asset_name: ${{ steps.prep_assets.outputs.pkg_tar }}
asset_content_type: application/zip
- name: Upload package release json
if: ${{ steps.to_release.outputs.release == 'Y' }}
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./pkg-release.json
asset_name: pkg-release.json
asset_content_type: application/json