codeveto 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. codeveto/__init__.py +3 -0
  2. codeveto/__main__.py +8 -0
  3. codeveto/ai/__init__.py +19 -0
  4. codeveto/ai/harness.py +303 -0
  5. codeveto/ai/packets.py +855 -0
  6. codeveto/ai/policy.py +222 -0
  7. codeveto/ai/prompt.py +101 -0
  8. codeveto/ai/providers/__init__.py +178 -0
  9. codeveto/ai/providers/claude.py +247 -0
  10. codeveto/ai/providers/openai_compat.py +246 -0
  11. codeveto/ai/runner.py +293 -0
  12. codeveto/ai/verify.py +324 -0
  13. codeveto/anchor.py +211 -0
  14. codeveto/cli.py +247 -0
  15. codeveto/cli_explain.py +49 -0
  16. codeveto/cli_hook.py +31 -0
  17. codeveto/cli_init.py +254 -0
  18. codeveto/cli_mcp.py +29 -0
  19. codeveto/cli_packets.py +35 -0
  20. codeveto/cli_publish.py +29 -0
  21. codeveto/cli_review.py +362 -0
  22. codeveto/cli_rules.py +78 -0
  23. codeveto/cli_verify.py +47 -0
  24. codeveto/config.py +1229 -0
  25. codeveto/data/README.md +16 -0
  26. codeveto/data/ai-wire.schema.json +53 -0
  27. codeveto/data/prompts/system.md +57 -0
  28. codeveto/data/report-v1.schema.json +268 -0
  29. codeveto/data/templates/forgejo-codeveto.yml +104 -0
  30. codeveto/data/templates/github-codeveto.yml +18 -0
  31. codeveto/embedded.py +311 -0
  32. codeveto/engine.py +1570 -0
  33. codeveto/git.py +1549 -0
  34. codeveto/globs.py +348 -0
  35. codeveto/integrations/__init__.py +1 -0
  36. codeveto/integrations/hooks.py +327 -0
  37. codeveto/integrations/mcp.py +770 -0
  38. codeveto/integrations/mcp_ai.py +77 -0
  39. codeveto/integrations/prepush.py +222 -0
  40. codeveto/jsonsafe.py +60 -0
  41. codeveto/languages.py +539 -0
  42. codeveto/lexers.py +2560 -0
  43. codeveto/model.py +372 -0
  44. codeveto/publish/__init__.py +28 -0
  45. codeveto/publish/action.py +330 -0
  46. codeveto/publish/common.py +84 -0
  47. codeveto/publish/diff.py +208 -0
  48. codeveto/publish/event.py +241 -0
  49. codeveto/publish/forgejo.py +184 -0
  50. codeveto/publish/github.py +380 -0
  51. codeveto/publish/http.py +263 -0
  52. codeveto/publish/pull.py +218 -0
  53. codeveto/publish/untrusted.py +110 -0
  54. codeveto/py.typed +0 -0
  55. codeveto/redact.py +113 -0
  56. codeveto/render/__init__.py +64 -0
  57. codeveto/render/agent.py +43 -0
  58. codeveto/render/github.py +101 -0
  59. codeveto/render/json.py +23 -0
  60. codeveto/render/markdown.py +208 -0
  61. codeveto/render/safe.py +249 -0
  62. codeveto/render/sarif.py +217 -0
  63. codeveto/render/text.py +210 -0
  64. codeveto/report.py +252 -0
  65. codeveto/rules/__init__.py +84 -0
  66. codeveto/rules/agent.py +2972 -0
  67. codeveto/rules/base.py +1026 -0
  68. codeveto/rules/ci.py +1708 -0
  69. codeveto/rules/config.py +493 -0
  70. codeveto/rules/deps.py +1693 -0
  71. codeveto/rules/docker.py +479 -0
  72. codeveto/rules/examples/__init__.py +148 -0
  73. codeveto/rules/examples/agent.py +839 -0
  74. codeveto/rules/examples/ci.py +1046 -0
  75. codeveto/rules/examples/config.py +191 -0
  76. codeveto/rules/examples/deps.py +369 -0
  77. codeveto/rules/examples/docker.py +157 -0
  78. codeveto/rules/examples/go.py +241 -0
  79. codeveto/rules/examples/hygiene.py +466 -0
  80. codeveto/rules/examples/js.py +462 -0
  81. codeveto/rules/examples/python.py +595 -0
  82. codeveto/rules/examples/rust.py +268 -0
  83. codeveto/rules/examples/secrets.py +561 -0
  84. codeveto/rules/examples/security.py +608 -0
  85. codeveto/rules/examples/shell.py +174 -0
  86. codeveto/rules/examples/sql.py +194 -0
  87. codeveto/rules/examples/tests.py +497 -0
  88. codeveto/rules/go.py +328 -0
  89. codeveto/rules/hygiene.py +1094 -0
  90. codeveto/rules/js.py +768 -0
  91. codeveto/rules/python.py +1642 -0
  92. codeveto/rules/rust.py +209 -0
  93. codeveto/rules/secrets.py +1335 -0
  94. codeveto/rules/security.py +3680 -0
  95. codeveto/rules/shell.py +867 -0
  96. codeveto/rules/sql.py +629 -0
  97. codeveto/rules/tests.py +1404 -0
  98. codeveto/schema.py +384 -0
  99. codeveto/statements.py +607 -0
  100. codeveto/worktree.py +1176 -0
  101. codeveto/yamlish.py +1179 -0
  102. codeveto-0.1.0.dist-info/METADATA +253 -0
  103. codeveto-0.1.0.dist-info/RECORD +106 -0
  104. codeveto-0.1.0.dist-info/WHEEL +4 -0
  105. codeveto-0.1.0.dist-info/entry_points.txt +2 -0
  106. codeveto-0.1.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,1046 @@
