ci(workflow): build all images on manual trigger instead of specific input

Refactor the image detection strategy in the build-images workflow.

- Remove the `image` input parameter from `workflow_dispatch`.
- Update detection logic to handle events differently:
  - On manual triggers (`workflow_dispatch`), the script now scans the `images/` directory and builds ALL valid images found.
  - On push events, the script retains the `git diff` logic to only build images that have explicitly changed.
This commit is contained in:
darnodo
2025-12-07 21:10:57 +01:00
parent 95e251f2f2
commit a6f7c9799f

View File

@@ -6,10 +6,7 @@ on:
paths:
- 'images/**'
workflow_dispatch:
inputs:
image:
description: 'Image to build (e.g., terraform-ci)'
required: false
# No inputs needed as we build all images on manual trigger
env:
REGISTRY: gitea.arnodo.fr
@@ -36,50 +33,39 @@ jobs:
- name: Detect changed images
id: changes
env:
INPUT_IMAGE: ${{ inputs.image }}
run: |
# 1. Handle Manual Input
if [ -n "$INPUT_IMAGE" ]; then
# Clean input
IMAGE=$(echo "$INPUT_IMAGE" | xargs)
echo "DEBUG: Processing manual input image: '$IMAGE'"
if [ -n "$IMAGE" ]; then
if [ -d "images/$IMAGE" ] && [ -f "images/$IMAGE/Dockerfile" ]; then
echo "DEBUG: Image directory and Dockerfile exist."
# Use printf for safer output
printf "image_list=[\"%s\"]\n" "$IMAGE" >> $GITHUB_OUTPUT
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "DEBUG: Set image_list=['$IMAGE']"
exit 0
else
echo "Error: Image '$IMAGE' not found or missing Dockerfile at images/$IMAGE/Dockerfile"
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "image_list=[]" >> $GITHUB_OUTPUT
exit 0
fi
else
echo "DEBUG: Input image name was empty after trimming."
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "image_list=[]" >> $GITHUB_OUTPUT
exit 0
fi
fi
# 2. Handle Automatic Detection (Git Diff)
echo "DEBUG: Running git diff detection..."
> valid_images.txt
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD -- images/ 2>/dev/null || true)
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "DEBUG: Manual trigger detected. Scanning all images..."
if [ -d "images" ]; then
# Loop through all items in images/ directory
for DIR in images/*; do
# Check if it's a directory and has a Dockerfile
if [ -d "$DIR" ] && [ -f "$DIR/Dockerfile" ]; then
BASENAME=$(basename "$DIR")
echo "DEBUG: Found image: $BASENAME"
echo "$BASENAME" >> valid_images.txt
fi
done
else
echo "DEBUG: images/ directory not found."
fi
else
echo "DEBUG: Push event detected. Analyzing git diff..."
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD -- images/ 2>/dev/null || true)
CANDIDATES=$(echo "$CHANGED_FILES" | cut -d'/' -f2 | sort -u | grep -v '^$')
for CANDIDATE in $CANDIDATES; do
if [ -d "images/$CANDIDATE" ] && [ -f "images/$CANDIDATE/Dockerfile" ]; then
echo "DEBUG: Change detected in image: $CANDIDATE"
echo "$CANDIDATE" >> valid_images.txt
fi
done
fi
if [ ! -s valid_images.txt ]; then
echo "No valid images detected."