@syntopica/create-baseline 0.10.6 → 0.12.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 (51) hide show
  1. package/CHANGELOG.md +427 -0
  2. package/baseline-versions.json +5 -5
  3. package/bin/baseline-estate.mjs +63 -19
  4. package/bin/conformance/checkCoverageThresholds.mjs +26 -27
  5. package/bin/conformance/coverageBlockPattern.mjs +1 -0
  6. package/bin/conformance/coverageTestScripts.mjs +26 -0
  7. package/bin/conformance/coverageThresholdPattern.mjs +2 -0
  8. package/bin/conformance/delegatesCoverageTests.mjs +16 -0
  9. package/bin/conformance/isCoverageTestCommand.mjs +19 -0
  10. package/bin/dart/checkDartPins.mjs +39 -0
  11. package/bin/dart/checkGateJobs.mjs +20 -0
  12. package/bin/dart/checkLintsDependency.mjs +28 -0
  13. package/bin/dart/dartJobId.mjs +9 -0
  14. package/bin/dart/lintsSection.mjs +15 -0
  15. package/bin/dart/loadDartContext.mjs +27 -0
  16. package/bin/dart/runDartConformance.mjs +22 -0
  17. package/bin/estate/conformRows.mjs +17 -0
  18. package/bin/estate/findDartConsumers.mjs +25 -0
  19. package/bin/estate/findGoConsumers.mjs +23 -0
  20. package/bin/estate/findProjects.mjs +39 -0
  21. package/bin/estate/findSwiftConsumers.mjs +23 -0
  22. package/bin/estate/formatDartEstate.mjs +15 -0
  23. package/bin/estate/formatEstate.mjs +7 -1
  24. package/bin/estate/formatGoEstate.mjs +14 -0
  25. package/bin/estate/formatSwiftEstate.mjs +14 -0
  26. package/bin/estate/formatToolEstate.mjs +28 -0
  27. package/bin/estate/hasJob.mjs +4 -0
  28. package/bin/estate/pinFinding.mjs +26 -0
  29. package/bin/estate/readText.mjs +11 -0
  30. package/bin/go/checkGoGateJob.mjs +16 -0
  31. package/bin/go/checkGoPin.mjs +21 -0
  32. package/bin/go/goJobId.mjs +9 -0
  33. package/bin/go/loadGoContext.mjs +19 -0
  34. package/bin/go/runGoConformance.mjs +12 -0
  35. package/bin/scaffold/actionPins.mjs +4 -4
  36. package/bin/scaffold/baselineScripts.mjs +5 -1
  37. package/bin/scaffold/ciWorkflow.mjs +70 -9
  38. package/bin/scaffold/hasTaduBacklog.mjs +18 -0
  39. package/bin/scaffold/lefthookConfig.mjs +30 -5
  40. package/bin/scaffold/oxlintConfig.mjs +16 -8
  41. package/bin/scaffold/writeCiWorkflow.mjs +6 -1
  42. package/bin/scaffold/writeMissing.mjs +8 -2
  43. package/bin/swift/checkSwiftGateJob.mjs +16 -0
  44. package/bin/swift/checkSwiftPin.mjs +22 -0
  45. package/bin/swift/loadSwiftContext.mjs +14 -0
  46. package/bin/swift/runSwiftConformance.mjs +12 -0
  47. package/dart-versions.json +4 -0
  48. package/go-versions.json +3 -0
  49. package/package.json +11 -7
  50. package/python-versions.json +1 -1
  51. package/swift-versions.json +3 -0
@@ -12,6 +12,64 @@ import { ACTION_PINS } from './actionPins.mjs'
12
12
  // two cannot drift.
13
13
  const GITLEAKS_VERSION = '8.30.1'
14
14
 
