@@ -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 :
2525 outputs :
2626 tag : ${{ steps.ver.outputs.tag }}
2727 version : ${{ steps.ver.outputs.version }}
28+ is_pr_merge : ${{ steps.ver.outputs.is_pr_merge }}
2829 steps :
2930 - name : Extract Tag and Version
3031 id : ver
3435 if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
3536 RAW="${{ inputs.version }}"
3637 TAG="v${RAW#v}"
38+ PR_MERGE=false
3739 else
38- TAG="${GITHUB_REF_NAME}"
39- RAW="${TAG#v}"
40+ # pull_request closed event (merged into main)
41+ TITLE="${{ github.event.pull_request.title }}"
42+ if [[ "$TITLE" =~ v([0-9]+\.[0-9]+\.[0-9]+) ]]; then
43+ RAW="${BASH_REMATCH[1]}"
44+ TAG="v${RAW}"
45+ else
46+ echo "Failed to extract version from PR title: $TITLE" >&2
47+ exit 1
48+ fi
49+ PR_MERGE="${{ github.event.pull_request.merged }}"
4050 fi
4151 CLEANED="${RAW#v}"
4252 if [[ ! "$CLEANED" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
@@ -45,10 +55,45 @@ jobs:
4555 fi
4656 echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
4757 echo "version=${CLEANED}" >> "$GITHUB_OUTPUT"
58+ echo "is_pr_merge=${PR_MERGE}" >> "$GITHUB_OUTPUT"
59+
60+ create-tag :
61+ name : Create Tag
62+ needs : version
63+ if : needs.version.outputs.is_pr_merge == 'true' || github.event_name == 'workflow_dispatch'
64+ runs-on : ubuntu-latest
65+ permissions :
66+ contents : write
67+ steps :
68+ - name : Checkout merge commit (PR merge)
69+ if : github.event_name == 'pull_request'
70+ uses : actions/checkout@v4
71+ with :
72+ ref : ${{ github.event.pull_request.merge_commit_sha }}
73+
74+ - name : Checkout main (manual dispatch)
75+ if : github.event_name == 'workflow_dispatch'
76+ uses : actions/checkout@v4
77+
78+ - name : Create and Push Tag
79+ shell : bash
80+ env :
81+ TAG : ${{ needs.version.outputs.tag }}
82+ run : |
83+ set -euo pipefail
84+ git fetch --tags
85+ if git rev-parse "$TAG" >/dev/null 2>&1; then
86+ echo "Tag $TAG already exists; skipping creation."
87+ exit 0
88+ fi
89+ git config user.name "github-actions[bot]"
90+ git config user.email "github-actions[bot]@users.noreply.github.com"
91+ git tag -a "$TAG" -m "Release $TAG"
92+ git push origin "$TAG"
4893
4994 build-and-push :
5095 name : Build and Push Docker Images
51- needs : version
96+ needs : [ version, create-tag]
5297 strategy :
5398 matrix :
5499 image : [etl-api, etl-replicator]
@@ -60,11 +105,12 @@ jobs:
60105 push : true
61106 tag_with_version : true
62107 version : ${{ needs.version.outputs.version }}
108+ checkout_ref : refs/tags/${{ needs.version.outputs.tag }}
63109 secrets : inherit
64110
65111 github-release :
66112 name : Create GitHub Release
67- needs : [version, build-and-push]
113+ needs : [version, create-tag, build-and-push]
68114 runs-on : ubuntu-latest
69115 steps :
70116 - name : Generate Release Notes
0 commit comments