Skip to content

Commit a1a71c1

Browse files
author
Lukas Puehringer
committed
build: update CI/CD workflow to run in series
- Change CI workflow to also run on push to (release) tag - Change CD workflow to run on successful CI run, and only if a (release) tag push triggered the CI NOTE: Unfortunately the setup is not very robust (see code comment in cd.yml) Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
1 parent 5bfe897 commit a1a71c1

2 files changed

Lines changed: 26 additions & 8 deletions

File tree

.github/workflows/cd.yml

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,35 @@
11
name: CD
22
concurrency: cd
33

4-
# Trigger workflow on release tag push
4+
# Trigger workflow on completed CI (further checks below)
55
on:
6-
push:
7-
# TODO: Should we restrict to vX.Y.Z tags?
8-
tags: v*
6+
workflow_run:
7+
workflows: [CI]
8+
types: [completed]
99

1010
jobs:
1111
build:
1212
name: Build
1313
runs-on: ubuntu-latest
14+
# Skip unless CI was successful and ran on a ref starting with 'v' (release tag)
15+
if: ${{ github.event.workflow_run.conclusion == 'success' && startsWith(github.event.workflow_run.head_branch, 'v') }}
16+
# NOTE: This works because we currently only trigger CI on a push to the 'develop'
17+
# branch or a 'v*'-tag, but it seems rather brittle.
18+
# Unfortunately, there is not much more info we get from the CI workflow
19+
# ('workflow_run') than the ref name. No ref, ref_type, etc., so we don't even know
20+
# if a tag or a branch was pushed. :(
21+
# See https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#workflow_run
22+
# NOTE: (2) An alternative solution might be to restructure workflows, so that all
23+
# test logic from 'ci.yml' is moved to a separate workflow file '_test.yml', that
24+
# can be included in both CI (triggered on push to 'develop'-branch) and CD
25+
# (triggered on push to 'v*'-tag) workflows.
1426
outputs:
1527
release_id: ${{ steps.gh-release.outputs.id }}
1628
steps:
1729
- name: Checkout release tag
1830
uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846
31+
with:
32+
ref: ${{ github.event.workflow_run.head_branch }}
1933

2034
- name: Set up Python
2135
uses: actions/setup-python@0ebf233433c08fb9061af664d501c3f3ff0e9e20
@@ -32,8 +46,8 @@ jobs:
3246
name: Publish GitHub release candiate
3347
uses: softprops/action-gh-release@1e07f4398721186383de40550babbdf2b84acfc5
3448
with:
35-
name: ${{ github.ref_name }}-rc
36-
tag_name: ${{ github.ref }}
49+
name: ${{ github.event.workflow_run.head_branch }}-rc
50+
tag_name: ${{ github.event.workflow_run.head_branch }}
3751
body: "Release waiting for review..."
3852
files: dist/*
3953

@@ -75,6 +89,6 @@ jobs:
7589
owner: context.repo.owner,
7690
repo: context.repo.repo,
7791
release_id: '${{ needs.build.outputs.release_id }}',
78-
name: '${{ github.ref_name }}',
79-
body: 'See [CHANGELOG.md](https://github.com/'+ context.repo.owner +'/'+ context.repo.repo +'/blob/${{ github.ref_name }}/docs/CHANGELOG.md) for details.'
92+
name: '${{ github.event.workflow_run.head_branch }}',
93+
body: 'See [CHANGELOG.md](https://github.com/'+ context.repo.owner +'/'+ context.repo.repo +'/blob/${{ github.event.workflow_run.head_branch }}/docs/CHANGELOG.md) for details.'
8094
})

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ on:
44
push:
55
branches:
66
- develop
7+
tags:
8+
# TODO: Should we restrict to vX.Y.Z tags?
9+
- v*
10+
711
pull_request:
812
workflow_dispatch:
913

0 commit comments

Comments
 (0)