packer-images/ci/build.sh
Ben Vincent 4d3e0ba4cf
All checks were successful
Build / build (pull_request) Successful in 16s
feat: add build workflows
- enable fetch-depth for code_checkout
- fetch master branch before checking for changed files
- ensure the clean target is called with the default
- improve makefile failure handling
- ensure VAULT_ADDR is set before VAULT_TOKEN
2025-01-25 18:24:07 +11:00

36 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
# Check for changes in images/ folder and the builds/ folder
git fetch origin master:master
if [ "$(git branch --show-current)" = "master" ]; then
builds_changes=$(git diff --name-only HEAD^...master | grep -E '^builds/')
images_changes=$(git diff --name-only HEAD^...master | grep -E '^images/')
else
builds_changes=$(git diff --name-only master | grep -E '^builds/')
images_changes=$(git diff --name-only master | grep -E '^images/')
fi
# Run `make all` if there are changes in builds/
if [ -n "$builds_changes" ]; then
echo "Changes detected in builds/. Running 'make all'..."
make all
fi
# Run specific `make` commands for each changed file in images/
if [ -n "$images_changes" ]; then
echo "Changes detected in images/. Running specific 'make' commands..."
# Extract unique paths for `make` commands
export TARGETS=$(echo "$images_changes" | sed -E 's|images/||; s|/[^/]+$||' | sort -u)
echo $TARGETS
for target in $TARGETS; do
echo "Running 'make $target'..."
make "$target"
done
fi
# If no changes, output a message
if [ -z "$builds_changes" ] && [ -z "$images_changes" ]; then
echo "No relevant changes detected."
fi