15
+ // The tadu release the backlog job installs, pinned for the same reason as
16
+ // gitleaks. pipx is preinstalled on ubuntu-latest, so no action is needed.
17
+ const TADU_VERSION = '0.2.0'
18
+
19
+ // Conditions every gate job on the change not being backlog-only.
20
+ const CODE_ONLY = ` needs: changes
21
+ if: needs.changes.outputs.code == 'true'
22
+ `
23
+
24
+ const changesJob = () => ` changes:
25
+ name: Classify the change
26
+ runs-on: ubuntu-latest
27
+ timeout-minutes: 5
28
+ outputs:
29
+ code: \${{ steps.classify.outputs.code }}
30
+ backlog: \${{ steps.classify.outputs.backlog }}
31
+ steps:
32
+ - uses: ${ACTION_PINS.checkout.uses} # ${ACTION_PINS.checkout.tag}
33
+ with:
34
+ fetch-depth: 0
35
+ persist-credentials: false
36
+
37
+ # A change that touches only the tadu backlog skips the gates and runs
38
+ # tadu doctor instead. A job skipped by \`if\` reports success, so a
39
+ # required check stays satisfied, which \`paths-ignore\` would not do.
40
+ - name: Classify the changed paths
41
+ id: classify
42
+ env:
43
+ BASE: \${{ github.event.pull_request.base.sha || github.event.before }}
44
+ run: |
45
+ backlog=(todo TODO.md TODO_LOG.md TODO_HISTORY_INDEX.jsonl)
46
+ outside=(.)
47
+ for path in "\${backlog[@]}"; do outside+=(":(exclude)$path"); done
48
+ code=true
49
+ touched=true
50
+ # No usable base (a new branch, or history GitHub did not send): run everything.
51
+ if [ -n "\${BASE//0/}" ] && git cat-file -e "$BASE^{commit}" 2>/dev/null; then
52
+ git diff --quiet --no-renames "$BASE" HEAD -- "\${outside[@]}" && code=false
53
+ git diff --quiet --no-renames "$BASE" HEAD -- "\${backlog[@]}" && touched=false
54
+ fi
55
+ echo "code=$code" >> "$GITHUB_OUTPUT"
56
+ echo "backlog=$touched" >> "$GITHUB_OUTPUT"
57
+
58
+ backlog:
59
+ name: tadu doctor
60
+ needs: changes
61
+ if: needs.changes.outputs.backlog == 'true'
62
+ runs-on: ubuntu-latest
63
+ timeout-minutes: 5
64
+ steps:
65
+ - uses: ${ACTION_PINS.checkout.uses} # ${ACTION_PINS.checkout.tag}
66
+ with:
67
+ persist-credentials: false
68
+
69
+ - run: pipx run --spec tadu==${TADU_VERSION} tadu doctor .
70
+
71
+ `
72
+
15
73
  const setup = (
16
74
  node,
17
75
  ) => ` - uses: ${ACTION_PINS.checkout.uses} # ${ACTION_PINS.checkout.tag}
@@ -27,14 +85,13 @@ const setup = (
27
85
 
28
86
  - run: pnpm install --frozen-lockfile`
29
87
 
30
- const buildJob = (node) => `
88
+ const buildJob = (node, tadu) => `
31
89
 
32
90
  build:
33
91
  name: Production build
34
92
  runs-on: ubuntu-latest
35
93
  timeout-minutes: 20
36
- needs: verify
37
- steps:
94
+ ${tadu ? " needs: [changes, verify]\n if: needs.changes.outputs.code == 'true'\n" : ' needs: verify\n'} steps:
38
95
  ${setup(node)}
39
96
 
