diff --git a/.github/workflows/images-build-ci.yml b/.github/workflows/images-build-ci.yml index f683c398a4..e2600e1145 100644 --- a/.github/workflows/images-build-ci.yml +++ b/.github/workflows/images-build-ci.yml @@ -46,18 +46,7 @@ jobs: - name: Compute matrix JSON id: out - run: | - set -euo pipefail - distros="${{ inputs.distros }}" - json="$(printf '%s' "$distros" | jq -Rc 'split(" ") | map(select(length>0))')" - image_tag="${{ inputs.image_tag }}" - if [ -z "${image_tag}" ]; then - image_tag="ci-${GITHUB_SHA}" - fi - echo "matrix=${json}" >> "$GITHUB_OUTPUT" - echo "image_tag=${image_tag}" >> "$GITHUB_OUTPUT" - echo "Using matrix: ${json}" - echo "Using image tag: ${image_tag}" + run: scripts/github/runner/images_build_outputs.sh "${{ inputs.distros }}" "${{ inputs.image_tag }}" build: name: 🏗️ Build (${{ matrix.distro }}) @@ -100,14 +89,7 @@ jobs: - name: Disk pressure (pre-build) shell: bash - run: | - set -euo pipefail - echo "=== Disk pressure: PRE-BUILD ===" - df -h - echo - docker system df || true - echo - docker buildx du || true + run: bash scripts/github/runner/disk_pressure_report.sh PRE-BUILD - name: Resolve repository owner id: owner @@ -133,14 +115,7 @@ jobs: - name: Disk pressure (post-build) if: always() shell: bash - run: | - set -euo pipefail - echo "=== Disk pressure: POST-BUILD ===" - df -h - echo - docker system df || true - echo - docker buildx du || true + run: bash scripts/github/runner/disk_pressure_report.sh POST-BUILD - name: Cleanup (always) if: always() diff --git a/.github/workflows/test-dns.yml b/.github/workflows/test-dns.yml index 82ef3068a7..46ed5f2e34 100644 --- a/.github/workflows/test-dns.yml +++ b/.github/workflows/test-dns.yml @@ -57,8 +57,7 @@ jobs: run: | set -euo pipefail distros="${{ inputs.distros }}" - distros="${distros:-debian}" - json="$(printf '%s' "${distros}" | jq -Rc 'split(" ") | map(select(length>0))')" + json="$(scripts/github/runner/distros_matrix.sh "${distros:-debian}")" echo "matrix=${json}" >> "$GITHUB_OUTPUT" echo "Using matrix: ${json}" diff --git a/scripts/github/runner/distros_matrix.sh b/scripts/github/runner/distros_matrix.sh new file mode 100755 index 0000000000..d47b50df3a --- /dev/null +++ b/scripts/github/runner/distros_matrix.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +# +# Emit a JSON array matrix from a space-separated distro list. Used by +# images-build-ci and test-dns workflows to feed the matrix strategy. +# +# Usage: +# distros_matrix.sh "arch debian ubuntu" +# echo "matrix=$(distros_matrix.sh "${INPUT}")" >> "$GITHUB_OUTPUT" +set -euo pipefail + +distros="${1:-}" +printf '%s' "${distros}" | jq -Rc 'split(" ") | map(select(length>0))' diff --git a/scripts/github/runner/images_build_outputs.sh b/scripts/github/runner/images_build_outputs.sh new file mode 100755 index 0000000000..8aebf17a9f --- /dev/null +++ b/scripts/github/runner/images_build_outputs.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +# +# Compute the matrix JSON + effective image_tag for images-build-ci and +# write both to $GITHUB_OUTPUT. Replaces the inline `run:` block of the +# "Compute matrix JSON" step. +# +# Usage: +# images_build_outputs.sh "" "" +set -euo pipefail + +distros="${1:-}" +override="${2:-}" + +script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +json="$(bash "${script_dir}/distros_matrix.sh" "${distros}")" + +if [[ -n "${override}" ]]; then + image_tag="${override}" +else + : "${GITHUB_SHA:?GITHUB_SHA must be set when no image_tag override is provided}" + image_tag="ci-${GITHUB_SHA}" +fi + +: "${GITHUB_OUTPUT:?GITHUB_OUTPUT must be set}" +{ + echo "matrix=${json}" + echo "image_tag=${image_tag}" +} >>"${GITHUB_OUTPUT}" + +echo "Using matrix: ${json}" +echo "Using image tag: ${image_tag}"