fix tagging
This commit is contained in:
45
.github/workflows/build.yml
vendored
45
.github/workflows/build.yml
vendored
@@ -33,6 +33,11 @@ jobs:
|
|||||||
|
|
||||||
# Discover lanes: immediate subdirs under docker/
|
# Discover lanes: immediate subdirs under docker/
|
||||||
mapfile -t ALL_LANES < <(find docker -mindepth 1 -maxdepth 1 -type d | sort)
|
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
|
if [[ ${#ALL_LANES[@]} -eq 0 ]]; then
|
||||||
echo "No lanes found under docker/. Nothing to do."
|
echo "No lanes found under docker/. Nothing to do."
|
||||||
echo "should_build=false" >> $GITHUB_OUTPUT
|
echo "should_build=false" >> $GITHUB_OUTPUT
|
||||||
@@ -64,17 +69,19 @@ jobs:
|
|||||||
echo "Changed files:"
|
echo "Changed files:"
|
||||||
echo "$CHANGED"
|
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
|
if grep -qx ".github/workflows/build.yml" <<< "$CHANGED"; then
|
||||||
echo "Workflow changed; rebuilding all lanes."
|
echo "Workflow changed; rebuilding all lanes."
|
||||||
TARGET_DIRS=("${ALL_LANES[@]}")
|
TARGET_DIRS=("${ALL_NAMES[@]}")
|
||||||
else
|
else
|
||||||
# Build only lanes with changes under their directories
|
# Build only lanes with changes under their directories
|
||||||
TARGET_DIRS=()
|
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
|
# Any change directly under lane dir counts; include Dockerfile or subpaths
|
||||||
if grep -q "^${lane}/" <<< "$CHANGED"; then
|
if grep -q "^${lane_path}/" <<< "$CHANGED"; then
|
||||||
TARGET_DIRS+=("$lane")
|
TARGET_DIRS+=("${lane_name}")
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
@@ -127,36 +134,40 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
DIR="${{ matrix.dir }}"
|
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
|
if [[ -z "${DIR}" || "${DIR}" == "." ]]; then
|
||||||
echo "matrix.dir is empty or '.'; treating as repo root"
|
echo "ERROR: Ambiguous lane: matrix.dir is empty or '.'."
|
||||||
DIR='.'
|
echo "Provide a specific lane directory under docker/ (e.g. '7.4' or 'nginx')."
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
NAME="$(basename "${DIR}")" # e.g. '7.4' or 'nginx'
|
NAME="$(basename "${DIR}")" # e.g. '7.4' or 'nginx'
|
||||||
SHA=${GITHUB_SHA::7}
|
SHA=${GITHUB_SHA::7}
|
||||||
|
|
||||||
# Decide repository and tag scheme:
|
# Decide repository and tag scheme. Must be deterministic.
|
||||||
# - nginx lane -> gitea.auvem.com/auvem/wordpress-nginx:stable
|
|
||||||
# - other lanes (assumed php variants) -> gitea.auvem.com/auvem/wordpress-php-fpm:<version>-stable
|
|
||||||
if [[ "${NAME}" == "nginx" ]]; then
|
if [[ "${NAME}" == "nginx" ]]; then
|
||||||
IMAGE="gitea.auvem.com/auvem/wordpress-docker/nginx"
|
IMAGE="gitea.auvem.com/auvem/wordpress-docker/nginx"
|
||||||
TAG="stable"
|
TAG="stable"
|
||||||
else
|
else
|
||||||
IMAGE="gitea.auvem.com/auvem/wordpress-docker/php-fpm"
|
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
|
# Accept only lanes that encode a numeric version like '7.4' or '8'.
|
||||||
if [[ -n "${NAME}" && "${NAME}" =~ ([0-9]+\.[0-9]+) ]]; then
|
if [[ "${NAME}" =~ ^([0-9]+\.[0-9]+)$ ]]; then
|
||||||
VERSION="${BASH_REMATCH[1]}"
|
VERSION="${BASH_REMATCH[1]}"
|
||||||
TAG="${VERSION}-stable"
|
TAG="${VERSION}-stable"
|
||||||
elif [[ -n "${NAME}" && "${NAME}" =~ ([0-9]+) ]]; then
|
elif [[ "${NAME}" =~ ^([0-9]+)$ ]]; then
|
||||||
VERSION="${BASH_REMATCH[1]}"
|
VERSION="${BASH_REMATCH[1]}"
|
||||||
TAG="${VERSION}-stable"
|
TAG="${VERSION}-stable"
|
||||||
elif [[ -n "${NAME}" ]]; then
|
|
||||||
TAG="${NAME}-stable"
|
|
||||||
else
|
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
|
||||||
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 "image=$IMAGE" >> $GITHUB_OUTPUT
|
||||||
echo "tags=$IMAGE:${TAG},$IMAGE:git-${SHA}" >> $GITHUB_OUTPUT
|
echo "tags=$IMAGE:${TAG},$IMAGE:git-${SHA}" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user