@@ -5,9 +5,9 @@ concurrency:
55 cancel-in-progress : false
66
77on :
8- push :
9- tags :
10- - ' v* '
8+ pull_request :
9+ types : [closed]
10+ branches : [main]
1111 workflow_dispatch :
1212 inputs :
1313 version :
2222 version :
2323 name : Determine Version
2424 runs-on : ubuntu-latest
25+ # Gate: manual dispatch OR merged PRs labeled 'release'.
26+ if : |
27+ github.event_name == 'workflow_dispatch' || (
28+ github.event_name == 'pull_request' &&
29+ github.event.pull_request.merged == true &&
30+ contains(github.event.pull_request.labels.*.name, 'release')
31+ )
2532 outputs :
2633 tag : ${{ steps.ver.outputs.tag }}
2734 version : ${{ steps.ver.outputs.version }}
35+ is_pr_merge : ${{ steps.ver.outputs.is_pr_merge }}
2836 steps :
2937 - name : Extract Tag and Version
3038 id : ver
3442 if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
3543 RAW="${{ inputs.version }}"
3644 TAG="v${RAW#v}"
45+ PR_MERGE=false
3746 else
38- TAG="${GITHUB_REF_NAME}"
39- RAW="${TAG#v}"
47+ # pull_request closed event (merged into main)
48+ HEAD_REF="${{ github.event.pull_request.head.ref }}"
49+ if [[ "$HEAD_REF" =~ ^release/v([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
50+ RAW="${BASH_REMATCH[1]}"
51+ else
52+ echo "Failed to extract version from PR branch name: $HEAD_REF (expected release/vX.Y.Z)" >&2
53+ exit 1
54+ fi
55+ TAG="v${RAW}"
56+ PR_MERGE="${{ github.event.pull_request.merged }}"
4057 fi
4158 CLEANED="${RAW#v}"
4259 if [[ ! "$CLEANED" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
@@ -45,10 +62,45 @@ jobs:
4562 fi
4663 echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
4764 echo "version=${CLEANED}" >> "$GITHUB_OUTPUT"
65+ echo "is_pr_merge=${PR_MERGE}" >> "$GITHUB_OUTPUT"
66+
67+ create-tag :
68+ name : Create Tag
69+ needs : version
70+ if : needs.version.outputs.is_pr_merge == 'true' || github.event_name == 'workflow_dispatch'
71+ runs-on : ubuntu-latest
72+ permissions :
73+ contents : write
74+ steps :
75+ - name : Checkout merge commit (PR merge)
76+ if : github.event_name == 'pull_request'
77+ uses : actions/checkout@v4
78+ with :
79+ ref : ${{ github.event.pull_request.merge_commit_sha }}
80+
81+ - name : Checkout main (manual dispatch)
82+ if : github.event_name == 'workflow_dispatch'
83+ uses : actions/checkout@v4
84+
85+ - name : Create and Push Tag
86+ shell : bash
87+ env :
88+ TAG : ${{ needs.version.outputs.tag }}
89+ run : |
90+ set -euo pipefail
91+ git fetch --tags
92+ if git rev-parse "$TAG" >/dev/null 2>&1; then
93+ echo "Tag $TAG already exists; skipping creation."
94+ exit 0
95+ fi
96+ git config user.name "github-actions[bot]"
97+ git config user.email "github-actions[bot]@users.noreply.github.com"
98+ git tag -a "$TAG" -m "Release $TAG"
99+ git push origin "$TAG"
48100
49101 build-and-push :
50102 name : Build and Push Docker Images
51- needs : version
103+ needs : [ version, create-tag]
52104 strategy :
53105 matrix :
54106 image : [etl-api, etl-replicator]
@@ -60,11 +112,12 @@ jobs:
60112 push : true
61113 tag_with_version : true
62114 version : ${{ needs.version.outputs.version }}
115+ checkout_ref : refs/tags/${{ needs.version.outputs.tag }}
63116 secrets : inherit
64117
65118 github-release :
66119 name : Create GitHub Release
67- needs : [version, build-and-push]
120+ needs : [version, create-tag, build-and-push]
68121 runs-on : ubuntu-latest
69122 steps :
70123 - name : Generate Release Notes
0 commit comments