-
-
Notifications
You must be signed in to change notification settings - Fork 16
180 lines (160 loc) · 5.92 KB
/
Copy pathcode-quality.yml
File metadata and controls
180 lines (160 loc) · 5.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# SPDX-License-Identifier: Apache-2.0
name: Code Quality
on:
pull_request:
paths:
- 'charts/**'
- '**.md'
- 'scripts/**'
permissions:
contents: read
pull-requests: write
jobs:
markdown-lint:
name: Markdown Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Detect changed markdown files
id: detect
run: |
FILES=$(git diff --diff-filter=d --name-only origin/${{ github.base_ref }}...HEAD \
| grep '\.md$' || true)
if [ -z "$FILES" ]; then
echo "skip=true" >> $GITHUB_OUTPUT
else
echo "skip=false" >> $GITHUB_OUTPUT
# Write files to a temporary glob file for markdownlint-cli2
echo "$FILES" > /tmp/md-files.txt
fi
- name: Run markdownlint on changed files
if: steps.detect.outputs.skip != 'true'
run: |
npx -y markdownlint-cli2 $(cat /tmp/md-files.txt | tr '\n' ' ')
values-quality:
name: Values Quality
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Detect changed values files
id: detect
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep 'values\.yaml$' || true)
else
FILES=""
fi
echo "files<<EOF" >> $GITHUB_OUTPUT
echo "$FILES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: ASCII check
if: steps.detect.outputs.files != ''
run: |
FAIL=0
while IFS= read -r f; do
[ -z "$f" ] && continue
[ -f "$f" ] || continue
if LC_ALL=C grep -Pn '[^\x00-\x7F]' "$f"; then
echo "::error file=$f::Non-ASCII characters found in $f"
FAIL=1
fi
done <<< "${{ steps.detect.outputs.files }}"
exit $FAIL
- name: Floating tag check
if: steps.detect.outputs.files != ''
run: |
FAIL=0
while IFS= read -r f; do
[ -z "$f" ] && continue
[ -f "$f" ] || continue
# Skip commented lines; also match tags followed by inline comments
if grep -nE '^[^#]*tag:\s*["'"'"']?(latest|main|master|dev|nightly|edge|stable)["'"'"']?\s*(#.*)?$' "$f"; then
echo "::error file=$f::Floating image tag detected — pinned tags required (GR-004/GR-040)"
FAIL=1
fi
done <<< "${{ steps.detect.outputs.files }}"
exit $FAIL
- name: Schema presence check
if: steps.detect.outputs.files != ''
run: |
while IFS= read -r f; do
[ -z "$f" ] && continue
[ -f "$f" ] || continue
# Resolve to chart root (charts/<name>/) not ci/ or examples/ subdirectories
CHART_DIR=$(echo "$f" | sed -n 's|^\(charts/[^/]*\)/.*|\1|p')
[ -z "$CHART_DIR" ] && continue
if [ ! -f "$CHART_DIR/values.schema.json" ]; then
echo "::warning file=$f::Missing values.schema.json for $(basename $CHART_DIR)"
fi
done <<< "${{ steps.detect.outputs.files }}"
license-headers:
name: License Headers
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Check SPDX headers on changed files
id: check
run: |
FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD \
| grep -E '\.(yaml|tpl|sh)$' \
| grep -v 'node_modules' \
| grep -v '.github/' \
|| true)
MISSING=""
while IFS= read -r f; do
[ -z "$f" ] && continue
[ -f "$f" ] || continue
if ! head -5 "$f" | grep -q "SPDX-License-Identifier"; then
MISSING="$MISSING- \`$f\`\n"
fi
done <<< "$FILES"
if [ -n "$MISSING" ]; then
echo "missing<<EOF" >> $GITHUB_OUTPUT
printf '%b' "$MISSING" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "has_missing=true" >> $GITHUB_OUTPUT
fi
- name: Comment on PR
if: ${{ steps.check.outputs.has_missing == 'true' && !github.event.pull_request.head.repo.fork && github.actor != 'dependabot[bot]' }}
uses: actions/github-script@v9
env:
MISSING_FILES: ${{ steps.check.outputs.missing }}
with:
script: |
const missing = process.env.MISSING_FILES;
const body = `### ℹ️ Missing License Headers
The following changed files are missing SPDX license headers:
${missing}
Consider adding the following to the top of each file:
\`\`\`yaml
# SPDX-License-Identifier: Apache-2.0
\`\`\`
> This is informational only and does not block merge.`.replace(/^ /gm, '');
// Check for existing comment to avoid duplicates
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number
});
const existing = comments.find(c => c.body.includes('Missing License Headers'));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body: body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: body
});
}