From 4e28eba8834b3fa93438869aa932d8cc20c0094c Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Sat, 13 Dec 2025 14:34:15 +0100 Subject: [PATCH] refactor(ci,build,test): rename distro to PKGMGR_DISTRO for consistent environment handling https://chatgpt.com/share/693d6b63-12cc-800f-b55f-abc52ee7fb52 --- .github/workflows/test-e2e.yml | 2 +- .github/workflows/test-env-nix.yml | 2 +- .github/workflows/test-env-virtual.yml | 2 +- .github/workflows/test-integration.yml | 2 +- .github/workflows/test-unit.yml | 2 +- .github/workflows/test-virgin-root.yml | 2 +- .github/workflows/test-virgin-user.yml | 2 +- Makefile | 4 ++-- scripts/build/base.sh | 6 +++--- scripts/build/image.sh | 14 +++++++------- scripts/build/publish.sh | 6 +++--- scripts/test/test-e2e.sh | 8 ++++---- scripts/test/test-env-nix.sh | 10 +++++----- scripts/test/test-env-virtual.sh | 6 +++--- scripts/test/test-integration.sh | 8 ++++---- scripts/test/test-unit.sh | 8 ++++---- 16 files changed, 42 insertions(+), 42 deletions(-) diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml index 384b6fe..60b4da8 100644 --- a/.github/workflows/test-e2e.yml +++ b/.github/workflows/test-e2e.yml @@ -22,4 +22,4 @@ jobs: - name: Run E2E tests via make (${{ matrix.distro }}) run: | set -euo pipefail - distro="${{ matrix.distro }}" make test-e2e + PKGMGR_DISTRO="${{ matrix.distro }}" make test-e2e diff --git a/.github/workflows/test-env-nix.yml b/.github/workflows/test-env-nix.yml index b41fdf5..4161fb6 100644 --- a/.github/workflows/test-env-nix.yml +++ b/.github/workflows/test-env-nix.yml @@ -23,4 +23,4 @@ jobs: - name: Nix flake-only test (${{ matrix.distro }}) run: | set -euo pipefail - distro="${{ matrix.distro }}" make test-env-nix + PKGMGR_DISTRO="${{ matrix.distro }}" make test-env-nix diff --git a/.github/workflows/test-env-virtual.yml b/.github/workflows/test-env-virtual.yml index e3a4680..f5f59d8 100644 --- a/.github/workflows/test-env-virtual.yml +++ b/.github/workflows/test-env-virtual.yml @@ -25,4 +25,4 @@ jobs: - name: Run container tests (${{ matrix.distro }}) run: | set -euo pipefail - distro="${{ matrix.distro }}" make test-env-virtual + PKGMGR_DISTRO="${{ matrix.distro }}" make test-env-virtual diff --git a/.github/workflows/test-integration.yml b/.github/workflows/test-integration.yml index 78f090f..2e44b67 100644 --- a/.github/workflows/test-integration.yml +++ b/.github/workflows/test-integration.yml @@ -16,4 +16,4 @@ jobs: run: docker version - name: Run integration tests via make (Arch container) - run: make test-integration distro="arch" + run: make test-integration PKGMGR_DISTRO="arch" diff --git a/.github/workflows/test-unit.yml b/.github/workflows/test-unit.yml index 408173a..9dfc9f7 100644 --- a/.github/workflows/test-unit.yml +++ b/.github/workflows/test-unit.yml @@ -16,4 +16,4 @@ jobs: run: docker version - name: Run unit tests via make (Arch container) - run: make test-unit distro="arch" + run: make test-unit PKGMGR_DISTRO="arch" diff --git a/.github/workflows/test-virgin-root.yml b/.github/workflows/test-virgin-root.yml index 570eb52..c856d5f 100644 --- a/.github/workflows/test-virgin-root.yml +++ b/.github/workflows/test-virgin-root.yml @@ -23,7 +23,7 @@ jobs: - name: Build virgin container (${{ matrix.distro }}) run: | set -euo pipefail - distro="${{ matrix.distro }}" make build-missing-virgin + PKGMGR_DISTRO="${{ matrix.distro }}" make build-missing-virgin # 🔹 RUN test inside virgin image - name: Virgin ${{ matrix.distro }} pkgmgr test (root) diff --git a/.github/workflows/test-virgin-user.yml b/.github/workflows/test-virgin-user.yml index e7bcf4e..8887938 100644 --- a/.github/workflows/test-virgin-user.yml +++ b/.github/workflows/test-virgin-user.yml @@ -23,7 +23,7 @@ jobs: - name: Build virgin container (${{ matrix.distro }}) run: | set -euo pipefail - distro="${{ matrix.distro }}" make build-missing-virgin + PKGMGR_DISTRO="${{ matrix.distro }}" make build-missing-virgin # 🔹 RUN test inside virgin image as non-root - name: Virgin ${{ matrix.distro }} pkgmgr test (user) diff --git a/Makefile b/Makefile index 0895470..a2faa61 100644 --- a/Makefile +++ b/Makefile @@ -75,7 +75,7 @@ build-no-cache-all: @set -e; \ for d in $(DISTROS); do \ echo "=== build-no-cache: $$d ==="; \ - distro="$$d" $(MAKE) build-no-cache; \ + PKGMGR_DISTRO="$$d" $(MAKE) build-no-cache; \ done # ------------------------------------------------------------ @@ -101,7 +101,7 @@ test-env-nix: build-missing test: test-env-virtual test-unit test-integration test-e2e delete-volumes: - @docker volume rm "pkgmgr_nix_store_${distro}" "pkgmgr_nix_cache_${distro}" || echo "No volumes to delete." + @docker volume rm "pkgmgr_nix_store_${PKGMGR_DISTRO}" "pkgmgr_nix_cache_${PKGMGR_DISTRO}" || echo "No volumes to delete." purge: delete-volumes build-no-cache diff --git a/scripts/build/base.sh b/scripts/build/base.sh index a37a4c1..2aa4867 100755 --- a/scripts/build/base.sh +++ b/scripts/build/base.sh @@ -8,13 +8,13 @@ set -euo pipefail : "${BASE_IMAGE_CENTOS:=quay.io/centos/centos:stream9}" resolve_base_image() { - local distro="$1" - case "$distro" in + local PKGMGR_DISTRO="$1" + case "$PKGMGR_DISTRO" in arch) echo "$BASE_IMAGE_ARCH" ;; debian) echo "$BASE_IMAGE_DEBIAN" ;; ubuntu) echo "$BASE_IMAGE_UBUNTU" ;; fedora) echo "$BASE_IMAGE_FEDORA" ;; centos) echo "$BASE_IMAGE_CENTOS" ;; - *) echo "ERROR: Unknown distro '$distro'" >&2; exit 1 ;; + *) echo "ERROR: Unknown distro '$PKGMGR_DISTRO'" >&2; exit 1 ;; esac } diff --git a/scripts/build/image.sh b/scripts/build/image.sh index 3dbc200..61645eb 100755 --- a/scripts/build/image.sh +++ b/scripts/build/image.sh @@ -22,13 +22,13 @@ IS_STABLE="false" # "true" -> publish stable tags DEFAULT_DISTRO="arch" usage() { - local default_tag="pkgmgr-${distro}" + local default_tag="pkgmgr-${PKGMGR_DISTRO}" if [[ -n "${TARGET:-}" ]]; then default_tag="${default_tag}-${TARGET}" fi cat < $0 [options] +Usage: PKGMGR_DISTRO= $0 [options] Build options: --missing Build only if the image does not already exist (local build only) @@ -103,13 +103,13 @@ done # Derive default local tag if not provided if [[ -z "${IMAGE_TAG}" ]]; then - IMAGE_TAG="${REPO_PREFIX}-${distro}" + IMAGE_TAG="${REPO_PREFIX}-${PKGMGR_DISTRO}" if [[ -n "${TARGET}" ]]; then IMAGE_TAG="${IMAGE_TAG}-${TARGET}" fi fi -BASE_IMAGE="$(resolve_base_image "$distro")" +BASE_IMAGE="$(resolve_base_image "$PKGMGR_DISTRO")" # Local-only "missing" shortcut if [[ "${MISSING_ONLY}" == "1" ]]; then @@ -141,7 +141,7 @@ fi echo echo "------------------------------------------------------------" echo "[build] Building image" -echo "distro = ${distro}" +echo "distro = ${PKGMGR_DISTRO}" echo "BASE_IMAGE = ${BASE_IMAGE}" if [[ -n "${TARGET}" ]]; then echo "target = ${TARGET}"; fi if [[ "${NO_CACHE}" == "1" ]]; then echo "cache = disabled"; fi @@ -167,14 +167,14 @@ if [[ -n "${TARGET}" ]]; then fi compute_publish_tags() { - local distro_tag_base="${REGISTRY}/${OWNER}/${REPO_PREFIX}-${distro}" + local distro_tag_base="${REGISTRY}/${OWNER}/${REPO_PREFIX}-${PKGMGR_DISTRO}" local alias_tag_base="" if [[ -n "${TARGET}" ]]; then distro_tag_base="${distro_tag_base}-${TARGET}" fi - if [[ "${distro}" == "${DEFAULT_DISTRO}" ]]; then + if [[ "${PKGMGR_DISTRO}" == "${DEFAULT_DISTRO}" ]]; then alias_tag_base="${REGISTRY}/${OWNER}/${REPO_PREFIX}" if [[ -n "${TARGET}" ]]; then alias_tag_base="${alias_tag_base}-${TARGET}" diff --git a/scripts/build/publish.sh b/scripts/build/publish.sh index f4289cf..37a7c8a 100755 --- a/scripts/build/publish.sh +++ b/scripts/build/publish.sh @@ -30,11 +30,11 @@ echo "[publish] DISTROS=${DISTROS}" for d in ${DISTROS}; do echo echo "============================================================" - echo "[publish] distro=${d}" + echo "[publish] PKGMGR_DISTRO=${d}" echo "============================================================" # virgin - distro="${d}" bash "${SCRIPT_DIR}/image.sh" \ + PKGMGR_DISTRO="${d}" bash "${SCRIPT_DIR}/image.sh" \ --publish \ --registry "${REGISTRY}" \ --owner "${OWNER}" \ @@ -43,7 +43,7 @@ for d in ${DISTROS}; do --target virgin # full (default target) - distro="${d}" bash "${SCRIPT_DIR}/image.sh" \ + PKGMGR_DISTRO="${d}" bash "${SCRIPT_DIR}/image.sh" \ --publish \ --registry "${REGISTRY}" \ --owner "${OWNER}" \ diff --git a/scripts/test/test-e2e.sh b/scripts/test/test-e2e.sh index 0ffaf97..d23bcf2 100755 --- a/scripts/test/test-e2e.sh +++ b/scripts/test/test-e2e.sh @@ -2,17 +2,17 @@ set -euo pipefail echo "============================================================" -echo ">>> Running E2E tests: $distro" +echo ">>> Running E2E tests: $PKGMGR_DISTRO" echo "============================================================" docker run --rm \ -v "$(pwd):/src" \ - -v "pkgmgr_nix_store_${distro}:/nix" \ - -v "pkgmgr_nix_cache_${distro}:/root/.cache/nix" \ + -v "pkgmgr_nix_store_${PKGMGR_DISTRO}:/nix" \ + -v "pkgmgr_nix_cache_${PKGMGR_DISTRO}:/root/.cache/nix" \ -e REINSTALL_PKGMGR=1 \ -e TEST_PATTERN="${TEST_PATTERN}" \ --workdir /src \ - "pkgmgr-${distro}" \ + "pkgmgr-${PKGMGR_DISTRO}" \ bash -lc ' set -euo pipefail diff --git a/scripts/test/test-env-nix.sh b/scripts/test/test-env-nix.sh index 268fdc2..aacd76d 100755 --- a/scripts/test/test-env-nix.sh +++ b/scripts/test/test-env-nix.sh @@ -1,17 +1,17 @@ #!/usr/bin/env bash set -euo pipefail -IMAGE="pkgmgr-${distro}" +IMAGE="pkgmgr-${PKGMGR_DISTRO}" echo "============================================================" -echo ">>> Running Nix flake-only test in ${distro} container" +echo ">>> Running Nix flake-only test in ${PKGMGR_DISTRO} container" echo ">>> Image: ${IMAGE}" echo "============================================================" docker run --rm \ -v "$(pwd):/src" \ - -v "pkgmgr_nix_store_${distro}:/nix" \ - -v "pkgmgr_nix_cache_${distro}:/root/.cache/nix" \ + -v "pkgmgr_nix_store_${PKGMGR_DISTRO}:/nix" \ + -v "pkgmgr_nix_cache_${PKGMGR_DISTRO}:/root/.cache/nix" \ --workdir /src \ -e REINSTALL_PKGMGR=1 \ "${IMAGE}" \ @@ -27,7 +27,7 @@ docker run --rm \ echo ">>> preflight: nix must exist in image" if ! command -v nix >/dev/null 2>&1; then echo "NO_NIX" - echo "ERROR: nix not found in image '\'''"${IMAGE}"''\'' (distro='"${distro}"')" + echo "ERROR: nix not found in image '\'''"${IMAGE}"''\'' (PKGMGR_DISTRO='"${PKGMGR_DISTRO}"')" echo "HINT: Ensure Nix is installed during image build for this distro." exit 1 fi diff --git a/scripts/test/test-env-virtual.sh b/scripts/test/test-env-virtual.sh index 3f00cfd..c9883b8 100755 --- a/scripts/test/test-env-virtual.sh +++ b/scripts/test/test-env-virtual.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -euo pipefail -IMAGE="pkgmgr-$distro" +IMAGE="pkgmgr-$PKGMGR_DISTRO" echo echo "------------------------------------------------------------" @@ -16,9 +16,9 @@ echo # Run the command and capture the output if OUTPUT=$(docker run --rm \ -e REINSTALL_PKGMGR=1 \ - -v pkgmgr_nix_store_${distro}:/nix \ + -v pkgmgr_nix_store_${PKGMGR_DISTRO}:/nix \ -v "$(pwd):/src" \ - -v "pkgmgr_nix_cache_${distro}:/root/.cache/nix" \ + -v "pkgmgr_nix_cache_${PKGMGR_DISTRO}:/root/.cache/nix" \ "$IMAGE" 2>&1); then echo "$OUTPUT" echo diff --git a/scripts/test/test-integration.sh b/scripts/test/test-integration.sh index a0330ce..8ca16e1 100755 --- a/scripts/test/test-integration.sh +++ b/scripts/test/test-integration.sh @@ -2,17 +2,17 @@ set -euo pipefail echo "============================================================" -echo ">>> Running INTEGRATION tests in ${distro} container" +echo ">>> Running INTEGRATION tests in ${PKGMGR_DISTRO} container" echo "============================================================" docker run --rm \ -v "$(pwd):/src" \ - -v pkgmgr_nix_store_${distro}:/nix \ - -v "pkgmgr_nix_cache_${distro}:/root/.cache/nix" \ + -v pkgmgr_nix_store_${PKGMGR_DISTRO}:/nix \ + -v "pkgmgr_nix_cache_${PKGMGR_DISTRO}:/root/.cache/nix" \ --workdir /src \ -e REINSTALL_PKGMGR=1 \ -e TEST_PATTERN="${TEST_PATTERN}" \ - "pkgmgr-${distro}" \ + "pkgmgr-${PKGMGR_DISTRO}" \ bash -lc ' set -e; git config --global --add safe.directory /src || true; diff --git a/scripts/test/test-unit.sh b/scripts/test/test-unit.sh index 4af6222..7526fec 100755 --- a/scripts/test/test-unit.sh +++ b/scripts/test/test-unit.sh @@ -2,17 +2,17 @@ set -euo pipefail echo "============================================================" -echo ">>> Running UNIT tests in ${distro} container" +echo ">>> Running UNIT tests in ${PKGMGR_DISTRO} container" echo "============================================================" docker run --rm \ -v "$(pwd):/src" \ - -v "pkgmgr_nix_cache_${distro}:/root/.cache/nix" \ - -v pkgmgr_nix_store_${distro}:/nix \ + -v "pkgmgr_nix_cache_${PKGMGR_DISTRO}:/root/.cache/nix" \ + -v pkgmgr_nix_store_${PKGMGR_DISTRO}:/nix \ --workdir /src \ -e REINSTALL_PKGMGR=1 \ -e TEST_PATTERN="${TEST_PATTERN}" \ - "pkgmgr-${distro}" \ + "pkgmgr-${PKGMGR_DISTRO}" \ bash -lc ' set -e; git config --global --add safe.directory /src || true;