Add GitHub Actions workflow to validate blueprint structure and meta.json

This commit is contained in:
Mauricio Siu 2025-03-09 17:32:09 -06:00
parent 1476adcbea
commit ea1f5bddad

101
.github/workflows/validate.yml vendored Normal file
View File

@ -0,0 +1,101 @@
name: Validate Blueprints Structure and Meta
on:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
validate:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Validate blueprint folders
run: |
echo "🔍 Validating blueprints folder structure..."
ERROR=0
# Loop through each blueprint folder
for dir in blueprints/*; do
if [ -d "$dir" ]; then
TEMPLATE_NAME=$(basename "$dir")
COMPOSE_FILE="$dir/docker-compose.yml"
TEMPLATE_FILE="$dir/template.yml"
if [ ! -f "$COMPOSE_FILE" ]; then
echo "❌ Missing docker-compose.yml in $TEMPLATE_NAME"
ERROR=1
fi
if [ ! -f "$TEMPLATE_FILE" ]; then
echo "❌ Missing template.yml in $TEMPLATE_NAME"
ERROR=1
fi
fi
done
if [ $ERROR -eq 1 ]; then
echo "❌ Blueprint folder validation failed."
exit 1
else
echo "✅ Blueprint folders validated successfully."
fi
- name: Validate meta.json matches blueprint folders
run: |
echo "🔍 Validating meta.json against blueprint folders..."
ERROR=0
# Read all blueprint folder names into an array
FOLDERS=($(ls -1 blueprints))
# Extract ids from meta.json
META_IDS=$(jq -r '.[].id' meta.json)
# Validate each id in meta.json exists as a folder
for ID in $META_IDS; do
FOUND=0
for FOLDER in "${FOLDERS[@]}"; do
if [ "$ID" == "$FOLDER" ]; then
FOUND=1
break
fi
done
if [ "$FOUND" -eq 0 ]; then
echo "❌ meta.json id \"$ID\" does not match any folder in blueprints/"
ERROR=1
fi
done
# Validate each folder has an entry in meta.json
for FOLDER in "${FOLDERS[@]}"; do
FOUND=0
for ID in $META_IDS; do
if [ "$FOLDER" == "$ID" ]; then
FOUND=1
break
fi
done
if [ "$FOUND" -eq 0 ]; then
echo "❌ Folder \"$FOLDER\" has no matching id in meta.json"
ERROR=1
fi
done
if [ $ERROR -eq 1 ]; then
echo "❌ meta.json validation failed."
exit 1
else
echo "✅ meta.json validated successfully."
fi