diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 1246c06e46..fbd63a1d31 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -29,6 +29,7 @@ jobs: tags: ${{ steps.attributes.outputs.tags }} labels: ${{ steps.attributes.outputs.labels }} push: ${{ steps.attributes.outputs.push }} + merge: ${{ steps.attributes.outputs.merge }} steps: - name: Checkout uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 @@ -62,6 +63,7 @@ jobs: typeset -A tag_hash typeset -A push_hash matrix=() + merge=false while IFS=$'\n' read -r version; do tags=() if [[ "${GITHUB_EVENT_NAME}" == "release" ]]; then @@ -91,8 +93,12 @@ jobs: fi if [[ "${#tags[@]}" -ne 0 ]]; then - tag_hash["${version}"]="${tags[*]}" + tags_as_json_array="$( + jq --null-input --compact-output '$ARGS.positional' --args "${tags[@]}" + )" + tag_hash["${version}"]="${tags_as_json_array}" push_hash["${version}"]=true + merge=true matrix+=("${version}") else push_hash["${version}"]=false @@ -101,6 +107,7 @@ jobs: # Transform the `matrix` variable into a JSON array. echo "matrix=$(jq --null-input --compact-output '$ARGS.positional' --args "${matrix[@]}")" >>"${GITHUB_OUTPUT}" + echo "merge=${merge}" >>"${GITHUB_OUTPUT}" { DELIMITER="END_TAGS_$(uuidgen)" @@ -109,7 +116,7 @@ jobs: printf '{' for version in "${!tag_hash[@]}"; do [[ -n "${has_previous:-}" ]] && printf ',' - printf '"%s": "%s"' "${version}" "${tag_hash[$version]}" + printf '"%s": %s' "${version}" "${tag_hash[$version]}" has_previous=1 done echo '}' @@ -123,7 +130,7 @@ jobs: printf '{' for version in "${!push_hash[@]}"; do [[ -n "${has_previous:-}" ]] && printf ',' - printf '"%s": "%s"' "${version}" "${push_hash[$version]}" + printf '"%s": %s' "${version}" "${push_hash[$version]}" has_previous=1 done echo '}' @@ -234,7 +241,7 @@ jobs: merge: needs: [generate-tags, build] - if: github.repository_owner == 'Homebrew' + if: github.repository_owner == 'Homebrew' && fromJSON(needs.generate-tags.outputs.merge) runs-on: ubuntu-latest strategy: fail-fast: false @@ -266,22 +273,17 @@ jobs: username: BrewTestBot password: ${{ secrets.HOMEBREW_BREW_GITHUB_PACKAGES_TOKEN }} - - name: Export TAGS and VERSION to environment + - name: Merge and push Docker image env: TAGS: ${{ needs.generate-tags.outputs.tags }} VERSION: ${{ matrix.version }} run: | - filter="$(printf '.["%s"]' "${VERSION}")" - echo "TAGS=$(jq --raw-output "${filter}" <<<"${TAGS}")" >>"${GITHUB_ENV}" - echo "VERSION=${VERSION}" >>"${GITHUB_ENV}" - - - name: Merge and push Docker image - run: | + filter="$(printf '.["%s"].[]' "${VERSION}")" tag_args=() while IFS=$'\n' read -r tag; do [[ -n "${tag}" ]] || continue tag_args+=("--tag=${tag}") - done <<<"${TAGS}" + done <<<"$(jq --raw-output "${filter}" <<<"${TAGS}")" image_args=("ghcr.io/homebrew/ubuntu${VERSION}@sha256:$(<"${RUNNER_TEMP}/digests/${VERSION}-x86_64")") if [[ "${VERSION}" != 18.04 ]]; then