|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" |
| 5 | + |
| 6 | +assert_output() { |
| 7 | + local kind="$1" |
| 8 | + local full_matrix="$2" |
| 9 | + local expected="$3" |
| 10 | + local actual |
| 11 | + |
| 12 | + actual="$(METADATA="${TEST_METADATA}" REBUILD_VARIANTS="${REBUILD_VARIANTS:-}" "${SCRIPT_DIR}/ci-build-matrix.sh" "${kind}" "${full_matrix}")" |
| 13 | + if [[ "${actual}" != "${expected}" ]]; then |
| 14 | + printf 'expected:\n%s\nactual:\n%s\n' "${expected}" "${actual}" >&2 |
| 15 | + return 1 |
| 16 | + fi |
| 17 | +} |
| 18 | + |
| 19 | +TEST_METADATA='{ |
| 20 | + "group": { |
| 21 | + "default": { |
| 22 | + "targets": [ |
| 23 | + "builder-php-8-2-bookworm", |
| 24 | + "builder-php-8-2-trixie", |
| 25 | + "builder-php-8-3-bookworm", |
| 26 | + "builder-php-8-3-trixie", |
| 27 | + "runner-php-8-2-bookworm", |
| 28 | + "runner-php-8-2-trixie", |
| 29 | + "runner-php-8-3-bookworm", |
| 30 | + "runner-php-8-3-trixie" |
| 31 | + ] |
| 32 | + } |
| 33 | + }, |
| 34 | + "target": { |
| 35 | + "builder-php-8-2-bookworm": { |
| 36 | + "platforms": ["linux/amd64", "linux/arm64"] |
| 37 | + }, |
| 38 | + "static-builder-musl": { |
| 39 | + "platforms": ["linux/amd64", "linux/arm64"] |
| 40 | + } |
| 41 | + } |
| 42 | +}' |
| 43 | + |
| 44 | +assert_output docker false $'variants=["php-8-2-bookworm","php-8-3-bookworm"]\nplatforms=["linux/amd64"]' |
| 45 | +assert_output docker true $'variants=["php-8-2-bookworm","php-8-2-trixie","php-8-3-bookworm","php-8-3-trixie"]\nplatforms=["linux/amd64","linux/arm64"]' |
| 46 | +assert_output static false 'platforms=["linux/amd64"]' |
| 47 | +assert_output static true 'platforms=["linux/amd64","linux/arm64"]' |
| 48 | + |
| 49 | +# On scheduled rebuilds REBUILD_VARIANTS narrows the docker matrix to the changed bases only. |
| 50 | +REBUILD_VARIANTS='["php-8-2-trixie","php-8-3-bookworm"]' \ |
| 51 | + assert_output docker true $'variants=["php-8-2-trixie","php-8-3-bookworm"]\nplatforms=["linux/amd64","linux/arm64"]' |
| 52 | +# The empty-array sentinel leaves the matrix untouched. |
| 53 | +REBUILD_VARIANTS='[]' \ |
| 54 | + assert_output docker true $'variants=["php-8-2-bookworm","php-8-2-trixie","php-8-3-bookworm","php-8-3-trixie"]\nplatforms=["linux/amd64","linux/arm64"]' |
0 commit comments