@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.
Files changed (52) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +85 -0
  3. package/baseline-versions.json +16 -0
  4. package/bin/baseline-estate.mjs +85 -0
  5. package/bin/conformance/applyFixes.mjs +101 -0
  6. package/bin/conformance/checkActionPins.mjs +43 -0
  7. package/bin/conformance/checkCiWorkflow.mjs +52 -0
  8. package/bin/conformance/checkCoverageThresholds.mjs +112 -0
  9. package/bin/conformance/checkGateCoverage.mjs +128 -0
  10. package/bin/conformance/checkHooksInstalled.mjs +43 -0
  11. package/bin/conformance/checkLintFlag.mjs +86 -0
  12. package/bin/conformance/checkTsconfigPresets.mjs +58 -0
  13. package/bin/conformance/checkTsconfigProjects.mjs +47 -0
  14. package/bin/conformance/checkVersionRanges.mjs +51 -0
  15. package/bin/conformance/ciEntrypoints.mjs +37 -0
  16. package/bin/conformance/expandScripts.mjs +76 -0
  17. package/bin/conformance/formatFindings.mjs +36 -0
  18. package/bin/conformance/loadContext.mjs +175 -0
  19. package/bin/conformance/loadExceptions.mjs +73 -0
  20. package/bin/conformance/rangeFloor.mjs +23 -0
  21. package/bin/conformance/readWorkflows.mjs +29 -0
  22. package/bin/conformance/runConformance.mjs +57 -0
  23. package/bin/create-baseline.mjs +432 -0
  24. package/bin/estate/findConsumers.mjs +46 -0
  25. package/bin/estate/findPythonConsumers.mjs +58 -0
  26. package/bin/estate/formatEstate.mjs +67 -0
  27. package/bin/estate/formatPythonEstate.mjs +37 -0
  28. package/bin/python/checkGateWorkflow.mjs +33 -0
  29. package/bin/python/checkLockPin.mjs +36 -0
  30. package/bin/python/checkQualityGroup.mjs +33 -0
  31. package/bin/python/loadPythonContext.mjs +32 -0
  32. package/bin/python/repositoryRoot.mjs +24 -0
  33. package/bin/python/runPythonConformance.mjs +25 -0
  34. package/bin/scaffold/actionPins.mjs +34 -0
  35. package/bin/scaffold/baselineScripts.mjs +44 -0
  36. package/bin/scaffold/checkPeers.mjs +87 -0
  37. package/bin/scaffold/ciWorkflow.mjs +144 -0
  38. package/bin/scaffold/collectDeps.mjs +10 -0
  39. package/bin/scaffold/composedSubpaths.mjs +41 -0
  40. package/bin/scaffold/depCruiserConfig.mjs +30 -0
  41. package/bin/scaffold/detectFramework.mjs +18 -0
  42. package/bin/scaffold/eslintSubpathPeers.mjs +60 -0
  43. package/bin/scaffold/knipConfig.mjs +9 -0
  44. package/bin/scaffold/lefthookConfig.mjs +33 -0
  45. package/bin/scaffold/oxlintConfig.mjs +19 -0
  46. package/bin/scaffold/readManifest.mjs +17 -0
  47. package/bin/scaffold/renovateConfig.mjs +11 -0
  48. package/bin/scaffold/workspaceRoots.mjs +89 -0
  49. package/bin/scaffold/writeCiWorkflow.mjs +54 -0
  50. package/bin/scaffold/writeMissing.mjs +116 -0
  51. package/package.json +59 -0
  52. package/python-versions.json +3 -0
