Skip to content

Commit e9ca96c

Browse files
committed
workflows: Add static linter
Again, vibe generated using Cursor AI. :-) Signed-off-by: Fabiano Fidêncio <ffidencio@nvidia.com>
1 parent 5a7d460 commit e9ca96c

File tree

1 file changed

+165
-0
lines changed

1 file changed

+165
-0
lines changed

.github/workflows/static-lint.yaml

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
name: Static Lint
2+
3+
on:
4+
pull_request:
5+
types:
6+
- edited
7+
- opened
8+
- reopened
9+
- synchronize
10+
11+
jobs:
12+
yaml-lint:
13+
name: YAML Lint
14+
runs-on: ubuntu-22.04
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: '3.x'
23+
24+
- name: Install yamllint
25+
run: pip install yamllint
26+
27+
- name: Create yamllint config
28+
run: |
29+
cat > .yamllint.yaml << 'EOF'
30+
extends: default
31+
rules:
32+
line-length:
33+
max: 120
34+
level: warning
35+
comments:
36+
min-spaces-from-content: 1
37+
indentation:
38+
spaces: 2
39+
indent-sequences: true
40+
document-start: disable
41+
truthy:
42+
allowed-values: ['true', 'false', 'on', 'off']
43+
ignore: |
44+
node_modules/
45+
.github/
46+
charts/
47+
EOF
48+
49+
- name: Run yamllint
50+
id: yamllint
51+
continue-on-error: true
52+
run: |
53+
echo "🔍 Running yamllint..."
54+
yamllint . > /tmp/yamllint-output.txt 2>&1 || true
55+
56+
if [ -s /tmp/yamllint-output.txt ]; then
57+
echo "result=found_issues" >> $GITHUB_OUTPUT
58+
cat /tmp/yamllint-output.txt
59+
echo "::error::YAML lint issues found. See job output for details."
60+
else
61+
echo "✅ No YAML lint issues found"
62+
echo "result=success" >> $GITHUB_OUTPUT
63+
fi
64+
65+
- name: Show YAML lint summary
66+
if: always()
67+
run: |
68+
if [ "${{ steps.yamllint.outputs.result }}" = "found_issues" ]; then
69+
echo "## ⚠️ YAML Lint Issues Found" >> $GITHUB_STEP_SUMMARY
70+
echo "" >> $GITHUB_STEP_SUMMARY
71+
echo '```' >> $GITHUB_STEP_SUMMARY
72+
cat /tmp/yamllint-output.txt >> $GITHUB_STEP_SUMMARY
73+
echo '```' >> $GITHUB_STEP_SUMMARY
74+
echo "" >> $GITHUB_STEP_SUMMARY
75+
echo "### How to Fix:" >> $GITHUB_STEP_SUMMARY
76+
echo "1. Install yamllint: \`pip install yamllint\`" >> $GITHUB_STEP_SUMMARY
77+
echo "2. Run \`yamllint .\` to see all issues" >> $GITHUB_STEP_SUMMARY
78+
echo "3. Common issues:" >> $GITHUB_STEP_SUMMARY
79+
echo " - Indentation errors (use 2 spaces)" >> $GITHUB_STEP_SUMMARY
80+
echo " - Line too long (max 120 characters)" >> $GITHUB_STEP_SUMMARY
81+
echo " - Trailing spaces" >> $GITHUB_STEP_SUMMARY
82+
echo " - Missing spaces after colons" >> $GITHUB_STEP_SUMMARY
83+
echo "4. Modify .yamllint.yaml to adjust rules if needed" >> $GITHUB_STEP_SUMMARY
84+
else
85+
echo "## ✅ YAML Lint Passed" >> $GITHUB_STEP_SUMMARY
86+
fi
87+
88+
- name: Fail if YAML lint found issues
89+
if: steps.yamllint.outputs.result == 'found_issues'
90+
run: |
91+
echo "=========================================="
92+
echo "❌ YAML Lint FAILED"
93+
echo "=========================================="
94+
echo ""
95+
echo "Issues found in YAML files:"
96+
echo ""
97+
cat /tmp/yamllint-output.txt
98+
echo ""
99+
echo "=========================================="
100+
echo "How to fix:"
101+
echo " 1. Review the errors listed above"
102+
echo " 2. Run 'yamllint .' locally to see all issues"
103+
echo " 3. Fix the reported problems"
104+
echo "=========================================="
105+
exit 1
106+
107+
action-lint:
108+
name: GitHub Actions Lint
109+
runs-on: ubuntu-22.04
110+
steps:
111+
- name: Checkout code
112+
uses: actions/checkout@v4
113+
114+
- name: Run actionlint
115+
uses: reviewdog/action-actionlint@v1
116+
with:
117+
fail_on_error: false
118+
reporter: github-check
119+
continue-on-error: true
120+
id: actionlint
121+
122+
- name: Show GitHub Actions lint summary
123+
if: always()
124+
run: |
125+
if [ "${{ steps.actionlint.outcome }}" = "failure" ]; then
126+
echo "## ⚠️ GitHub Actions Workflow Issues Found" >> $GITHUB_STEP_SUMMARY
127+
echo "" >> $GITHUB_STEP_SUMMARY
128+
echo "### How to Fix:" >> $GITHUB_STEP_SUMMARY
129+
echo "1. Install actionlint:" >> $GITHUB_STEP_SUMMARY
130+
echo " \`\`\`bash" >> $GITHUB_STEP_SUMMARY
131+
echo " go install github.com/rhysd/actionlint/cmd/actionlint@latest" >> $GITHUB_STEP_SUMMARY
132+
echo " # or" >> $GITHUB_STEP_SUMMARY
133+
echo " brew install actionlint" >> $GITHUB_STEP_SUMMARY
134+
echo " \`\`\`" >> $GITHUB_STEP_SUMMARY
135+
echo "2. Run \`actionlint\` in your repo root" >> $GITHUB_STEP_SUMMARY
136+
echo "3. Common issues:" >> $GITHUB_STEP_SUMMARY
137+
echo " - Invalid workflow syntax" >> $GITHUB_STEP_SUMMARY
138+
echo " - Undefined environment variables" >> $GITHUB_STEP_SUMMARY
139+
echo " - Deprecated actions or syntax" >> $GITHUB_STEP_SUMMARY
140+
echo " - Invalid shell commands in run steps" >> $GITHUB_STEP_SUMMARY
141+
echo "4. See https://github.com/rhysd/actionlint for details" >> $GITHUB_STEP_SUMMARY
142+
else
143+
echo "## ✅ GitHub Actions Lint Passed" >> $GITHUB_STEP_SUMMARY
144+
fi
145+
146+
- name: Fail if actionlint found issues
147+
if: steps.actionlint.outcome == 'failure'
148+
run: |
149+
echo "=========================================="
150+
echo "❌ GitHub Actions Lint FAILED"
151+
echo "=========================================="
152+
echo ""
153+
echo "Issues found in workflow files (.github/workflows/*.yaml)"
154+
echo ""
155+
echo "Please check the actionlint output above for specific errors."
156+
echo "The errors are annotated directly on the workflow files."
157+
echo ""
158+
echo "=========================================="
159+
echo "How to fix:"
160+
echo " 1. Look at the annotations in the 'Files changed' tab"
161+
echo " 2. Run 'actionlint' locally to see all issues"
162+
echo " 3. Fix the reported workflow syntax/logic errors"
163+
echo "=========================================="
164+
exit 1
165+

0 commit comments

Comments
 (0)