Skip to content

Commit d5327b2

Browse files
Comprehensive CI/CD improvements: lint, validation, annotations
## Enhanced Lint Workflow - Fix lint.yml to validate ALL YAML files instead of only itself - Switch to proper yamllint with comprehensive configuration - Add workflow syntax validation for required fields - Better error reporting with GitHub Actions annotations ## Enhanced Template Validation - Improved schema validation with template-specific error messages - Better GitHub Actions annotations with file paths and error context - Categorized error reporting (schema, file, other errors) - Enhanced success/warning annotations with detailed summaries ## Improved Workflow Status Checks - Added caching for Python dependencies in validation workflow - Enhanced JSON syntax checking with file-specific error reporting - Better file size monitoring with graduated warning levels - Comprehensive validation summary step with overall status ## GitHub Actions Annotation Improvements - File-specific error annotations with titles and context - Categorized warnings (orphaned files, missing files, large files) - Success notifications with validation statistics - Enhanced status reporting throughout all validation steps These improvements provide much better developer experience with: - Faster feedback through caching - Clear error locations and context - Better status visibility in GitHub UI - Comprehensive validation coverage
1 parent 2bd6b5d commit d5327b2

3 files changed

Lines changed: 272 additions & 46 deletions

File tree

β€Ž.github/workflows/lint.ymlβ€Ž

Lines changed: 87 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@ on:
44
push:
55
branches: [main]
66
paths:
7-
- '.github/workflows/lint.yml'
7+
- '.github/workflows/*.yml'
8+
- '.github/workflows/*.yaml'
9+
- '*.yml'
10+
- '*.yaml'
811
pull_request:
912
branches: [main]
1013
paths:
11-
- '.github/workflows/lint.yml'
14+
- '.github/workflows/*.yml'
15+
- '.github/workflows/*.yaml'
16+
- '*.yml'
17+
- '*.yaml'
1218

1319
jobs:
1420
yaml-lint:
@@ -17,13 +23,85 @@ jobs:
1723
- name: Checkout code
1824
uses: actions/checkout@v4
1925

20-
- name: Set up Node.js
21-
uses: actions/setup-node@v4
26+
- name: Set up Python
27+
uses: actions/setup-python@v5
2228
with:
23-
node-version: "20"
29+
python-version: "3.x"
2430

25-
- name: Install YAML linter
26-
run: npm install -g yaml-lint
31+
- name: Install yamllint
32+
run: pip install yamllint
2733

