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 1
1
name : Docker CI
2
2
3
3
on :
4
- push :
5
- branches : [main ]
4
+ pull_request :
5
+ types : [closed ]
6
6
workflow_dispatch :
7
+ inputs :
8
+ ref :
9
+ description : " Git ref to build (branch, tag, or SHA)"
10
+ type : string
11
+ required : false
7
12
8
13
permissions :
9
14
contents : read
10
15
11
16
jobs :
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
+
12
43
build :
13
44
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
+ )
14
53
strategy :
15
54
matrix :
16
55
image : [etl-api, etl-replicator]
22
61
file : ./${{ matrix.image }}/Dockerfile
23
62
push : true
24
63
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