Skip to content

Commit 1c0e38a

Browse files
authored
Dispatch release workflow from CI workflow (#481)
Belongs to dnsimple/dnsimple-engineering#361
1 parent 522b13d commit 1c0e38a

File tree

2 files changed

+45
-13
lines changed

2 files changed

+45
-13
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 & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +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 to PyPI
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/[email protected]
16-
timeout-minutes: 15
17-
with:
18-
ref: 'refs/heads/main'
19-
running-workflow-name: 'Publish to PyPI'
20-
repo-token: ${{ secrets.GITHUB_TOKEN }}
21-
wait-interval: 10
22-
allowed-conclusions: success
23-
2454
- uses: actions/checkout@v5
2555

2656
- name: Set up Python

0 commit comments

Comments
 (0)