28-
- name: Lint YAML files
29-
run: yamllint .github/workflows/*.{yml,yaml}
34+
- name: Create yamllint config
35+
run: |
36+
cat > .yamllint.yml << 'EOF'
37+
extends: default
38+
rules:
39+
line-length:
40+
max: 120
41+
level: warning
42+
comments:
43+
min-spaces-from-content: 1
44+
braces:
45+
max-spaces-inside: 1
46+
max-spaces-inside-empty: 0
47+
brackets:
48+
max-spaces-inside: 1
49+
max-spaces-inside-empty: 0
50+
indentation:
51+
spaces: 2
52+
EOF
53+
54+
- name: Lint GitHub Actions workflows
55+
run: |
56+
echo "πŸ” Linting GitHub Actions workflows..."
57+
if ! yamllint .github/workflows/; then
58+
echo "❌ YAML lint errors found in workflows"
59+
echo "::error::YAML formatting issues in GitHub Actions workflows"
60+
exit 1
61+
fi
62+
echo "βœ… All workflow files passed YAML linting"
63+
64+
- name: Lint other YAML files
65+
run: |
66+
echo "πŸ” Linting other YAML files..."
67+
# Find all YAML files in repo (excluding node_modules, .git, etc.)
68+
YAML_FILES=$(find . -name "*.yml" -o -name "*.yaml" | grep -v -E '(node_modules|\.git|\.venv|dist)' | grep -v '.yamllint.yml')
69+
70+
if [ -z "$YAML_FILES" ]; then
71+
echo "ℹ️ No additional YAML files found"
72+
exit 0
73+
fi
74+
75+
echo "Found YAML files: $YAML_FILES"
76+
77+
if ! echo "$YAML_FILES" | xargs yamllint; then
78+
echo "❌ YAML lint errors found in project files"
79+
echo "::error::YAML formatting issues in project files"
80+
exit 1
81+
fi
82+
echo "βœ… All project YAML files passed linting"
83+
84+
- name: Validate workflow syntax
85+
run: |
86+
echo "πŸ” Validating GitHub Actions workflow syntax..."
87+
# Use GitHub's own action syntax validation
88+
for file in .github/workflows/*.yml .github/workflows/*.yaml; do
89+
if [[ -f "$file" ]]; then
90+
echo "Validating $file..."
91+
# Basic syntax check - yamllint already validated YAML syntax
92+
# Check for required fields
93+
if ! grep -q "^name:" "$file"; then
94+
echo "::error file=$file::Missing required 'name' field"
95+
exit 1
96+
fi
97+
if ! grep -q "^on:" "$file"; then
98+
echo "::error file=$file::Missing required 'on' field"
99+
exit 1
100+
fi
101+
if ! grep -q "^jobs:" "$file"; then
102+
echo "::error file=$file::Missing required 'jobs' field"
103+
exit 1
104+
fi
105+
fi
106+
done
107+
echo "βœ… All workflows have required structure"

β€Ž.github/workflows/validate-templates.ymlβ€Ž

Lines changed: 97 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,42 +25,96 @@ jobs:
2525
uses: actions/setup-python@v5
2626
with:
2727
python-version: '3.11'
28+
cache: 'pip'
29+
30+
- name: Cache validation dependencies
31+
uses: actions/cache@v4
32+
with:
33+
path: ~/.cache/pip
34+
key: ${{ runner.os }}-pip-validation-${{ hashFiles('requirements.txt', 'scripts/validate_templates.py') }}
35+
restore-keys: |
36+
${{ runner.os }}-pip-validation-
2837
2938
- name: Install dependencies
3039
run: |
3140
python -m pip install --upgrade pip
3241
pip install jsonschema
3342
34-
- name: Run validation script
35-
run: python scripts/validate_templates.py
43+
- name: Run enhanced validation script
44+
id: validation
45+
run: |
46+
echo "πŸ” Starting comprehensive template validation..."
47+
echo "validation_status=running" >> $GITHUB_OUTPUT
48+
49+
if python scripts/validate_templates.py; then
50+
echo "validation_status=passed" >> $GITHUB_OUTPUT
51+
echo "::notice title=Validation Success::All template validations passed successfully"
52+
else
53+
echo "validation_status=failed" >> $GITHUB_OUTPUT
54+
echo "::error title=Validation Failed::Template validation found errors that must be fixed"
55+
exit 1
56+
fi
3657
3758
- name: Check JSON syntax
59+
id: json-check
3860
run: |
39-
echo "Checking JSON syntax..."
61+
echo "πŸ” Checking JSON syntax for all template files..."
62+
INVALID_FILES=""
63+
TOTAL_FILES=0
64+
4065
for file in templates/*.json; do
41-
if ! python -m json.tool "$file" > /dev/null 2>&1; then
42-
echo "❌ Invalid JSON syntax in $file"
43-
exit 1
66+
if [[ -f "$file" && "$file" != "templates/index.schema.json" ]]; then
67+
TOTAL_FILES=$((TOTAL_FILES + 1))
68+
if ! python -m json.tool "$file" > /dev/null 2>&1; then
69+
echo "❌ Invalid JSON syntax in $file"
70+
echo "::error file=$file::Invalid JSON syntax - file cannot be parsed"
71+
INVALID_FILES="$INVALID_FILES $file"
72+
fi
4473
fi
4574
done
46-
echo "βœ… All JSON files have valid syntax"
75+
76+
if [[ -n "$INVALID_FILES" ]]; then
77+
echo "::error title=JSON Syntax Errors::Found invalid JSON syntax in: $INVALID_FILES"
78+
exit 1
79+
else
80+
echo "βœ… All $TOTAL_FILES JSON files have valid syntax"
81+
echo "::notice title=JSON Validation::All $TOTAL_FILES template files have valid JSON syntax"
82+
fi
4783
4884
- name: Check file sizes
85+
id: size-check
4986
run: |
50-
echo "Checking file sizes..."
87+
echo "πŸ” Checking file sizes for optimization opportunities..."
5188
LARGE_FILES=0
89+
VERY_LARGE_FILES=""
90+
TOTAL_SIZE=0
91+
5292
for file in templates/*; do
5393
if [ -f "$file" ]; then
5494
SIZE=$(stat -c%s "$file" 2>/dev/null || stat -f%z "$file" 2>/dev/null)
95+
TOTAL_SIZE=$((TOTAL_SIZE + SIZE))
5596
SIZE_MB=$((SIZE / 1048576))
56-
if [ "$SIZE_MB" -gt 5 ]; then
57-
echo "⚠️ Warning: $file is larger than 5MB (${SIZE_MB}MB)"
97+
98+
if [ "$SIZE_MB" -gt 10 ]; then
99+
echo "⚠️ Very large file: $file is ${SIZE_MB}MB"
100+
echo "::warning file=$file,title=Very Large File::File is ${SIZE_MB}MB - consider compression"
101+
VERY_LARGE_FILES="$VERY_LARGE_FILES $file"
102+
LARGE_FILES=$((LARGE_FILES + 1))
103+
elif [ "$SIZE_MB" -gt 5 ]; then
104+
echo "⚠️ Large file: $file is ${SIZE_MB}MB"
105+
echo "::warning file=$file,title=Large File::File is ${SIZE_MB}MB - consider compression"
58106
LARGE_FILES=$((LARGE_FILES + 1))
59107
fi
60108
fi
61109
done
110+
111+
TOTAL_SIZE_MB=$((TOTAL_SIZE / 1048576))
112+
echo "πŸ“Š Total templates size: ${TOTAL_SIZE_MB}MB"
113+
62114
if [ "$LARGE_FILES" -gt 0 ]; then
63-
echo "Found $LARGE_FILES large files. Consider compressing thumbnails."
115+
echo "::notice title=File Size Check::Found $LARGE_FILES files >5MB (total: ${TOTAL_SIZE_MB}MB). Consider optimizing large files."
116+
else
117+
echo "::notice title=File Size Check::All files are optimally sized (total: ${TOTAL_SIZE_MB}MB)"
64118
fi
65119
66120
- name: Check for third-party nodes
@@ -176,4 +230,35 @@ jobs:
176230
owner: context.repo.owner,
177231
repo: context.repo.repo,
178232
body: comment
179-
});
233+
});
234+
235+
- name: Validation Summary
236+
if: always()
237+
run: |
238+
echo "πŸ“Š Template Validation Summary"
239+
echo "============================="
240+
241+
# Collect status from all steps
242+
VALIDATION_STATUS="${{ steps.validation.outputs.validation_status || 'not-run' }}"
243+
THIRD_PARTY_FOUND="${{ steps.third_party_check.outputs.third_party_found || 'false' }}"
244+
THUMBNAIL_ISSUES="${{ steps.thumbnail_check.outputs.thumbnail_issues || 'false' }}"
245+
246+
echo "πŸ” Schema & Structure Validation: $VALIDATION_STATUS"
247+
echo "πŸ“„ JSON Syntax Check: $([ '${{ steps.json-check.outcome }}' = 'success' ] && echo 'passed' || echo 'failed')"
248+
echo "πŸ“ File Size Check: $([ '${{ steps.size-check.outcome }}' = 'success' ] && echo 'completed' || echo 'failed')"
249+
echo "πŸ”§ Third-party Nodes: $([ '$THIRD_PARTY_FOUND' = 'true' ] && echo 'found (warning)' || echo 'clean')"
250+
echo "πŸ–ΌοΈ Thumbnail Validation: $([ '$THUMBNAIL_ISSUES' = 'true' ] && echo 'issues found' || echo 'passed')"
251+
252+
# Overall status
253+
if [ "$VALIDATION_STATUS" = "passed" ] && [ "${{ steps.json-check.outcome }}" = "success" ]; then
254+
if [ "$THIRD_PARTY_FOUND" = "true" ] || [ "$THUMBNAIL_ISSUES" = "true" ]; then
255+
echo "::warning title=Validation Complete::βœ… Core validation passed with warnings"
256+
echo "🟑 Overall Status: PASSED WITH WARNINGS"
257+
else
258+
echo "::notice title=Validation Complete::βœ… All validations passed successfully"
259+
echo "🟒 Overall Status: ALL CHECKS PASSED"
260+
fi
261+
else
262+
echo "::error title=Validation Complete::❌ Validation failed - issues must be resolved"
263+
echo "πŸ”΄ Overall Status: FAILED"
264+
fi

0 commit comments

Comments
Β (0)