1
+ """Examples for the ci pack."""
2
+
3
+ from codeveto.rules.base import Change, Example, bad, good
4
+
5
+ SHA = "08eba0b27e820071cde6df949e0beb9ba4906955"
6
+ CHECKOUT = f"actions/checkout@{SHA}"
7
+ WF = ".github/workflows/ci.yml"
8
+
9
+ PRT_HEAD = f"""on: pull_request_target
10
+ permissions:
11
+ contents: read
12
+ jobs:
13
+ test:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: {CHECKOUT}
17
+ with:
18
+ ref: ${{{{ github.event.pull_request.head.sha }}}} # expect
19
+ persist-credentials: false
20
+ - run: npm ci && npm test
21
+ """
22
+
23
+ PUSH_HEADER = """on:
24
+ push:
25
+ branches: [main]
26
+ permissions:
27
+ contents: read
28
+ jobs:
29
+ build:
30
+ runs-on: ubuntu-latest
31
+ steps:
32
+ """
33
+
34
+ EXAMPLES = {
35
+ "ci/untrusted-checkout": [
36
+ bad(WF, PRT_HEAD, note="The PR head runs with the base repository's secrets."),
37
+ bad(
38
+ ".github/workflows/ok-to-test.yml",
39
+ """on:
40
+ pull_request_target:
41
+ types: [labeled]
42
+ permissions:
43
+ contents: read
44
+ jobs:
45
+ e2e:
46
+ runs-on: ubuntu-latest
47
+ steps:
48
+ - run: |
49
+ gh pr checkout ${{ github.event.pull_request.number }} # expect
50
+ make e2e
51
+ env:
52
+ GH_TOKEN: ${{ github.token }}
53
+ """,
54
+ note="gh pr checkout in a run step, then a build in the same script.",
55
+ ),
56
+ bad(
57
+ ".github/workflows/size.yml",
58
+ f"""on: pull_request_target
59
+ permissions:
60
+ contents: read
61
+ jobs:
62
+ size:
63
+ runs-on: ubuntu-latest
64
+ steps:
65
+ - uses: {CHECKOUT}
66
+ with:
67
+ persist-credentials: false
68
+ - uses: {CHECKOUT}
69
+ with:
70
+ ref: ${{{{ github.event.pull_request.head.sha }}}} # expect
71
+ path: pr
72
+ persist-credentials: false
73
+ - run: du -sh dist
74
+ """,
75
+ note="Head checked out only as data into pr/: reported as a warning.",
76
+ ),
77
+ good(
78
+ WF,
79
+ PRT_HEAD.replace("pull_request_target", "pull_request").replace(" # expect", ""),
80
+ note="pull_request runs fork code without secrets.",
81
+ ),
82
+ good(
83
+ WF,
84
+ PRT_HEAD.replace(
85
+ " runs-on: ubuntu-latest\n",
86
+ " if: github.event.pull_request.head.repo.full_name == github.repository\n"
87
+ " runs-on: ubuntu-latest\n",
88
+ ).replace(" # expect", ""),
89
+ note="Only same-repository pull requests reach the job.",
90
+ ),
91
+ good(
92
+ ".github/workflows/label.yml",
93
+ f"""on: pull_request_target
94
+ permissions:
95
+ contents: read
96
+ pull-requests: write
97
+ jobs:
98
+ label:
99
+ runs-on: ubuntu-latest
100
+ steps:
101
+ - uses: {CHECKOUT}
102
+ with:
103
+ persist-credentials: false
104
+ - run: ./scripts/label.sh "${{{{ github.event.pull_request.number }}}}"
105
+ """,
106
+ note="The base branch is checked out, not the head.",
107
+ ),
108
+ bad(
109
+ ".github/workflows/ok-to-test.yml",
110
+ f"""on:
111
+ issue_comment:
112
+ types: [created]
113
+ permissions:
114
+ contents: read
115
+ jobs:
116
+ test:
117
+ if: github.event.issue.pull_request && github.event.comment.body == '/test'
118
+ runs-on: ubuntu-latest
119
+ steps:
120
+ - uses: {CHECKOUT}
121
+ with:
122
+ ref: refs/pull/${{{{ github.event.issue.number }}}}/head # expect
123
+ persist-credentials: false
124
+ - run: make test
125
+ """,
126
+ note="A PR comment runs in the base context; the comment gate does not vet the code.",
127
+ ),
128
+ bad(
129
+ ".github/workflows/benchmark.yml",
130
+ f"""on: issue_comment
131
+ permissions:
132
+ contents: read
133
+ jobs:
134
+ bench:
135
+ runs-on: ubuntu-latest
136
+ steps:
137
+ - id: pr
138
+ uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
139
+ with:
140
+ script: |
141
+ const {{ data }} = await github.rest.pulls.get({{
142
+ ...context.repo, pull_number: context.issue.number }})
143
+ core.setOutput('head_sha', data.head.sha)
144
+ - uses: {CHECKOUT}
145
+ with:
146
+ ref: ${{{{ steps.pr.outputs.head_sha }}}} # expect
147
+ persist-credentials: false
148
+ - uses: ./.github/actions/bench
149
+ """,
150
+ note="The head SHA read from the pull request API.",
151
+ ),
152
+ good(
153
+ ".github/workflows/ok-to-test.yml",
154
+ f"""on: issue_comment
155
+ permissions:
156
+ contents: read
157
+ jobs:
158
+ docs:
159
+ runs-on: ubuntu-latest
160
+ steps:
161
+ - uses: {CHECKOUT}
162
+ with:
163
+ persist-credentials: false
164
+ - run: make docs
165
+ """,
166
+ note="An issue_comment job that runs the base branch only.",
167
+ ),
168
+ ],
169
+ "ci/script-injection": [
170
+ bad(
171
+ ".github/workflows/triage.yml",
172
+ """on:
173
+ issues:
174
+ types: [opened]
175
+ permissions:
176
+ issues: write
177
+ jobs:
178
+ triage:
179
+ runs-on: ubuntu-latest
180
+ steps:
181
+ - run: echo "New issue - ${{ github.event.issue.title }}" # expect
182
+ """,
183
+ ),
184
+ bad(
185
+ ".github/workflows/comment.yml",
186
+ """on: issue_comment
187
+ permissions:
188
+ issues: write
189
+ jobs:
190
+ reply:
191
+ runs-on: ubuntu-latest
192
+ steps:
193
+ - uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
194
+ with:
195
+ script: |
196
+ const body = `${{ github.event.comment.body }}` # expect
197
+ core.info(body)
198
+ """,
199
+ note="github-script evaluates the expanded text as JavaScript.",
200
+ ),
201
+ bad(
202
+ ".github/workflows/branch.yml",
203
+ """on: pull_request
204
+ permissions:
205
+ contents: read
206
+ jobs:
207
+ meta:
208
+ runs-on: ubuntu-latest
209
+ steps:
210
+ - env:
211
+ BRANCH: ${{ github.head_ref }}
212
+ run: |
213
+ echo "Building $BRANCH"
214
+ echo "branch=$BRANCH" >> "$GITHUB_ENV" # expect
215
+ """,
216
+ note="A newline in the branch name would set any variable for later steps.",
217
+ ),
218
+ bad(
219
+ ".github/workflows/notes.yml",
220
+ """on: pull_request
221
+ permissions:
222
+ contents: read
223
+ jobs:
224
+ notes:
225
+ runs-on: ubuntu-latest
226
+ steps:
227
+ - run: |
228
+ title='${{ github.event['pull_request']['title'] }}' # expect
229
+ echo "$title" > notes.txt
230
+ """,
231
+ note="Bracket syntax and single quotes do not help: expansion is textual.",
232
+ ),
233
+ good(
234
+ ".github/workflows/triage.yml",
235
+ """on:
236
+ issues:
237
+ types: [opened]
238
+ permissions:
239
+ issues: write
240
+ jobs:
241
+ triage:
242
+ runs-on: ubuntu-latest
243
+ steps:
244
+ - env:
245
+ TITLE: ${{ github.event.issue.title }}
246
+ run: echo "New issue - $TITLE"
247
+ """,
248
+ note="The title reaches the shell as data through env.",
249
+ ),
250
+ good(
251
+ ".github/workflows/bugs.yml",
252
+ """on:
253
+ issues:
254
+ types: [opened]
255
+ permissions:
256
+ issues: write
257
+ jobs:
258
+ label:
259
+ if: contains(github.event.issue.title, 'bug')
260
+ runs-on: ubuntu-latest
261
+ steps:
262
+ - run: |
263
+ echo "is bug: ${{ contains(github.event.issue.title, 'bug') }}"
264
+ gh issue edit ${{ github.event.issue.number }} --add-label bug
265
+ env:
266
+ GH_TOKEN: ${{ github.token }}
267
+ """,
268
+ note="A boolean and a number are not attacker text.",
269
+ ),
270
+ good(
271
+ ".github/workflows/env.yml",
272
+ """on: pull_request
273
+ permissions:
274
+ contents: read
275
+ jobs:
276
+ meta:
277
+ runs-on: ubuntu-latest
278
+ steps:
279
+ - env:
280
+ TITLE: ${{ github.event.pull_request.title }}
281
+ run: |
282
+ cat <<'EOF' >> "$GITHUB_ENV"
283
+ PR_TITLE_VAR=$TITLE
284
+ EOF
285
+ echo "sha=${{ github.sha }}" >> "$GITHUB_OUTPUT"
286
+ """,
287
+ note="A quoted heredoc writes the literal text; github.sha is trusted.",
288
+ ),
289
+ ],
290
+ "ci/untrusted-artifact": [
291
+ bad(
292
+ ".github/workflows/report.yml",
293
+ """on:
294
+ workflow_run:
295
+ workflows: [ci]
296
+ types: [completed]
297
+ permissions:
298
+ contents: read
299
+ pull-requests: write
300
+ jobs:
301
+ report:
302
+ runs-on: ubuntu-latest
303
+ steps:
304
+ - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 # expect
305
+ with:
306
+ run-id: ${{ github.event.workflow_run.id }}
307
+ github-token: ${{ github.token }}
308
+ - run: ./post-report.sh
309
+ """,
310
+ ),
311
+ bad(
312
+ ".github/workflows/deploy-preview.yml",
313
+ """on:
314
+ workflow_run:
315
+ workflows: [build]
316
+ types: [completed]
317
+ permissions:
318
+ contents: read
319
+ jobs:
320
+ deploy:
321
+ runs-on: ubuntu-latest
322
+ steps:
323
+ - uses: dawidd6/action-download-artifact@ac66b43f0e6a346234dd65d4d0c8fbb31cb316e5 # expect
324
+ with:
325
+ workflow: build.yml
326
+ path: .
327
+ - uses: ./.github/actions/deploy
328
+ """,
329
+ ),
330
+ good(
331
+ ".github/workflows/report.yml",
332
+ """on:
333
+ workflow_run:
334
+ workflows: [ci]
335
+ types: [completed]
336
+ permissions:
337
+ contents: read
338
+ jobs:
339
+ report:
340
+ runs-on: ubuntu-latest
341
+ steps:
342
+ - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
343
+ with:
344
+ run-id: ${{ github.event.workflow_run.id }}
345
+ github-token: ${{ github.token }}
346
+ path: ${{ runner.temp }}/report
347
+ - run: jq . "$RUNNER_TEMP/report/summary.json"
348
+ """,
349
+ note="Downloaded into a dedicated directory and read as data.",
350
+ ),
351
+ good(
352
+ ".github/workflows/release.yml",
353
+ """on:
354
+ push:
355
+ tags: ["v*"]
356
+ permissions:
357
+ contents: read
358
+ jobs:
359
+ publish:
360
+ runs-on: ubuntu-latest
361
+ steps:
362
+ - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
363
+ - run: ls dist
364
+ """,
365
+ note="Artifacts of the same, trusted run.",
366
+ ),
367
+ ],
368
+ "ci/write-all-permissions": [
369
+ bad(
370
+ WF,
371
+ """on: push
372
+ permissions: write-all # expect
373
+ jobs:
374
+ build:
375
+ runs-on: ubuntu-latest
376
+ steps:
377
+ - run: make
378
+ """,
379
+ ),
380
+ bad(
381
+ WF,
382
+ """on: push
383
+ permissions:
384
+ contents: read
385
+ jobs:
386
+ release:
387
+ runs-on: ubuntu-latest
388
+ permissions: write-all # expect
389
+ steps:
390
+ - run: make release
391
+ """,
392
+ note="Job-level grants count too.",
393
+ ),
394
+ good(
395
+ WF,
396
+ """on: push
397
+ permissions: read-all
398
+ jobs:
399
+ release:
400
+ runs-on: ubuntu-latest
401
+ permissions:
402
+ contents: write
403
+ steps:
404
+ - run: make release
405
+ """,
406
+ ),
407
+ good(
408
+ WF,
409
+ """on: push
410
+ # permissions: write-all was too broad
411
+ permissions:
412
+ contents: read
413
+ jobs:
414
+ build:
415
+ runs-on: ubuntu-latest
416
+ steps:
417
+ - run: 'echo "permissions: write-all"'
418
+ """,
419
+ note="Comments and script text are not settings.",
420
+ ),
421
+ ],
422
+ "ci/secret-echo": [
423
+ bad(
424
+ ".github/workflows/deploy.yml",
425
+ """on: push
426
+ permissions:
427
+ contents: read
428
+ jobs:
429
+ deploy:
430
+ runs-on: ubuntu-latest
431
+ steps:
432
+ - run: |
433
+ echo "Deploying with ${{ secrets.DEPLOY_KEY }}" # expect
434
+ ./deploy.sh
435
+ """,
436
+ ),
437
+ bad(
438
+ ".github/workflows/debug.yml",
439
+ """on: workflow_dispatch
440
+ permissions:
441
+ contents: read
442
+ jobs:
443
+ debug:
444
+ runs-on: ubuntu-latest
445
+ env:
446
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
447
+ steps:
448
+ - run: echo "$NPM_TOKEN" | base64 # expect
449
+ """,
450
+ note="Encoding the secret defeats log masking.",
451
+ ),
452
+ good(
453
+ ".github/workflows/deploy.yml",
454
+ """on: push
455
+ permissions:
456
+ contents: read
457
+ jobs:
458
+ deploy:
459
+ runs-on: ubuntu-latest
460
+ steps:
461
+ - env:
462
+ REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
463
+ run: |
464
+ echo "::add-mask::$REGISTRY_TOKEN"
465
+ echo "$REGISTRY_TOKEN" | docker login ghcr.io -u bot --password-stdin
466
+ printf '%s' "$REGISTRY_TOKEN" > "$RUNNER_TEMP/token"
467
+ """,
468
+ note="Piped into a consumer or written to a file, not printed.",
469
+ ),
470
+ good(
471
+ ".github/workflows/check.yml",
472
+ """on: push
473
+ permissions:
474
+ contents: read
475
+ jobs:
476
+ check:
477
+ runs-on: ubuntu-latest
478
+ steps:
479
+ - run: |
480
+ echo "has key: ${{ secrets.DEPLOY_KEY != '' }}"
481
+ echo 'Use $DEPLOY_KEY from the environment'
482
+ """,
483
+ note="A comparison is a boolean; single quotes are literal.",
484
+ ),
485
+ ],
486
+ "ci/curl-pipe-shell": [
487
+ bad(
488
+ WF,
489
+ PUSH_HEADER + " - run: curl -fsSL http://get.example.com/i.sh | sh # expect\n",
490
+ note="Plain http: an error.",
491
+ ),
492
+ bad(
493
+ WF,
494
+ PUSH_HEADER + " - run: curl -fsSL https://sh.rustup.rs | bash -s # expect\n",
495
+ note="https from a fixed host: a warning.",
496
+ ),
497
+ bad(
498
+ WF,
499
+ PUSH_HEADER
500
+ + " - run: |\n"
501
+ + ' sh -c "$(curl -fsSL https://get.example.com/setup.sh)" # expect\n',
502
+ ),
503
+ bad(
504
+ WF,
505
+ PUSH_HEADER
506
+ + " - env:\n INSTALLER: ${{ vars.INSTALLER_URL }}\n"
507
+ + ' run: wget -qO- "$INSTALLER" | sudo bash # expect\n',
508
+ note="A variable URL run as root.",
509
+ ),
510
+ good(
511
+ WF,
512
+ PUSH_HEADER
513
+ + " - run: |\n"
514
+ + " curl -fsSLo install.sh https://get.example.com/install.sh\n"
515
+ + ' echo "$INSTALL_SHA256 install.sh" | sha256sum -c -\n'
516
+ + " sh install.sh\n",
517
+ note="Downloaded, verified, then run.",
518
+ ),
519
+ good(
520
+ WF,
521
+ PUSH_HEADER
522
+ + " - run: |\n"
523
+ + " curl -fsS https://api.example.com/v1/status | jq -r .state\n"
524
+ + " curl -fsS https://api.example.com/v1/build | python3 -c 'import json,sys; "
525
+ + "print(json.load(sys.stdin))'\n"
526
+ + " # curl https://example.com/x | sh\n",
527
+ note="The download is data for jq and inline Python; a comment is not a command.",
528
+ ),
529
+ ],
530
+ "ci/unpinned-action": [
531
+ bad(
532
+ WF,
533
+ PUSH_HEADER + " - uses: actions/checkout@v4 # expect\n",
534
+ note="First-party actions count too.",
535
+ ),
536
+ bad(
537
+ WF,
538
+ """on: push
539
+ permissions:
540
+ contents: read
541
+ jobs:
542
+ lint:
543
+ uses: example-org/workflows/.github/workflows/lint.yml@main # expect
544
+ """,
545
+ note="A reusable workflow on a branch.",
546
+ ),
547
+ good(
548
+ WF,
549
+ PUSH_HEADER
550
+ + f" - uses: {CHECKOUT} # v4.3.0\n"
551
+ + " with:\n persist-credentials: false\n",
552
+ ),
553
+ good(
554
+ WF,
555
+ PUSH_HEADER
556
+ + " - uses: ./.github/actions/setup\n"
557
+ + " - uses: docker://alpine@sha256:"
558
+ + "4bcff63911fcb4448bd4fdacec207030997caf25e9bea4045fa6c8c44de311d1\n",
559
+ note="Local actions and image digests are pinned.",
560
+ ),
561
+ ],
562
+ "ci/unpinned-image": [
563
+ bad(
564
+ WF,
565
+ """on: push
566
+ permissions:
567
+ contents: read
568
+ jobs:
569
+ test:
570
+ runs-on: ubuntu-latest
571
+ container: node:20-bookworm # expect
572
+ services:
573
+ db:
574
+ image: postgres:16 # expect
575
+ steps:
576
+ - run: npm test
577
+ """,
578
+ ),
579
+ bad(
580
+ "tools/lint/action.yml",
581
+ """name: lint
582
+ runs:
583
+ using: docker
584
+ image: docker://ghcr.io/example/linter:latest # expect
585
+ """,
586
+ note="A docker action image by tag.",
587
+ ),
588
+ good(
589
+ WF,
590
+ """on: push
591
+ permissions:
592
+ contents: read
593
+ jobs:
594
+ test:
595
+ runs-on: ubuntu-latest
596
+ container:
597
+ image: node@sha256:8f8b1a3a5c4c1cd5e6b4fbc6b2b0f2c3f1b9ad1a0f6b6a7f7e3a1cf3bd2c1e0a
598
+ steps:
599
+ - run: npm test
600
+ """,
601
+ ),
602
+ good(
603
+ WF,
604
+ """on: push
605
+ permissions:
606
+ contents: read
607
+ jobs:
608
+ test:
609
+ runs-on: ubuntu-latest
610
+ strategy:
611
+ matrix:
612
+ image: ["python@sha256:1a2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6e7f809"]
613
+ container: ${{ matrix.image }}
614
+ steps:
615
+ - run: make test
616
+ """,
617
+ note="An expression is not judged.",
618
+ ),
619
+ ],
620
+ "ci/persist-credentials": [
621
+ bad(WF, PUSH_HEADER + f" - uses: {CHECKOUT} # expect\n"),
622
+ bad(
623
+ WF,
624
+ PUSH_HEADER
625
+ + f" - uses: {CHECKOUT}\n"
626
+ + " with:\n persist-credentials: true # expect\n",
627
+ ),
628
+ good(
629
+ WF,
630
+ PUSH_HEADER
631
+ + f" - uses: {CHECKOUT}\n"
632
+ + " with:\n persist-credentials: false\n",
633
+ ),
634
+ good(
635
+ WF,
636
+ (PUSH_HEADER + f" - uses: {CHECKOUT}\n - run: make\n").replace(
637
+ "runs-on", "timeout-minutes: 10\n runs-on"
638
+ ),
639
+ old=PUSH_HEADER + f" - uses: {CHECKOUT}\n - run: make\n",
640
+ note="An existing checkout is not re-reported for an unrelated edit.",
641
+ ),
642
+ ],
643
+ "ci/secrets-inherit": [
644
+ bad(
645
+ WF,
646
+ """on: push
647
+ permissions:
648
+ contents: read
649
+ jobs:
650
+ deploy:
651
+ uses: example-org/ci/.github/workflows/deploy.yml@08eba0b27e820071cde6df949e0beb9ba4906955
652
+ secrets: inherit # expect
653
+ """,
654
+ ),
655
+ bad(
656
+ WF,
657
+ """on: push
658
+ permissions:
659
+ contents: read
660
+ jobs:
661
+ deploy:
662
+ uses: ./.github/workflows/deploy.yml
663
+ secrets: inherit # expect
664
+ """,
665
+ old="""on: push
666
+ permissions:
667
+ contents: read
668
+ jobs:
669
+ deploy:
670
+ uses: ./.github/workflows/deploy.yml
671
+ secrets:
672
+ DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
673
+ """,
674
+ ),
675
+ good(
676
+ WF,
677
+ """on: push
678
+ permissions:
679
+ contents: read
680
+ jobs:
681
+ deploy:
682
+ uses: ./.github/workflows/deploy.yml
683
+ secrets:
684
+ DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
685
+ """,
686
+ ),
687
+ good(
688
+ WF,
689
+ PUSH_HEADER + " - run: 'echo \"secrets: inherit is not used here\"'\n",
690
+ ),
691
+ ],
692
+ "ci/self-hosted-pr": [
693
+ bad(
694
+ WF,
695
+ """on:
696
+ pull_request: # expect
697
+ permissions:
698
+ contents: read
699
+ jobs:
700
+ test:
701
+ runs-on: [self-hosted, linux] # expect
702
+ steps:
703
+ - run: make test
704
+ """,
705
+ ),
706
+ Example(
707
+ kind="bad",
708
+ files={
709
+ WF: Change(
710
+ old="""on:
711
+ push:
712
+ permissions:
713
+ contents: read
714
+ jobs:
715
+ test:
716
+ runs-on: self-hosted
717
+ steps:
718
+ - run: make test
719
+ """,
720
+ new="""on:
721
+ push:
722
+ pull_request:
723
+ permissions:
724
+ contents: read
725
+ jobs:
726
+ test:
727
+ runs-on: self-hosted
728
+ steps:
729
+ - run: make test
730
+ """,
731
+ )
732
+ },
733
+ expect=((WF, 3, "new"),),
734
+ note="Adding the pull request trigger to a self-hosted workflow.",
735
+ ),
736
+ good(
737
+ WF,
738
+ """on:
739
+ push:
740
+ branches: [main]
741
+ permissions:
742
+ contents: read
743
+ jobs:
744
+ deploy:
745
+ runs-on: [self-hosted, deploy]
746
+ steps:
747
+ - run: make deploy
748
+ """,
749
+ ),
750
+ good(
751
+ WF,
752
+ """on: pull_request
753
+ permissions:
754
+ contents: read
755
+ jobs:
756
+ test:
757
+ runs-on: ubuntu-latest
758
+ steps:
759
+ - run: make test
760
+ """,
761
+ ),
762
+ ],
763
+ "ci/continue-on-error": [
764
+ bad(
765
+ WF,
766
+ """on: push
767
+ permissions:
768
+ contents: read
769
+ jobs:
770
+ audit:
771
+ runs-on: ubuntu-latest
772
+ continue-on-error: true # expect
773
+ steps:
774
+ - run: npm audit
775
+ """,
776
+ ),
777
+ bad(
778
+ WF,
779
+ PUSH_HEADER + " - run: make lint\n continue-on-error: true # expect\n",
780
+ ),
781
+ good(
782
+ WF,
783
+ """on: push
784
+ permissions:
785
+ contents: read
786
+ jobs:
787
+ test:
788
+ runs-on: ubuntu-latest
789
+ continue-on-error: ${{ matrix.experimental }}
790
+ strategy:
791
+ matrix:
792
+ experimental: [false]
793
+ steps:
794
+ - run: make test
795
+ """,
796
+ ),
797
+ good(WF, PUSH_HEADER + " - run: make lint\n continue-on-error: false\n"),
798
+ ],
799
+ "ci/disabled-check": [
800
+ bad(
801
+ WF,
802
+ """on: push
803
+ permissions:
804
+ contents: read
805
+ jobs:
806
+ test:
807
+ if: false # expect
808
+ runs-on: ubuntu-latest
809
+ steps:
810
+ - run: make test
811
+ """,
812
+ ),
813
+ bad(
814
+ WF,
815
+ PUSH_HEADER
816
+ + " - run: |\n"
817
+ + " npm ci\n"
818
+ + " npm test || true # expect\n"
819
+ + " uv run pytest -q || exit 0 # expect\n",
820
+ ),
821
+ bad(
822
+ WF,
823
+ PUSH_HEADER
824
+ + " - run: |\n"
825
+ + " git commit -am 'Update snapshots' --no-verify # expect\n",
826
+ ),
827
+ good(
828
+ WF,
829
+ PUSH_HEADER
830
+ + " - run: |\n"
831
+ + " rm -rf build || true\n"
832
+ + " npm test\n",
833
+ note="Only checks are protected; cleanup may ignore failures.",
834
+ ),
835
+ good(
836
+ WF,
837
+ """on: push
838
+ permissions:
839
+ contents: read
840
+ jobs:
841
+ test:
842
+ if: ${{ github.event_name == 'push' }}
843
+ runs-on: ubuntu-latest
844
+ steps:
845
+ - run: make test
846
+ """,
847
+ ),
848
+ ],
849
+ "ci/dangerous-trigger": [
850
+ bad(
851
+ ".github/workflows/label.yml",
852
+ """on:
853
+ pull_request_target: # expect
854
+ types: [opened]
855
+ permissions:
856
+ pull-requests: write
857
+ jobs:
858
+ label:
859
+ runs-on: ubuntu-latest
860
+ steps:
861
+ - run: gh pr edit "$PR" --add-label triage
862
+ env:
863
+ PR: ${{ github.event.pull_request.number }}
864
+ GH_TOKEN: ${{ github.token }}
865
+ """,
866
+ ),
867
+ bad(
868
+ ".forgejo/workflows/report.yml",
869
+ """on: [push, workflow_run] # expect
870
+ jobs:
871
+ report:
872
+ runs-on: docker
873
+ steps:
874
+ - run: echo done
875
+ """,
876
+ note="Forgejo workflows too.",
877
+ ),
878
+ good(
879
+ WF,
880
+ """on: pull_request
881
+ permissions:
882
+ contents: read
883
+ jobs:
884
+ test:
885
+ runs-on: ubuntu-latest
886
+ steps:
887
+ - run: make test
888
+ """,
889
+ ),
890
+ good(
891
+ ".github/workflows/label.yml",
892
+ """on: pull_request_target
893
+ permissions:
894
+ pull-requests: write
895
+ jobs:
896
+ label:
897
+ runs-on: ubuntu-latest
898
+ steps:
899
+ - run: gh pr edit "$PR" --add-label needs-review
900
+ env:
901
+ PR: ${{ github.event.pull_request.number }}
902
+ GH_TOKEN: ${{ github.token }}
903
+ """,
904
+ old="""on: pull_request_target
905
+ permissions:
906
+ pull-requests: write
907
+ jobs:
908
+ label:
909
+ runs-on: ubuntu-latest
910
+ steps:
911
+ - run: gh pr edit "$PR" --add-label triage
912
+ env:
913
+ PR: ${{ github.event.pull_request.number }}
914
+ GH_TOKEN: ${{ github.token }}
915
+ """,
916
+ note="The trigger already existed.",
917
+ ),
918
+ ],
919
+ "ci/git-hooks-changed": [
920
+ Example(
921
+ kind="bad",
922
+ files={".husky/pre-commit": Change(new="npx lint-staged\n")},
923
+ expect=((".husky/pre-commit", None, "new"),),
924
+ ),
925
+ Example(
926
+ kind="bad",
927
+ files={
928
+ ".pre-commit-config.yaml": Change(
929
+ old="repos:\n - repo: https://github.com/astral-sh/ruff-pre-commit\n"
930
+ " rev: v0.6.0\n hooks:\n - id: ruff\n",
931
+ new="repos:\n - repo: https://github.com/astral-sh/ruff-pre-commit\n"
932
+ " rev: v0.7.0\n hooks:\n - id: ruff\n",
933
+ )
934
+ },
935
+ expect=((".pre-commit-config.yaml", 3, "new"),),
936
+ ),
937
+ good("docs/git-hooks.md", "# Hooks\n\nRun `npx husky init` once.\n"),
938
+ good("scripts/hooks.py", "HOOKS = ['pre-commit', 'pre-push']\n"),
939
+ ],
940
+ "ci/default-permissions": [
941
+ Example(
942
+ kind="bad",
943
+ files={
944
+ WF: Change(
945
+ new="""on: push
946
+ jobs:
947
+ build:
948
+ runs-on: ubuntu-latest
949
+ steps:
950
+ - run: make
951
+ """
952
+ )
953
+ },
954
+ expect=((WF, 3, "new"),),
955
+ note="A new workflow without a permissions block.",
956
+ ),
957
+ Example(
958
+ kind="bad",
959
+ files={
960
+ WF: Change(
961
+ old="""on: push
962
+ permissions:
963
+ contents: read
964
+ jobs:
965
+ build:
966
+ runs-on: ubuntu-latest
967
+ steps:
968
+ - run: make
969
+ """,
970
+ new="""on: push
971
+ jobs:
972
+ build:
973
+ runs-on: ubuntu-latest
974
+ steps:
975
+ - run: make
976
+ """,
977
+ )
978
+ },
979
+ expect=((WF, 1, "new"),),
980
+ note="The top-level block was removed.",
981
+ ),
982
+ good(
983
+ WF,
984
+ """on: push
985
+ jobs:
986
+ build:
987
+ runs-on: ubuntu-latest
988
+ permissions:
989
+ contents: read
990
+ steps:
991
+ - run: make
992
+ """,
993
+ ),
994
+ good(
995
+ ".forgejo/workflows/ci.yml",
996
+ """on: push
997
+ jobs:
998
+ build:
999
+ runs-on: docker
1000
+ steps:
1001
+ - run: make
1002
+ """,
1003
+ note="Forgejo has no permissions block.",
1004
+ ),
1005
+ good(
1006
+ WF,
1007
+ """on: push
1008
+ jobs:
1009
+ build:
1010
+ runs-on: ubuntu-latest
1011
+ steps:
1012
+ - run: make all
1013
+ """,
1014
+ old="""on: push
1015
+ jobs:
1016
+ build:
1017
+ runs-on: ubuntu-latest
1018
+ steps:
1019
+ - run: make
1020
+ """,
1021
+ note="The job had no permissions before either.",
1022
+ ),
1023
+ ],
1024
+ "ci/workflow-changed": [
1025
+ Example(
1026
+ kind="bad",
1027
+ files={WF: Change(new="on: push\npermissions: {}\njobs: {}\n")},
1028
+ expect=((WF, None, "new"),),
1029
+ ),
1030
+ Example(
1031
+ kind="bad",
1032
+ files={
1033
+ "action.yml": Change(
1034
+ old="name: setup\nruns:\n using: composite\n steps:\n"
1035
+ " - run: make setup\n shell: bash\n",
1036
+ new="name: setup\nruns:\n using: composite\n steps:\n"
1037
+ " - run: make setup install\n shell: bash\n",
1038
+ )
1039
+ },
1040
+ expect=(("action.yml", 5, "new"),),
1041
+ note="Composite actions are workflows too.",
1042
+ ),
1043
+ good("config/ci.yml", "retries: 3\n"),
1044
+ good("docs/workflows/release.md", "# Release\n\nTag and push.\n"),
1045
+ ],
1046
+ }