Refactor CI distro handling and container build scripts
- Introduce a GitHub Actions matrix for `test-container` and `test-e2e` to run against arch, debian, ubuntu, fedora, and centos - Run unit and integration tests only in the Arch container by passing `distro="arch"` via make in the corresponding workflows - Replace the global DISTROS loop with a single `distro` variable in the Makefile, defaulting to `arch`, and export it for all scripts - Update build scripts (build-image, build-image-no-cache, build-image-missing) to build images for the selected distro only - Simplify test-container script to validate a single distro image using the `distro` environment variable - Simplify E2E, unit, and integration test scripts to run against a single distro container instead of iterating over all distros https://chatgpt.com/share/693acbba-9e30-800f-94fb-fea4489e9078
This commit is contained in:
10
.github/workflows/test-container.yml
vendored
10
.github/workflows/test-container.yml
vendored
@@ -7,6 +7,10 @@ jobs:
|
|||||||
test-container:
|
test-container:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 30
|
timeout-minutes: 30
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
distro: [arch, debian, ubuntu, fedora, centos]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
@@ -15,5 +19,7 @@ jobs:
|
|||||||
- name: Show Docker version
|
- name: Show Docker version
|
||||||
run: docker version
|
run: docker version
|
||||||
|
|
||||||
- name: Run container tests
|
- name: Run container tests (${{ matrix.distro }})
|
||||||
run: make test-container
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
distro="${{ matrix.distro }}" make test-container
|
||||||
|
|||||||
12
.github/workflows/test-e2e.yml
vendored
12
.github/workflows/test-e2e.yml
vendored
@@ -6,7 +6,11 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
test-e2e:
|
test-e2e:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 60 # E2E + all distros can be heavier
|
timeout-minutes: 60 # E2E can be heavier
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
distro: [arch, debian, ubuntu, fedora, centos]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
@@ -15,5 +19,7 @@ jobs:
|
|||||||
- name: Show Docker version
|
- name: Show Docker version
|
||||||
run: docker version
|
run: docker version
|
||||||
|
|
||||||
- name: Run E2E tests via make (all distros)
|
- name: Run E2E tests via make (${{ matrix.distro }})
|
||||||
run: make test-e2e
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
distro="${{ matrix.distro }}" make test-e2e
|
||||||
|
|||||||
2
.github/workflows/test-integration.yml
vendored
2
.github/workflows/test-integration.yml
vendored
@@ -16,4 +16,4 @@ jobs:
|
|||||||
run: docker version
|
run: docker version
|
||||||
|
|
||||||
- name: Run integration tests via make (Arch container)
|
- name: Run integration tests via make (Arch container)
|
||||||
run: make test-integration DISTROS="arch"
|
run: make test-integration distro="arch"
|
||||||
|
|||||||
2
.github/workflows/test-unit.yml
vendored
2
.github/workflows/test-unit.yml
vendored
@@ -16,4 +16,4 @@ jobs:
|
|||||||
run: docker version
|
run: docker version
|
||||||
|
|
||||||
- name: Run unit tests via make (Arch container)
|
- name: Run unit tests via make (Arch container)
|
||||||
run: make test-unit DISTROS="arch"
|
run: make test-unit distro="arch"
|
||||||
|
|||||||
9
Makefile
9
Makefile
@@ -2,11 +2,15 @@
|
|||||||
test build build-no-cache test-unit test-e2e test-integration \
|
test build build-no-cache test-unit test-e2e test-integration \
|
||||||
test-container
|
test-container
|
||||||
|
|
||||||
|
# Distro
|
||||||
|
# Options: arch debian ubuntu fedora centos
|
||||||
|
distro ?= arch
|
||||||
|
export distro
|
||||||
|
|
||||||
# ------------------------------------------------------------
|
# ------------------------------------------------------------
|
||||||
# Distro list and base images
|
# Base images
|
||||||
# (kept for documentation/reference; actual build logic is in scripts/build)
|
# (kept for documentation/reference; actual build logic is in scripts/build)
|
||||||
# ------------------------------------------------------------
|
# ------------------------------------------------------------
|
||||||
DISTROS := arch debian ubuntu fedora centos
|
|
||||||
BASE_IMAGE_ARCH := archlinux:latest
|
BASE_IMAGE_ARCH := archlinux:latest
|
||||||
BASE_IMAGE_DEBIAN := debian:stable-slim
|
BASE_IMAGE_DEBIAN := debian:stable-slim
|
||||||
BASE_IMAGE_UBUNTU := ubuntu:latest
|
BASE_IMAGE_UBUNTU := ubuntu:latest
|
||||||
@@ -14,7 +18,6 @@ BASE_IMAGE_FEDORA := fedora:latest
|
|||||||
BASE_IMAGE_CENTOS := quay.io/centos/centos:stream9
|
BASE_IMAGE_CENTOS := quay.io/centos/centos:stream9
|
||||||
|
|
||||||
# Make them available in scripts
|
# Make them available in scripts
|
||||||
export DISTROS
|
|
||||||
export BASE_IMAGE_ARCH
|
export BASE_IMAGE_ARCH
|
||||||
export BASE_IMAGE_DEBIAN
|
export BASE_IMAGE_DEBIAN
|
||||||
export BASE_IMAGE_UBUNTU
|
export BASE_IMAGE_UBUNTU
|
||||||
|
|||||||
@@ -4,32 +4,21 @@ set -euo pipefail
|
|||||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||||
source "${SCRIPT_DIR}/resolve-base-image.sh"
|
source "${SCRIPT_DIR}/resolve-base-image.sh"
|
||||||
|
|
||||||
echo "============================================================"
|
IMAGE="package-manager-test-$distro"
|
||||||
echo ">>> Building ONLY missing container images"
|
BASE_IMAGE="$(resolve_base_image "$distro")"
|
||||||
echo "============================================================"
|
|
||||||
|
|
||||||
for distro in $DISTROS; do
|
if docker image inspect "$IMAGE" >/dev/null 2>&1; then
|
||||||
IMAGE="package-manager-test-$distro"
|
echo "[build-missing] Image already exists: $IMAGE (skipping)"
|
||||||
BASE_IMAGE="$(resolve_base_image "$distro")"
|
exit 0
|
||||||
|
fi
|
||||||
if docker image inspect "$IMAGE" >/dev/null 2>&1; then
|
|
||||||
echo "[build-missing] Image already exists: $IMAGE (skipping)"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo
|
|
||||||
echo "------------------------------------------------------------"
|
|
||||||
echo "[build-missing] Building missing image: $IMAGE"
|
|
||||||
echo "BASE_IMAGE = $BASE_IMAGE"
|
|
||||||
echo "------------------------------------------------------------"
|
|
||||||
|
|
||||||
docker build \
|
|
||||||
--build-arg BASE_IMAGE="$BASE_IMAGE" \
|
|
||||||
-t "$IMAGE" \
|
|
||||||
.
|
|
||||||
done
|
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "============================================================"
|
echo "------------------------------------------------------------"
|
||||||
echo ">>> build-missing: Done"
|
echo "[build-missing] Building missing image: $IMAGE"
|
||||||
echo "============================================================"
|
echo "BASE_IMAGE = $BASE_IMAGE"
|
||||||
|
echo "------------------------------------------------------------"
|
||||||
|
|
||||||
|
docker build \
|
||||||
|
--build-arg BASE_IMAGE="$BASE_IMAGE" \
|
||||||
|
-t "$IMAGE" \
|
||||||
|
.
|
||||||
|
|||||||
@@ -4,14 +4,12 @@ set -euo pipefail
|
|||||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||||
source "${SCRIPT_DIR}/resolve-base-image.sh"
|
source "${SCRIPT_DIR}/resolve-base-image.sh"
|
||||||
|
|
||||||
for distro in $DISTROS; do
|
base_image="$(resolve_base_image "$distro")"
|
||||||
base_image="$(resolve_base_image "$distro")"
|
|
||||||
|
|
||||||
echo ">>> Building test image for distro '$distro' with NO CACHE (BASE_IMAGE=$base_image)..."
|
echo ">>> Building test image for distro '$distro' with NO CACHE (BASE_IMAGE=$base_image)..."
|
||||||
|
|
||||||
docker build \
|
docker build \
|
||||||
--no-cache \
|
--no-cache \
|
||||||
--build-arg BASE_IMAGE="$base_image" \
|
--build-arg BASE_IMAGE="$base_image" \
|
||||||
-t "package-manager-test-$distro" \
|
-t "package-manager-test-$distro" \
|
||||||
.
|
.
|
||||||
done
|
|
||||||
|
|||||||
@@ -4,13 +4,11 @@ set -euo pipefail
|
|||||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||||
source "${SCRIPT_DIR}/resolve-base-image.sh"
|
source "${SCRIPT_DIR}/resolve-base-image.sh"
|
||||||
|
|
||||||
for distro in $DISTROS; do
|
base_image="$(resolve_base_image "$distro")"
|
||||||
base_image="$(resolve_base_image "$distro")"
|
|
||||||
|
|
||||||
echo ">>> Building test image for distro '$distro' (BASE_IMAGE=$base_image)..."
|
echo ">>> Building test image for distro '$distro' (BASE_IMAGE=$base_image)..."
|
||||||
|
|
||||||
docker build \
|
docker build \
|
||||||
--build-arg BASE_IMAGE="$base_image" \
|
--build-arg BASE_IMAGE="$base_image" \
|
||||||
-t "package-manager-test-$distro" \
|
-t "package-manager-test-$distro" \
|
||||||
.
|
.
|
||||||
done
|
|
||||||
|
|||||||
@@ -1,41 +1,30 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
echo "============================================================"
|
IMAGE="package-manager-test-$distro"
|
||||||
echo ">>> Running sanity test: verifying test containers start"
|
|
||||||
echo "============================================================"
|
|
||||||
|
|
||||||
for distro in $DISTROS; do
|
|
||||||
IMAGE="package-manager-test-$distro"
|
|
||||||
|
|
||||||
echo
|
|
||||||
echo "------------------------------------------------------------"
|
|
||||||
echo ">>> Testing container: $IMAGE"
|
|
||||||
echo "------------------------------------------------------------"
|
|
||||||
|
|
||||||
echo "[test-container] Running: docker run --rm --entrypoint pkgmgr $IMAGE --help"
|
|
||||||
echo
|
|
||||||
|
|
||||||
# Run the command and capture the output
|
|
||||||
if OUTPUT=$(docker run --rm \
|
|
||||||
-e PKGMGR_DEV=1 \
|
|
||||||
-v pkgmgr_nix_store_${distro}:/nix \
|
|
||||||
-v "$(pwd):/src" \
|
|
||||||
-v "pkgmgr_nix_cache_${distro}:/root/.cache/nix" \
|
|
||||||
"$IMAGE" 2>&1); then
|
|
||||||
echo "$OUTPUT"
|
|
||||||
echo
|
|
||||||
echo "[test-container] SUCCESS: $IMAGE responded to 'pkgmgr --help'"
|
|
||||||
|
|
||||||
else
|
|
||||||
echo "$OUTPUT"
|
|
||||||
echo
|
|
||||||
echo "[test-container] ERROR: $IMAGE failed to run 'pkgmgr --help'"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "============================================================"
|
echo "------------------------------------------------------------"
|
||||||
echo ">>> All containers passed the sanity check"
|
echo ">>> Testing container: $IMAGE"
|
||||||
echo "============================================================"
|
echo "------------------------------------------------------------"
|
||||||
|
|
||||||
|
echo "[test-container] Running: docker run --rm --entrypoint pkgmgr $IMAGE --help"
|
||||||
|
echo
|
||||||
|
|
||||||
|
# Run the command and capture the output
|
||||||
|
if OUTPUT=$(docker run --rm \
|
||||||
|
-e PKGMGR_DEV=1 \
|
||||||
|
-v pkgmgr_nix_store_${distro}:/nix \
|
||||||
|
-v "$(pwd):/src" \
|
||||||
|
-v "pkgmgr_nix_cache_${distro}:/root/.cache/nix" \
|
||||||
|
"$IMAGE" 2>&1); then
|
||||||
|
echo "$OUTPUT"
|
||||||
|
echo
|
||||||
|
echo "[test-container] SUCCESS: $IMAGE responded to 'pkgmgr --help'"
|
||||||
|
|
||||||
|
else
|
||||||
|
echo "$OUTPUT"
|
||||||
|
echo
|
||||||
|
echo "[test-container] ERROR: $IMAGE failed to run 'pkgmgr --help'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
@@ -1,64 +1,60 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
echo ">>> Running E2E tests in all distros: $DISTROS"
|
echo "============================================================"
|
||||||
|
echo ">>> Running E2E tests: $distro"
|
||||||
|
echo "============================================================"
|
||||||
|
|
||||||
for distro in $DISTROS; do
|
docker run --rm \
|
||||||
echo "============================================================"
|
-v "$(pwd):/src" \
|
||||||
echo ">>> Running E2E tests: $distro"
|
-v "pkgmgr_nix_store_${distro}:/nix" \
|
||||||
echo "============================================================"
|
-v "pkgmgr_nix_cache_${distro}:/root/.cache/nix" \
|
||||||
|
-e PKGMGR_DEV=1 \
|
||||||
|
-e TEST_PATTERN="${TEST_PATTERN}" \
|
||||||
|
--workdir /src \
|
||||||
|
"package-manager-test-${distro}" \
|
||||||
|
bash -lc '
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
docker run --rm \
|
# Load distro info
|
||||||
-v "$(pwd):/src" \
|
if [ -f /etc/os-release ]; then
|
||||||
-v "pkgmgr_nix_store_${distro}:/nix" \
|
. /etc/os-release
|
||||||
-v "pkgmgr_nix_cache_${distro}:/root/.cache/nix" \
|
fi
|
||||||
-e PKGMGR_DEV=1 \
|
|
||||||
-e TEST_PATTERN="${TEST_PATTERN}" \
|
|
||||||
--workdir /src \
|
|
||||||
"package-manager-test-${distro}" \
|
|
||||||
bash -lc '
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
# Load distro info
|
echo "Running tests inside distro: ${ID:-unknown}"
|
||||||
if [ -f /etc/os-release ]; then
|
|
||||||
. /etc/os-release
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Running tests inside distro: ${ID:-unknown}"
|
# Load Nix environment if available
|
||||||
|
if [ -f "/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh" ]; then
|
||||||
|
. "/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh"
|
||||||
|
fi
|
||||||
|
|
||||||
# Load Nix environment if available
|
if [ -f "$HOME/.nix-profile/etc/profile.d/nix.sh" ]; then
|
||||||
if [ -f "/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh" ]; then
|
. "$HOME/.nix-profile/etc/profile.d/nix.sh"
|
||||||
. "/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh"
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -f "$HOME/.nix-profile/etc/profile.d/nix.sh" ]; then
|
PATH="/nix/var/nix/profiles/default/bin:$HOME/.nix-profile/bin:$PATH"
|
||||||
. "$HOME/.nix-profile/etc/profile.d/nix.sh"
|
|
||||||
fi
|
|
||||||
|
|
||||||
PATH="/nix/var/nix/profiles/default/bin:$HOME/.nix-profile/bin:$PATH"
|
command -v nix >/dev/null || {
|
||||||
|
echo "ERROR: nix not found."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
command -v nix >/dev/null || {
|
# Mark the mounted repository as safe to avoid Git ownership errors.
|
||||||
echo "ERROR: nix not found."
|
# Newer Git (e.g. on Ubuntu) complains about the gitdir (/src/.git),
|
||||||
exit 1
|
# older versions about the worktree (/src). Nix turns "." into the
|
||||||
}
|
# flake input "git+file:///src", which then uses Git under the hood.
|
||||||
|
if command -v git >/dev/null 2>&1; then
|
||||||
|
# Worktree path
|
||||||
|
git config --global --add safe.directory /src || true
|
||||||
|
# Gitdir path shown in the "dubious ownership" error
|
||||||
|
git config --global --add safe.directory /src/.git || true
|
||||||
|
# Ephemeral CI containers: allow all paths as a last resort
|
||||||
|
git config --global --add safe.directory '*' || true
|
||||||
|
fi
|
||||||
|
|
||||||
# Mark the mounted repository as safe to avoid Git ownership errors.
|
# Run the E2E tests inside the Nix development shell
|
||||||
# Newer Git (e.g. on Ubuntu) complains about the gitdir (/src/.git),
|
nix develop .#default --no-write-lock-file -c \
|
||||||
# older versions about the worktree (/src). Nix turns "." into the
|
python3 -m unittest discover \
|
||||||
# flake input "git+file:///src", which then uses Git under the hood.
|
-s /src/tests/e2e \
|
||||||
if command -v git >/dev/null 2>&1; then
|
-p "$TEST_PATTERN"
|
||||||
# Worktree path
|
'
|
||||||
git config --global --add safe.directory /src || true
|
|
||||||
# Gitdir path shown in the "dubious ownership" error
|
|
||||||
git config --global --add safe.directory /src/.git || true
|
|
||||||
# Ephemeral CI containers: allow all paths as a last resort
|
|
||||||
git config --global --add safe.directory '*' || true
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Run the E2E tests inside the Nix development shell
|
|
||||||
nix develop .#default --no-write-lock-file -c \
|
|
||||||
python3 -m unittest discover \
|
|
||||||
-s /src/tests/e2e \
|
|
||||||
-p "$TEST_PATTERN"
|
|
||||||
'
|
|
||||||
done
|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
: "${distro:=arch}"
|
|
||||||
|
|
||||||
echo "============================================================"
|
echo "============================================================"
|
||||||
echo ">>> Running INTEGRATION tests in ${distro} container"
|
echo ">>> Running INTEGRATION tests in ${distro} container"
|
||||||
echo "============================================================"
|
echo "============================================================"
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
: "${distro:=arch}"
|
|
||||||
|
|
||||||
echo "============================================================"
|
echo "============================================================"
|
||||||
echo ">>> Running UNIT tests in ${distro} container"
|
echo ">>> Running UNIT tests in ${distro} container"
|
||||||
echo "============================================================"
|
echo "============================================================"
|
||||||
|
|||||||
Reference in New Issue
Block a user