@@ -5,9 +5,9 @@ concurrency:
5
5
cancel-in-progress : false
6
6
7
7
on :
8
- push :
9
- tags :
10
- - ' v* '
8
+ pull_request :
9
+ types : [closed]
10
+ branches : [main]
11
11
workflow_dispatch :
12
12
inputs :
13
13
version :
22
22
version :
23
23
name : Determine Version
24
24
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
+ )
25
32
outputs :
26
33
tag : ${{ steps.ver.outputs.tag }}
27
34
version : ${{ steps.ver.outputs.version }}
35
+ is_pr_merge : ${{ steps.ver.outputs.is_pr_merge }}
28
36
steps :
29
37
- name : Extract Tag and Version
30
38
id : ver
34
42
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
35
43
RAW="${{ inputs.version }}"
36
44
TAG="v${RAW#v}"
45
+ PR_MERGE=false
37
46
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 }}"
40
57
fi
41
58
CLEANED="${RAW#v}"
42
59
if [[ ! "$CLEANED" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
@@ -45,10 +62,45 @@ jobs:
45
62
fi
46
63
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
47
64
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"
48
100
49
101
build-and-push :
50
102
name : Build and Push Docker Images
51
- needs : version
103
+ needs : [ version, create-tag]
52
104
strategy :
53
105
matrix :
54
106
image : [etl-api, etl-replicator]
@@ -60,11 +112,12 @@ jobs:
60
112
push : true
61
113
tag_with_version : true
62
114
version : ${{ needs.version.outputs.version }}
115
+ checkout_ref : refs/tags/${{ needs.version.outputs.tag }}
63
116
secrets : inherit
64
117
65
118
github-release :
66
119
name : Create GitHub Release
67
- needs : [version, build-and-push]
120
+ needs : [version, create-tag, build-and-push]
68
121
runs-on : ubuntu-latest
69
122
steps :
70
123
- name : Generate Release Notes
0 commit comments