refactor: Enhance base64 templates workflow with improved error handling and diff detection

This commit is contained in:
Mauricio Siu
2025-03-09 20:59:22 -06:00
parent 6fd5c52d6c
commit 6b24af43bf

View File

@@ -1,23 +1,25 @@
name: Generate Base64 for Changed Blueprints
on: on:
pull_request: pull_request:
branches: branches:
- main - main
jobs: jobs:
encode-and-comment: encode-changed:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout repo - name: Checkout repo
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Get changed blueprint folders - name: Get changed blueprints folders
id: changes id: changes
run: | run: |
echo "folders=$(git diff --name-only ${{ github.event.pull_request.base.sha }} | grep '^blueprints/' | cut -d/ -f2 | sort -u | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT CHANGED=$(git diff --name-only origin/${{ github.event.pull_request.base.ref }} | grep '^blueprints/' | cut -d/ -f2 | sort -u)
echo "folders=$(echo $CHANGED | jq -R -s -c 'split(" ") | map(select(length > 0))')" >> $GITHUB_OUTPUT
- name: Generate base64 for changed blueprints only - name: Generate base64 for changed blueprints
id: generate
run: | run: |
CHANGED_FOLDERS=$(echo '${{ steps.changes.outputs.folders }}' | jq -r '.[]') CHANGED_FOLDERS=$(echo '${{ steps.changes.outputs.folders }}' | jq -r '.[]')
@@ -32,7 +34,8 @@ jobs:
echo '' >> comment.md echo '' >> comment.md
for dir in $CHANGED_FOLDERS; do for dir in $CHANGED_FOLDERS; do
TEMPLATE_NAME="$dir" echo "Processing $dir..."
COMPOSE_FILE="blueprints/$dir/docker-compose.yml" COMPOSE_FILE="blueprints/$dir/docker-compose.yml"
TEMPLATE_FILE="blueprints/$dir/template.yml" TEMPLATE_FILE="blueprints/$dir/template.yml"
@@ -43,12 +46,14 @@ jobs:
JSON="{\"compose\":$COMPOSE_CONTENT,\"config\":$TEMPLATE_CONTENT}" JSON="{\"compose\":$COMPOSE_CONTENT,\"config\":$TEMPLATE_CONTENT}"
BASE64_JSON=$(echo -n "$JSON" | base64 -w 0) BASE64_JSON=$(echo -n "$JSON" | base64 -w 0)
echo "#### $TEMPLATE_NAME" >> comment.md echo "#### $dir" >> comment.md
echo '' >> comment.md echo '' >> comment.md
echo '```' >> comment.md echo '```' >> comment.md
echo "$BASE64_JSON" >> comment.md echo "$BASE64_JSON" >> comment.md
echo '```' >> comment.md echo '```' >> comment.md
echo '' echo ''
else
echo "❌ Missing files in $dir" >> comment.md
fi fi
done done
@@ -57,6 +62,5 @@ jobs:
- name: Post comment to PR - name: Post comment to PR
uses: marocchino/sticky-pull-request-comment@v2 uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request'
with: with:
path: comment.md path: comment.md