fix tagging

This commit is contained in:
Elijah Duffy
2025-12-07 18:40:27 -08:00
parent bfccacb192
commit a21cb2674a

View File

@@ -33,6 +33,11 @@ jobs:
# Discover lanes: immediate subdirs under docker/
mapfile -t ALL_LANES < <(find docker -mindepth 1 -maxdepth 1 -type d | sort)
# Also capture lane basenames (e.g. '7.4', 'nginx') for stable naming
ALL_NAMES=()
for _d in "${ALL_LANES[@]}"; do
ALL_NAMES+=("$(basename "${_d}")")
done
if [[ ${#ALL_LANES[@]} -eq 0 ]]; then
echo "No lanes found under docker/. Nothing to do."
echo "should_build=false" >> $GITHUB_OUTPUT
@@ -64,17 +69,19 @@ jobs:
echo "Changed files:"
echo "$CHANGED"
# If workflow changed, rebuild all lanes
# If workflow changed, rebuild all lanes (use basenames)
if grep -qx ".github/workflows/build.yml" <<< "$CHANGED"; then
echo "Workflow changed; rebuilding all lanes."
TARGET_DIRS=("${ALL_LANES[@]}")
TARGET_DIRS=("${ALL_NAMES[@]}")
else
# Build only lanes with changes under their directories
TARGET_DIRS=()
for lane in "${ALL_LANES[@]}"; do
for idx in "${!ALL_LANES[@]}"; do
lane_path="${ALL_LANES[$idx]}"
lane_name="${ALL_NAMES[$idx]}"
# Any change directly under lane dir counts; include Dockerfile or subpaths
if grep -q "^${lane}/" <<< "$CHANGED"; then
TARGET_DIRS+=("$lane")
if grep -q "^${lane_path}/" <<< "$CHANGED"; then
TARGET_DIRS+=("${lane_name}")
fi
done
fi
@@ -127,36 +134,40 @@ jobs:
run: |
set -euo pipefail
DIR="${{ matrix.dir }}"
# Ensure DIR is set and use basename to derive a reliable NAME
# Fail fast on ambiguous/empty matrix.dir. We require a deterministic lane.
if [[ -z "${DIR}" || "${DIR}" == "." ]]; then
echo "matrix.dir is empty or '.'; treating as repo root"
DIR='.'
echo "ERROR: Ambiguous lane: matrix.dir is empty or '.'."
echo "Provide a specific lane directory under docker/ (e.g. '7.4' or 'nginx')."
exit 1
fi
NAME="$(basename "${DIR}")" # e.g. '7.4' or 'nginx'
SHA=${GITHUB_SHA::7}
# Decide repository and tag scheme:
# - nginx lane -> gitea.auvem.com/auvem/wordpress-nginx:stable
# - other lanes (assumed php variants) -> gitea.auvem.com/auvem/wordpress-php-fpm:<version>-stable
# Decide repository and tag scheme. Must be deterministic.
if [[ "${NAME}" == "nginx" ]]; then
IMAGE="gitea.auvem.com/auvem/wordpress-docker/nginx"
TAG="stable"
else
IMAGE="gitea.auvem.com/auvem/wordpress-docker/php-fpm"
# Extract version like 7.4 or 8.1 from the lane name; otherwise use lane name
if [[ -n "${NAME}" && "${NAME}" =~ ([0-9]+\.[0-9]+) ]]; then
# Accept only lanes that encode a numeric version like '7.4' or '8'.
if [[ "${NAME}" =~ ^([0-9]+\.[0-9]+)$ ]]; then
VERSION="${BASH_REMATCH[1]}"
TAG="${VERSION}-stable"
elif [[ -n "${NAME}" && "${NAME}" =~ ([0-9]+) ]]; then
elif [[ "${NAME}" =~ ^([0-9]+)$ ]]; then
VERSION="${BASH_REMATCH[1]}"
TAG="${VERSION}-stable"
elif [[ -n "${NAME}" ]]; then
TAG="${NAME}-stable"
else
TAG="stable"
echo "ERROR: Cannot deterministically derive a version tag from lane name '${NAME}'."
echo "Expected lane names like '7.4' or '8' for php-fpm lanes."
exit 1
fi
fi
# Debug output for name resolution
echo "Computed values: DIR='${DIR}', NAME='${NAME}', IMAGE='${IMAGE}', TAG='${TAG}', SHA='${SHA}'"
echo "image=$IMAGE" >> $GITHUB_OUTPUT
echo "tags=$IMAGE:${TAG},$IMAGE:git-${SHA}" >> $GITHUB_OUTPUT