File tree Expand file tree Collapse file tree 1 file changed +43
-2
lines changed Expand file tree Collapse file tree 1 file changed +43
-2
lines changed Original file line number Diff line number Diff line change 11name : Docker CI
22
33on :
4- push :
5- branches : [main ]
4+ pull_request :
5+ types : [closed ]
66 workflow_dispatch :
7+ inputs :
8+ ref :
9+ description : " Git ref to build (branch, tag, or SHA)"
10+ type : string
11+ required : false
712
813permissions :
914 contents : read
1015
1116jobs :
17+ resolve-ref :
18+ name : Resolve Checkout Ref
19+ runs-on : ubuntu-latest
20+ outputs :
21+ ref : ${{ steps.pick.outputs.ref }}
22+ steps :
23+ - name : Pick ref
24+ id : pick
25+ shell : bash
26+ run : |
27+ set -euo pipefail
28+ EVENT_NAME="${GITHUB_EVENT_NAME}"
29+ MERGE_SHA=$(jq -r '.pull_request.merge_commit_sha // empty' "$GITHUB_EVENT_PATH")
30+ INPUT_REF=$(jq -r '.inputs.ref // empty' "$GITHUB_EVENT_PATH")
31+
32+ if [[ "$EVENT_NAME" == "pull_request" && -n "$MERGE_SHA" ]]; then
33+ REF="$MERGE_SHA"
34+ elif [[ -n "$INPUT_REF" ]]; then
35+ REF="$INPUT_REF"
36+ else
37+ echo "Error: no merge commit or input ref provided" >&2
38+ exit 1
39+ fi
40+
41+ echo "ref=$REF" >> "$GITHUB_OUTPUT"
42+
1243 build :
1344 name : Build and Push Images
45+ needs : resolve-ref
46+ # Run only when the PR is merged and is NOT a release PR, or manual run.
47+ if : |
48+ github.event_name == 'workflow_dispatch' || (
49+ github.event_name == 'pull_request' &&
50+ github.event.pull_request.merged == true &&
51+ !contains(github.event.pull_request.labels.*.name, 'release')
52+ )
1453 strategy :
1554 matrix :
1655 image : [etl-api, etl-replicator]
2261 file : ./${{ matrix.image }}/Dockerfile
2362 push : true
2463 tag_with_version : false
64+ # Build from the resolved ref: merge commit for PRs, or provided ref, fallback to current SHA.
65+ checkout_ref : ${{ needs.resolve-ref.outputs.ref }}
You can’t perform that action at this time.
0 commit comments