forked from NVIDIA/cuda-quantum
-
Notifications
You must be signed in to change notification settings - Fork 0
537 lines (472 loc) · 24.7 KB
/
publishing.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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
on:
workflow_dispatch:
inputs:
deployment_id:
type: string
description: The workflow id of the deployment that triggered the release creation.
required: true
assets_from_run:
type: string
description: Optional argument to facilitate rerunning a failed workflow without re-building the assets.
required: false
workflow_run:
workflows:
- Deployments
types:
- completed
name: Packages
jobs:
assets:
name: Assets
if: github.event_name == 'workflow_dispatch' || (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.actor.id == '135836288')
runs-on: ubuntu-latest
timeout-minutes: ${{ github.event_name == 'workflow_dispatch' && 360 || 100 }}
permissions:
contents: read
environment:
name: ghcr-deployment
url: ${{ vars.deployment_url }}
outputs:
artifacts_url: ${{ steps.artifacts.outputs.artifacts_url }}
github_commit: ${{ steps.artifacts.outputs.github_commit }}
docker_images: ${{ steps.artifacts.outputs.docker_images }}
python_wheels: ${{ steps.artifacts.outputs.python_wheels }}
releases: ${{ steps.artifacts.outputs.releases }}
release_title: ${{ steps.artifacts.outputs.release_title }}
release_version: ${{ steps.artifacts.outputs.release_version }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ vars.data_branch }}
token: ${{ secrets.REPO_BOT_ACCESS_TOKEN }}
- name: Download build info
id: artifacts
run: |
if ${{ inputs.deployment_id != '' }}; then
artifacts_url=https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ inputs.deployment_id }}/artifacts
else
artifacts_url=${{ github.event.workflow_run.artifacts_url }}
echo "Artifacts downloaded from https://github.com/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}" >> $GITHUB_STEP_SUMMARY
fi
artifacts=$(gh api $artifacts_url -q '.artifacts[] | {name: .name, url: .archive_download_url}')
function download {
gh api $1 > info.zip
unzip -d info info.zip
for file in `find info/ -type f`; do
cat "$file" >> $2.txt
done
rm -rf info info.zip
}
docker_images="{\"info_files\":[]}"
python_wheels="{\"info_files\":[]}"
for artifact in `echo "$artifacts"`; do
name=`echo $artifact | jq -r '.name'`
url=`echo $artifact | jq -r '.url'`
if [ "${name#build_info}" != "$name" ] || [ "${name#python_info}" != "$name" ]; then
download "$url" "$name"
platforms=`cat "$name.txt" | egrep -o 'platforms?: \S*' | cut -d ' ' -f 2`
if [ -n "$(echo $platforms | grep ',')" ]; then runner=linux-amd64-cpu8
else runner=$(echo $platforms | tr / -)-cpu8
fi
# Make sure to push all staging commits to a separate branch
# to ensure that a pipeline runs for each commit.
staging_branch=bot/${{ inputs.assets_from_run || github.run_id }}/$name
# Use a dedicated draft release for each set of assets to avoid issues
# with race conditions when running artifacts builds concurrently.
release_id=${{ inputs.assets_from_run || github.run_id }}_$name
releases+="$release_id "
info={\"$name\":{\"release_id\":\"$release_id\",\"staging_branch\":\"$staging_branch\",\"runner\":\"$runner\"}}
fi
if [ "${name#build_info}" != "$name" ]; then
docker_images=`echo $docker_images | jq ".info_files |= . + [\"$name\"]"`
docker_images=`echo $docker_images | jq ". |= . + $info"`
elif [ "${name#python_info}" != "$name" ]; then
python_wheels=`echo $python_wheels | jq ".info_files |= . + [\"$name\"]"`
python_wheels=`echo $python_wheels | jq ". |= . + $info"`
elif [ "${name#deployment_info}" != "$name" ]; then
download "$url" "$name"
github_commit=`cat "$name.txt" | grep -o 'source-sha: \S*' | cut -d ' ' -f 2`
release_title=`cat "$name.txt" | grep -o 'release-title: \S*' | cut -d ' ' -f 2`
release_version=`cat "$name.txt" | grep -o 'release-version: \S*' | cut -d ' ' -f 2`
fi
done
echo "release_title=$release_title" >> $GITHUB_OUTPUT
echo "release_version=$release_version" >> $GITHUB_OUTPUT
echo "releases='$releases'" >> $GITHUB_OUTPUT
echo "github_commit=$github_commit" >> $GITHUB_OUTPUT
echo "docker_images=$(echo $docker_images)" >> $GITHUB_OUTPUT
echo "python_wheels=$(echo $python_wheels)" >> $GITHUB_OUTPUT
echo "artifacts_url=$artifacts_url" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ github.token }}
- name: Trigger assets creation
if: inputs.assets_from_run == ''
run: |
# The commit title of the staging commit needs to match
# the docker image that is used to build additional components.
# Using the image sha as the file name and the docker image name
# as the folder is convenient for the GitLab CI.
git config --global user.name "cuda-quantum-bot"
git config --global user.email "[email protected]"
current_branch=$(git rev-parse --abbrev-ref HEAD)
function create_assets {
release_id=`echo "$4" | jq -r ".$1.release_id"`
staging_branch=`echo "$4" | jq -r ".$1.staging_branch"`
staging_folder="deployments/staging/$3"
image_hash=`cat "$1.txt" | grep -o "$2: \S*" | cut -d ' ' -f 2`
file_id=`echo $image_hash | rev | cut -d ':' -f 1 | rev`
echo "asset-name: $1" >> "$1.txt"
echo "release-id: $release_id" >> "$1.txt"
mkdir -p "$staging_folder" && mv "$1.txt" "$staging_folder/$file_id"
echo "Pushing $1 to $staging_branch"
git add "$staging_folder" && git commit -m "$image_hash"
git push origin $current_branch:$staging_branch
}
for file in ${{ join(fromJson(steps.artifacts.outputs.docker_images).info_files, ' ') }}; do
create_assets $file cuda-quantum-dev-image cuda-quantum-dev '${{ steps.artifacts.outputs.docker_images }}'
done
for file in ${{ join(fromJson(steps.artifacts.outputs.python_wheels).info_files, ' ') }}; do
create_assets $file cuda-quantum-wheeldeps-image cuda-quantum-devdeps '${{ steps.artifacts.outputs.python_wheels }}'
done
- name: Wait for assets
run: |
for release_id in `echo ${{ steps.artifacts.outputs.releases }}`; do
while [ -z "$(gh release list -R ${{ github.repository }} | grep -s $release_id)" ];
do echo "Waiting for assets $release_id ..." && sleep 300;
done
done
env:
GH_TOKEN: ${{ secrets.REPO_BOT_ACCESS_TOKEN }}
cudaq_hpc:
name: CUDA Quantum Docker image
needs: assets
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
environment:
name: ghcr-deployment
url: ${{ vars.deployment_url }}
strategy:
matrix:
info_file: ${{ fromJson(needs.assets.outputs.docker_images).info_files }}
fail-fast: false
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ needs.assets.outputs.github_commit }}
token: ${{ secrets.REPO_BOT_ACCESS_TOKEN }}
- name: Retrieve assets
id: release_info
run: |
release_id=${{ fromJson(needs.assets.outputs.docker_images)[format('{0}', matrix.info_file)].release_id }}
assets_folder=assets && mkdir "$assets_folder" && cd "$assets_folder"
while [ -z `ls | egrep '${{ matrix.info_file }}'` ]; do
(gh release download $release_id -R ${{ github.repository }}) || true
sleep 30 # waiting for assets to be created...
done
build_info=${{ matrix.info_file }}*
platforms=`cat $build_info | grep -o 'platforms: \S*' | cut -d ' ' -f 2`
cudaq_image=`cat $build_info | grep -o 'cuda-quantum-image: \S*' | cut -d ' ' -f 2`
cudaq_ngc_image=`cat $build_info | grep -o 'cuda-quantum-ngc-image: \S*' | cut -d ' ' -f 2`
cudaqdev_image=`cat $build_info | grep -o 'cuda-quantum-dev-image: \S*' | cut -d ' ' -f 2`
cudaqdevdeps_image=`cat $build_info | grep -o 'cuda-quantum-devdeps-image: \S*' | cut -d ' ' -f 2`
for file in `ls *zip`; do unzip "$file" && rm "$file"; done && cd -
docker pull $cudaq_image
repo_owner=${{ github.repository_owner }}
image_short_name=cuda-quantum
base_tag=`docker inspect $cudaq_image --format='{{json .Config.Labels}}' | jq -r '."org.opencontainers.image.version"'`
image_title=`docker inspect $cudaq_image --format='{{json .Config.Labels}}' | jq -r '."org.opencontainers.image.title"'`
image_description=`docker inspect $cudaq_image --format='{{json .Config.Labels}}' | jq -r '."org.opencontainers.image.description"'`
docker image rm $cudaq_image
docker image prune --force
registry=${{ vars.registry || 'localhost:5000' }}/${repo_owner,,}
if [ -n "$(echo "$platforms" | grep ',')" ] && ${{ secrets.secrets.NGC_CREDENTIALS != '' }}; then
if [ -n "$cudaq_ngc_image" ]; then
ngc_registry=nvcr.io/${repo_owner,,}/cudaquantdev
fi
fi
echo "release_id=$release_id" >> $GITHUB_OUTPUT
echo "registry=$registry" >> $GITHUB_OUTPUT
echo "ngc_registry=$ngc_registry" >> $GITHUB_OUTPUT
echo "image_short_name=$image_short_name" >> $GITHUB_OUTPUT
echo "image_name=${ngc_registry:-$registry}/$image_short_name" >> $GITHUB_OUTPUT
echo "image_tag=${base_tag%-base}" >> $GITHUB_OUTPUT
echo "image_title=$image_title" >> $GITHUB_OUTPUT
echo "image_description=$image_description" >> $GITHUB_OUTPUT
echo "platforms=$platforms" >> $GITHUB_OUTPUT
echo "cudaq_image=$cudaq_image" >> $GITHUB_OUTPUT
echo "cudaqdev_image=$cudaqdev_image" >> $GITHUB_OUTPUT
echo "cudaqdevdeps_image=$cudaqdevdeps_image" >> $GITHUB_OUTPUT
echo "assets_folder=$assets_folder" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ secrets.REPO_BOT_ACCESS_TOKEN }}
- name: Log in to the registry
if: steps.release_info.outputs.ngc_registry || vars.registry
uses: docker/login-action@v2
with:
registry: ${{ steps.release_info.outputs.ngc_registry || vars.registry }}
username: ${{ (steps.release_info.outputs.ngc_registry != '' && '$oauthtoken') || github.actor }}
password: ${{ (steps.release_info.outputs.ngc_registry != '' && secrets.NGC_CREDENTIALS) || github.token }}
- name: Set up buildx runner
uses: docker/setup-buildx-action@v2
- name: Extract cuda-quantum metadata
id: metadata
uses: docker/metadata-action@v4
with:
images: ${{ steps.release_info.outputs.image_name }}
flavor: latest=false
tags: type=raw,value=${{ steps.release_info.outputs.image_tag }}
labels: |
org.opencontainers.image.title=${{ steps.release_info.outputs.image_title }}
org.opencontainers.image.description=${{ steps.release_info.outputs.image_description }}
- name: Build cuda-quantum image
id: cudaq_build
uses: docker/build-push-action@v4
with:
context: .
file: ./docker/release/cudaq.ext.Dockerfile
build-args: |
base_image=${{ steps.release_info.outputs.cudaq_image }}
assets=${{ steps.release_info.outputs.assets_folder }}
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
platforms: ${{ steps.release_info.outputs.platforms }}
push: true
- name: Install Cosign
uses: sigstore/[email protected]
- name: Sign image with GitHub OIDC Token
if: steps.release_info.outputs.ngc_registry == ''
env:
DIGEST: ${{ steps.cudaq_build.outputs.digest }}
TAGS: ${{ steps.metadata.outputs.tags }}
run: cosign sign --yes --recursive "${TAGS}@${DIGEST}"
- name: Log in to the container registry
if: vars.registry
uses: docker/login-action@v2
with:
registry: ${{ vars.registry }}
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Set up redirect
id: redirect
if: steps.release_info.outputs.ngc_registry != ''
run: |
echo "FROM ${{ steps.release_info.outputs.image_name }}@${{ steps.cudaq_build.outputs.digest }}" >> redirect.Dockerfile
echo "image_name=${{ steps.release_info.outputs.registry }}/${{ steps.release_info.outputs.image_short_name }}" >> $GITHUB_OUTPUT
- name: Update cuda-quantum metadata
id: updated_metadata
if: steps.redirect.outcome != 'skipped'
uses: docker/metadata-action@v4
with:
images: ${{ steps.redirect.outputs.image_name }}
flavor: latest=false
tags: type=raw,value=${{ steps.release_info.outputs.image_tag }}
labels: |
org.opencontainers.image.title=${{ steps.release_info.outputs.image_title }}
org.opencontainers.image.description=${{ steps.release_info.outputs.image_description }}
- name: Build cuda-quantum image redirect
id: docker_build
if: steps.redirect.outcome != 'skipped'
uses: docker/build-push-action@v4
with:
context: .
file: redirect.Dockerfile
tags: ${{ steps.updated_metadata.outputs.tags }}
labels: ${{ steps.updated_metadata.outputs.labels }}
platforms: ${{ steps.release_info.outputs.platforms }}
push: true
- name: Sign image with GitHub OIDC Token
if: steps.redirect.outcome != 'skipped'
env:
DIGEST: ${{ steps.docker_build.outputs.digest }}
TAGS: ${{ steps.updated_metadata.outputs.tags }}
run: cosign sign --yes --recursive "${TAGS}@${DIGEST}"
- name: Update release information
run: |
release_id=${{ steps.release_info.outputs.release_id }}
gh release view $release_id --json body --jq .body > rel_notes.txt
header_length=`cat rel_notes.txt | grep -n "Release notes generated" | cut -d ':' -f 1`
head -n $(($header_length - 1)) rel_notes.txt > new_notes.txt
redirect=${{ steps.redirect.outputs.image_name }}
echo -e "\nImages for ${{ steps.release_info.outputs.platforms }}:\n" >> new_notes.txt
echo "- cuda-quantum (base image): ${{ steps.release_info.outputs.cudaq_image }}" >> new_notes.txt
echo "- cuda-quantum (with hpc components): ${{ steps.release_info.outputs.image_name }}@${{ steps.cudaq_build.outputs.digest }}${redirect:+ or $redirect@${{ steps.docker_build.outputs.digest }}}" >> new_notes.txt
echo "- cuda-quantum-dev (for extension development): ${{ steps.release_info.outputs.cudaqdev_image }}" >> new_notes.txt
echo "- cuda-quantum-devdeps (development dependencies only): ${{ steps.release_info.outputs.cudaqdevdeps_image }}" >> new_notes.txt
(echo && tail -n +$header_length rel_notes.txt) >> new_notes.txt
gh release edit $release_id -R ${{ github.repository }} --notes-file new_notes.txt
env:
GH_TOKEN: ${{ secrets.REPO_BOT_ACCESS_TOKEN }}
- name: Clean up
run: |
# Clean up the staging branch that was used to trigger the GitLab pipeline.
staging_branch=${{ fromJson(needs.assets.outputs.docker_images)[format('{0}', matrix.info_file)].staging_branch }}
git config --global user.name "cuda-quantum-bot"
git config --global user.email "[email protected]"
git push origin --delete $staging_branch || ${{ inputs.assets_from_run != '' && true || false }}
cudaq_wheels:
name: CUDA Quantum Python wheels
needs: assets
runs-on: ubuntu-latest
environment:
name: ghcr-deployment
url: ${{ vars.deployment_url }}
strategy:
matrix:
info_file: ${{ fromJson(needs.assets.outputs.python_wheels).info_files }}
fail-fast: false
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ needs.assets.outputs.github_commit }}
token: ${{ secrets.REPO_BOT_ACCESS_TOKEN }}
- name: Retrieve assets
id: release_info
run: |
release_id=${{ fromJson(needs.assets.outputs.python_wheels)[format('{0}', matrix.info_file)].release_id }}
assets_folder=assets && mkdir "$assets_folder" && cd "$assets_folder"
while [ -z `ls | egrep '${{ matrix.info_file }}'` ]; do
(gh release download $release_id -R ${{ github.repository }}) || true
sleep 30 # waiting for assets to be created...
done
build_info=${{ matrix.info_file }}*
platform=`cat $build_info | grep -o 'platform: \S*' | cut -d ' ' -f 2`
platform_id=`echo $platform | sed 's/linux\///g' | tr -d ' '`
platform_arch=`([ "$platform_id" == "amd64" ] && echo x86_64) || ([ "$platform_id" == "arm64" ] && echo aarch64) || echo any`
cudaqwheeldeps_image=`cat $build_info | grep -o 'cuda-quantum-wheeldeps-image: \S*' | cut -d ' ' -f 2`
for file in `ls *zip`; do unzip "$file" && rm "$file"; done && cd -
echo "platform=$platform"
echo "platform_id=$platform_id"
echo "platform_arch=$platform_arch"
echo "release_id=$release_id" >> $GITHUB_OUTPUT
echo "platform=$platform" >> $GITHUB_OUTPUT
echo "platform_arch=$platform_arch" >> $GITHUB_OUTPUT
echo "cudaqwheeldeps_image=$cudaqwheeldeps_image" >> $GITHUB_OUTPUT
echo "assets_folder=$assets_folder" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ secrets.REPO_BOT_ACCESS_TOKEN }}
# TODO: Create python wheels that include simulator extensions.
# For now, we just download the already built wheels from the deployment run.
- name: Build cuda-quantum wheel
id: build_wheel
run: |
artifacts_url=${{ needs.assets.outputs.artifacts_url }}
artifacts=$(gh api $artifacts_url -q '.artifacts[] | {name: .name, url: .archive_download_url}')
mkdir -p /tmp/wheels
for artifact in `echo "$artifacts"`; do
name=`echo $artifact | jq -r '.name'`
if [ "${name#pycudaq-}" != "$name" ]; then
url=`echo $artifact | jq -r '.url'`
gh api $url > _pycudaq.zip
unzip -d _pycudaq _pycudaq.zip && cd _pycudaq
for wheel in `ls cuda_quantum-*-manylinux_*_${{ steps.release_info.outputs.platform_arch }}.whl 2> /dev/null`; do
echo "Adding wheel $wheel."
mv $wheel "/tmp/wheels/$wheel"
done
cd .. && rm -rf _pycudaq*
fi
done
env:
GH_TOKEN: ${{ github.token }}
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: ${{ steps.release_info.outputs.platform_arch }}-wheels
path: /tmp/wheels
retention-days: 1
if-no-files-found: error
- name: Update release information
run: |
release_id=${{ steps.release_info.outputs.release_id }}
gh release view $release_id --json body --jq .body > rel_notes.txt
header_length=`cat rel_notes.txt | grep -n "Release notes generated" | cut -d ':' -f 1`
head -n $(($header_length - 1)) rel_notes.txt > new_notes.txt
echo -e "\nImage to create ${{ steps.release_info.outputs.platforms }} wheels:\n" >> new_notes.txt
echo "- cuda-quantum-devdeps (development dependencies only): ${{ steps.release_info.outputs.cudaqwheeldeps_image }}" >> new_notes.txt
(echo && tail -n +$header_length rel_notes.txt) >> new_notes.txt
gh release edit $release_id -R ${{ github.repository }} --notes-file new_notes.txt
env:
GH_TOKEN: ${{ secrets.REPO_BOT_ACCESS_TOKEN }}
- name: Clean up
run: |
# Clean up the staging branch that was used to trigger the GitLab pipeline.
staging_branch=${{ fromJson(needs.assets.outputs.python_wheels)[format('{0}', matrix.info_file)].staging_branch }}
git config --global user.name "cuda-quantum-bot"
git config --global user.email "[email protected]"
git push origin --delete $staging_branch || ${{ inputs.assets_from_run != '' && true || false }}
create_release:
name: CUDA Quantum Release
needs: [assets, cudaq_hpc, cudaq_wheels]
if: needs.assets.outputs.release_title
runs-on: ubuntu-latest
environment:
name: ghcr-deployment
url: ${{ vars.deployment_url }}
steps:
- name: Download cuda-quantum wheels
uses: actions/download-artifact@v3
with:
path: wheelhouse
# The python wheels are uploaded as a release asset, but not pushed to anywhere else.
# Note that PyPI packages cannot be updated once pushed;
# - We could upload wheels to test-pypi when creating a release.
# - The push to pypi itself should be done manually.
# See also:
# https://github.com/pypa/gh-action-pypi-publish
# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
- name: Create release
run: |
for dir in `ls wheelhouse/`; do
mv "wheelhouse/$dir"/* wheelhouse/ && rmdir "wheelhouse/$dir"
done
zip -r wheelhouse.zip wheelhouse
release_id=${{ inputs.assets_from_run || github.run_id }}
release_title="${{ needs.assets.outputs.release_title }}"
github_commit=${{ needs.assets.outputs.github_commit }}
version=${{ needs.assets.outputs.release_version }}
versions=`gh release list -R ${{ github.repository }} --exclude-drafts --exclude-pre-releases | egrep -o "([0-9]{1,}\.)+[0-9]{1,}\S*" | sort -r -V`
latest_tag=`echo $versions | cut -d ' ' -f 1`
prerelease=`([ "$(echo $version | egrep -o '([0-9]{1,}\.)+[0-9]{1,}')" == "$version" ] && echo '') || echo '--prerelease'`
rel_notes="Release created by workflow [${{ github.run_id }}](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})."
rel_notes+=$(echo "<br/>GitHub commit [$github_commit](https://github.com/${{ github.repository }}/tree/$github_commit)")
gh release create $release_id --title $release_id -R ${{ github.repository }} \
--target $github_commit --draft $prerelease \
--generate-notes --notes-start-tag $latest_tag --notes "$rel_notes"
gh release upload $release_id -R ${{ github.repository }} wheelhouse.zip --clobber
gh release edit $release_id -R ${{ github.repository }} \
--title "$release_title" --tag $version $prerelease # --draft=false
env:
GH_TOKEN: ${{ secrets.REPO_BOT_ACCESS_TOKEN }}
clean_up:
name: Clean up
needs: [assets, cudaq_hpc, cudaq_wheels, create_release]
# Force this job to run even when some of the dependencies above are skipped.
if: always() && !cancelled() && needs.assets.result != 'skipped' && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled')
runs-on: ubuntu-latest
environment:
name: ghcr-deployment
url: ${{ vars.deployment_url }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Clean up
id: cleanup
run: |
# Delete the draft release(s) used to exchange data between GitLab and GitHub.
for release_id in `echo ${{ needs.assets.outputs.releases }}`; do
if [ -n "$(gh release list | grep -s $release_id)" ]; then
echo "## Draft Release $release_id:" >> $GITHUB_STEP_SUMMARY
gh release view $release_id --json body --jq .body > rel_notes.txt
header_length=`cat rel_notes.txt | grep -n "Release notes generated" | cut -d ':' -f 1`
head -n $(($header_length - 1)) rel_notes.txt >> $GITHUB_STEP_SUMMARY
gh release delete $release_id -R ${{ github.repository }} -y
echo "Deleted release $release_id."
fi
done
env:
GH_TOKEN: ${{ secrets.REPO_BOT_ACCESS_TOKEN }}