Skip to content

Commit 7489b86

Browse files
committed
fix: reverse sync workflow
1 parent 89a3bea commit 7489b86

1 file changed

Lines changed: 37 additions & 17 deletions

File tree

workflows/reusable-docker-build-publish/reusable-docker-build-publish.yml

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,15 @@ on:
103103
required: false
104104
type: string
105105
default: "false"
106+
build-amd64-image:
107+
description: "Enable amd64 Docker image build. Set to 'false' to disable jobs which only
108+
build arm64 images."
109+
required: false
110+
type: string
111+
default: "true"
106112
build-arm64-image:
107-
description: "Enable arm64 Docker image build. Set to 'false' to disable which only
108-
builds amd64 images."
113+
description: "Enable arm64 Docker image build. Set to 'false' to disable jobs which only
114+
build amd64 images."
109115
required: false
110116
type: string
111117
default: "true"
@@ -383,12 +389,19 @@ jobs:
383389
env:
384390
GITHUB_EVENT_NAME: ${{ inputs.github-event-name }}
385391
GITHUB_REF_NAME: ${{ inputs.github-ref-name }}
392+
BUILD_AMD64_IMAGE: ${{ inputs.build-amd64-image }}
393+
BUILD_ARM64_IMAGE: ${{ inputs.build-arm64-image }}
386394
run: |
387395
echo "Validating event and ref inputs..."
388396
if [[ "${GITHUB_EVENT_NAME:-}" == "pull_request" && ! "${GITHUB_REF_NAME:-}" =~ ^[0-9]+/merge$ ]]; then
389397
echo "::error::GITHUB_EVENT_NAME is pull_request but GITHUB_REF_NAME does not match expected format of: <pr_number>/merge."
390398
exit 1
391399
fi
400+
401+
if [[ "${BUILD_AMD64_IMAGE}" != "true" && "${BUILD_ARM64_IMAGE}" != "true" ]]; then
402+
echo "::error::At least one of build-amd64-image or build-arm64-image must be set to true."
403+
exit 1
404+
fi
392405
- name: Set extra outputs
393406
id: set-extra-outputs
394407
env:
@@ -467,13 +480,21 @@ jobs:
467480
env:
468481
GITHUB_RUNNER_AMD64: ${{ inputs.github-runner-amd64 }}
469482
GITHUB_RUNNER_ARM64: ${{ inputs.github-runner-arm64 }}
483+
BUILD_AMD64_IMAGE: ${{ inputs.build-amd64-image }}
470484
BUILD_ARM64_IMAGE: ${{ inputs.build-arm64-image }}
471485
run: |
472-
matrix="[{\"runner\":\"${GITHUB_RUNNER_AMD64}\",\"arch\":\"amd64\"}"
486+
matrix="[]"
487+
488+
if [[ "${BUILD_AMD64_IMAGE}" == "true" ]]; then
489+
matrix=$(jq -c --arg runner "$GITHUB_RUNNER_AMD64" \
490+
'. += [{"runner": $runner, "arch": "amd64"}]' <<< "$matrix")
491+
fi
492+
473493
if [[ "${BUILD_ARM64_IMAGE}" == "true" ]]; then
474-
matrix+=",{\"runner\":\"${GITHUB_RUNNER_ARM64}\",\"arch\":\"arm64\"}"
494+
matrix=$(jq -c --arg runner "$GITHUB_RUNNER_ARM64" \
495+
'. += [{"runner": $runner, "arch": "arm64"}]' <<< "$matrix")
475496
fi
476-
matrix+="]"
497+
477498
echo "matrix=$matrix" | tee -a "$GITHUB_OUTPUT"
478499
479500
build-publish:
@@ -660,26 +681,25 @@ jobs:
660681
env:
661682
DOCKER_IMAGE_SHA_DIGEST_AMD64: ${{ needs.build-publish.outputs.docker-image-sha-digest-amd64 }}
662683
DOCKER_IMAGE_SHA_DIGEST_ARM64: ${{ needs.build-publish.outputs.docker-image-sha-digest-arm64 }}
684+
BUILD_AMD64_IMAGE: ${{ inputs.build-amd64-image }}
663685
BUILD_ARM64_IMAGE: ${{ inputs.build-arm64-image }}
664686
run: |
665-
# Set default empty arm64 digest
687+
echo "amd64_digest=" >> "$GITHUB_OUTPUT"
666688
echo "arm64_digest=" >> "$GITHUB_OUTPUT"
667689
668-
# Always include the AMD64 build
669-
amd64_digest="${DOCKER_IMAGE_SHA_DIGEST_AMD64}"
670-
echo "amd64_digest=$amd64_digest" | tee -a "$GITHUB_OUTPUT"
690+
digests=()
671691
672-
image_digests="$amd64_digest"
692+
if [[ "${BUILD_AMD64_IMAGE}" == "true" && -n "${DOCKER_IMAGE_SHA_DIGEST_AMD64}" ]]; then
693+
echo "amd64_digest=${DOCKER_IMAGE_SHA_DIGEST_AMD64}" | tee -a "$GITHUB_OUTPUT"
694+
digests+=("${DOCKER_IMAGE_SHA_DIGEST_AMD64}")
695+
fi
673696
674-
# Only include ARM64 if enabled and build succeeded
675-
if [[ "${BUILD_ARM64_IMAGE}" == "true" ]]; then
676-
arm64_digest="${DOCKER_IMAGE_SHA_DIGEST_ARM64}"
677-
if [[ -n "$arm64_digest" ]]; then
678-
image_digests="$image_digests,$arm64_digest"
679-
echo "arm64_digest=$arm64_digest" | tee -a "$GITHUB_OUTPUT"
680-
fi
697+
if [[ "${BUILD_ARM64_IMAGE}" == "true" && -n "${DOCKER_IMAGE_SHA_DIGEST_ARM64}" ]]; then
698+
echo "arm64_digest=${DOCKER_IMAGE_SHA_DIGEST_ARM64}" | tee -a "$GITHUB_OUTPUT"
699+
digests+=("${DOCKER_IMAGE_SHA_DIGEST_ARM64}")
681700
fi
682701
702+
image_digests="$(IFS=,; echo "${digests[*]}")"
683703
echo "image_digests=$image_digests" | tee -a "$GITHUB_OUTPUT"
684704
685705
- name: Generate manifest annotations

0 commit comments

Comments
 (0)