@avi2dg/checks 0.69.0 → 0.71.0

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.
@@ -1,257 +0,0 @@
1
- ---
2
- kind: reference
3
- audience: consumers
4
- ---
5
- # checks-night-run
6
-
7
- `checks-night-run` turns each finding of a night run on `main` into a GitHub issue.
8
- A finding is a file whose mutation score fell, a failing test, a failed nightly gate or a missing mutation report.
9
- It closes the issue of a test, gate or missing mutation report that a later night no longer reports, and it comments on a mutation issue it no longer reports without closing it, but only when a previous night exists and every requested mutation report is present.
10
-
11
- ## What it checks
12
-
13
- It scores each file of tonight's Stryker reports as Stryker does, the `Killed` and `Timeout` mutants over every mutant but the `Ignored`, `CompileError`, `RuntimeError` and `Pending` ones.
14
- It compares each file's score with the same file's score from the previous night.
15
- A file whose score is lower than the previous night's is a finding.
16
- A file only one night holds is no finding, since it lacks one of the two scores.
17
- A file with no scored mutant has no score, so it is no finding either.
18
- An equal score is no finding, even when it counts other mutants.
19
- Each failing test in a JUnit report is a finding, whatever the previous night holds.
20
- Each nightly gate the lint log names as failed is a finding.
21
- A log where every named gate is undecided files `checks-lint` itself, with no per-gate issue.
22
- A log with no passing run and no named gate files `checks-lint` itself, so a gate run that never finished still reaches an issue.
23
- A file whose test worker crashed is one finding, since Bun reports none of its tests.
24
- With no previous night it compares no score and still files each failing test.
25
- Each mutation report `--mutation` names that does not exist is a finding, since the mutation job that writes it failed, timed out or was cancelled.
26
- With no mutation report it compares and records no score and still files each failing test.
27
- With some mutation reports missing it compares the files the others hold and records no score.
28
- The next night then compares every file with the last night that scored them all.
29
-
30
- Each finding has a key that stays the same from night to night:
31
-
32
- | Finding | Key |
33
- | --- | --- |
34
- | a file whose mutation score fell | `mutation:<file>` |
35
- | a failing test | `test:<file> > <describe> > <name>` |
36
- | a file whose test worker crashed | `test:<file>` |
37
- | a nightly gate that failed | `gates:<gate>` |
38
- | a missing mutation report | `mutation-report:<path>` |
39
-
40
- ## How it files a finding
41
-
42
- It creates the `night-run` label when the repository lacks it.
43
- It reads every open issue labelled `night-run`, and reads the key each one carries in a hidden marker in its body.
44
- A finding whose key an open issue carries gets one comment on that issue, so a regression that lasts two nights stays one issue.
45
- Any other finding opens one issue labelled `night-run`.
46
- The issue and the comment name tonight's run, the file and the test, the score of both nights or the failed gate.
47
- The body holds the file, the full test name or the failed gate, and the finding key.
48
- A title longer than GitHub's 256 characters is cut to at most 256 and ends in `…`.
49
- A night with no finding creates no label and writes no issue, and only reads the open issues to close any test, gate or mutation-report issue whose finding is gone and, when a previous night exists and every requested mutation report is present, to comment on any mutation issue whose finding is gone.
50
- Closing an issue ends it, and the same finding on a later night opens a new one.
51
-
52
- ## How it closes an issue
53
-
54
- An open test, gate or mutation-report issue whose key tonight's findings lack gets one comment naming tonight's run and the key.
55
- It then closes as completed.
56
- When a previous night exists and every requested mutation report is present, an open mutation issue whose key tonight's findings lack gets one comment that names tonight's run and the key, and stays open.
57
- A closed issue is no longer read, so a later night without the finding comments on it no more.
58
- A comment that reports the finding carries a reported marker, and a note that a mutation finding is gone carries a noted marker.
59
- A mutation issue whose latest marked comment already notes the finding gone gets no further note.
60
- So a mutation finding gone for many nights is noted once, and noted again only after a later night reports it again.
61
- A person's comment carries no marker, so it never makes the run note an issue twice.
62
- It judges a key only from a report it read tonight:
63
-
64
- | Key | Closes when |
65
- | --- | --- |
66
- | `test:<file> > <describe> > <name>` | tonight read a JUnit report, the test is not failing, and `<file>`'s worker did not crash |
67
- | `test:<file>` | tonight read a JUnit report and `<file>`'s worker did not crash |
68
- | `gates:<gate>` | tonight read a lint log that passes or names its failed gates, and `<gate>` is not among them |
69
- | `mutation-report:<path>` | tonight read the mutation report at `<path>` |
70
- | `mutation:<file>` | never |
71
-
72
- A crashed worker loses every result of its file, so the issue of a test in that file stays open.
73
- A lint log that is undecided or never finished says nothing of any one gate, so every gate issue stays open.
74
- A mutation finding is a fall from one night to the next.
75
- A later night that does not fall again still holds the lower score.
76
- Only a night that compared scores with every requested mutation report present comments on the mutation issue without closing it, since a score can recover and drop again.
77
- So a person closes a mutation issue once the score is back.
78
- An issue with no key in its body is never read, so a person's issue under the `night-run` label is never commented on or closed.
79
- A run off `main` comments on and closes no issue.
80
- Agents and people fix each issue as a task of its own, so no pull request waits for a night run.
81
- A run on any ref but `refs/heads/main` files no issue and records no score, and lists each finding in its log only.
82
-
83
- ## What it reads
84
-
85
- It reads tonight's Stryker `mutation.json` reports and any number of JUnit reports, such as the ones `checks-test --junit=<file>` keeps, as [checks-test](checks-test.md#arguments) says.
86
- It reads the lint log `--gates` names for the `gate(s) failed:` line `checks-lint --night` prints.
87
- It scans the newest 30 successful runs of the same workflow on `main` from newest to oldest.
88
- It takes the first run whose `night-run` artifact still exists as the previous night.
89
- That artifact holds `night-run.json`, the scores the run recorded.
90
- When no scanned run holds the artifact it compares no score.
91
- A run on another branch never becomes the previous night.
92
- On `main` with every mutation report present it writes tonight's scores to `reports/night-run.json`, and the workflow uploads that file as the `night-run` artifact.
93
- It reads the run from `GITHUB_SERVER_URL`, `GITHUB_REPOSITORY`, `GITHUB_RUN_ID`, `GITHUB_WORKFLOW_REF` and `GITHUB_REF`, so it runs only inside a GitHub Actions job.
94
- It calls `gh` with the job's `GH_TOKEN`, which needs `actions: read` for the previous night and `issues: write` for the issues.
95
-
96
- ## Arguments
97
-
98
- ```sh
99
- checks-night-run [--mutation <mutation-report>]... [--tests <junit-report>]... [--gates <lint-log>]
100
- ```
101
-
102
- `--mutation` names one of tonight's Stryker reports and is given once per report the workflow's mutation jobs write, whether or not each job wrote it.
103
- `--tests` names one JUnit report and is given once per report.
104
- `--gates` names tonight's `checks-lint --night` log and is given at most once.
105
- At least one report is given.
106
-
107
- ## Exit codes
108
-
109
- | Code | When |
110
- | --- | --- |
111
- | 0 | it filed every finding, closed each issue whose finding is gone and recorded tonight's scores, it found nothing to file, or the run is off `main` and it listed each finding |
112
- | 2 | an argument does not parse, a report or the lint log does not decode, a GitHub Actions variable is unset or a `gh` call fails |
113
-
114
- It never exits 1, because a finding becomes an issue rather than a failed run.
115
-
116
- ## Sample output
117
-
118
- ```
119
- checks-night-run: the night run https://github.com/acme/widget/actions/runs/12 compared with the night run https://github.com/acme/widget/actions/runs/11; 2 finding(s)
120
- opened #31 for mutation:src/cart.ts
121
- commented on #27 for test:tests/unit/cart.test.ts > totals > rounds half to even
122
- closed #24 for gates:checks-repetition
123
- checks-night-run: recorded 42 file score(s) in reports/night-run.json
124
- ```
125
-
126
- ## When it runs
127
-
128
- Only a night workflow the repository writes runs it, after that workflow's full mutation run, its long test tiers and its nightly lint gates.
129
-
130
- ## Running it by hand
131
-
132
- A repository runs it from a workflow named `night-run`, which someone starts with `gh workflow run night-run`.
133
- The workflow holds no schedule, since [checks-ci-wiring](checks-ci-wiring.md#schedules) refuses one:
134
-
135
- ```yaml
136
- name: night-run
137
- on:
138
- workflow_dispatch:
139
- permissions:
140
- contents: read
141
- concurrency:
142
- group: night-run
143
- cancel-in-progress: false
144
- jobs:
145
- mutation:
146
- runs-on: ubuntu-latest
147
- timeout-minutes: 60
148
- steps:
149
- - uses: actions/checkout@v5
150
- - uses: oven-sh/setup-bun@v2
151
- with:
152
- bun-version-file: .bun-version
153
- - run: bun install --frozen-lockfile
154
- - run: bunx stryker run
155
- - uses: actions/upload-artifact@v4
156
- with:
157
- name: night-run-mutation
158
- path: reports/mutation/mutation.json
159
- retention-days: 1
160
- tests:
161
- runs-on: ubuntu-latest
162
- timeout-minutes: 20
163
- steps:
164
- - uses: actions/checkout@v5
165
- - uses: oven-sh/setup-bun@v2
166
- with:
167
- bun-version-file: .bun-version
168
- - run: bun install --frozen-lockfile
169
- - run: |
170
- bunx checks-test --tier=live --junit=reports/night-run-tests/live.xml || true
171
- bunx checks-test --tier=pixel --junit=reports/night-run-tests/pixel.xml || true
172
- - uses: actions/upload-artifact@v4
173
- with:
174
- name: night-run-tests
175
- path: reports/night-run-tests/
176
- retention-days: 1
177
- gates:
178
- runs-on: ubuntu-latest
179
- timeout-minutes: 20
180
- steps:
181
- - uses: actions/checkout@v5
182
- with:
183
- fetch-depth: 0
184
- - uses: oven-sh/setup-bun@v2
185
- with:
186
- bun-version-file: .bun-version
187
- - run: bun install --frozen-lockfile
188
- - run: mkdir -p reports/night-run-gates && bunx checks-lint --night > reports/night-run-gates/gates.log 2>&1 || true
189
- - uses: actions/upload-artifact@v4
190
- with:
191
- name: night-run-gates
192
- path: reports/night-run-gates/
193
- retention-days: 1
194
- report:
195
- needs: [mutation, gates, tests]
196
- if: ${{ !cancelled() && needs.tests.result == 'success' }}
197
- runs-on: ubuntu-latest
198
- timeout-minutes: 15
199
- permissions:
200
- contents: read
201
- actions: read
202
- issues: write
203
- steps:
204
- - uses: actions/checkout@v5
205
- - uses: oven-sh/setup-bun@v2
206
- with:
207
- bun-version-file: .bun-version
208
- - run: bun install --frozen-lockfile
209
- - uses: actions/download-artifact@v4
210
- with:
211
- pattern: night-run-mutation
212
- path: reports/mutation
213
- - if: needs.gates.result == 'success'
214
- uses: actions/download-artifact@v4
215
- with:
216
- name: night-run-gates
217
- path: reports/night-run-gates
218
- - uses: actions/download-artifact@v4
219
- with:
220
- name: night-run-tests
221
- path: reports/night-run-tests
222
- - env:
223
- GH_TOKEN: ${{ github.token }}
224
- run: bunx checks-night-run --mutation reports/mutation/night-run-mutation/mutation.json --tests reports/night-run-tests/live.xml --tests reports/night-run-tests/pixel.xml ${{ needs.gates.result == 'success' && '--gates reports/night-run-gates/gates.log' || '' }}
225
- - uses: actions/upload-artifact@v4
226
- with:
227
- name: night-run
228
- path: reports/night-run.json
229
- if-no-files-found: ignore
230
- retention-days: 90
231
- ```
232
-
233
- The tests job runs each long tier the repository holds, `live` and `pixel` as [checks-test](checks-test.md#test-tiers) names them, and keeps each JUnit report.
234
- Each `|| true` lets the job go on to the upload after a failing test, since that test becomes an issue.
235
- A tier that writes no report fails the report job, because `checks-night-run` cannot read it.
236
- The gates job runs the nightly lint gates and keeps the log, since a failing gate becomes an issue.
237
- The report job runs whenever the tests job succeeds, so a failing test that also stops Stryker still becomes an issue.
238
- It always passes `--mutation`, so a mutation job that failed or timed out leaves a missing report that becomes an issue.
239
- The download names the artifact by `pattern`, which downloads nothing rather than failing when the artifact is missing.
240
- A full run too long for one job splits into a matrix of shards.
241
- Each shard uploads its own artifact under the one pattern, and each report gets its own `--mutation`.
242
- It passes `--gates` only when the gates job succeeded, and the failed gates job still fails the run.
243
- The concurrency group queues a run behind one already going, so two runs never file the same finding twice.
244
- A dispatch on a branch runs both jobs and lists its findings in the report job's log, and `if-no-files-found: ignore` lets that run upload no record.
245
- `issues: write` on the report job is the one permission beyond reading the repository and its runs.
246
- A public repository keeps `runs-on: ubuntu-latest` on every job.
247
- A private repository sets `runs-on` on the mutation job to the labels declared under `checks.mutationRunner` in `package.json`, and [checks-ci-wiring](checks-ci-wiring.md#runners) refuses a mutation job that names `CI_RUNS_ON`.
248
- A private repository sets `runs-on: ${{ vars.CI_RUNS_ON || 'ubuntu-latest' }}` on the tests, gates, and report jobs.
249
- A successful run with every mutation report present uploads `night-run`, so the next night compares with it, and a run that failed or missed a report uploads nothing a later night reads.
250
- The artifact keeps 90 days, so a gap of nights still leaves a previous night to compare with.
251
-
252
- ## Related topics
253
-
254
- - [checks-test](checks-test.md)
255
- - [checks-mutation](checks-mutation.md)
256
- - [checks-mutation-compare](checks-mutation-compare.md)
257
- - [checks-ci-wiring](checks-ci-wiring.md)
@@ -1,79 +0,0 @@
1
- import { ENTRY_POINT } from "../core/gates.ts";
2
- import { runsBin } from "./mutation-job.ts";
3
- import type { ScheduleContext } from "./release-schedule.ts";
4
- import { jobRuns } from "./runner-policy.ts";
5
- import type { Command } from "./shell-command.ts";
6
- import { isRecord, localUses, names, skippedBy, switchedOff, type Workflow } from "./workflow-references.ts";
7
-
8
- const NIGHT_STEP = `${ENTRY_POINT.bin} --night`;
9
-
10
- export type NightStepFault = {
11
- readonly gate: string;
12
- };
13
-
14
- const NIGHT_BINS = [ENTRY_POINT.bin, ENTRY_POINT.script];
15
-
16
- function isNightLint([head = "", ...rest]: Command): boolean {
17
- return NIGHT_BINS.some((name) => head === name || head.endsWith("/" + name)) && rest.length === 1 && rest[0] === "--night";
18
- }
19
-
20
- function rootBlocker(workflow: Workflow): string | undefined {
21
- const on = isRecord(workflow.document) ? workflow.document["on"] : undefined;
22
- const events = isRecord(on) ? Object.keys(on) : (names(on) ?? []);
23
- if (events.length > 0 && events.every((event) => event.toLowerCase() === "workflow_call")) {
24
- return `${workflow.path} runs only when called`;
25
- }
26
- return undefined;
27
- }
28
-
29
- function workflowRunsNightStep(
30
- workflow: Workflow,
31
- context: ScheduleContext,
32
- byPath: ReadonlyMap<string, Workflow>,
33
- walkedWorkflows: readonly string[],
34
- inherited: string | undefined,
35
- ): boolean {
36
- const files = (file: string) => context.files.get(file);
37
- const jobs = isRecord(workflow.document) ? workflow.document["jobs"] : undefined;
38
- if (!isRecord(jobs)) return false;
39
- return Object.entries(jobs).some(([id, job]) => {
40
- if (!isRecord(job)) return false;
41
- const skipped = skippedBy(jobs, id, []);
42
- const jobBlocker =
43
- inherited ?? switchedOff(job, `job ${id}`) ?? (skipped === undefined ? undefined : `job ${id} needs a job that never runs: ${skipped}`);
44
- const steps = Array.isArray(job["steps"]) ? job["steps"] : [];
45
- const runRecords: readonly Readonly<Record<string, unknown>>[] = steps.flatMap((step: unknown) =>
46
- isRecord(step) && typeof step["run"] === "string" ? [step] : [],
47
- );
48
- const unblocked = jobRuns(workflow, job).some(
49
- (run, index) =>
50
- (jobBlocker ?? switchedOff(runRecords[index] ?? {}, "the step")) === undefined &&
51
- runsBin(run, context.scripts, files, isNightLint, true),
52
- );
53
- if (unblocked) return true;
54
- const called = localUses(job["uses"]);
55
- if (called === undefined || walkedWorkflows.includes(called)) return false;
56
- const next = byPath.get(called);
57
- return next !== undefined && workflowRunsNightStep(next, context, byPath, [...walkedWorkflows, called], jobBlocker);
58
- });
59
- }
60
-
61
- function runsNightStep(workflows: readonly Workflow[], context: ScheduleContext): boolean {
62
- const byPath = new Map(workflows.map((workflow) => [workflow.path, workflow] as const));
63
- return workflows.some((workflow) => workflowRunsNightStep(workflow, context, byPath, [workflow.path], rootBlocker(workflow)));
64
- }
65
-
66
- export function findNightStepFaults(
67
- tracksTypeScript: boolean,
68
- workflows: readonly Workflow[],
69
- context: ScheduleContext,
70
- ): readonly NightStepFault[] {
71
- return tracksTypeScript && !runsNightStep(workflows, context) ? [{ gate: NIGHT_STEP }] : [];
72
- }
73
-
74
- export function formatNightStepReport(faults: readonly NightStepFault[]): string {
75
- return [
76
- "ci-wiring: " + faults.length + " gate(s) never run on the night run:",
77
- ...faults.flatMap(({ gate }) => [" " + gate, " no run step invokes it"]),
78
- ].join("\n");
79
- }