Skip to content

Commit 8195281

Browse files
authored
fix(ci): Trigger Docker build step on pull request close (#330)
1 parent dac5731 commit 8195281

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

.github/workflows/docker-ci.yml

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,55 @@
11
name: Docker CI
22

33
on:
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

813
permissions:
914
contents: read
1015

1116
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+
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]
@@ -22,3 +61,5 @@ jobs:
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 }}

0 commit comments

Comments
 (0)