40
97
  - run: pnpm run build`
@@ -42,6 +99,9 @@ ${setup(node)}
42
99
  /**
43
100
  * The CI workflow every baseline project runs.
44
101
  *
102
+ * With `tadu`, a change that touches only the backlog skips the gates and runs
103
+ * `tadu doctor` instead.
104
+ *
45
105
  * Four jobs rather than one script: `verify` and `quality` are independent, so
46
106
  * running them in parallel keeps both inside a sane timeout on a repo where
47
107
  * typed linting alone takes minutes. Locally the same gates run as one command
@@ -53,7 +113,8 @@ ${setup(node)}
53
113
  * so type-check, tests, knip, jscpd, dependency-cruiser and type-coverage have
54
114
  * no automatic trigger at all.
55
115
  */
56
- export function ciWorkflow({ node = 22, hasBuild = false } = {}) {
116
+ export function ciWorkflow({ node = 22, hasBuild = false, tadu = false } = {}) {
117
+ const gate = tadu ? CODE_ONLY : ''
57
118
  return `# Written by \`create-baseline --write\`. Four jobs, three commands:
58
119
  # \`check:ci\`, \`check:quality\` and \`check:security\` are the same entrypoints
59
120
  # you run locally, so a red job reproduces with one line.
@@ -77,11 +138,11 @@ permissions:
77
138
  contents: read
78
139
 
79
140
  jobs:
80
- verify:
141
+ ${tadu ? changesJob() : ''} verify:
81
142
  name: type-check + lint + format + test + dupes + knip
82
143
  runs-on: ubuntu-latest
83
144
  timeout-minutes: 30
84
- steps:
145
+ ${gate} steps:
85
146
  ${setup(node)}
86
147
 
87
148
  - name: check:ci
@@ -91,7 +152,7 @@ ${setup(node)}
91
152
  name: dependency graph + type coverage
92
153
  runs-on: ubuntu-latest
93
154
  timeout-minutes: 20
94
- steps:
155
+ ${gate} steps:
95
156
  ${setup(node)}
96
157
 
97
158
  - name: check:quality
@@ -101,7 +162,7 @@ ${setup(node)}
101
162
  name: secrets + advisories + workflows
102
163
  runs-on: ubuntu-latest
103
164
  timeout-minutes: 15
104
- steps:
165
+ ${gate} steps:
105
166
  # Full history: gitleaks cannot see a secret committed three commits ago
106
167
  # from a shallow clone.
107
168
  - uses: ${ACTION_PINS.checkout.uses} # ${ACTION_PINS.checkout.tag}
@@ -142,6 +203,6 @@ ${setup(node)}
142
203
  - name: Workflow security
143
204
  uses: ${ACTION_PINS.zizmor.uses} # ${ACTION_PINS.zizmor.tag}
144
205
  with:
