-
Notifications
You must be signed in to change notification settings - Fork 3
307 lines (283 loc) · 11.3 KB
/
Copy pathstatic-checks.yml
File metadata and controls
307 lines (283 loc) · 11.3 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
name: Static Checks
on:
pull_request:
push:
branches:
- main
permissions:
contents: read
concurrency:
group: static-checks-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
changes:
name: Detect affected surfaces
runs-on: ubuntu-24.04
timeout-minutes: 5
outputs:
base_sha: ${{ steps.scope.outputs.base_sha }}
code: ${{ steps.scope.outputs.code }}
global_code: ${{ steps.scope.outputs.global_code }}
head_sha: ${{ steps.scope.outputs.head_sha }}
knip_browser_driver: ${{ steps.scope.outputs.knip_browser_driver }}
knip_skill_runtime: ${{ steps.scope.outputs.knip_skill_runtime }}
nonworkspace_code: ${{ steps.scope.outputs.nonworkspace_code }}
root_code: ${{ steps.scope.outputs.root_code }}
skills: ${{ steps.scope.outputs.skills }}
workflow: ${{ steps.scope.outputs.workflow }}
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
with:
fetch-depth: 0
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
- name: Validate pull request title
if: github.event_name == 'pull_request'
env:
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
python3 - <<'PY'
import os
import re
author = os.environ["PR_AUTHOR"]
title = os.environ["PR_TITLE"]
pattern = re.compile(
r"(?:build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)"
r"(?:\([a-z0-9][a-z0-9._/-]*\))?!?: \S.*"
)
if pattern.fullmatch(title) is None:
raise SystemExit("Pull request titles must use Conventional Commits.")
# Dependabot titles are machine-generated from group/directory names, grow past 72 chars, and are not configurable; commitlint's own ceiling is 100.
if len(title) > 72 and author != "dependabot[bot]":
raise SystemExit("Pull request titles must be at most 72 characters.")
PY
- name: Classify changed files
id: scope
env:
EVENT_NAME: ${{ github.event_name }}
EVENT_BEFORE_SHA: ${{ github.event.before }}
EVENT_HEAD_SHA: ${{ github.sha }}
PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
set -Eeuo pipefail
if [ "$EVENT_NAME" = "pull_request" ]; then
base_sha="$PR_BASE_SHA"
head_sha="$PR_HEAD_SHA"
else
base_sha="$EVENT_BEFORE_SHA"
head_sha="$EVENT_HEAD_SHA"
fi
force_global=false
if [[ ! "$base_sha" =~ ^[0-9a-f]{40}$ ]] ||
[ "$base_sha" = "0000000000000000000000000000000000000000" ]; then
if parent_sha="$(git rev-parse "$head_sha^" 2>/dev/null)"; then
base_sha="$parent_sha"
else
base_sha="$head_sha"
force_global=true
fi
fi
code="$force_global"
global_code="$force_global"
nonworkspace_code="$force_global"
root_code="$force_global"
skills=false
workflow=false
knip_browser_driver=false
knip_skill_runtime=false
while IFS= read -r -d '' file; do
case "$file" in
.github/actions/* | .github/workflows/*)
workflow=true
;;
apps/* | packages/*)
if [[ "$file" != *.md ]]; then code=true; fi
;;
skills/*)
code=true
nonworkspace_code=true
skills=true
;;
scripts/*.ts)
code=true
nonworkspace_code=true
root_code=true
;;
.dependency-cruiser.cjs | .npmrc | .nvmrc | biome.jsonc | knip.jsonc | package.json | pnpm-lock.yaml | pnpm-workspace.yaml | tsconfig.base.json | turbo.json)
code=true
global_code=true
nonworkspace_code=true
root_code=true
;;
commitlint.config.js | lefthook.yml | tsconfig.scripts.json)
code=true
nonworkspace_code=true
root_code=true
;;
infra/containers/sandbox/*.js | infra/containers/sandbox/*.json | infra/containers/sandbox/*.jsonc | infra/containers/sandbox/*.mjs | infra/containers/sandbox/*.ts | infra/containers/sandbox/*.tsx)
code=true
nonworkspace_code=true
;;
esac
case "$file" in
infra/containers/sandbox/browser-driver/*)
knip_browser_driver=true
;;
infra/containers/sandbox/skill-runtime/*)
knip_skill_runtime=true
;;
esac
done < <(git diff --name-only --diff-filter=ACMR -z "$base_sha" "$head_sha")
{
echo "base_sha=$base_sha"
echo "code=$code"
echo "global_code=$global_code"
echo "head_sha=$head_sha"
echo "knip_browser_driver=$knip_browser_driver"
echo "knip_skill_runtime=$knip_skill_runtime"
echo "nonworkspace_code=$nonworkspace_code"
echo "root_code=$root_code"
echo "skills=$skills"
echo "workflow=$workflow"
} >> "$GITHUB_OUTPUT"
workflow-lint:
name: Workflow lint
needs: changes
if: needs.changes.outputs.workflow == 'true'
runs-on: ubuntu-24.04
timeout-minutes: 10
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
- name: Lint GitHub Actions and embedded shell
uses: raven-actions/actionlint@3d39aea434753780c3b3d4a1a31c854b4dbf49d7 # v2.2.0
with:
pyflakes: false
shellcheck: true
version: 1.7.12
code-checks:
name: Affected code checks
needs: changes
if: needs.changes.outputs.code == 'true'
runs-on: ubuntu-24.04
timeout-minutes: 45
env:
BASE_SHA: ${{ needs.changes.outputs.base_sha }}
GLOBAL_CODE: ${{ needs.changes.outputs.global_code }}
HEAD_SHA: ${{ needs.changes.outputs.head_sha }}
SKILLS_CHANGED: ${{ needs.changes.outputs.skills }}
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
with:
fetch-depth: 0
ref: ${{ needs.changes.outputs.head_sha }}
- uses: ./.github/actions/setup-repository
- name: Resolve dependency-aware workspace scope
id: workspace-scope
run: |
set -Eeuo pipefail
filters=()
if [ "$GLOBAL_CODE" != true ]; then
filters+=("--filter=...[$BASE_SHA...$HEAD_SHA]")
if [ "$SKILLS_CHANGED" = true ]; then
filters+=("--filter=...@cheatcode/skills")
fi
fi
scope="$(pnpm exec turbo run build "${filters[@]}" --dry-run=json)"
echo "packages=$(jq --compact-output '[.packages[] | select(. != "//")] | unique' <<< "$scope")" >> "$GITHUB_OUTPUT"
echo "directories=$(jq --compact-output '[.tasks[].directory] | unique' <<< "$scope")" >> "$GITHUB_OUTPUT"
- name: Lint all files under a changed global configuration
if: needs.changes.outputs.global_code == 'true'
run: pnpm lint
- name: Lint changed non-workspace files
if: needs.changes.outputs.global_code != 'true' && needs.changes.outputs.nonworkspace_code == 'true'
run: |
set -Eeuo pipefail
lintable=()
while IFS= read -r -d '' file; do
case "$file" in
*.css | *.js | *.json | *.jsonc | *.jsx | *.mjs | *.ts | *.tsx)
lintable+=("$file")
;;
esac
done < <(git diff --name-only --diff-filter=ACMR -z "$BASE_SHA" "$HEAD_SHA")
if [ "${#lintable[@]}" -gt 0 ]; then
pnpm exec biome check --error-on-warnings --no-errors-on-unmatched "${lintable[@]}"
fi
- name: Lint, typecheck, and build affected workspaces
if: steps.workspace-scope.outputs.packages != '[]'
env:
CLERK_SECRET_KEY: sk_test_static_checks_do_not_authenticate
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: pk_test_c3RhdGljLWNoZWNrcy0wMC5jbGVyay5hY2NvdW50cy5kZXYk
NEXT_PUBLIC_GATEWAY_URL: ${{ vars.NEXT_PUBLIC_GATEWAY_URL }}
VERCEL_GIT_COMMIT_SHA: ${{ github.sha }}
run: |
set -Eeuo pipefail
filters=()
if [ "$GLOBAL_CODE" != true ]; then
filters+=("--filter=...[$BASE_SHA...$HEAD_SHA]")
if [ "$SKILLS_CHANGED" = true ]; then
filters+=("--filter=...@cheatcode/skills")
fi
fi
pnpm exec turbo run lint typecheck build "${filters[@]}"
- name: Typecheck operational scripts
if: needs.changes.outputs.root_code == 'true'
run: pnpm typecheck:scripts
- name: Check affected architecture boundaries
if: steps.workspace-scope.outputs.directories != '[]'
env:
DIRECTORIES: ${{ steps.workspace-scope.outputs.directories }}
run: |
set -Eeuo pipefail
mapfile -t directories < <(jq --raw-output '.[]' <<< "$DIRECTORIES")
pnpm exec dependency-cruise \
--config .dependency-cruiser.cjs \
--ts-config tsconfig.base.json \
--exclude '(^|/)(\.next|\.turbo|node_modules)/' \
"${directories[@]}"
- name: Check dead code
env:
KNIP_BROWSER_DRIVER: ${{ needs.changes.outputs.knip_browser_driver }}
KNIP_SKILL_RUNTIME: ${{ needs.changes.outputs.knip_skill_runtime }}
PACKAGES: ${{ steps.workspace-scope.outputs.packages }}
ROOT_CODE: ${{ needs.changes.outputs.root_code }}
run: |
set -Eeuo pipefail
if [ "$GLOBAL_CODE" = true ] || [ "$ROOT_CODE" = true ]; then
pnpm deadcode
exit 0
fi
workspaces=()
while IFS= read -r package; do
workspaces+=(--workspace "$package")
done < <(jq --raw-output '.[]' <<< "$PACKAGES")
if [ "$KNIP_BROWSER_DRIVER" = true ]; then
workspaces+=(--workspace @cheatcode/sandbox-browser-driver)
fi
if [ "$KNIP_SKILL_RUNTIME" = true ]; then
workspaces+=(--workspace @cheatcode/sandbox-skills-runtime)
fi
if [ "${#workspaces[@]}" -gt 0 ]; then
pnpm exec knip --cache "${workspaces[@]}"
fi
static-checks:
name: static-checks
needs: [changes, workflow-lint, code-checks]
if: always()
runs-on: ubuntu-24.04
timeout-minutes: 5
steps:
- name: Require every applicable check to pass
env:
CHANGES_RESULT: ${{ needs.changes.result }}
CODE_RESULT: ${{ needs.code-checks.result }}
WORKFLOW_LINT_RESULT: ${{ needs.workflow-lint.result }}
run: |
set -Eeuo pipefail
for result in "$CHANGES_RESULT" "$CODE_RESULT" "$WORKFLOW_LINT_RESULT"; do
case "$result" in
success | skipped) ;;
*) exit 1 ;;
esac
done