Skip to content

Update Anima note (#534) #1025

Update Anima note (#534)

Update Anima note (#534) #1025

name: Validate Templates
on:
push:
branches: [ main, spec ]
pull_request:
types: [opened, synchronize]
branches: [ main ]
paths:
- 'templates/**'
- 'scripts/validate_templates.py'
- 'scripts/validate_thumbnails.py'
- '.github/workflows/validate-templates.yml'
jobs:
validate:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install jsonschema
- name: Run validation script
id: validation
run: |
python scripts/validate_templates.py 2>&1 | tee validation_output.txt
echo "exit_code=${PIPESTATUS[0]}" >> $GITHUB_OUTPUT
continue-on-error: true
- name: Comment on PR with validation errors
if: steps.validation.outputs.exit_code != '0' && github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
let output = '';
try {
output = fs.readFileSync('validation_output.txt', 'utf8');
} catch (error) {
output = 'Unable to read validation output';
}
const body = '## ❌ Template Validation Failed\n\n```\n' + output + '\n```';
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});
- name: Check JSON syntax
run: |
echo "Checking JSON syntax..."
for file in templates/*.json; do
if ! python -m json.tool "$file" > /dev/null 2>&1; then
echo "❌ Invalid JSON syntax in $file"
exit 1
fi
done
echo "✅ All JSON files have valid syntax"
- name: Check file sizes
run: |
echo "Checking file sizes..."
LARGE_FILES=0
for file in templates/*; do
if [ -f "$file" ]; then
SIZE=$(stat -c%s "$file" 2>/dev/null || stat -f%z "$file" 2>/dev/null)
SIZE_MB=$((SIZE / 1048576))
if [ "$SIZE_MB" -gt 5 ]; then
echo "⚠️ Warning: $file is larger than 5MB (${SIZE_MB}MB)"
LARGE_FILES=$((LARGE_FILES + 1))
fi
fi
done
if [ "$LARGE_FILES" -gt 0 ]; then
echo "Found $LARGE_FILES large files. Consider compressing thumbnails."
fi
- name: Validate thumbnails
id: thumbnail_check
run: |
echo "Validating template thumbnails..."
python3 scripts/validate_thumbnails.py > thumbnail_report.txt 2>&1 || echo "thumbnail_issues=true" >> $GITHUB_OUTPUT
cat thumbnail_report.txt
# Check if thumbnail validation failed
if grep -q "Thumbnail validation failed" thumbnail_report.txt; then
echo "thumbnail_issues=true" >> $GITHUB_OUTPUT
echo "::error::Thumbnail validation failed. Please check thumbnail files and configurations."
else
echo "thumbnail_issues=false" >> $GITHUB_OUTPUT
fi
continue-on-error: true
- name: Comment on PR about thumbnail issues
if: steps.thumbnail_check.outputs.thumbnail_issues == 'true' && github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
// Read thumbnail validation report
let report = '';
try {
report = fs.readFileSync('thumbnail_report.txt', 'utf8');
} catch (error) {
report = 'Unable to read thumbnail validation report';
}
const comment = '## ❌ Thumbnail Validation Failed\n\n```\n' +
report +
'\n```\n\n**Fix:**\n' +
'- Missing: Add `template-1.webp`\n' +
'- Dual thumbnails (`compareSlider`/`hoverDissolve`): Need both `-1` and `-2` files\n' +
'- Check naming: `{name}-{number}.{ext}`';
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
- name: Fail workflow if validation failed
if: steps.validation.outputs.exit_code != '0' || steps.thumbnail_check.outputs.thumbnail_issues == 'true'
run: |
echo "❌ Validation failed"
exit 1