@syntopica/create-baseline 0.9.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.
- package/LICENSE +21 -0
- package/README.md +85 -0
- package/baseline-versions.json +16 -0
- package/bin/baseline-estate.mjs +85 -0
- package/bin/conformance/applyFixes.mjs +101 -0
- package/bin/conformance/checkActionPins.mjs +43 -0
- package/bin/conformance/checkCiWorkflow.mjs +52 -0
- package/bin/conformance/checkCoverageThresholds.mjs +112 -0
- package/bin/conformance/checkGateCoverage.mjs +128 -0
- package/bin/conformance/checkHooksInstalled.mjs +43 -0
- package/bin/conformance/checkLintFlag.mjs +86 -0
- package/bin/conformance/checkTsconfigPresets.mjs +58 -0
- package/bin/conformance/checkTsconfigProjects.mjs +47 -0
- package/bin/conformance/checkVersionRanges.mjs +51 -0
- package/bin/conformance/ciEntrypoints.mjs +37 -0
- package/bin/conformance/expandScripts.mjs +76 -0
- package/bin/conformance/formatFindings.mjs +36 -0
- package/bin/conformance/loadContext.mjs +175 -0
- package/bin/conformance/loadExceptions.mjs +73 -0
- package/bin/conformance/rangeFloor.mjs +23 -0
- package/bin/conformance/readWorkflows.mjs +29 -0
- package/bin/conformance/runConformance.mjs +57 -0
- package/bin/create-baseline.mjs +432 -0
- package/bin/estate/findConsumers.mjs +46 -0
- package/bin/estate/findPythonConsumers.mjs +58 -0
- package/bin/estate/formatEstate.mjs +67 -0
- package/bin/estate/formatPythonEstate.mjs +37 -0
- package/bin/python/checkGateWorkflow.mjs +33 -0
- package/bin/python/checkLockPin.mjs +36 -0
- package/bin/python/checkQualityGroup.mjs +33 -0
- package/bin/python/loadPythonContext.mjs +32 -0
- package/bin/python/repositoryRoot.mjs +24 -0
- package/bin/python/runPythonConformance.mjs +25 -0
- package/bin/scaffold/actionPins.mjs +34 -0
- package/bin/scaffold/baselineScripts.mjs +44 -0
- package/bin/scaffold/checkPeers.mjs +87 -0
- package/bin/scaffold/ciWorkflow.mjs +144 -0
- package/bin/scaffold/collectDeps.mjs +10 -0
- package/bin/scaffold/composedSubpaths.mjs +41 -0
- package/bin/scaffold/depCruiserConfig.mjs +30 -0
- package/bin/scaffold/detectFramework.mjs +18 -0
- package/bin/scaffold/eslintSubpathPeers.mjs +60 -0
- package/bin/scaffold/knipConfig.mjs +9 -0
- package/bin/scaffold/lefthookConfig.mjs +33 -0
- package/bin/scaffold/oxlintConfig.mjs +19 -0
- package/bin/scaffold/readManifest.mjs +17 -0
- package/bin/scaffold/renovateConfig.mjs +11 -0
- package/bin/scaffold/workspaceRoots.mjs +89 -0
- package/bin/scaffold/writeCiWorkflow.mjs +54 -0
- package/bin/scaffold/writeMissing.mjs +116 -0
- package/package.json +59 -0
- package/python-versions.json +3 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) BusiRocket
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# @syntopica/create-baseline
|
|
2
|
+
|
|
3
|
+
Small CLI to print install commands and verify that your project lists the
|
|
4
|
+
`@busirocket` baseline config packages (`eslint-config`, `prettier-config`,
|
|
5
|
+
`tsconfig`, `quality-config`) and optionally checks for a flat ESLint config
|
|
6
|
+
file and the quality-gate config files (`knip.config.ts`/`.js`, `lefthook.yml`,
|
|
7
|
+
`renovate.json`).
|
|
8
|
+
|
|
9
|
+
This CLI does not scaffold or copy files. It reports what's missing; you (or the
|
|
10
|
+
closest template under `templates/*`) provide the file.
|
|
11
|
+
|
|
12
|
+
## Requirements
|
|
13
|
+
|
|
14
|
+
- Node.js 20+
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
Use via `pnpm dlx` / `npx` (no need to add as a dependency for one-off checks):
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pnpm dlx @syntopica/create-baseline@^0.1.0 --soft
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
| Flag | Behavior |
|
|
27
|
+
| --------- | ----------------------------------------------------------------------------------------------------------------------- |
|
|
28
|
+
| `--soft` | Print recommended `pnpm` / `npm` install lines (default if no other flag); also advises on missing config files |
|
|
29
|
+
| `--check` | Exit non-zero if baseline packages are missing from `package.json` |
|
|
30
|
+
| `--hard` | Like `--check`, and require `eslint.config.*` plus `knip.config.ts`/`.js`, `lefthook.yml`, and `renovate.json` to exist |
|
|
31
|
+
| `--write` | Scaffold the quality-gate wiring this project is missing, then print what is still to install |
|
|
32
|
+
|
|
33
|
+
### `--write`
|
|
34
|
+
|
|
35
|
+
Writes `knip.config.ts`, `lefthook.yml`, `renovate.json` and
|
|
36
|
+
`.dependency-cruiser.cjs` when they are absent, and adds the baseline scripts
|
|
37
|
+
`package.json` does not already define. The knip preset is read off the
|
|
38
|
+
project's dependencies, so a Tauri app gets `tauri` and a Nest service gets
|
|
39
|
+
`nestjs`.
|
|
40
|
+
|
|
41
|
+
**Nothing that exists is overwritten.** A file already in the repo is the
|
|
42
|
+
project's, however it got there, and a tuned knip config is exactly what an
|
|
43
|
+
adopter spends time on; the same goes for a `lint` script scoped to `src`.
|
|
44
|
+
Re-running is a no-op.
|
|
45
|
+
|
|
46
|
+
Two things the generated wiring cannot know and you should review before
|
|
47
|
+
committing: `deps:graph` scopes itself to `src`, and a project with e2e specs or
|
|
48
|
+
hand-run scripts needs those declared as knip entry points.
|
|
49
|
+
|
|
50
|
+
### ESLint peer verification
|
|
51
|
+
|
|
52
|
+
Every mode also reports the ESLint peers your config actually reaches for:
|
|
53
|
+
missing ones, and installed ones at a version the config cannot use. The
|
|
54
|
+
subpaths are read from your `eslint.config.*`, so a project that never composes
|
|
55
|
+
`/tailwind` is never told about `eslint-plugin-tailwindcss`.
|
|
56
|
+
|
|
57
|
+
`@syntopica/eslint-config` ships TypeScript source rather than a build, so these
|
|
58
|
+
resolve from your project. pnpm reports a mismatch as one line among hundreds on
|
|
59
|
+
install; the consequence shows up much later as a crash from inside ESLint that
|
|
60
|
+
names neither the baseline nor the peer. Adopting calculadora hit three of them
|
|
61
|
+
in a row - one absent, one on a prerelease whose config was still
|
|
62
|
+
eslintrc-format, one a major behind the schema the config emits - and each took
|
|
63
|
+
a separate diagnosis.
|
|
64
|
+
|
|
65
|
+
Recommended baseline package versions are defined in `baseline-versions.json`
|
|
66
|
+
shipped with this package; update that file when releasing aligned semver bumps.
|
|
67
|
+
|
|
68
|
+
### Framework-generated TypeScript setups
|
|
69
|
+
|
|
70
|
+
`@syntopica/tsconfig` is not required when the project's own `tsconfig.json`
|
|
71
|
+
extends a config inside a dot-directory - build output its framework
|
|
72
|
+
regenerates, such as Nuxt's `./.nuxt/tsconfig.json`. There the framework owns
|
|
73
|
+
the compiler options end to end and the shared presets have no insertion point,
|
|
74
|
+
so demanding the dependency would only add a package nothing reads, which an
|
|
75
|
+
unused-dependency gate then reports as dead weight. Every other baseline package
|
|
76
|
+
is still required, and a `tsconfig.json` that cannot be parsed as JSON is
|
|
77
|
+
treated as authored, so an unreadable file never silently drops the requirement.
|
|
78
|
+
|
|
79
|
+
## Repository
|
|
80
|
+
|
|
81
|
+
Source and issues:
|
|
82
|
+
[github.com/BusiRocket/create-baseline](https://github.com/BusiRocket/create-baseline).
|
|
83
|
+
|
|
84
|
+
Adoption guides:
|
|
85
|
+
[engineering-baseline/docs/adoption](https://github.com/BusiRocket/engineering-baseline/tree/main/docs/adoption).
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"@syntopica/eslint-config": "^0.8.0",
|
|
3
|
+
"@syntopica/prettier-config": "^0.2.0",
|
|
4
|
+
"@syntopica/tsconfig": "^0.3.0",
|
|
5
|
+
"@syntopica/quality-config": "^0.11.0",
|
|
6
|
+
"eslint-plugin-code-policy": "^0.7.4",
|
|
7
|
+
"dependency-cruiser": "^18.1.1",
|
|
8
|
+
"jiti": "^2.7.0",
|
|
9
|
+
"jscpd": "^5.0.14",
|
|
10
|
+
"knip": "^6.31.0",
|
|
11
|
+
"lefthook": "^2.1.10",
|
|
12
|
+
"type-coverage": "^2.30.1",
|
|
13
|
+
"oxlint": "^1.80.0",
|
|
14
|
+
"@commitlint/cli": "^21.2.2",
|
|
15
|
+
"@commitlint/config-conventional": "^21.2.2"
|
|
16
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readFile } from 'node:fs/promises'
|
|
3
|
+
import { dirname, resolve } from 'node:path'
|
|
4
|
+
import { argv, cwd, exit } from 'node:process'
|
|
5
|
+
import { fileURLToPath } from 'node:url'
|
|
6
|
+
|
|
7
|
+
import { runConformance } from './conformance/runConformance.mjs'
|
|
8
|
+
import { findConsumers } from './estate/findConsumers.mjs'
|
|
9
|
+
import { findPythonConsumers } from './estate/findPythonConsumers.mjs'
|
|
10
|
+
import { formatEstate } from './estate/formatEstate.mjs'
|
|
11
|
+
import { formatPythonEstate } from './estate/formatPythonEstate.mjs'
|
|
12
|
+
import { runPythonConformance } from './python/runPythonConformance.mjs'
|
|
13
|
+
|
|
14
|
+
// Formalises the manual pre-publish sweep. Every release of these packages was
|
|
15
|
+
// already being A/B'd by hand against the repositories that consume them -
|
|
16
|
+
// that routine caught three defects the templates and the unit tests both
|
|
17
|
+
// missed - and this is that routine as one command.
|
|
18
|
+
const PACKAGE_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..')
|
|
19
|
+
|
|
20
|
+
async function main() {
|
|
21
|
+
const root = resolve(cwd(), argv[2] ?? '.')
|
|
22
|
+
const versions = JSON.parse(
|
|
23
|
+
await readFile(resolve(PACKAGE_ROOT, 'baseline-versions.json'), 'utf8'),
|
|
24
|
+
)
|
|
25
|
+
const pythonVersions = JSON.parse(
|
|
26
|
+
await readFile(resolve(PACKAGE_ROOT, 'python-versions.json'), 'utf8'),
|
|
27
|
+
)
|
|
28
|
+
const today = new Date().toISOString().slice(0, 10)
|
|
29
|
+
|
|
30
|
+
const consumers = await findConsumers(root)
|
|
31
|
+
const pythonConsumers = await findPythonConsumers(root)
|
|
32
|
+
if (!consumers.length && !pythonConsumers.length) {
|
|
33
|
+
console.log(`baseline-estate: no @syntopica consumers under ${root}.`)
|
|
34
|
+
return
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const rows = []
|
|
38
|
+
for (const consumer of consumers) {
|
|
39
|
+
try {
|
|
40
|
+
const { findings } = await runConformance(consumer.path, versions, today)
|
|
41
|
+
rows.push({ name: consumer.name, findings })
|
|
42
|
+
} catch (error) {
|
|
43
|
+
// One unreadable repository must not take the sweep down with it: the
|
|
44
|
+
// report is most useful precisely when part of the estate is broken.
|
|
45
|
+
rows.push({ name: consumer.name, error: String(error.message) })
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (rows.length) console.log(formatEstate(rows))
|
|
50
|
+
|
|
51
|
+
// The Python projects are a second table with their own columns: the
|
|
52
|
+
// audit that added them found nine gates green on one laptop and running
|
|
53
|
+
// nowhere else, which the JavaScript table could not see at all.
|
|
54
|
+
const pythonRows = []
|
|
55
|
+
for (const consumer of pythonConsumers) {
|
|
56
|
+
try {
|
|
57
|
+
const { findings } = await runPythonConformance(
|
|
58
|
+
consumer.path,
|
|
59
|
+
pythonVersions,
|
|
60
|
+
)
|
|
61
|
+
pythonRows.push({ name: consumer.name, findings })
|
|
62
|
+
} catch (error) {
|
|
63
|
+
pythonRows.push({ name: consumer.name, error: String(error.message) })
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (pythonRows.length) {
|
|
67
|
+
if (rows.length) console.log('')
|
|
68
|
+
console.log(formatPythonEstate(pythonRows))
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const failing = [...rows, ...pythonRows].filter(
|
|
72
|
+
(row) => row.error || row.findings.some((f) => f.level === 'error'),
|
|
73
|
+
)
|
|
74
|
+
// Exit non-zero so this can gate a release the same way any other check
|
|
75
|
+
// does. The estate is the release's blast radius; publishing into a red one
|
|
76
|
+
// is the mistake this is meant to prevent.
|
|
77
|
+
if (failing.length) exit(1)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
await main()
|
|
82
|
+
} catch (err) {
|
|
83
|
+
console.error(err)
|
|
84
|
+
exit(1)
|
|
85
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { readFile, writeFile } from 'node:fs/promises'
|
|
2
|
+
import { resolve } from 'node:path'
|
|
3
|
+
|
|
4
|
+
import { writeCiWorkflow } from '../scaffold/writeCiWorkflow.mjs'
|
|
5
|
+
|
|
6
|
+
const THRESHOLDS = ` thresholds: {
|
|
7
|
+
// vitest's own ratchet: the first run with --coverage raises each
|
|
8
|
+
// value to what the suite actually reaches and writes it back here.
|
|
9
|
+
// Entering an existing repository at a flat 80 turns the build red on
|
|
10
|
+
// day one, and a gate that starts red gets deleted rather than met.
|
|
11
|
+
autoUpdate: true,
|
|
12
|
+
lines: 0,
|
|
13
|
+
functions: 0,
|
|
14
|
+
branches: 0,
|
|
15
|
+
statements: 0,
|
|
16
|
+
},
|
|
17
|
+
`
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Applies the mechanical half of a conformance report.
|
|
21
|
+
*
|
|
22
|
+
* Only findings that carry a `fix` are touched, and only the kinds below.
|
|
23
|
+
* Everything else is left for a human: a missing test suite, a workflow that
|
|
24
|
+
* runs some entrypoints but not others, and an action pinned to a tag all
|
|
25
|
+
* need a decision this tool does not have.
|
|
26
|
+
*
|
|
27
|
+
* Returns the list of changes made, in the order they were applied.
|
|
28
|
+
*/
|
|
29
|
+
export async function applyFixes(root, findings) {
|
|
30
|
+
const applied = []
|
|
31
|
+
const manifestPath = resolve(root, 'package.json')
|
|
32
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
33
|
+
const manifest = JSON.parse(await readFile(manifestPath, 'utf8'))
|
|
34
|
+
let manifestDirty = false
|
|
35
|
+
|
|
36
|
+
for (const finding of findings) {
|
|
37
|
+
const fix = finding.fix
|
|
38
|
+
if (!fix) continue
|
|
39
|
+
|
|
40
|
+
if (fix.kind === 'set-script') {
|
|
41
|
+
manifest.scripts ??= {}
|
|
42
|
+
manifest.scripts[fix.name] = fix.value
|
|
43
|
+
manifestDirty = true
|
|
44
|
+
applied.push(`scripts.${fix.name} = ${fix.value}`)
|
|
45
|
+
continue
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (fix.kind === 'append-to-script') {
|
|
49
|
+
manifest.scripts ??= {}
|
|
50
|
+
const current = manifest.scripts[fix.name]
|
|
51
|
+
// Appending the same command twice never helps: when a fix re-fires
|
|
52
|
+
// (two findings sharing a target, or a re-run before the gate goes
|
|
53
|
+
// green) the entrypoint must not accumulate duplicates.
|
|
54
|
+
if (current?.split(' && ').includes(fix.value)) continue
|
|
55
|
+
manifest.scripts[fix.name] = current
|
|
56
|
+
? `${current} && ${fix.value}`
|
|
57
|
+
: fix.value
|
|
58
|
+
manifestDirty = true
|
|
59
|
+
applied.push(`scripts.${fix.name} += ${fix.value}`)
|
|
60
|
+
continue
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (fix.kind === 'set-dependency') {
|
|
64
|
+
const field = manifest.devDependencies?.[fix.name]
|
|
65
|
+
? 'devDependencies'
|
|
66
|
+
: manifest.dependencies?.[fix.name]
|
|
67
|
+
? 'dependencies'
|
|
68
|
+
: 'devDependencies'
|
|
69
|
+
manifest[field] ??= {}
|
|
70
|
+
manifest[field][fix.name] = fix.value
|
|
71
|
+
manifestDirty = true
|
|
72
|
+
applied.push(`${field}.${fix.name} = ${fix.value}`)
|
|
73
|
+
continue
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (fix.kind === 'write-workflow') {
|
|
77
|
+
const result = await writeCiWorkflow(root, {
|
|
78
|
+
hasBuild: Boolean(manifest.scripts?.build),
|
|
79
|
+
})
|
|
80
|
+
if (result.written) applied.push(`wrote ${result.written}`)
|
|
81
|
+
continue
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (fix.kind === 'insert-coverage-thresholds') {
|
|
85
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
86
|
+
const text = await readFile(fix.path, 'utf8')
|
|
87
|
+
const patched = text.replace(/(\bcoverage\s*:\s*\{\n)/, `$1${THRESHOLDS}`)
|
|
88
|
+
if (patched === text) continue
|
|
89
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
90
|
+
await writeFile(fix.path, patched, 'utf8')
|
|
91
|
+
applied.push(`added coverage thresholds to ${fix.path}`)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (manifestDirty) {
|
|
96
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
97
|
+
await writeFile(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return applied
|
|
101
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// `uses: owner/repo@ref` in a workflow. Local (`./.github/actions/x`) and
|
|
2
|
+
// container (`docker://`) references have no tag to move and are skipped.
|
|
3
|
+
const USES = /^\s*(?:-\s*)?uses:\s*['"]?([^'"\s#]+)['"]?/gm
|
|
4
|
+
const SHA_PINNED = /@[0-9a-f]{40}$/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Every third-party action must be pinned to a commit SHA.
|
|
8
|
+
*
|
|
9
|
+
* A tag is mutable. Whoever controls the action repository can move `v6` to
|
|
10
|
+
* any commit at any time, and every workflow referencing it runs the new code
|
|
11
|
+
* on the next push with no diff in this repository to review. This is the
|
|
12
|
+
* shape of the tj-actions/changed-files compromise, and it is not theoretical.
|
|
13
|
+
*
|
|
14
|
+
* One repository in the estate (verticagtm) pinned by SHA; the baseline repo
|
|
15
|
+
* itself did not. That asymmetry is what this check exists to remove.
|
|
16
|
+
*/
|
|
17
|
+
export function checkActionPins({ workflows }) {
|
|
18
|
+
const unpinned = new Map()
|
|
19
|
+
|
|
20
|
+
for (const workflow of workflows) {
|
|
21
|
+
for (const match of workflow.text.matchAll(USES)) {
|
|
22
|
+
const ref = match[1]
|
|
23
|
+
if (ref.startsWith('./') || ref.startsWith('docker://')) continue
|
|
24
|
+
if (SHA_PINNED.test(ref)) continue
|
|
25
|
+
if (!unpinned.has(ref)) unpinned.set(ref, new Set())
|
|
26
|
+
unpinned.get(ref).add(workflow.name)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!unpinned.size) return []
|
|
31
|
+
|
|
32
|
+
return [...unpinned].map(([ref, files]) => ({
|
|
33
|
+
id: `action-pin:${ref}`,
|
|
34
|
+
level: 'error',
|
|
35
|
+
message: `\`${ref}\` is pinned to a tag, not a commit`,
|
|
36
|
+
detail:
|
|
37
|
+
`In ${[...files].join(', ')}. Resolve it with ` +
|
|
38
|
+
`\`gh api repos/${ref.split('@')[0]}/git/ref/tags/${ref.split('@')[1] ?? 'v1'}\` ` +
|
|
39
|
+
'(dereference a second time through `git/tags/<sha>` if it reports an ' +
|
|
40
|
+
'annotated tag) and keep the tag name as a trailing comment so Renovate ' +
|
|
41
|
+
'can still offer the upgrade.',
|
|
42
|
+
}))
|
|
43
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// A workflow that fires on the events code arrives through. A pipeline that
|
|
2
|
+
// only runs on `workflow_dispatch` or a schedule is not a gate: nothing stops
|
|
3
|
+
// a push that breaks it.
|
|
4
|
+
const AUTOMATIC_TRIGGER = /^\s*(?:push|pull_request|pull_request_target)\s*:/m
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Something has to run the gates on every push.
|
|
8
|
+
*
|
|
9
|
+
* lefthook's pre-commit lints staged files and its pre-push scans for secrets;
|
|
10
|
+
* neither runs type-check, tests, knip, jscpd, dependency-cruiser or
|
|
11
|
+
* type-coverage. Without a workflow those gates have no automatic trigger
|
|
12
|
+
* anywhere, which described eight of seventeen adopters at the time this check
|
|
13
|
+
* was written - every one of them with the full gate set installed as scripts.
|
|
14
|
+
*
|
|
15
|
+
* A hook is also skippable (`--no-verify`) and a local machine is not a clean
|
|
16
|
+
* install; CI is the only place a gate is actually mandatory.
|
|
17
|
+
*
|
|
18
|
+
* Which gates the pipeline runs is `checkGateCoverage`'s question, and it
|
|
19
|
+
* reads them off these same workflows. This check only asks whether there is a
|
|
20
|
+
* pipeline and whether code arriving in the repository triggers it.
|
|
21
|
+
*/
|
|
22
|
+
export function checkCiWorkflow({ workflows }) {
|
|
23
|
+
if (!workflows.length) {
|
|
24
|
+
return [
|
|
25
|
+
{
|
|
26
|
+
id: 'ci-workflow',
|
|
27
|
+
level: 'error',
|
|
28
|
+
message: 'no GitHub Actions workflow',
|
|
29
|
+
detail:
|
|
30
|
+
'The gates are installed and unreachable: nothing runs them on ' +
|
|
31
|
+
'push. `create-baseline --write` writes .github/workflows/ci.yml.',
|
|
32
|
+
fix: { kind: 'write-workflow' },
|
|
33
|
+
},
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (workflows.some((workflow) => AUTOMATIC_TRIGGER.test(workflow.text))) {
|
|
38
|
+
return []
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return [
|
|
42
|
+
{
|
|
43
|
+
id: 'ci-workflow',
|
|
44
|
+
level: 'error',
|
|
45
|
+
message: 'no workflow runs on push or pull request',
|
|
46
|
+
detail:
|
|
47
|
+
`Workflows present (${workflows.map((w) => w.name).join(', ')}) but ` +
|
|
48
|
+
'every one of them is manual or scheduled, so nothing gates the code ' +
|
|
49
|
+
'that arrives between runs.',
|
|
50
|
+
},
|
|
51
|
+
]
|
|
52
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
const HAS_THRESHOLDS = /\bthresholds\s*:|\bcoverageThreshold\s*:/
|
|
2
|
+
const HAS_COVERAGE_BLOCK = /\bcoverage\s*:\s*\{/g
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Coverage has to be measured, and the measurement has to fail a build.
|
|
6
|
+
*
|
|
7
|
+
* Every template sets `thresholds: { lines: 80, functions: 80, branches: 80,
|
|
8
|
+
* statements: 80 }` in its vitest config. No adopter did - the invariant only
|
|
9
|
+
* ever existed for projects scaffolded from scratch, because this tool wrote
|
|
10
|
+
* package scripts and never touched a test-runner config. Fifteen of
|
|
11
|
+
* seventeen did not even pass `--coverage`, so the number was not being
|
|
12
|
+
* produced, let alone enforced.
|
|
13
|
+
*
|
|
14
|
+
* The `--fix` for a missing threshold block writes `autoUpdate: true` with a
|
|
15
|
+
* floor of zero rather than a flat 80. That is vitest's own ratchet: the first
|
|
16
|
+
* run with `--coverage` raises every threshold to the level the suite actually
|
|
17
|
+
* reaches and writes it back to the config, and from then on the number can
|
|
18
|
+
* only go up. Entering an existing repository at 80 would turn fifteen
|
|
19
|
+
* builds red on the first day, and a gate that starts red gets deleted rather
|
|
20
|
+
* than met.
|
|
21
|
+
*/
|
|
22
|
+
export function checkCoverageThresholds({ scripts, testConfig }) {
|
|
23
|
+
const findings = []
|
|
24
|
+
const test = scripts.test
|
|
25
|
+
|
|
26
|
+
// A monorepo root runs its suites through the workspaces, and its coverage
|
|
27
|
+
// configuration lives in each of them. Judging the root would report the
|
|
28
|
+
// reference implementation as having no tests at all.
|
|
29
|
+
if (delegates(scripts)) {
|
|
30
|
+
return [
|
|
31
|
+
{
|
|
32
|
+
id: 'coverage',
|
|
33
|
+
level: 'info',
|
|
34
|
+
message: 'tests run through workspaces',
|
|
35
|
+
detail:
|
|
36
|
+
'Coverage is configured per workspace; this check cannot see them ' +
|
|
37
|
+
'from the root. Run the conformance check inside each workspace.',
|
|
38
|
+
},
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (!test) {
|
|
43
|
+
return [
|
|
44
|
+
{
|
|
45
|
+
id: 'coverage',
|
|
46
|
+
level: 'error',
|
|
47
|
+
message: 'no `test` script',
|
|
48
|
+
detail: 'Nothing to measure coverage of.',
|
|
49
|
+
},
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (!/--coverage\b/.test(test) && !/\bcoverage\b/.test(test)) {
|
|
54
|
+
findings.push({
|
|
55
|
+
id: 'coverage-run',
|
|
56
|
+
level: 'error',
|
|
57
|
+
message: '`test` does not produce a coverage report',
|
|
58
|
+
detail: 'Without `--coverage` the thresholds below are never evaluated.',
|
|
59
|
+
fix: {
|
|
60
|
+
kind: 'set-script',
|
|
61
|
+
name: 'test',
|
|
62
|
+
value: `${test.trim()} --coverage`,
|
|
63
|
+
},
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (!testConfig) {
|
|
68
|
+
findings.push({
|
|
69
|
+
id: 'coverage-thresholds',
|
|
70
|
+
level: 'error',
|
|
71
|
+
message: 'no test-runner config to hold coverage thresholds',
|
|
72
|
+
detail:
|
|
73
|
+
'Expected one of vitest.config.*, vite.config.* or jest.config.*.',
|
|
74
|
+
})
|
|
75
|
+
return findings
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (HAS_THRESHOLDS.test(testConfig.text)) return findings
|
|
79
|
+
|
|
80
|
+
const coverageBlocks = [...testConfig.text.matchAll(HAS_COVERAGE_BLOCK)]
|
|
81
|
+
findings.push({
|
|
82
|
+
id: 'coverage-thresholds',
|
|
83
|
+
level: 'error',
|
|
84
|
+
message: `no coverage thresholds in ${testConfig.name}`,
|
|
85
|
+
detail:
|
|
86
|
+
'Coverage is reported and ignored. Add a `thresholds` block with ' +
|
|
87
|
+
'`autoUpdate: true` and a floor of 0: the next run sets every value to ' +
|
|
88
|
+
'what the suite reaches today, and it can only rise from there.',
|
|
89
|
+
// Exactly one `coverage: {` is required for the automatic edit. Two means
|
|
90
|
+
// the file configures more than one project or environment, and guessing
|
|
91
|
+
// which one owns the gate would silently protect the wrong half.
|
|
92
|
+
fix:
|
|
93
|
+
coverageBlocks.length === 1
|
|
94
|
+
? { kind: 'insert-coverage-thresholds', path: testConfig.path }
|
|
95
|
+
: undefined,
|
|
96
|
+
})
|
|
97
|
+
return findings
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Whether the project hands its test run to a workspace runner rather than
|
|
101
|
+
// running a suite of its own. Matched against every script, not just `test`:
|
|
102
|
+
// the baseline repo reaches its suites through `check:ci`, which calls
|
|
103
|
+
// `turbo run ... test ...`, and defines no root `test` script at all.
|
|
104
|
+
function delegates(scripts) {
|
|
105
|
+
return Object.values(scripts).some(
|
|
106
|
+
(command) =>
|
|
107
|
+
typeof command === 'string' &&
|
|
108
|
+
/\b(?:turbo|nx|lerna)\s+run\s+(?:[\w:-]+\s+)*test\b|(?:pnpm|npm|yarn)\s+(?:-r|--recursive)\s+(?:run\s+)?test\b/.test(
|
|
109
|
+
command,
|
|
110
|
+
),
|
|
111
|
+
)
|
|
112
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { ciEntrypoints } from './ciEntrypoints.mjs'
|
|
2
|
+
import { expandScripts } from './expandScripts.mjs'
|
|
3
|
+
|
|
4
|
+
// The fallback entrypoints, used only when there is no workflow to read the
|
|
5
|
+
// real ones from.
|
|
6
|
+
const ENTRIES = ['check:ci', 'check:quality', 'check:security']
|
|
7
|
+
|
|
8
|
+
// Each gate, the script name that conventionally runs it, and the command
|
|
9
|
+
// fragment that proves it ran even when the project spells it inline. Matching
|
|
10
|
+
// on both is what lets a repo write `pnpm exec knip` or `depcruise src`
|
|
11
|
+
// directly instead of going through the named script.
|
|
12
|
+
const GATES = [
|
|
13
|
+
{
|
|
14
|
+
id: 'type-check',
|
|
15
|
+
script: 'type-check',
|
|
16
|
+
tool: /\btsc\b|\bvue-tsc\b|\btype-check\b/,
|
|
17
|
+
},
|
|
18
|
+
// Only ESLint satisfies this. oxlint is a pre-filter with no type
|
|
19
|
+
// information, so it cannot see most of what the baseline enforces;
|
|
20
|
+
// accepting it here would let a repository drop the real gate and still
|
|
21
|
+
// report as wired.
|
|
22
|
+
{ id: 'lint', script: 'lint', tool: /\beslint\b/ },
|
|
23
|
+
{ id: 'format', script: 'format:check', tool: /prettier\s+--check/ },
|
|
24
|
+
{ id: 'test', script: 'test', tool: /\bvitest\b|\bjest\b|\bnode --test\b/ },
|
|
25
|
+
{ id: 'dupes', script: 'dupes', tool: /baseline-dupes|\bjscpd\b/ },
|
|
26
|
+
{ id: 'knip', script: 'knip', tool: /\bknip\b/ },
|
|
27
|
+
{
|
|
28
|
+
id: 'deps:graph',
|
|
29
|
+
script: 'deps:graph',
|
|
30
|
+
tool: /baseline-deps-graph|\bdepcruise\b|dependency-cruiser/,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
id: 'type-coverage',
|
|
34
|
+
script: 'type-coverage',
|
|
35
|
+
tool: /baseline-type-coverage|\btype-coverage\b/,
|
|
36
|
+
},
|
|
37
|
+
{ id: 'secrets', script: 'secrets:check', tool: /\bgitleaks\b/ },
|
|
38
|
+
{ id: 'audit', script: 'audit:check', tool: /\baudit\b/ },
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Every gate must be reachable from what CI runs.
|
|
43
|
+
*
|
|
44
|
+
* Measured from the pipeline, not from a name. Asserting that a workflow says
|
|
45
|
+
* `check:ci` was the wrong question: verticagtm runs every gate in CI as its
|
|
46
|
+
* own step and never uses that word, and it is the best-wired repository in
|
|
47
|
+
* the estate. So the entrypoints are whatever scripts the workflows invoke,
|
|
48
|
+
* and the assertion is that the union of everything reachable from them
|
|
49
|
+
* covers all ten gates - not which entrypoint holds which gate.
|
|
50
|
+
*
|
|
51
|
+
* With no workflow at all the check falls back to the three `check:*` scripts,
|
|
52
|
+
* so the report still says which gates are missing locally. `checkCiWorkflow`
|
|
53
|
+
* reports the absent pipeline separately; both findings are true, and fixing
|
|
54
|
+
* the pipeline without fixing the gates would leave half the report standing.
|
|
55
|
+
*
|
|
56
|
+
* This is the estate's most common failure by a wide margin: eleven of
|
|
57
|
+
* seventeen adopters had `check:quality` written into package.json by this
|
|
58
|
+
* tool and nothing calling it, which made knip, dependency-cruiser and
|
|
59
|
+
* type-coverage - the findings a reviewer cannot see in a diff - dead
|
|
60
|
+
* configuration.
|
|
61
|
+
*/
|
|
62
|
+
export function checkGateCoverage({ scripts, workflows = [], runners = {} }) {
|
|
63
|
+
const fromCi = ciEntrypoints(workflows, scripts)
|
|
64
|
+
const entries = fromCi.length ? fromCi : ENTRIES
|
|
65
|
+
const source = fromCi.length ? 'CI' : 'any check:* entrypoint'
|
|
66
|
+
|
|
67
|
+
if (!entries.some((name) => Object.hasOwn(scripts, name))) {
|
|
68
|
+
return [
|
|
69
|
+
{
|
|
70
|
+
id: 'check-entrypoints',
|
|
71
|
+
level: 'error',
|
|
72
|
+
message: 'no `check:ci`, `check:quality` or `check:security` script',
|
|
73
|
+
detail: 'Run `create-baseline --write` to add them.',
|
|
74
|
+
},
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const { names, text } = expandScripts(scripts, entries, runners)
|
|
79
|
+
const present = entries.filter((name) => Object.hasOwn(scripts, name))
|
|
80
|
+
const findings = []
|
|
81
|
+
|
|
82
|
+
for (const gate of GATES) {
|
|
83
|
+
if (names.has(gate.script) || gate.tool.test(text)) continue
|
|
84
|
+
findings.push({
|
|
85
|
+
id: `gate:${gate.id}`,
|
|
86
|
+
level: 'error',
|
|
87
|
+
message: `\`${gate.id}\` is never invoked`,
|
|
88
|
+
detail: scripts[gate.script]
|
|
89
|
+
? `The \`${gate.script}\` script exists but ${source} never reaches it.`
|
|
90
|
+
: `No \`${gate.script}\` script, and ${source} does not run the tool directly.`,
|
|
91
|
+
fix: scripts[gate.script]
|
|
92
|
+
? {
|
|
93
|
+
kind: 'append-to-script',
|
|
94
|
+
name: entryFor(gate.id, present),
|
|
95
|
+
value: `pnpm ${gate.script}`,
|
|
96
|
+
}
|
|
97
|
+
: undefined,
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return findings
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Where a missing gate is appended when `--fix` runs: the fast path for the
|
|
105
|
+
// gates a developer expects before pushing, the slower whole-tree pass for the
|
|
106
|
+
// ones that walk the graph, the full-clone job for the ones that need it.
|
|
107
|
+
// Constrained to the entrypoints the pipeline actually reaches: appending to
|
|
108
|
+
// a conventional script CI never invokes recreates the dead-configuration
|
|
109
|
+
// failure this check exists to catch, and `--fix` never converges.
|
|
110
|
+
function entryFor(id, present) {
|
|
111
|
+
const preferred =
|
|
112
|
+
id === 'secrets' || id === 'audit'
|
|
113
|
+
? 'check:security'
|
|
114
|
+
: id === 'deps:graph' || id === 'type-coverage'
|
|
115
|
+
? 'check:quality'
|
|
116
|
+
: 'check:ci'
|
|
117
|
+
if (present.includes(preferred)) return preferred
|
|
118
|
+
// Only an aggregate check script is a sane host for a gate. Appending to
|
|
119
|
+
// whatever CI happens to run first put `type-coverage` inside one repo's
|
|
120
|
+
// `build` and another's `lint:prune`; when no check entrypoint is
|
|
121
|
+
// reachable, keep the conventional name and leave the finding standing for
|
|
122
|
+
// a human to wire the pipeline.
|
|
123
|
+
const aggregate = present.find(
|
|
124
|
+
(name) =>
|
|
125
|
+
name === 'check:ci' || name === 'check' || name.startsWith('check:'),
|
|
126
|
+
)
|
|
127
|
+
return aggregate ?? preferred
|
|
128
|
+
}
|