@@ -0,0 +1,67 @@
1
+ const COLUMNS = [
2
+ ['lint 0', (ids) => !ids.has('lint-flag') && !ids.has('lint-script')],
3
+ ['ci', (ids) => !ids.has('ci-workflow')],
4
+ ['pins', (ids) => ![...ids].some((id) => id.startsWith('action-pin:'))],
5
+ [
6
+ 'gates',
7
+ (ids) =>
8
+ // A repository with no check:* entrypoint at all reports
9
+ // `check-entrypoints` instead of ten `gate:` findings; without it here,
10
+ // having none of the wiring would read as having all of it.
11
+ !ids.has('check-entrypoints') &&
12
+ ![...ids].some((id) => id.startsWith('gate:')),
13
+ ],
14
+ ['tscfg', (ids) => ![...ids].some((id) => id.startsWith('tsconfig-'))],
15
+ ['cov', (ids) => !ids.has('coverage-run') && !ids.has('coverage-thresholds')],
16
+ ['hooks', (ids) => !ids.has('hooks')],
17
+ ['vers', (ids) => ![...ids].some((id) => id.startsWith('version:'))],
18
+ ]
19
+
20
+ /**
21
+ * The estate as one table: a row per repository, a column per class of gate.
22
+ *
23
+ * The point is the shape of the estate rather than any one repository's
24
+ * detail - a column of crosses says the baseline is missing a mechanism, not
25
+ * that seventeen authors each made the same oversight. Every finding this
26
+ * summarises is still available in full by running `create-baseline --check`
27
+ * inside the repository the row names.
28
+ */
29
+ export function formatEstate(rows) {
30
+ const width = Math.max(10, ...rows.map((row) => row.name.length))
31
+ const lines = [
32
+ `${'repository'.padEnd(width)} ${COLUMNS.map(([label]) => label.padEnd(7)).join('')}`,
33
+ '-'.repeat(width + 2 + COLUMNS.length * 7),
34
+ ]
35
+
36
+ for (const row of rows) {
37
+ if (row.error) {
38
+ lines.push(`${row.name.padEnd(width)} ${row.error}`)
39
+ continue
40
+ }
41
+ // Only failures colour a cell. An informational finding - a monorepo
42
+ // root whose lint delegates to its workspaces, say - is a note, not a
43
+ // gap, and colouring it would make the estate look worse than it is.
44
+ const ids = new Set(
45
+ row.findings
46
+ .filter((finding) => finding.level !== 'info')
47
+ .map((finding) => finding.id),
48
+ )
49
+ const cells = COLUMNS.map(([, passes]) =>
50
+ (passes(ids) ? 'ok' : 'FAIL').padEnd(7),
51
+ )
52
+ lines.push(`${row.name.padEnd(width)} ${cells.join('')}`)
53
+ }
54
+
55
+ const clean = rows.filter(
56
+ (row) =>
57
+ !row.error && !row.findings.some((finding) => finding.level !== 'info'),
58
+ ).length
59
+ lines.push(
60
+ '',
61
+ `${rows.length} consumers, ${clean} fully wired.`,
62
+ 'Run `create-baseline --check` inside a repository for its findings, or',
63
+ '`create-baseline --fix` to repair the mechanical ones.',
64
+ )
65
+
66
+ return lines.join('\n')
67
+ }
@@ -0,0 +1,37 @@
1
+ const COLUMNS = [
2
+ ['group', (ids) => !ids.has('py-tool') && !ids.has('py-quality-group')],
3
+ ['ci', (ids) => !ids.has('py-ci-workflow')],
4
+ ['pins', (ids) => ![...ids].some((id) => id.startsWith('action-pin:'))],
5
+ ['lock', (ids) => !ids.has('py-lock')],
6
+ ]
7
+
8
+ /**
9
+ * The Python side of the estate as one table, a row per project.
10
+ *
11
+ * Kept apart from the JavaScript table because the columns differ: there is
12
+ * no tsconfig or lint flag to check, and a shared table would show every
13
+ * Python row failing gates it does not have.
14
+ */
15
+ export function formatPythonEstate(rows) {
16
+ const width = Math.max(10, ...rows.map((row) => row.name.length))
17
+ const lines = [
18
+ `${'python'.padEnd(width)} ${COLUMNS.map(([label]) => label.padEnd(7)).join('')}`,
19
+ '-'.repeat(width + 2 + COLUMNS.length * 7),
20
+ ]
21
+ for (const row of rows) {
22
+ if (row.error) {
23
+ lines.push(`${row.name.padEnd(width)} ${row.error}`)
24
+ continue
25
+ }
26
+ const ids = new Set(row.findings.map((finding) => finding.id))
27
+ const cells = COLUMNS.map(([, passes]) =>
28
+ (passes(ids) ? 'ok' : 'FAIL').padEnd(7),
29
+ )
30
+ lines.push(`${row.name.padEnd(width)} ${cells.join('')}`)
31
+ }
32
+ const clean = rows.filter(
33
+ (row) => !row.error && row.findings.length === 0,
34
+ ).length
35
+ lines.push('', `${rows.length} Python projects, ${clean} fully wired.`)
36
+ return lines.join('\n')
37
+ }
@@ -0,0 +1,33 @@
1
+ const AUTOMATIC_TRIGGER = /^\s*(?:push|pull_request|pull_request_target)\s*:/m
2
+ const RUNS_GATE = /\bbaseline-py\s+gate\b/
3
+
4
+ /**
5
+ * Something has to run `baseline-py gate` on every push.
6
+ *
7
+ * The 2026-09-01 audit found every adopted repository green locally and not
8
+ * one of them running the gate anywhere else; one still ran its
9
+ * pre-adoption pip-and-pytest workflow beside a full quality group it never
10
+ * installed. A hook is skippable and a laptop is not a clean install; CI is
11
+ * the only place the gate is mandatory.
12
+ */
13
+ export function checkGateWorkflow({ workflows }) {
14
+ const gated = workflows.filter((workflow) => RUNS_GATE.test(workflow.text))
15
+ if (gated.some((workflow) => AUTOMATIC_TRIGGER.test(workflow.text))) {
16
+ return []
17
+ }
18
+ const message = gated.length
19
+ ? 'the workflow running baseline-py gate is manual or scheduled'
20
+ : workflows.length
21
+ ? 'no workflow runs baseline-py gate'
22
+ : 'no GitHub Actions workflow'
23
+ return [
24
+ {
25
+ id: 'py-ci-workflow',
26
+ level: 'error',
27
+ message,
28
+ detail:
29
+ 'The gate is installed and unreachable: nothing runs it on push. ' +
30
+ '`baseline-py init --ci --apply` writes .github/workflows/quality.yml.',
31
+ },
32
+ ]
33
+ }
@@ -0,0 +1,36 @@
1
+ const TOOL = 'busirocket-baseline-py'
2
+ const LOCKED = /^name = "busirocket-baseline-py"\nversion = "([^"]+)"/m
3
+
4
+ /**
5
+ * The lockfile must pin the current release of the tool.
6
+ *
7
+ * A consumer's uv.lock holds the version, and `uv lock --check` passes as
8
+ * long as the range allows it - which is how two repositories sat on 0.1.0
9
+ * and 0.1.7 through a sweep that believed it had upgraded everything. A
10
+ * consumer on an old pin runs the old stages silently.
11
+ */
12
+ export function checkLockPin({ lock, versions }) {
13
+ const expected = versions[TOOL]
14
+ if (!expected) return []
15
+ if (!lock) {
16
+ return [
17
+ {
18
+ id: 'py-lock',
19
+ level: 'error',
20
+ message: 'no uv.lock',
21
+ detail:
22
+ 'Run `uv lock` and commit the result; CI installs with --locked.',
23
+ },
24
+ ]
25
+ }
26
+ const locked = LOCKED.exec(lock)?.[1]
27
+ if (locked === expected) return []
28
+ return [
29
+ {
30
+ id: 'py-lock',
31
+ level: 'error',
32
+ message: `uv.lock pins ${TOOL} ${locked ?? 'nowhere'}, current is ${expected}`,
33
+ detail: `Run \`uv lock --upgrade-package ${TOOL}\` and commit the result.`,
34
+ },
35
+ ]
36
+ }
@@ -0,0 +1,33 @@
1
+ const TOOL = 'busirocket-baseline-py'
2
+ const GROUP = /^\s*quality\s*=\s*\[[^\]]*busirocket-baseline-py/m
3
+
4
+ /**
5
+ * The gate's tools must be declared as a `quality` dependency group.
6
+ *
7
+ * `baseline-py gate` runs ruff, mypy, deptry, pip-audit and pytest from the
8
+ * environment it is invoked in; a project that lists only the tool cannot
9
+ * run its gate, and one whose floor is below 3.11 cannot list it at all.
10
+ */
11
+ export function checkQualityGroup({ pyproject }) {
12
+ if (!pyproject.includes(TOOL)) {
13
+ return [
14
+ {
15
+ id: 'py-tool',
16
+ level: 'error',
17
+ message: `${TOOL} is not a dependency`,
18
+ detail: 'Add the quality group with `baseline-py init --apply`.',
19
+ },
20
+ ]
21
+ }
22
+ if (GROUP.test(pyproject)) return []
23
+ return [
24
+ {
25
+ id: 'py-quality-group',
26
+ level: 'error',
27
+ message: `${TOOL} is declared outside the quality dependency group`,
28
+ detail:
29
+ 'The gate needs ruff, mypy, deptry, pip-audit, pytest and pytest-cov ' +
30
+ 'beside it; `baseline-py init --apply` declares the group.',
31
+ },
32
+ ]
33
+ }
@@ -0,0 +1,32 @@
1
+ import { readFile } from 'node:fs/promises'
2
+ import { resolve } from 'node:path'
3
+
4
+ import { readWorkflows } from '../conformance/readWorkflows.mjs'
5
+ import { repositoryRoot } from './repositoryRoot.mjs'
6
+
7
+ /**
8
+ * Everything the Python conformance checks read, gathered once.
9
+ *
10
+ * Workflows are read from the enclosing repository, since a nested project's
11
+ * workflow lives at that root. `pyproject` and `lock` are raw text: the checks look for one dependency
12
+ * name and one pinned version, and a TOML parser would be a dependency
13
+ * carried for two string searches.
14
+ */
15
+ export async function loadPythonContext(root, versions) {
16
+ return {
17
+ root,
18
+ versions,
19
+ pyproject: await readText(resolve(root, 'pyproject.toml')),
20
+ lock: await readText(resolve(root, 'uv.lock')),
21
+ workflows: await readWorkflows(await repositoryRoot(root)),
22
+ }
23
+ }
24
+
25
+ async function readText(path) {
26
+ try {
27
+ // eslint-disable-next-line security/detect-non-literal-fs-filename
28
+ return await readFile(path, 'utf8')
29
+ } catch {
30
+ return ''
31
+ }
32
+ }
@@ -0,0 +1,24 @@
1
+ import { access } from 'node:fs/promises'
2
+ import { dirname, resolve } from 'node:path'
3
+
4
+ /**
5
+ * The nearest ancestor holding `.git`, or the project itself.
6
+ *
7
+ * A Python project nested inside a repository keeps its workflow at that
8
+ * repository's root, because GitHub reads workflows nowhere else; the check
9
+ * has to look where the workflow can actually be.
10
+ */
11
+ export async function repositoryRoot(root) {
12
+ let dir = root
13
+ for (;;) {
14
+ try {
15
+ await access(resolve(dir, '.git'))
16
+ return dir
17
+ } catch {
18
+ /* keep climbing */
19
+ }
20
+ const parent = dirname(dir)
21
+ if (parent === dir) return root
22
+ dir = parent
23
+ }
24
+ }
@@ -0,0 +1,25 @@
1
+ import { checkActionPins } from '../conformance/checkActionPins.mjs'
2
+ import { checkGateWorkflow } from './checkGateWorkflow.mjs'
3
+ import { checkLockPin } from './checkLockPin.mjs'
4
+ import { checkQualityGroup } from './checkQualityGroup.mjs'
5
+ import { loadPythonContext } from './loadPythonContext.mjs'
6
+
7
+ const CHECKS = [
8
+ checkQualityGroup,
9
+ checkGateWorkflow,
10
+ checkActionPins,
11
+ checkLockPin,
12
+ ]
13
+
14
+ /**
15
+ * Whether a Python project's gate is wired, not merely installed.
16
+ *
17
+ * The same question `runConformance` asks of a JavaScript repository, with
18
+ * the answers read from pyproject.toml, uv.lock and the workflows. The
19
+ * findings share the JavaScript ids where the check is the same
20
+ * (`action-pin:*`) and carry a `py-` prefix where it is not.
21
+ */
22
+ export async function runPythonConformance(root, versions) {
23
+ const context = await loadPythonContext(root, versions)
24
+ return { context, findings: CHECKS.flatMap((check) => check(context)) }
25
+ }
@@ -0,0 +1,34 @@
1
+ // GitHub Actions pinned to a commit SHA, not a tag.
2
+ //
3
+ // A tag is mutable: whoever controls the action repository can move `v6` to
4
+ // any commit at any time, and every workflow that references it runs the new
5
+ // code on the next push with no diff anywhere in this repo. A SHA cannot be
6
+ // moved. The trailing comment records which tag the SHA was resolved from, so
7
+ // Renovate can still offer the upgrade and a reader can still tell the version.
8
+ //
9
+ // Resolved via `gh api repos/<owner>/<repo>/git/ref/tags/<tag>`. An annotated
10
+ // tag (pnpm/action-setup) points at a tag object, so its commit needs a second
11
+ // dereference through `git/tags/<sha>` - taking the first SHA would pin a
12
+ // tag object the runner cannot check out.
13
+ export const ACTION_PINS = {
14
+ checkout: {
15
+ uses: 'actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803',
16
+ tag: 'v6',
17
+ },
18
+ setupNode: {
19
+ uses: 'actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38',
20
+ tag: 'v6',
21
+ },
22
+ setupPnpm: {
23
+ uses: 'pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86',
24
+ tag: 'v6',
25
+ },
26
+ actionlint: {
27
+ uses: 'raven-actions/actionlint@3d39aea434753780c3b3d4a1a31c854b4dbf49d7',
28
+ tag: 'v2',
29
+ },
30
+ zizmor: {
31
+ uses: 'zizmorcore/zizmor-action@3dc1ecc9bcb9e94e9b2c709687979e1298497054',
32
+ tag: 'v0.6.2',
33
+ },
34
+ }
@@ -0,0 +1,44 @@
1
+ // The package.json scripts a fully wired baseline project runs. Only the ones
2
+ // a project does not already define are added: an existing `lint` that scopes
3
+ // itself to `src` is the project's decision, not drift.
4
+ //
5
+ // `dupes` and `type-coverage` go through the runners in
6
+ // @syntopica/quality-config rather than naming jscpd and type-coverage
7
+ // directly, so the shared config is read in place instead of copied.
8
+ //
9
+ // The three `check:*` entrypoints are what CI invokes, one job each. They are
10
+ // split by cost, not by category: `check:ci` is the fast path a developer runs
11
+ // before pushing, `check:quality` holds the whole-tree gates that need a
12
+ // second pass over the graph, `check:security` needs a full clone and a
13
+ // gitleaks binary. Between them they must invoke every gate - the conformance
14
+ // check asserts exactly that union, not this particular split, so a project
15
+ // that moves `knip` from one to another stays conformant.
16
+ export function baselineScripts() {
17
+ return {
18
+ // Without this the generated lefthook.yml is inert: the hooks are only
19
+ // written into .git/hooks when `lefthook install` runs. Three repos in a
20
+ // row adopted the gates with the file in place and no hook installed.
21
+ prepare: 'lefthook install',
22
+ // A two-second pass over the same files before the typed one, which takes
23
+ // minutes on a large repository. Catches the breaks that do not need type
24
+ // information; ESLint remains the authority.
25
+ 'lint:fast': 'oxlint --deny-warnings .',
26
+ 'lint:suppress': 'eslint . --suppress-all',
27
+ 'lint:prune': 'eslint . --prune-suppressions',
28
+ dupes: 'baseline-dupes .',
29
+ knip: 'knip',
30
+ 'deps:graph': 'depcruise src',
31
+ 'type-coverage': 'baseline-type-coverage',
32
+ 'secrets:check': 'gitleaks detect --no-banner --redact',
33
+ // Gated at `moderate`, not `high`, because a known exception is now
34
+ // expressible: `baseline-audit` reads `.baseline-advisories.json`, where
35
+ // every waiver carries a reason and an expiry date and comes back on its
36
+ // own when that date passes. Without somewhere to put a judged finding,
37
+ // the only way to silence one is to raise the level for everything.
38
+ 'audit:check': 'baseline-audit --level moderate',
39
+ 'check:ci':
40
+ 'pnpm lint:fast && pnpm type-check && pnpm lint && pnpm format:check && pnpm test && pnpm dupes && pnpm knip',
41
+ 'check:quality': 'pnpm deps:graph && pnpm type-coverage',
42
+ 'check:security': 'pnpm secrets:check && pnpm audit:check',
43
+ }
44
+ }
@@ -0,0 +1,87 @@
1
+ import { readFile } from 'node:fs/promises'
2
+ import { resolve } from 'node:path'
3
+
4
+ import { composedSubpaths } from './composedSubpaths.mjs'
5
+ import { ESLINT_SUBPATH_PEERS } from './eslintSubpathPeers.mjs'
6
+
7
+ const CONFIG_PACKAGE = '@syntopica/eslint-config'
8
+
9
+ // Reports the ESLint peers a project's config needs and does not have, and the
10
+ // ones it has at a version the config cannot use.
11
+ //
12
+ // pnpm already prints "Issues with peer dependencies found" on install, but
13
+ // it is one line among hundreds and the consequence only shows up later, as a
14
+ // crash from inside ESLint that names neither the baseline nor the peer.
15
+ // Measured adopting calculadora: three separate peers, three opaque failures,
16
+ // each diagnosed by hand.
17
+ export async function checkPeers(root) {
18
+ const config = await manifestOf(root, CONFIG_PACKAGE)
19
+ const declared = config?.peerDependencies
20
+ if (!declared) return null /* not installed here; nothing to check against */
21
+
22
+ const subpaths = await composedSubpaths(root)
23
+ const needed = new Set(
24
+ subpaths.flatMap((subpath) => ESLINT_SUBPATH_PEERS[subpath] ?? []),
25
+ )
26
+
27
+ const missing = []
28
+ const mismatched = []
29
+ for (const [name, range] of Object.entries(declared)) {
30
+ if (name === 'typescript' || name === 'eslint') continue
31
+ let version
32
+ try {
33
+ version = (await manifestOf(root, name))?.version
34
+ if (!version) throw new Error('unresolved')
35
+ } catch {
36
+ if (needed.has(name)) missing.push({ name, range })
37
+ continue
38
+ }
39
+ if (!satisfies(version, range)) mismatched.push({ name, range, version })
40
+ }
41
+
42
+ return { missing, mismatched }
43
+ }
44
+
45
+ // A package's own package.json, read from the project's node_modules.
46
+ //
47
+ // Not through require.resolve: these packages define `exports` without a root
48
+ // entry or a `./package.json` entry, so resolving either throws
49
+ // ERR_PACKAGE_PATH_NOT_EXPORTED while the package is installed and working.
50
+ // @syntopica/eslint-config is one of them. The directory is what every
51
+ // layout - pnpm's symlink included - actually has.
52
+ async function manifestOf(root, name) {
53
+ try {
54
+ // A path under the project's own node_modules, produced by its install.
55
+ // eslint-disable-next-line security/detect-non-literal-fs-filename
56
+ const raw = await readFile(
57
+ resolve(root, 'node_modules', name, 'package.json'),
58
+ 'utf8',
59
+ )
60
+ return JSON.parse(raw)
61
+ } catch {
62
+ return null
63
+ }
64
+ }
65
+
66
+ // A deliberately small range check: the peer ranges this config declares are
67
+ // all `>=x.y.z` or `^x.y.z`, and pulling in a semver dependency to parse two
68
+ // shapes would be the larger cost. Anything else is reported as unknown rather
69
+ // than guessed at.
70
+ function satisfies(version, range) {
71
+ const parse = (value) => value.split('-')[0].split('.').map(Number)
72
+ const compare = (a, b) =>
73
+ a[0] - b[0] || (a[1] ?? 0) - (b[1] ?? 0) || (a[2] ?? 0) - (b[2] ?? 0)
74
+ const prerelease = version.includes('-')
75
+
76
+ const gte = /^>=\s*(\d+\.\d+\.\d+)$/.exec(range)
77
+ if (gte) return !prerelease && compare(parse(version), parse(gte[1])) >= 0
78
+
79
+ const caret = /^\^\s*(\d+\.\d+\.\d+)$/.exec(range)
80
+ if (caret) {
81
+ const floor = parse(caret[1])
82
+ const actual = parse(version)
83
+ if (prerelease) return false
84
+ return actual[0] === floor[0] && compare(actual, floor) >= 0
85
+ }
86
+ return true
87
+ }
@@ -0,0 +1,144 @@
1
+ import { ACTION_PINS } from './actionPins.mjs'
2
+
3
+ // The gitleaks release the security job installs. Pinned to a fixed version
4
+ // rather than a floating tag, and verified against the release's own checksum
5
+ // manifest so a swapped asset fails the step instead of scanning with an
6
+ // unknown binary.
7
+ //
8
+ // The official gitleaks-action is not used: it requires GITLEAKS_LICENSE for
9
+ // organization-owned repositories with no public-repo exemption, and aborts
10
+ // before scanning anything without one. The CLI itself is MIT, and running it
11
+ // directly means CI runs the exact command local `secrets:check` runs, so the
12
+ // two cannot drift.
13
+ const GITLEAKS_VERSION = '8.30.1'
14
+
15
+ const setup = (
16
+ node,
17
+ ) => ` - uses: ${ACTION_PINS.checkout.uses} # ${ACTION_PINS.checkout.tag}
18
+
19
+ - uses: ${ACTION_PINS.setupPnpm.uses} # ${ACTION_PINS.setupPnpm.tag}
20
+
21
+ - uses: ${ACTION_PINS.setupNode.uses} # ${ACTION_PINS.setupNode.tag}
22
+ with:
23
+ node-version: ${node}
24
+ cache: pnpm
25
+
26
+ - run: pnpm install --frozen-lockfile`
27
+
28
+ const buildJob = (node) => `
29
+
30
+ build:
31
+ name: Production build
32
+ runs-on: ubuntu-latest
33
+ timeout-minutes: 20
34
+ needs: verify
35
+ steps:
36
+ ${setup(node)}
37
+
38
+ - run: pnpm run build`
39
+
40
+ /**
41
+ * The CI workflow every baseline project runs.
42
+ *
43
+ * Four jobs rather than one script: `verify` and `quality` are independent, so
44
+ * running them in parallel keeps both inside a sane timeout on a repo where
45
+ * typed linting alone takes minutes. Locally the same gates run as one command
46
+ * each - `check:ci`, `check:quality`, `check:security` - so a developer never
47
+ * has to reproduce the job layout to reproduce a failure.
48
+ *
49
+ * Without this file the gates are installed and unreachable: lefthook's
50
+ * pre-commit only lints staged files and its pre-push only scans for secrets,
51
+ * so type-check, tests, knip, jscpd, dependency-cruiser and type-coverage have
52
+ * no automatic trigger at all.
53
+ */
54
+ export function ciWorkflow({ node = 22, hasBuild = false } = {}) {
55
+ return `# Written by \`create-baseline --write\`. Four jobs, three commands:
56
+ # \`check:ci\`, \`check:quality\` and \`check:security\` are the same entrypoints
57
+ # you run locally, so a red job reproduces with one line.
58
+ #
59
+ # Every action is pinned to a commit SHA, not a tag. A tag can be moved by
60
+ # whoever owns the action; a SHA cannot. The trailing comment names the tag the
61
+ # SHA came from so Renovate can still offer the upgrade.
62
+ name: CI
63
+
64
+ on:
65
+ push:
66
+ branches: [main]
67
+ pull_request:
68
+ branches: [main]
69
+
70
+ concurrency:
71
+ group: \${{ github.workflow }}-\${{ github.ref }}
72
+ cancel-in-progress: true
73
+
74
+ permissions:
75
+ contents: read
76
+
77
+ jobs:
78
+ verify:
79
+ name: type-check + lint + format + test + dupes + knip
80
+ runs-on: ubuntu-latest
81
+ timeout-minutes: 30
82
+ steps:
83
+ ${setup(node)}
84
+
85
+ - name: check:ci
86
+ run: pnpm run check:ci
87
+
88
+ quality:
89
+ name: dependency graph + type coverage
90
+ runs-on: ubuntu-latest
91
+ timeout-minutes: 20
92
+ steps:
93
+ ${setup(node)}
94
+
95
+ - name: check:quality
96
+ run: pnpm run check:quality
97
+
98
+ security:
99
+ name: secrets + advisories + workflows
100
+ runs-on: ubuntu-latest
101
+ timeout-minutes: 15
102
+ steps:
103
+ # Full history: gitleaks cannot see a secret committed three commits ago
104
+ # from a shallow clone.
105
+ - uses: ${ACTION_PINS.checkout.uses} # ${ACTION_PINS.checkout.tag}
106
+ with:
107
+ fetch-depth: 0
108
+
109
+ - uses: ${ACTION_PINS.setupPnpm.uses} # ${ACTION_PINS.setupPnpm.tag}
110
+
111
+ - uses: ${ACTION_PINS.setupNode.uses} # ${ACTION_PINS.setupNode.tag}
112
+ with:
113
+ node-version: ${node}
114
+ cache: pnpm
115
+
116
+ - run: pnpm install --frozen-lockfile
117
+
118
+ - name: Install gitleaks
119
+ env:
120
+ GITLEAKS_VERSION: '${GITLEAKS_VERSION}'
121
+ run: |
122
+ curl -sSfLO "https://github.com/gitleaks/gitleaks/releases/download/v\${GITLEAKS_VERSION}/gitleaks_\${GITLEAKS_VERSION}_linux_x64.tar.gz"
123
+ curl -sSfLO "https://github.com/gitleaks/gitleaks/releases/download/v\${GITLEAKS_VERSION}/gitleaks_\${GITLEAKS_VERSION}_checksums.txt"
124
+ sha256sum --ignore-missing -c "gitleaks_\${GITLEAKS_VERSION}_checksums.txt"
125
+ tar -xzf "gitleaks_\${GITLEAKS_VERSION}_linux_x64.tar.gz" gitleaks
126
+ sudo install -m 0755 gitleaks /usr/local/bin/gitleaks
127
+ gitleaks version
128
+
129
+ - name: check:security
130
+ run: pnpm run check:security
131
+
132
+ # actionlint checks workflow syntax; zizmor checks workflow security -
133
+ # template injection through \`\${{ github.event.* }}\`, unpinned actions,
134
+ # over-broad GITHUB_TOKEN permissions, dangerous triggers. Neither
135
+ # subsumes the other.
136
+ - name: Workflow lint
137
+ uses: ${ACTION_PINS.actionlint.uses} # ${ACTION_PINS.actionlint.tag}
138
+
139
+ - name: Workflow security
140
+ uses: ${ACTION_PINS.zizmor.uses} # ${ACTION_PINS.zizmor.tag}
141
+ with:
142
+ advanced-security: false${hasBuild ? buildJob(node) : ''}
143
+ `
144
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * A manifest's runtime and development dependencies as one map.
3
+ *
4
+ * Which of the two a baseline package sits in is not something this tool has
5
+ * an opinion about, and several adopters put `@syntopica/tsconfig` in
6
+ * `dependencies` because their build reads it.
7
+ */
8
+ export function collectDeps(manifest) {
9
+ return { ...manifest.dependencies, ...manifest.devDependencies }
10
+ }
@@ -0,0 +1,41 @@
1
+ import { readdir, readFile } from 'node:fs/promises'
2
+ import { resolve } from 'node:path'
3
+
4
+ // The `@syntopica/eslint-config` subpaths a project's flat config imports.
5
+ //
6
+ // Read from the file rather than inferred from dependencies: a repo can carry
7
+ // Tailwind without composing `/tailwind`, and the peers that matter are the
8
+ // ones its config actually reaches for.
9
+ export async function composedSubpaths(root) {
10
+ let names
11
+ try {
12
+ // The directory the caller chose to run in, which is the point of this
13
+ // tool - not untrusted input.
14
+ // eslint-disable-next-line security/detect-non-literal-fs-filename
15
+ names = await readdir(root)
16
+ } catch {
17
+ return []
18
+ }
19
+ const config = names.find((name) => /^eslint\.config\.[cm]?[jt]s$/.test(name))
20
+ if (!config) return []
21
+
22
+ let source
23
+ try {
24
+ // A fixed filename in the directory the caller chose to run in.
25
+ // eslint-disable-next-line security/detect-non-literal-fs-filename
26
+ source = await readFile(resolve(root, config), 'utf8')
27
+ } catch {
28
+ return []
29
+ }
30
+
31
+ const found = new Set()
32
+ for (const match of source.matchAll(
33
+ /@syntopica\/eslint-config\/([a-z-]+)/g,
34
+ )) {
35
+ found.add(match[1])
36
+ }
37
+ // A bare `@syntopica/eslint-config` import is the barrel, which composes
38
+ // the base layer.
39
+ if (/@syntopica\/eslint-config['"]/.test(source)) found.add('base')
40
+ return [...found]
41
+ }