Repository navigation
494 lines (440 loc) · 19.6 KB
/
Copy pathci.yml
File metadata and controls
494 lines (440 loc) · 19.6 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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
name: quality
on:
pull_request:
# Contributions target dev. Promotions are pull requests from dev into main,
# validated here on their exact head before promote fast-forwards main.
branches: [dev, main]
permissions:
contents: read
concurrency:
group: quality-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
impact:
name: Contribution impact
runs-on: ubuntu-24.04
timeout-minutes: 5
outputs:
docs: ${{ steps.impact.outputs.docs }}
cli: ${{ steps.impact.outputs.cli }}
dialects: ${{ steps.impact.outputs.dialects }}
policies: ${{ steps.impact.outputs.policies }}
examples: ${{ steps.impact.outputs.examples }}
distribution: ${{ steps.impact.outputs.distribution }}
tooling: ${{ steps.impact.outputs.tooling }}
generated: ${{ steps.impact.outputs.generated }}
scenarios: ${{ steps.impact.outputs.scenarios }}
registry: ${{ steps.impact.outputs.registry }}
plan: ${{ steps.impact.outputs.plan }}
steps:
- name: Check out exact public source
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
- name: Install exact Bun
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
with:
bun-version: 1.4.0
- name: Check out trusted classification policy
if: github.event_name == 'pull_request'
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.event.pull_request.base.sha }}
path: artifacts/ci-trusted
persist-credentials: false
- name: Classify exact changes using base policy
id: impact
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
set -euo pipefail
mkdir -p artifacts
if [[ -f artifacts/ci-trusted/scripts/ci/classify.ts ]]; then
bun artifacts/ci-trusted/scripts/ci/classify.ts . "$BASE_SHA" "$HEAD_SHA" artifacts/impact.json
else
# A base without the classification policy cannot narrow checks: fail broad, never skip.
python3 - <<'PYTHON'
import json, os
lanes = ['docs', 'cli', 'dialects', 'policies', 'examples', 'distribution', 'tooling', 'generated']
plan = dict(version=1, lanes=dict.fromkeys(lanes, True), preview=True, scenarios=True, core=True, registry=True, reasons=['Full validation: trusted policy unavailable'])
with open('artifacts/impact.json', 'w') as f: json.dump(plan, f, indent=2)
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
for lane in lanes: f.write(f'{lane}=true\n')
f.write(f'scenarios=true\nregistry=true\nplan={json.dumps(plan)}\n')
PYTHON
fi
- name: Retain public impact report
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: contribution-impact-${{ github.event.pull_request.head.sha || github.sha }}
path: artifacts/impact.json
retention-days: 3
boundary:
name: Repository safety
runs-on: ubuntu-24.04
timeout-minutes: 10
steps:
- name: Check out exact public source
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
- name: Install exact Bun
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
with:
bun-version: 1.4.0
- name: Require promotion to fast-forward main from dev
if: github.base_ref == 'main'
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
PROMOTION_SOURCE: ${{ github.event.pull_request.head.repo.full_name }}:${{ github.head_ref }}
PULL_REQUEST: ${{ github.event.pull_request.number }}
run: |
set -euo pipefail
if [[ "$PROMOTION_SOURCE" != "$GITHUB_REPOSITORY:dev" ]]; then
echo "::error::main receives only promotions from $GITHUB_REPOSITORY:dev. Target dev instead."
exit 1
fi
if ! git merge-base --is-ancestor "$BASE_SHA" "$HEAD_SHA"; then
echo "::error::main is not an ancestor of dev. Promotion must be a fast-forward."
exit 1
fi
{
echo "## Promotion"
echo
echo "Fast-forwards main from \`$BASE_SHA\` to the exact dev commit \`$HEAD_SHA\` ($(git rev-list --count "$BASE_SHA..$HEAD_SHA") commits)."
echo "Once this check passes, run the promote workflow for pull request #$PULL_REQUEST."
} >> "$GITHUB_STEP_SUMMARY"
- name: Install exact dependencies without lifecycle scripts
run: bun install --frozen-lockfile --ignore-scripts
- name: Install verified Gitleaks
env:
GITLEAKS_ARCHIVE: gitleaks_8.30.1_linux_x64.tar.gz
GITLEAKS_SHA256: 551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb
GITLEAKS_VERSION: 8.30.1
run: |
set -euo pipefail
curl --fail --silent --show-error --location \
--output "$RUNNER_TEMP/$GITLEAKS_ARCHIVE" \
"https://github.com/gitleaks/gitleaks/releases/download/v$GITLEAKS_VERSION/$GITLEAKS_ARCHIVE"
printf '%s %s\n' "$GITLEAKS_SHA256" "$RUNNER_TEMP/$GITLEAKS_ARCHIVE" | sha256sum --check --strict
tar --extract --gzip --file "$RUNNER_TEMP/$GITLEAKS_ARCHIVE" --directory "$RUNNER_TEMP" gitleaks
printf '%s\n' "$RUNNER_TEMP" >> "$GITHUB_PATH"
- name: Install verified actionlint
env:
ACTIONLINT_ARCHIVE: actionlint_1.7.12_linux_amd64.tar.gz
ACTIONLINT_SHA256: 8aca8db96f1b94770f1b0d72b6dddcb1ebb8123cb3712530b08cc387b349a3d8
ACTIONLINT_VERSION: 1.7.12
run: |
set -euo pipefail
curl --fail --silent --show-error --location \
--output "$RUNNER_TEMP/$ACTIONLINT_ARCHIVE" \
"https://github.com/rhysd/actionlint/releases/download/v$ACTIONLINT_VERSION/$ACTIONLINT_ARCHIVE"
printf '%s %s\n' "$ACTIONLINT_SHA256" "$RUNNER_TEMP/$ACTIONLINT_ARCHIVE" | sha256sum --check --strict
tar --extract --gzip --file "$RUNNER_TEMP/$ACTIONLINT_ARCHIVE" --directory "$RUNNER_TEMP" actionlint
printf '%s\n' "$RUNNER_TEMP" >> "$GITHUB_PATH"
- name: Validate public boundary and formatting
env:
PUBLIC_TITLE: ${{ github.event.pull_request.title }}
PUBLIC_BODY: ${{ github.event.pull_request.body }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
run: |
bun scripts/check-publication.ts --metadata-env --range "$BASE_SHA..HEAD"
bun scripts/validate-repository.ts
bun run check:format
actionlint -no-color -oneline
- name: Scan working tree
run: gitleaks dir --no-banner --redact --config .gitleaks.toml .
- name: Scan introduced history
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
run: |
set -euo pipefail
if [[ -n "$BASE_SHA" ]]; then
gitleaks git --no-banner --redact --config .gitleaks.toml --log-opts="$BASE_SHA..HEAD" .
else
gitleaks git --no-banner --redact --config .gitleaks.toml .
fi
docs:
name: Documentation
needs: impact
if: needs.impact.outputs.docs == 'true'
runs-on: ubuntu-24.04
timeout-minutes: 20
steps:
- name: Check out exact public source
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
- name: Install exact Bun
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
with:
bun-version: 1.4.0
- name: Install exact dependencies without lifecycle scripts
run: bun install --frozen-lockfile --ignore-scripts
- name: Validate documentation
run: bun scripts/ci/run.ts docs
cli:
name: public CLI module
needs: impact
if: needs.impact.outputs.cli == 'true'
runs-on: ubuntu-24.04
timeout-minutes: 20
permissions:
contents: read
security-events: write
steps:
- name: Check out exact public source
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
- name: Install exact Bun
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
with:
bun-version: 1.4.0
- name: Install exact Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version: "1.26.7"
cache: false
- name: Install exact dependencies without lifecycle scripts
run: bun install --frozen-lockfile --ignore-scripts
- name: Initialize source security analysis
uses: github/codeql-action/init@24c54180a607b1449ed407dd24f251e4e9147c8d # v4
with:
languages: go
build-mode: manual
dependency-caching: false
- name: Validate public cli module
run: bun scripts/ci/run.ts cli
- name: Analyze source security
uses: github/codeql-action/analyze@24c54180a607b1449ed407dd24f251e4e9147c8d # v4
with:
category: /language:go
content:
name: Dialect, Policy and executable examples
needs: impact
if: needs.impact.outputs.dialects == 'true' || needs.impact.outputs.policies == 'true' || needs.impact.outputs.examples == 'true'
runs-on: ubuntu-24.04
timeout-minutes: 20
steps:
- name: Check out exact public source
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
- name: Install exact Bun
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
with:
bun-version: 1.4.0
- name: Install exact dependencies without lifecycle scripts
run: bun install --frozen-lockfile --ignore-scripts
- name: Validate selected runtime content against exact reference runtime
env:
DIALECTS: ${{ needs.impact.outputs.dialects }}
POLICIES: ${{ needs.impact.outputs.policies }}
EXAMPLES: ${{ needs.impact.outputs.examples }}
SCENARIOS: ${{ needs.impact.outputs.scenarios }}
run: |
set -euo pipefail
lanes=()
[[ "$DIALECTS" != true ]] || lanes+=(dialects)
[[ "$POLICIES" != true ]] || lanes+=(policies)
[[ "$EXAMPLES" != true ]] || lanes+=(examples)
[[ "$SCENARIOS" != true ]] || lanes+=(scenarios)
bun scripts/ci/run.ts "${lanes[@]}"
- name: Qualify changed registry examples with disposable local TLS
if: needs.impact.outputs.registry == 'true'
run: bun scripts/ci/run.ts registry
generated:
name: Generated references
needs: impact
if: needs.impact.outputs.generated == 'true'
runs-on: ubuntu-24.04
timeout-minutes: 20
steps:
- name: Check out exact public source
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
- name: Install exact Bun
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
with:
bun-version: 1.4.0
- name: Install exact Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version: "1.26.7"
cache: false
- name: Install exact dependencies without lifecycle scripts
run: bun install --frozen-lockfile --ignore-scripts
- name: Validate generated references
run: bun scripts/ci/run.ts generated
- name: Prepare expected generated diff after a failure
if: failure()
run: bun scripts/ci/generated-diff.ts
- name: Return expected generated output to the contributor
if: failure()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: expected-generated-references-${{ github.event.pull_request.head.sha || github.sha }}
path: artifacts/generated-references/*
retention-days: 3
if-no-files-found: warn
distribution:
name: Distribution contracts
needs: impact
if: needs.impact.outputs.distribution == 'true'
runs-on: ubuntu-24.04
timeout-minutes: 20
steps:
- name: Check out exact public source
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
- name: Install exact Bun
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
with:
bun-version: 1.4.0
- name: Install exact dependencies without lifecycle scripts
run: bun install --frozen-lockfile --ignore-scripts
- name: Install verified Trivy
env:
TRIVY_ARCHIVE: trivy_0.74.0_Linux-64bit.tar.gz
TRIVY_SHA256: 2ae6fe3ee734b7fdf11335663e18c75ea12dccc76062f09f164a3b0f8be4371a
TRIVY_VERSION: 0.74.0
run: |
set -euo pipefail
curl --fail --silent --show-error --location \
--output "$RUNNER_TEMP/$TRIVY_ARCHIVE" \
"https://github.com/aquasecurity/trivy/releases/download/v$TRIVY_VERSION/$TRIVY_ARCHIVE"
printf '%s %s\n' "$TRIVY_SHA256" "$RUNNER_TEMP/$TRIVY_ARCHIVE" | sha256sum --check --strict
tar --extract --gzip --file "$RUNNER_TEMP/$TRIVY_ARCHIVE" --directory "$RUNNER_TEMP" trivy
printf '%s\n' "$RUNNER_TEMP" >> "$GITHUB_PATH"
- name: Validate distribution contracts
run: bun scripts/ci/run.ts distribution
- name: Enforce OCI base vulnerability policy
run: |
set -euo pipefail
mapfile -t bases < <(awk 'toupper($1) == "FROM" { print $2 }' distribution/oci/Dockerfile)
test "${#bases[@]}" -eq 1
base="${bases[0]}"
[[ "$base" =~ ^alpine:[0-9]+\.[0-9]+@sha256:[0-9a-f]{64}$ ]]
first=true
for platform in linux/amd64 linux/arm64; do
update=()
if [[ "$first" = false ]]; then
update=(--skip-db-update)
fi
trivy image \
"${update[@]}" \
--platform "$platform" \
--scanners vuln \
--ignorefile .trivyignore.yaml \
--severity HIGH,CRITICAL \
--exit-code 1 \
"$base"
trivy image \
--skip-db-update \
--platform "$platform" \
--scanners vuln \
--ignorefile .trivyignore.yaml \
--severity MEDIUM,LOW \
--exit-code 0 \
"$base"
first=false
done
tooling:
name: Shared tooling
needs: impact
if: needs.impact.outputs.tooling == 'true'
runs-on: ubuntu-24.04
timeout-minutes: 20
permissions:
contents: read
security-events: write
steps:
- name: Check out exact public source
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
- name: Install exact Bun
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
with:
bun-version: 1.4.0
- name: Install exact dependencies without lifecycle scripts
run: bun install --frozen-lockfile --ignore-scripts
- name: Install verified Gitleaks
env:
GITLEAKS_ARCHIVE: gitleaks_8.30.1_linux_x64.tar.gz
GITLEAKS_SHA256: 551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb
GITLEAKS_VERSION: 8.30.1
run: |
set -euo pipefail
curl --fail --silent --show-error --location \
--output "$RUNNER_TEMP/$GITLEAKS_ARCHIVE" \
"https://github.com/gitleaks/gitleaks/releases/download/v$GITLEAKS_VERSION/$GITLEAKS_ARCHIVE"
printf '%s %s\n' "$GITLEAKS_SHA256" "$RUNNER_TEMP/$GITLEAKS_ARCHIVE" | sha256sum --check --strict
tar --extract --gzip --file "$RUNNER_TEMP/$GITLEAKS_ARCHIVE" --directory "$RUNNER_TEMP" gitleaks
printf '%s\n' "$RUNNER_TEMP" >> "$GITHUB_PATH"
- name: Initialize source security analysis
uses: github/codeql-action/init@24c54180a607b1449ed407dd24f251e4e9147c8d # v4
with:
languages: actions,javascript-typescript
build-mode: none
dependency-caching: false
- name: Validate shared tooling
run: bun scripts/ci/run.ts tooling
- name: Analyze source security
uses: github/codeql-action/analyze@24c54180a607b1449ed407dd24f251e4e9147c8d # v4
with:
category: /language:tooling
quality:
# Required context stays unchanged and is always produced, including failures.
name: public repository boundary
needs: [impact, boundary, docs, cli, content, generated, distribution, tooling]
if: always()
runs-on: ubuntu-24.04
timeout-minutes: 5
steps:
- name: Require every selected lane to succeed
env:
PLAN: ${{ needs.impact.outputs.plan }}
RESULTS: ${{ toJSON(needs) }}
run: |
python3 - <<'PYTHON'
import json, os
results = json.loads(os.environ['RESULTS'])
assert results['impact']['result'] == 'success', 'Impact classification did not succeed'
assert results['boundary']['result'] == 'success', 'Repository safety did not succeed'
plan = json.loads(os.environ['PLAN'])
assert plan['version'] == 1, 'Unknown impact policy'
required = dict(plan['lanes'])
content = [required.pop(k) for k in ['dialects', 'policies', 'examples']]
required['content'] = any(content)
lines = ['## Contribution validation', '', '| Check | Result |', '| --- | --- |']
failures = []
for lane, needed in required.items():
result = results[lane]['result']
if needed and result != 'success': failures.append(f'{lane}: {result}')
if not needed and result not in ['skipped', 'success']: failures.append(f'{lane}: {result}')
lines.append(f'| {lane} | {result}' + ('' if needed else ' (not required for this impact)') + ' |')
with open(os.environ['GITHUB_STEP_SUMMARY'], 'w') as f: f.write('\n'.join(lines) + '\n')
assert not failures, 'Required validations failed or did not execute: ' + ', '.join(failures)
PYTHON