refactor: Optimize base64 templates workflow to process only changed blueprints

This commit is contained in:
Mauricio Siu 2025-03-09 20:57:25 -06:00
parent 7e802027a4
commit 6fd5c52d6c

View File

@ -1,12 +1,7 @@
name: Generate Base64 Blueprints Table
on:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
encode-and-comment:
@ -16,23 +11,30 @@ jobs:
- name: Checkout repo
uses: actions/checkout@v4
- name: Generate base64 for blueprints
- name: Get changed blueprint folders
id: changes
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
- name: Generate base64 for changed blueprints only
id: generate
run: |
echo "### 📝 Blueprints Base64 Table" > comment.md
CHANGED_FOLDERS=$(echo '${{ steps.changes.outputs.folders }}' | jq -r '.[]')
echo "### 📝 Base64 for changed blueprints" > comment.md
echo '' >> comment.md
echo "You can use the base64 value to import the blueprint into the UI." >> comment.md
echo "<details>" >> comment.md
echo "<summary>🔍 Show all blueprints base64</summary>" >> comment.md
echo '' >> comment.md
if [ -z "$CHANGED_FOLDERS" ]; then
echo "✅ No blueprints changed." >> comment.md
else
echo "<details>" >> comment.md
echo "<summary>🔍 Show base64</summary>" >> comment.md
echo '' >> comment.md
for dir in blueprints/*; do
if [ -d "$dir" ]; then
TEMPLATE_NAME=$(basename "$dir")
COMPOSE_FILE="$dir/docker-compose.yml"
TEMPLATE_FILE="$dir/template.yml"
for dir in $CHANGED_FOLDERS; do
TEMPLATE_NAME="$dir"
COMPOSE_FILE="blueprints/$dir/docker-compose.yml"
TEMPLATE_FILE="blueprints/$dir/template.yml"
if [ -f "$COMPOSE_FILE" ] && [ -f "$TEMPLATE_FILE" ]; then
COMPOSE_CONTENT=$(jq -Rs . < "$COMPOSE_FILE")
@ -48,19 +50,13 @@ jobs:
echo '```' >> comment.md
echo ''
fi
fi
done
done
echo '</details>' >> comment.md
echo '</details>' >> comment.md
fi
- name: Post comment to PR
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request'
with:
path: comment.md
- name: Post comment to commit (fallback)
uses: peter-evans/commit-comment@v3
if: github.event_name != 'pull_request'
with:
body-path: comment.md