Skip to content

build: automatically cancel old tests/build on new push #53

build: automatically cancel old tests/build on new push

build: automatically cancel old tests/build on new push #53

Workflow file for this run

name: Docker CI
on:
pull_request:
types: [closed]
workflow_dispatch:
inputs:
ref:
description: "Git ref to build (branch, tag, or SHA)"
type: string
required: false
permissions:
contents: read
jobs:
resolve-ref:
name: Resolve Checkout Ref
runs-on: ubuntu-latest
outputs:
ref: ${{ steps.pick.outputs.ref }}
steps:
- name: Pick ref
id: pick
shell: bash
run: |
set -euo pipefail
EVENT_NAME="${GITHUB_EVENT_NAME}"
MERGE_SHA=$(jq -r '.pull_request.merge_commit_sha // empty' "$GITHUB_EVENT_PATH")
INPUT_REF=$(jq -r '.inputs.ref // empty' "$GITHUB_EVENT_PATH")
if [[ "$EVENT_NAME" == "pull_request" && -n "$MERGE_SHA" ]]; then
REF="$MERGE_SHA"
elif [[ -n "$INPUT_REF" ]]; then
REF="$INPUT_REF"
else
echo "Error: no merge commit or input ref provided" >&2
exit 1
fi
echo "ref=$REF" >> "$GITHUB_OUTPUT"
build:
name: Build and Push Images
needs: resolve-ref
# Run only when the PR is merged and is NOT a release PR, or manual run.
if: |
github.event_name == 'workflow_dispatch' || (
github.event_name == 'pull_request' &&
github.event.pull_request.merged == true &&
!contains(github.event.pull_request.labels.*.name, 'release')
)
strategy:
matrix:
image: [etl-api, etl-replicator]
uses: ./.github/workflows/docker-build.yml
secrets: inherit
with:
image: docker.io/${{ vars.DOCKERHUB_USERNAME }}/${{ matrix.image }}
context: .
file: ./${{ matrix.image }}/Dockerfile
push: true
tag_with_version: false
# Build from the resolved ref: merge commit for PRs, or provided ref, fallback to current SHA.
checkout_ref: ${{ needs.resolve-ref.outputs.ref }}