Skip to content

Commit 26aa382

Browse files
authored
Dispatch release workflow from CI workflow (#218)
This updates our workflows to dispatch Release from the CI workflow. Addresses #201
1 parent d0d5196 commit 26aa382

File tree

2 files changed

+45
-11
lines changed

2 files changed

+45
-11
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ on:
55
push:
66
branches:
77
- main
8+
tags:
9+
- v*.*.*
810
pull_request:
911
workflow_dispatch:
1012

.github/workflows/release.yml

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,55 @@
22
name: Release
33

44
on:
5-
push:
6-
tags:
7-
- v*.*.*
5+
workflow_run:
6+
workflows:
7+
- "CI"
8+
types:
9+
- completed
810

911
jobs:
12+
validate-tag:
13+
name: Check tag
14+
runs-on: ubuntu-latest
15+
outputs:
16+
valid_tag: ${{ steps.validation.outputs.valid_tag }}
17+
if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push' && startsWith(github.event.workflow_run.head_branch, 'v') }}
18+
steps:
19+
- name: Check out the repository including tags
20+
uses: actions/checkout@v5
21+
with:
22+
ref: ${{ github.event.workflow_run.head_sha }}
23+
fetch-depth: 0
24+
fetch-tags: true
25+
- name: Validate tag
26+
id: validation
27+
run: |
28+
# Validation is necessary in the unlikely case that a branch matching the tag naming pattern is pushed
29+
# and the CI workflow in that branch is modified to run upon a push to that branch
30+
REF='${{ github.event.workflow_run.head_branch }}' # This can be a branch or tag name
31+
if [[ "$REF" != v*.*.* ]]; then
32+
echo "valid_tag=false" >> "$GITHUB_OUTPUT"; exit 0
33+
fi
34+
# Validate that the tag exists
35+
if ! git rev-parse -q --verify "refs/tags/$REF" >/dev/null; then
36+
echo "There is no tag matching $REF - $REF is a branch"
37+
echo "valid_tag=false" >> "$GITHUB_OUTPUT"; exit 0
38+
fi
39+
# Validate that the tag is for the same commit that was pushed
40+
TAG_SHA="$(git rev-parse "$REF^{commit}")"
41+
COMMIT_SHA="${{ github.event.workflow_run.head_sha }}"
42+
if [ "$TAG_SHA" != "$COMMIT_SHA" ]; then
43+
echo "Tag SHA $TAG_SHA does not match pushed commit SHA $COMMIT_SHA"
44+
echo "valid_tag=false" >> "$GITHUB_OUTPUT"; exit 0
45+
fi
46+
echo "Tag $REF exists and is valid. Tag $TAG_SHA matches the pushed commit $COMMIT_SHA."
47+
echo "valid_tag=true" >> "$GITHUB_OUTPUT"
1048
publish:
1149
name: Publish Client
50+
needs: validate-tag
1251
runs-on: ubuntu-latest
52+
if: ${{ needs.validate-tag.outputs.valid_tag == 'true' && github.event.workflow_run.conclusion == 'success' }}
1353
steps:
14-
- name: Wait for tests to succeed
15-
uses: lewagon/wait-on-check-action@v1.4.0
16-
with:
17-
ref: 'refs/heads/main'
18-
running-workflow-name: 'Publish Client'
19-
repo-token: ${{ secrets.GITHUB_TOKEN }}
20-
wait-interval: 10
21-
allowed-conclusions: success
2254
- name: Checkout Code
2355
uses: actions/checkout@v5
2456
- name: Set up JVM

0 commit comments

Comments
 (0)