145
- advanced-security: false${hasBuild ? buildJob(node) : ''}
206
+ advanced-security: false${hasBuild ? buildJob(node, tadu) : ''}
146
207
  `
147
208
  }
@@ -0,0 +1,18 @@
1
+ import { access } from 'node:fs/promises'
2
+ import { resolve } from 'node:path'
3
+
4
+ // A format 2 backlog is `todo/tadu.json`; a format 1 backlog is `TODO.md`.
5
+ const MARKERS = ['todo/tadu.json', 'TODO.md']
6
+
7
+ /** Whether the repository at `root` keeps a tadu backlog in git. */
8
+ export async function hasTaduBacklog(root) {
9
+ for (const marker of MARKERS) {
10
+ try {
11
+ await access(resolve(root, marker))
12
+ return true
13
+ } catch {
14
+ /* not there */
15
+ }
16
+ }
17
+ return false
18
+ }
@@ -1,20 +1,45 @@
1
1
  // The git hooks every baseline project runs: lint and format on the staged
2
2
  // files at commit, secret scan before push. Mirrors createLefthookConfig() in
3
3
  // @syntopica/quality-config/lefthook.
4
- export function lefthookConfig() {
4
+ //
5
+ // With `tadu`, the backlog is left to `tadu doctor`: tadu writes JSON that
6
+ // prettier rejects, so the file checks exclude it and a `backlog` command
7
+ // validates it instead.
8
+ export function lefthookConfig({ tadu = false } = {}) {
9
+ const exclude = tadu
10
+ ? `
11
+ exclude:
12
+ - todo/**
13
+ - TODO.md
14
+ - TODO_LOG.md
15
+ - TODO_HISTORY_INDEX.jsonl`
16
+ : ''
17
+ const backlog = tadu
18
+ ? `
19
+ backlog:
20
+ glob:
21
+ - todo/**
22
+ - TODO.md
23
+ - TODO_LOG.md
24
+ - TODO_HISTORY_INDEX.jsonl
25
+ skip:
26
+ - run: '! command -v tadu'
27
+ run: tadu doctor .
28
+ `
29
+ : ''
5
30
  return `# Mirrors createLefthookConfig() in @syntopica/quality-config/lefthook.
6
31
  pre-commit:
7
32
  parallel: true
8
33
  commands:
9
34
  lint:fast:
10
- glob: '*.{js,jsx,ts,tsx,vue,astro,mjs,cjs}'
35
+ glob: '*.{js,jsx,ts,tsx,vue,astro,mjs,cjs}'${exclude}
11
36
  run: pnpm exec oxlint --deny-warnings {staged_files}
12
37
  lint:
13
- glob: '*.{js,jsx,ts,tsx,vue,astro,mjs,cjs}'
38
+ glob: '*.{js,jsx,ts,tsx,vue,astro,mjs,cjs}'${exclude}
14
39
  run: pnpm exec eslint --max-warnings 0 --no-warn-ignored {staged_files}
15
40
  format:
16
- glob: '*.{js,jsx,ts,tsx,vue,astro,mjs,cjs,json,md,css,yml,yaml}'
17
- run: pnpm exec prettier --check {staged_files}
41
+ glob: '*.{js,jsx,ts,tsx,vue,astro,mjs,cjs,json,md,css,yml,yaml}'${exclude}
42
+ run: pnpm exec prettier --check {staged_files}${backlog}
18
43
 
19
44
  # The release tooling reads the commit type to pick the semver bump and to
20
45
  # build the changelog, so a mistyped subject is a silent release defect. This
@@ -1,19 +1,27 @@
1
1
  import { readFileSync } from 'node:fs'
2
2
  import { createRequire } from 'node:module'
3
-
4
- const require = createRequire(import.meta.url)
3
+ import { join } from 'node:path'
5
4
 
6
5
  // The oxlint pre-filter config, read from @syntopica/quality-config rather
7
6
  // than restated here. oxlint takes a JSON file, not a factory, so the only way
8
7
  // to keep one source of truth is to copy the shipped file at scaffold time -
9
8
  // and to read it from the package, so a change there reaches new projects
10
9
  // without this file being touched.
11
- export function oxlintConfig() {
12
- // The path comes from this package's own dependency resolution, not from
10
+ //
11
+ // Resolved from the project first: under `pnpm dlx` this file lives in the dlx
12
+ // cache, where quality-config is not installed, and resolving only from here
13
+ // crashed with "Cannot find module" on a project that had it. This package's
14
+ // own resolution is the fallback, which is what the monorepo relies on.
15
+ export function oxlintConfig(root) {
16
+ const specifier = '@syntopica/quality-config/oxlint'
17
+ let path
18
+ try {
19
+ path = createRequire(join(root, 'package.json')).resolve(specifier)
20
+ } catch {
21
+ path = createRequire(import.meta.url).resolve(specifier)
22
+ }
23
+ // The path comes from module resolution of a fixed specifier, not from
13
24
  // anything a caller supplies.
14
25
  // eslint-disable-next-line security/detect-non-literal-fs-filename
15
- return readFileSync(
16
- require.resolve('@syntopica/quality-config/oxlint'),
17
- 'utf8',
18
- )
26
+ return readFileSync(path, 'utf8')
19
27
  }
@@ -2,6 +2,7 @@ import { mkdir, readdir, readFile, writeFile } from 'node:fs/promises'
2
2
  import { resolve } from 'node:path'
3
3
 
4
4
  import { ciWorkflow } from './ciWorkflow.mjs'
5
+ import { hasTaduBacklog } from './hasTaduBacklog.mjs'
5
6
 
6
7
  const WORKFLOW_DIR = '.github/workflows'
7
8
  const WORKFLOW_NAME = 'ci.yml'
@@ -49,6 +50,10 @@ export async function writeCiWorkflow(root, { hasBuild }) {
49
50
  // eslint-disable-next-line security/detect-non-literal-fs-filename
50
51
  await mkdir(dir, { recursive: true })
51
52
  // eslint-disable-next-line security/detect-non-literal-fs-filename
52
- await writeFile(resolve(dir, WORKFLOW_NAME), ciWorkflow({ hasBuild }), 'utf8')
53
+ await writeFile(
54
+ resolve(dir, WORKFLOW_NAME),
55
+ ciWorkflow({ hasBuild, tadu: await hasTaduBacklog(root) }),
56
+ 'utf8',
57
+ )
53
58
  return { written: `${WORKFLOW_DIR}/${WORKFLOW_NAME}`, existing: null }
54
59
  }
@@ -4,6 +4,7 @@ import { resolve } from 'node:path'
4
4
  import { baselineScripts } from './baselineScripts.mjs'
5
5
  import { depCruiserConfig } from './depCruiserConfig.mjs'
6
6
  import { detectFramework } from './detectFramework.mjs'
7
+ import { hasTaduBacklog } from './hasTaduBacklog.mjs'
7
8
  import { knipConfig } from './knipConfig.mjs'
8
9
  import { lefthookConfig } from './lefthookConfig.mjs'
9
10
  import { oxlintConfig } from './oxlintConfig.mjs'
@@ -27,6 +28,7 @@ export async function writeMissing(root, deps) {
27
28
  const written = []
28
29
  const shadowed = []
29
30
  const framework = detectFramework(deps)
31
+ const tadu = await hasTaduBacklog(root)
30
32
 
31
33
  const files = [
32
34
  [
@@ -42,8 +44,12 @@ export async function writeMissing(root, deps) {
42
44
  '.knip.jsonc',
43
45
  ],
44
46
  ],
45
- ['lefthook.yml', lefthookConfig, ['lefthook.yaml', '.lefthook.yml']],
46
- ['.oxlintrc.json', oxlintConfig, ['oxlint.json', '.oxlintrc']],
47
+ [
48
+ 'lefthook.yml',
49
+ () => lefthookConfig({ tadu }),
50
+ ['lefthook.yaml', '.lefthook.yml'],
51
+ ],
52
+ ['.oxlintrc.json', () => oxlintConfig(root), ['oxlint.json', '.oxlintrc']],
47
53
  [
48
54
  'renovate.json',
49
55
  renovateConfig,
@@ -0,0 +1,16 @@
1
+ import { hasJob } from '../estate/hasJob.mjs'
2
+
3
+ /** The root codeality.yml must hold the `swift` job codeality-swift init writes. */
4
+ export function checkSwiftGateJob({ codealityWorkflow }) {
5
+ if (codealityWorkflow && hasJob(codealityWorkflow, 'swift')) return []
6
+ return [
7
+ {
8
+ id: 'swift-gate-job-missing',
9
+ level: 'error',
10
+ message: codealityWorkflow
11
+ ? 'codeality.yml has no swift job'
12
+ : 'no .github/workflows/codeality.yml',
13
+ detail: 'Run `codeality-swift init --ci --apply`.',
14
+ },
15
+ ]
16
+ }
@@ -0,0 +1,22 @@
1
+ import { pinFinding } from '../estate/pinFinding.mjs'
2
+
3
+ const CHECKOUT = 'repository: syntopica/codeality'
4
+ const REF = /ref:\s*['"]?([^\s'"#]+)/
5
+ const TAG = /^codeality-swift-v(\d+\.\d+\.\d+)$/
6
+
7
+ /**
8
+ * The swift job builds codeality-swift from a release tag; it must be the
9
+ * current one. A branch or SHA is reported as not released.
10
+ */
11
+ export function checkSwiftPin({ codealityWorkflow, versions }) {
12
+ const current = versions['codeality-swift']
13
+ const at = (codealityWorkflow ?? '').indexOf(CHECKOUT)
14
+ if (!current || at === -1) return []
15
+ const ref = REF.exec(codealityWorkflow.slice(at))?.[1] ?? null
16
+ return pinFinding(
17
+ 'swift',
18
+ 'codeality-swift',
19
+ TAG.exec(ref ?? '')?.[1] ?? ref,
20
+ current,
21
+ )
22
+ }
@@ -0,0 +1,14 @@
1
+ import { readWorkflows } from '../conformance/readWorkflows.mjs'
2
+ import { repositoryRoot } from '../python/repositoryRoot.mjs'
3
+
4
+ /** Everything the Swift conformance checks read, gathered once. */
5
+ export async function loadSwiftContext(root, versions) {
6
+ const workflows = await readWorkflows(await repositoryRoot(root))
7
+ return {
8
+ root,
9
+ versions,
10
+ workflows,
11
+ codealityWorkflow:
12
+ workflows.find((w) => w.name === 'codeality.yml')?.text ?? '',
13
+ }
14
+ }
@@ -0,0 +1,12 @@
1
+ import { checkActionPins } from '../conformance/checkActionPins.mjs'
2
+ import { checkSwiftGateJob } from './checkSwiftGateJob.mjs'
3
+ import { checkSwiftPin } from './checkSwiftPin.mjs'
4
+ import { loadSwiftContext } from './loadSwiftContext.mjs'
5
+
6
+ const CHECKS = [checkSwiftGateJob, checkActionPins, checkSwiftPin]
7
+
8
+ /** Whether a Swift project's gate is wired: its job, pinned actions, current release. */
9
+ export async function runSwiftConformance(root, versions) {
10
+ const context = await loadSwiftContext(root, versions)
11
+ return { context, findings: CHECKS.flatMap((check) => check(context)) }
12
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "codeality_dart": "0.1.0",
3
+ "codeality_lints": "0.1.0"
4
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "codeality-go": "0.1.0"
3
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syntopica/create-baseline",
3
- "version": "0.10.6",
3
+ "version": "0.12.0",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "description": "CLI to verify and adopt @syntopica baseline config packages",
@@ -29,7 +29,11 @@
29
29
  "README.md",
30
30
  "baseline-versions.json",
31
31
  "python-versions.json",
32
- "bin"
32
+ "dart-versions.json",
33
+ "swift-versions.json",
34
+ "go-versions.json",
35
+ "bin",
36
+ "CHANGELOG.md"
33
37
  ],
34
38
  "keywords": [
35
39
  "eslint",
@@ -39,12 +43,12 @@
39
43
  ],
40
44
  "devDependencies": {
41
45
  "@arethetypeswrong/cli": "^0.18.5",
42
- "@syntopica/eslint-config": "0.10.0",
43
- "@vitest/coverage-v8": "^5.0.3",
44
- "eslint": "^10.12.0",
45
- "eslint-plugin-regexp": "^3.3.1",
46
+ "@syntopica/eslint-config": "0.10.2",
47
+ "@vitest/coverage-v8": "^5.1.1",
48
+ "eslint": "^10.15.0",
49
+ "eslint-plugin-regexp": "^3.3.3",
46
50
  "publint": "^0.3.25",
47
- "vitest": "^5.0.3"
51
+ "vitest": "^5.1.1"
48
52
  },
49
53
  "scripts": {
50
54
  "check:self": "node ./bin/create-baseline.mjs --check",
@@ -1,3 +1,3 @@
1
1
  {
2
- "syntopica-codeality-py": "0.2.6"
2
+ "syntopica-codeality-py": "0.3.0"
3
3
  }
@@ -0,0 +1,3 @@
1
+ {
2
+ "codeality-swift": "0.1.0"
3
+ }