@@ -5,29 +5,118 @@ concurrency:
55 cancel-in-progress : false
66
77on :
8+ # Auto promote after TEST succeeds
9+ workflow_run :
10+ workflows : ["3. CD | Deploy to Test"]
11+ types : [completed]
12+
13+ # Manual override path (kept)
814 workflow_dispatch :
915 inputs :
1016 ref :
1117 description : " Branch/Tag/SHA to deploy to preprod (dev tag)"
12- required : true
13- default : " main "
18+ required : false
19+ default : " "
1420 release_type :
15- description : " Version bump type (use 'rc' to keep the same base and just increment RC )"
16- required : true
17- default : " rc "
21+ description : " Version bump (rc|patch|minor|major )"
22+ required : false
23+ default : " "
1824 type : choice
19- options :
20- - rc
21- - patch
22- - minor
23- - major
25+ options : [rc, patch, minor, major]
2426
2527jobs :
28+ metadata :
29+ name : " Resolve ref + release_type"
30+ runs-on : ubuntu-latest
31+
32+ # Only run automatically if TEST succeeded,
33+ # or always if this is a manual dispatch
34+ if : >
35+ (github.event_name == 'workflow_run' &&
36+ github.event.workflow_run.conclusion == 'success')
37+ || github.event_name == 'workflow_dispatch'
38+
39+ outputs :
40+ ref : ${{ steps.resolve_ref.outputs.ref }}
41+ release_type : ${{ steps.resolve_release_type.outputs.release_type }}
42+
43+ steps :
44+ - name : " Checkout exact commit (auto path) or repo (manual path)"
45+ uses : actions/checkout@v5
46+ with :
47+ ref : ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_sha || 'main' }}
48+ fetch-depth : 0
49+
50+ - name : " Resolve the dev-* tag for this commit (auto path)"
51+ id : resolve_ref
52+ shell : bash
53+ run : |
54+ set -euo pipefail
55+ if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
56+ # manual override provided?
57+ if [[ -n "${{ github.event.inputs.ref }}" ]]; then
58+ echo "ref=${{ github.event.inputs.ref }}" >> $GITHUB_OUTPUT
59+ exit 0
60+ fi
61+ echo "No manual ref provided; attempting to derive from HEAD of default branch."
62+ SHA=$(git rev-parse HEAD)
63+ else
64+ SHA="${{ github.event.workflow_run.head_sha }}"
65+ fi
66+
67+ git fetch --tags --force
68+ TAG=$(git tag --points-at "$SHA" | grep '^dev-' | head -n1 || true)
69+ if [[ -z "$TAG" ]]; then
70+ echo "ERROR: No dev-* tag found on $SHA=$SHA and no manual ref provided." >&2
71+ exit 1
72+ fi
73+ echo "ref=$TAG" >> $GITHUB_OUTPUT
74+ echo "Resolved ref: $TAG"
75+
76+ - name : " Infer release_type from PR labels (fallback to rc)"
77+ id : resolve_release_type
78+ env :
79+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
80+ shell : bash
81+ run : |
82+ set -euo pipefail
83+
84+ # manual override wins
85+ if [[ "${{ github.event_name }}" == "workflow_dispatch" && -n "${{ github.event.inputs.release_type }}" ]]; then
86+ echo "release_type=${{ github.event.inputs.release_type }}" >> $GITHUB_OUTPUT
87+ exit 0
88+ fi
89+
90+ # find PR for the commit that went to TEST
91+ if [[ "${{ github.event_name }}" == "workflow_run" ]]; then
92+ SHA="${{ github.event.workflow_run.head_sha }}"
93+ else
94+ SHA=$(git rev-parse HEAD)
95+ fi
96+
97+ # Use the commits->pulls API to get the PR number
98+ PR_NUM=$(gh api \
99+ -H "Accept: application/vnd.github.groot-preview+json" \
100+ /repos/${{ github.repository }}/commits/$SHA/pulls \
101+ --jq '.[0].number // empty')
102+
103+ RELEASE_TYPE="rc" # safe default
104+ if [[ -n "$PR_NUM" ]]; then
105+ LABELS=$(gh api /repos/${{ github.repository }}/issues/$PR_NUM/labels --jq '.[].name')
106+ if echo "$LABELS" | grep -q '^release:major$'; then RELEASE_TYPE="major"; fi
107+ if echo "$LABELS" | grep -q '^release:minor$'; then RELEASE_TYPE="minor"; fi
108+ if echo "$LABELS" | grep -q '^release:patch$'; then RELEASE_TYPE="patch"; fi
109+ if echo "$LABELS" | grep -q '^release:rc$'; then RELEASE_TYPE="rc"; fi
110+ fi
111+
112+ echo "release_type=$RELEASE_TYPE" >> $GITHUB_OUTPUT
113+ echo "Resolved release_type: $RELEASE_TYPE"
114+
26115 call :
116+ needs : [metadata]
27117 uses : ./.github/workflows/base-deploy.yml
28118 with :
29119 environment : preprod
30- ref : ${{ inputs .ref }}
31- release_type : ${{ inputs .release_type }}
120+ ref : ${{ needs.metadata.outputs .ref }}
121+ release_type : ${{ needs.metadata.outputs .release_type }}
32122 secrets : inherit
33-
0 commit comments