@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.
- package/CHANGELOG.md +427 -0
- package/baseline-versions.json +5 -5
- package/bin/baseline-estate.mjs +63 -19
- package/bin/conformance/checkCoverageThresholds.mjs +26 -27
- package/bin/conformance/coverageBlockPattern.mjs +1 -0
- package/bin/conformance/coverageTestScripts.mjs +26 -0
- package/bin/conformance/coverageThresholdPattern.mjs +2 -0
- package/bin/conformance/delegatesCoverageTests.mjs +16 -0
- package/bin/conformance/isCoverageTestCommand.mjs +19 -0
- package/bin/dart/checkDartPins.mjs +39 -0
- package/bin/dart/checkGateJobs.mjs +20 -0
- package/bin/dart/checkLintsDependency.mjs +28 -0
- package/bin/dart/dartJobId.mjs +9 -0
- package/bin/dart/lintsSection.mjs +15 -0
- package/bin/dart/loadDartContext.mjs +27 -0
- package/bin/dart/runDartConformance.mjs +22 -0
- package/bin/estate/conformRows.mjs +17 -0
- package/bin/estate/findDartConsumers.mjs +25 -0
- package/bin/estate/findGoConsumers.mjs +23 -0
- package/bin/estate/findProjects.mjs +39 -0
- package/bin/estate/findSwiftConsumers.mjs +23 -0
- package/bin/estate/formatDartEstate.mjs +15 -0
- package/bin/estate/formatEstate.mjs +7 -1
- package/bin/estate/formatGoEstate.mjs +14 -0
- package/bin/estate/formatSwiftEstate.mjs +14 -0
- package/bin/estate/formatToolEstate.mjs +28 -0
- package/bin/estate/hasJob.mjs +4 -0
- package/bin/estate/pinFinding.mjs +26 -0
- package/bin/estate/readText.mjs +11 -0
- package/bin/go/checkGoGateJob.mjs +16 -0
- package/bin/go/checkGoPin.mjs +21 -0
- package/bin/go/goJobId.mjs +9 -0
- package/bin/go/loadGoContext.mjs +19 -0
- package/bin/go/runGoConformance.mjs +12 -0
- package/bin/scaffold/actionPins.mjs +4 -4
- package/bin/scaffold/baselineScripts.mjs +5 -1
- package/bin/scaffold/ciWorkflow.mjs +70 -9
- package/bin/scaffold/hasTaduBacklog.mjs +18 -0
- package/bin/scaffold/lefthookConfig.mjs +30 -5
- package/bin/scaffold/oxlintConfig.mjs +16 -8
- package/bin/scaffold/writeCiWorkflow.mjs +6 -1
- package/bin/scaffold/writeMissing.mjs +8 -2
- package/bin/swift/checkSwiftGateJob.mjs +16 -0
- package/bin/swift/checkSwiftPin.mjs +22 -0
- package/bin/swift/loadSwiftContext.mjs +14 -0
- package/bin/swift/runSwiftConformance.mjs +12 -0
- package/dart-versions.json +4 -0
- package/go-versions.json +3 -0
- package/package.json +11 -7
- package/python-versions.json +1 -1
- package/swift-versions.json +3 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Whether the project hands its test run to a workspace runner rather than
|
|
2
|
+
// running a suite of its own. Matched against every script, not just `test`:
|
|
3
|
+
// the baseline repo reaches its suites through `check:ci`, which calls
|
|
4
|
+
// `turbo run ... test ...`, and defines no root `test` script at all.
|
|
5
|
+
export function delegatesCoverageTests(scripts) {
|
|
6
|
+
for (const command of Object.values(scripts)) {
|
|
7
|
+
if (
|
|
8
|
+
typeof command === 'string' &&
|
|
9
|
+
/\b(?:turbo|nx|lerna)\s+run\s+(?:[\w:-]+\s+)*test\b|(?:pnpm|npm|yarn)\s+(?:-r|--recursive)\s+(?:run\s+)?test\b/.test(
|
|
10
|
+
command,
|
|
11
|
+
)
|
|
12
|
+
)
|
|
13
|
+
return true
|
|
14
|
+
}
|
|
15
|
+
return false
|
|
16
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Only static runner commands using the discovered root config are proven.
|
|
2
|
+
export function isCoverageTestCommand(command, testConfig) {
|
|
3
|
+
if (
|
|
4
|
+
/[;&|$`]|(?:^|\s)(?:--(?:config|root|dir|project|workspace)(?:=|\s|$)|-[cr])/.test(
|
|
5
|
+
command,
|
|
6
|
+
)
|
|
7
|
+
)
|
|
8
|
+
return false
|
|
9
|
+
if (testConfig) {
|
|
10
|
+
const runner = /\b(vitest|jest)\b/.exec(command)?.[1]
|
|
11
|
+
const configRunner = testConfig.name.startsWith('jest.config.')
|
|
12
|
+
? 'jest'
|
|
13
|
+
: 'vitest'
|
|
14
|
+
if (runner !== configRunner) return false
|
|
15
|
+
}
|
|
16
|
+
return /^\s*(?:(?:pnpm|npm|yarn|bun)\s+(?:exec\s+|dlx\s+|x\s+))?(?:vitest|jest)(?:\s|$)/.test(
|
|
17
|
+
command,
|
|
18
|
+
)
|
|
19
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { pinFinding } from '../estate/pinFinding.mjs'
|
|
2
|
+
import { lintsSection } from './lintsSection.mjs'
|
|
3
|
+
|
|
4
|
+
const CARET = /^\^?(\d+\.\d+\.\d+)$/
|
|
5
|
+
const ACTIVATE =
|
|
6
|
+
/dart pub global activate (?:--source git\b|codeality_dart\s+(\S+))/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Both pins must be the current pub.dev releases: the codeality_lints
|
|
10
|
+
* constraint and the codeality_dart version the CI job activates. A git or
|
|
11
|
+
* path source is reported as not released rather than parsed as semver.
|
|
12
|
+
*/
|
|
13
|
+
export function checkDartPins({ pubspec, codealityWorkflow, versions }) {
|
|
14
|
+
const findings = []
|
|
15
|
+
const lints = lintsSection(pubspec)
|
|
16
|
+
if (lints && versions.codeality_lints) {
|
|
17
|
+
const pinned = CARET.exec(lints.constraint)?.[1] ?? null
|
|
18
|
+
findings.push(
|
|
19
|
+
...pinFinding(
|
|
20
|
+
'dart',
|
|
21
|
+
'codeality_lints',
|
|
22
|
+
pinned,
|
|
23
|
+
versions.codeality_lints,
|
|
24
|
+
),
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
const activate = ACTIVATE.exec(codealityWorkflow ?? '')
|
|
28
|
+
if (activate && versions.codeality_dart) {
|
|
29
|
+
findings.push(
|
|
30
|
+
...pinFinding(
|
|
31
|
+
'dart',
|
|
32
|
+
'codeality_dart',
|
|
33
|
+
activate[1] ?? null,
|
|
34
|
+
versions.codeality_dart,
|
|
35
|
+
),
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
return findings
|
|
39
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { hasJob } from '../estate/hasJob.mjs'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The root codeality.yml must hold this project's job. In a monorepo each
|
|
5
|
+
* pubspec project has its own, and a missing one means that project's gate
|
|
6
|
+
* runs nowhere while the others are green.
|
|
7
|
+
*/
|
|
8
|
+
export function checkGateJobs({ jobId, projectPath, codealityWorkflow }) {
|
|
9
|
+
if (codealityWorkflow && hasJob(codealityWorkflow, jobId)) return []
|
|
10
|
+
return [
|
|
11
|
+
{
|
|
12
|
+
id: 'dart-gate-job-missing',
|
|
13
|
+
level: 'error',
|
|
14
|
+
message: codealityWorkflow
|
|
15
|
+
? `codeality.yml has no job ${jobId} for ${projectPath}`
|
|
16
|
+
: 'no .github/workflows/codeality.yml',
|
|
17
|
+
detail: `Run \`codeality-dart init --ci --apply\` in ${projectPath}.`,
|
|
18
|
+
},
|
|
19
|
+
]
|
|
20
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { lintsSection } from './lintsSection.mjs'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* codeality_lints belongs in `dev_dependencies`: under `dependencies` it
|
|
5
|
+
* ships to every consumer of the package and still lints nothing extra.
|
|
6
|
+
*/
|
|
7
|
+
export function checkLintsDependency({ pubspec }) {
|
|
8
|
+
const found = lintsSection(pubspec)
|
|
9
|
+
if (!found) {
|
|
10
|
+
return [
|
|
11
|
+
{
|
|
12
|
+
id: 'dart-lints',
|
|
13
|
+
level: 'error',
|
|
14
|
+
message: 'codeality_lints is not a dependency',
|
|
15
|
+
detail: 'Run `codeality-dart init --apply`.',
|
|
16
|
+
},
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
if (found.section === 'dev_dependencies') return []
|
|
20
|
+
return [
|
|
21
|
+
{
|
|
22
|
+
id: 'dart-lints-not-dev-dependency',
|
|
23
|
+
level: 'error',
|
|
24
|
+
message: `codeality_lints is declared under ${found.section}`,
|
|
25
|
+
detail: 'Move it to dev_dependencies.',
|
|
26
|
+
},
|
|
27
|
+
]
|
|
28
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The CI job id codeality-dart init gives a project: `dart-` plus its
|
|
3
|
+
* repository-relative path with `/` and `_` turned into `-`.
|
|
4
|
+
*/
|
|
5
|
+
export function dartJobId(projectPath) {
|
|
6
|
+
return projectPath === '' || projectPath === '.'
|
|
7
|
+
? 'dart'
|
|
8
|
+
: `dart-${projectPath.replaceAll(/[/_]/g, '-')}`
|
|
9
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The top-level pubspec key under which `codeality_lints` is declared, and
|
|
3
|
+
* the text after its colon ('' for a map form such as `git:` or `path:`);
|
|
4
|
+
* null when it is not declared.
|
|
5
|
+
*/
|
|
6
|
+
export function lintsSection(pubspec) {
|
|
7
|
+
let section = null
|
|
8
|
+
for (const line of pubspec.split('\n')) {
|
|
9
|
+
const key = /^([a-z_]+):/i.exec(line)
|
|
10
|
+
if (key) section = key[1]
|
|
11
|
+
const entry = /^\s+codeality_lints:(.*)$/.exec(line)
|
|
12
|
+
if (entry) return { section, constraint: entry[1].trim() }
|
|
13
|
+
}
|
|
14
|
+
return null
|
|
15
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { relative, resolve } from 'node:path'
|
|
2
|
+
|
|
3
|
+
import { readWorkflows } from '../conformance/readWorkflows.mjs'
|
|
4
|
+
import { readText } from '../estate/readText.mjs'
|
|
5
|
+
import { repositoryRoot } from '../python/repositoryRoot.mjs'
|
|
6
|
+
import { dartJobId } from './dartJobId.mjs'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Everything the Dart conformance checks read, gathered once. Workflows
|
|
10
|
+
* come from the enclosing repository: the root codeality.yml holds one job
|
|
11
|
+
* per pubspec project.
|
|
12
|
+
*/
|
|
13
|
+
export async function loadDartContext(root, versions) {
|
|
14
|
+
const repoRoot = await repositoryRoot(root)
|
|
15
|
+
const projectPath = relative(repoRoot, root) || '.'
|
|
16
|
+
const workflows = await readWorkflows(repoRoot)
|
|
17
|
+
return {
|
|
18
|
+
root,
|
|
19
|
+
versions,
|
|
20
|
+
projectPath,
|
|
21
|
+
jobId: dartJobId(projectPath),
|
|
22
|
+
pubspec: await readText(resolve(root, 'pubspec.yaml')),
|
|
23
|
+
workflows,
|
|
24
|
+
codealityWorkflow:
|
|
25
|
+
workflows.find((w) => w.name === 'codeality.yml')?.text ?? '',
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { checkActionPins } from '../conformance/checkActionPins.mjs'
|
|
2
|
+
import { checkDartPins } from './checkDartPins.mjs'
|
|
3
|
+
import { checkGateJobs } from './checkGateJobs.mjs'
|
|
4
|
+
import { checkLintsDependency } from './checkLintsDependency.mjs'
|
|
5
|
+
import { loadDartContext } from './loadDartContext.mjs'
|
|
6
|
+
|
|
7
|
+
const CHECKS = [
|
|
8
|
+
checkLintsDependency,
|
|
9
|
+
checkGateJobs,
|
|
10
|
+
checkActionPins,
|
|
11
|
+
checkDartPins,
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Whether a Dart project's gate is wired, not merely installed: the lints
|
|
16
|
+
* as a dev dependency, its job in the root codeality.yml, pinned actions
|
|
17
|
+
* and current releases. Shared checks keep their ids (`action-pin:*`).
|
|
18
|
+
*/
|
|
19
|
+
export async function runDartConformance(root, versions) {
|
|
20
|
+
const context = await loadDartContext(root, versions)
|
|
21
|
+
return { context, findings: CHECKS.flatMap((check) => check(context)) }
|
|
22
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run `conform(path)` over each consumer, as estate rows. One unreadable
|
|
3
|
+
* project becomes an error row instead of taking the sweep down: the report
|
|
4
|
+
* is most useful precisely when part of the estate is broken.
|
|
5
|
+
*/
|
|
6
|
+
export async function conformRows(consumers, conform) {
|
|
7
|
+
const rows = []
|
|
8
|
+
for (const consumer of consumers) {
|
|
9
|
+
try {
|
|
10
|
+
const { findings } = await conform(consumer.path)
|
|
11
|
+
rows.push({ name: consumer.name, findings })
|
|
12
|
+
} catch (error) {
|
|
13
|
+
rows.push({ name: consumer.name, error: String(error.message) })
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return rows
|
|
17
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { resolve } from 'node:path'
|
|
2
|
+
|
|
3
|
+
import { findProjects } from './findProjects.mjs'
|
|
4
|
+
import { readText } from './readText.mjs'
|
|
5
|
+
|
|
6
|
+
const NAMES_LINTS = /^\s+codeality_lints:/m
|
|
7
|
+
// codeality_dart's own pubspec takes the lints by path; a tool is not its
|
|
8
|
+
// own consumer.
|
|
9
|
+
const IS_A_TOOL = /^name:\s*codeality_(?:dart|lints)\s*$/m
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Every Dart project under `root` whose pubspec.yaml names codeality_lints,
|
|
13
|
+
* under `dev_dependencies` or, wrongly, `dependencies`: conformance reports
|
|
14
|
+
* the second, so the estate has to list it.
|
|
15
|
+
*/
|
|
16
|
+
export async function findDartConsumers(root, options) {
|
|
17
|
+
return findProjects(
|
|
18
|
+
root,
|
|
19
|
+
async (dir) => {
|
|
20
|
+
const pubspec = await readText(resolve(dir, 'pubspec.yaml'))
|
|
21
|
+
return NAMES_LINTS.test(pubspec) && !IS_A_TOOL.test(pubspec)
|
|
22
|
+
},
|
|
23
|
+
options,
|
|
24
|
+
)
|
|
25
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { access } from 'node:fs/promises'
|
|
2
|
+
import { resolve } from 'node:path'
|
|
3
|
+
|
|
4
|
+
import { findProjects } from './findProjects.mjs'
|
|
5
|
+
import { readText } from './readText.mjs'
|
|
6
|
+
|
|
7
|
+
const IS_THE_TOOL = /^module\s+\S+\/codeality-go$/m
|
|
8
|
+
|
|
9
|
+
/** Every module under `root` holding a `codeality-go.yaml`. */
|
|
10
|
+
export async function findGoConsumers(root, options) {
|
|
11
|
+
return findProjects(
|
|
12
|
+
root,
|
|
13
|
+
async (dir) => {
|
|
14
|
+
try {
|
|
15
|
+
await access(resolve(dir, 'codeality-go.yaml'))
|
|
16
|
+
} catch {
|
|
17
|
+
return false
|
|
18
|
+
}
|
|
19
|
+
return !IS_THE_TOOL.test(await readText(resolve(dir, 'go.mod')))
|
|
20
|
+
},
|
|
21
|
+
options,
|
|
22
|
+
)
|
|
23
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { readdir } from 'node:fs/promises'
|
|
2
|
+
import { relative, resolve } from 'node:path'
|
|
3
|
+
|
|
4
|
+
// Directories that never hold a project of ours, and would make the walk
|
|
5
|
+
// slow (node_modules), circular (.venv) or pointless (a build tree).
|
|
6
|
+
const SKIP = new Set(['node_modules', 'build', 'dist', 'target'])
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Every directory under `root`, up to `maxDepth` levels down, for which
|
|
10
|
+
* `isProject(dir)` resolves true. The walk stops descending at a project,
|
|
11
|
+
* and never enters dot- or underscore-prefixed directories.
|
|
12
|
+
*
|
|
13
|
+
* Returns `[{ name, path }]` sorted by name; `name` is the path relative to
|
|
14
|
+
* `root`, so a nested project is reported where it lives.
|
|
15
|
+
*/
|
|
16
|
+
export async function findProjects(root, isProject, { maxDepth = 3 } = {}) {
|
|
17
|
+
const projects = []
|
|
18
|
+
const walk = async (dir, depth) => {
|
|
19
|
+
if (depth > maxDepth) return
|
|
20
|
+
let entries
|
|
21
|
+
try {
|
|
22
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
23
|
+
entries = await readdir(dir, { withFileTypes: true })
|
|
24
|
+
} catch {
|
|
25
|
+
return
|
|
26
|
+
}
|
|
27
|
+
if (depth > 0 && (await isProject(dir))) {
|
|
28
|
+
projects.push({ name: relative(root, dir), path: dir })
|
|
29
|
+
return
|
|
30
|
+
}
|
|
31
|
+
for (const entry of entries) {
|
|
32
|
+
if (!entry.isDirectory() || /^[._]/.test(entry.name)) continue
|
|
33
|
+
if (SKIP.has(entry.name)) continue
|
|
34
|
+
await walk(resolve(dir, entry.name), depth + 1)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
await walk(root, 0)
|
|
38
|
+
return projects.sort((a, b) => a.name.localeCompare(b.name))
|
|
39
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { access } from 'node:fs/promises'
|
|
2
|
+
import { resolve } from 'node:path'
|
|
3
|
+
|
|
4
|
+
import { findProjects } from './findProjects.mjs'
|
|
5
|
+
import { readText } from './readText.mjs'
|
|
6
|
+
|
|
7
|
+
const IS_THE_TOOL = /name:\s*"codeality-swift"/
|
|
8
|
+
|
|
9
|
+
/** Every project under `root` holding a `codeality-swift.yaml`. */
|
|
10
|
+
export async function findSwiftConsumers(root, options) {
|
|
11
|
+
return findProjects(
|
|
12
|
+
root,
|
|
13
|
+
async (dir) => {
|
|
14
|
+
try {
|
|
15
|
+
await access(resolve(dir, 'codeality-swift.yaml'))
|
|
16
|
+
} catch {
|
|
17
|
+
return false
|
|
18
|
+
}
|
|
19
|
+
return !IS_THE_TOOL.test(await readText(resolve(dir, 'Package.swift')))
|
|
20
|
+
},
|
|
21
|
+
options,
|
|
22
|
+
)
|
|
23
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { formatToolEstate } from './formatToolEstate.mjs'
|
|
2
|
+
|
|
3
|
+
const none = (ids, prefix) => ![...ids].some((id) => id.startsWith(prefix))
|
|
4
|
+
|
|
5
|
+
const COLUMNS = [
|
|
6
|
+
['lints', (ids) => none(ids, 'dart-lints')],
|
|
7
|
+
['ci', (ids) => !ids.has('dart-gate-job-missing')],
|
|
8
|
+
['pins', (ids) => none(ids, 'action-pin:')],
|
|
9
|
+
['release', (ids) => none(ids, 'dart-pin-')],
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
/** The Dart side of the estate: lints dependency, CI job, pins, release. */
|
|
13
|
+
export function formatDartEstate(rows) {
|
|
14
|
+
return formatToolEstate('dart', 'Dart', COLUMNS, rows)
|
|
15
|
+
}
|
|
@@ -12,7 +12,13 @@ const COLUMNS = [
|
|
|
12
12
|
![...ids].some((id) => id.startsWith('gate:')),
|
|
13
13
|
],
|
|
14
14
|
['tscfg', (ids) => ![...ids].some((id) => id.startsWith('tsconfig-'))],
|
|
15
|
-
[
|
|
15
|
+
[
|
|
16
|
+
'cov',
|
|
17
|
+
(ids) =>
|
|
18
|
+
!ids.has('coverage') &&
|
|
19
|
+
!ids.has('coverage-run') &&
|
|
20
|
+
!ids.has('coverage-thresholds'),
|
|
21
|
+
],
|
|
16
22
|
['hooks', (ids) => !ids.has('hooks')],
|
|
17
23
|
['vers', (ids) => ![...ids].some((id) => id.startsWith('version:'))],
|
|
18
24
|
]
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { formatToolEstate } from './formatToolEstate.mjs'
|
|
2
|
+
|
|
3
|
+
const none = (ids, prefix) => ![...ids].some((id) => id.startsWith(prefix))
|
|
4
|
+
|
|
5
|
+
const COLUMNS = [
|
|
6
|
+
['ci', (ids) => !ids.has('go-gate-job-missing')],
|
|
7
|
+
['pins', (ids) => none(ids, 'action-pin:')],
|
|
8
|
+
['release', (ids) => none(ids, 'go-pin-')],
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
/** The Go side of the estate: CI job, action pins, released tool. */
|
|
12
|
+
export function formatGoEstate(rows) {
|
|
13
|
+
return formatToolEstate('go', 'Go', COLUMNS, rows)
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { formatToolEstate } from './formatToolEstate.mjs'
|
|
2
|
+
|
|
3
|
+
const none = (ids, prefix) => ![...ids].some((id) => id.startsWith(prefix))
|
|
4
|
+
|
|
5
|
+
const COLUMNS = [
|
|
6
|
+
['ci', (ids) => !ids.has('swift-gate-job-missing')],
|
|
7
|
+
['pins', (ids) => none(ids, 'action-pin:')],
|
|
8
|
+
['release', (ids) => none(ids, 'swift-pin-')],
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
/** The Swift side of the estate: CI job, action pins, release tag. */
|
|
12
|
+
export function formatSwiftEstate(rows) {
|
|
13
|
+
return formatToolEstate('swift', 'Swift', COLUMNS, rows)
|
|
14
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One language's side of the estate as a table, a row per project:
|
|
3
|
+
* `columns` are `[label, passes(ids)]`, `rows` are `{ name, findings }` or
|
|
4
|
+
* `{ name, error }`.
|
|
5
|
+
*/
|
|
6
|
+
export function formatToolEstate(label, noun, columns, rows) {
|
|
7
|
+
const width = Math.max(10, ...rows.map((row) => row.name.length))
|
|
8
|
+
const lines = [
|
|
9
|
+
`${label.padEnd(width)} ${columns.map(([column]) => column.padEnd(7)).join('')}`,
|
|
10
|
+
'-'.repeat(width + 2 + columns.length * 7),
|
|
11
|
+
]
|
|
12
|
+
for (const row of rows) {
|
|
13
|
+
if (row.error) {
|
|
14
|
+
lines.push(`${row.name.padEnd(width)} ${row.error}`)
|
|
15
|
+
continue
|
|
16
|
+
}
|
|
17
|
+
const ids = new Set(row.findings.map((finding) => finding.id))
|
|
18
|
+
const cells = columns.map(([, passes]) =>
|
|
19
|
+
(passes(ids) ? 'ok' : 'FAIL').padEnd(7),
|
|
20
|
+
)
|
|
21
|
+
lines.push(`${row.name.padEnd(width)} ${cells.join('')}`.trimEnd())
|
|
22
|
+
}
|
|
23
|
+
const clean = rows.filter(
|
|
24
|
+
(row) => !row.error && row.findings.length === 0,
|
|
25
|
+
).length
|
|
26
|
+
lines.push('', `${rows.length} ${noun} projects, ${clean} fully wired.`)
|
|
27
|
+
return lines.join('\n')
|
|
28
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A finding for a tool pinned to something other than the current release:
|
|
3
|
+
* `dart-pin-not-released` style when `pinned` is not a version, otherwise
|
|
4
|
+
* `-pin-outdated`.
|
|
5
|
+
*/
|
|
6
|
+
export function pinFinding(prefix, tool, pinned, current) {
|
|
7
|
+
if (pinned === current) return []
|
|
8
|
+
if (!/^\d+\.\d+\.\d+$/.test(pinned ?? '')) {
|
|
9
|
+
return [
|
|
10
|
+
{
|
|
11
|
+
id: `${prefix}-pin-not-released`,
|
|
12
|
+
level: 'error',
|
|
13
|
+
message: `${tool} is pinned to ${pinned ?? 'a source'}, not a release`,
|
|
14
|
+
detail: `Pin the released ${current} once it is published.`,
|
|
15
|
+
},
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
return [
|
|
19
|
+
{
|
|
20
|
+
id: `${prefix}-pin-outdated`,
|
|
21
|
+
level: 'error',
|
|
22
|
+
message: `${tool} is pinned to ${pinned}, current is ${current}`,
|
|
23
|
+
detail: 'Re-run init, or bump the pin by hand.',
|
|
24
|
+
},
|
|
25
|
+
]
|
|
26
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises'
|
|
2
|
+
|
|
3
|
+
/** The file at `path` as text, or '' when it cannot be read. */
|
|
4
|
+
export async function readText(path) {
|
|
5
|
+
try {
|
|
6
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
7
|
+
return await readFile(path, 'utf8')
|
|
8
|
+
} catch {
|
|
9
|
+
return ''
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { hasJob } from '../estate/hasJob.mjs'
|
|
2
|
+
|
|
3
|
+
/** The root codeality.yml must hold the job codeality-go init writes for this module. */
|
|
4
|
+
export function checkGoGateJob({ codealityWorkflow, jobId }) {
|
|
5
|
+
if (codealityWorkflow && hasJob(codealityWorkflow, jobId)) return []
|
|
6
|
+
return [
|
|
7
|
+
{
|
|
8
|
+
id: 'go-gate-job-missing',
|
|
9
|
+
level: 'error',
|
|
10
|
+
message: codealityWorkflow
|
|
11
|
+
? `codeality.yml has no ${jobId} job`
|
|
12
|
+
: 'no .github/workflows/codeality.yml',
|
|
13
|
+
detail: 'Run `codeality-go init --ci --apply`.',
|
|
14
|
+
},
|
|
15
|
+
]
|
|
16
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { pinFinding } from '../estate/pinFinding.mjs'
|
|
2
|
+
|
|
3
|
+
const INSTALL = /cmd\/codeality-go@(\S+)/
|
|
4
|
+
const VERSION = /^v(\d+\.\d+\.\d+)$/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The go job installs codeality-go with `go install ...@v<version>`; it must
|
|
8
|
+
* be the current release. `latest`, a branch or a SHA is reported as not
|
|
9
|
+
* released.
|
|
10
|
+
*/
|
|
11
|
+
export function checkGoPin({ codealityWorkflow, versions }) {
|
|
12
|
+
const current = versions['codeality-go']
|
|
13
|
+
const ref = INSTALL.exec(codealityWorkflow ?? '')?.[1]
|
|
14
|
+
if (!current || !ref) return []
|
|
15
|
+
return pinFinding(
|
|
16
|
+
'go',
|
|
17
|
+
'codeality-go',
|
|
18
|
+
VERSION.exec(ref)?.[1] ?? ref,
|
|
19
|
+
current,
|
|
20
|
+
)
|
|
21
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The id of the job `codeality-go init --ci` writes for the module in
|
|
3
|
+
* `workingDirectory`, relative to the repository root: `go` at the root,
|
|
4
|
+
* `go-<path>` below it.
|
|
5
|
+
*/
|
|
6
|
+
export function goJobId(workingDirectory) {
|
|
7
|
+
if (!workingDirectory || workingDirectory === '.') return 'go'
|
|
8
|
+
return `go-${workingDirectory.replaceAll(/\W/g, '-')}`
|
|
9
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { relative } from 'node:path'
|
|
2
|
+
|
|
3
|
+
import { readWorkflows } from '../conformance/readWorkflows.mjs'
|
|
4
|
+
import { repositoryRoot } from '../python/repositoryRoot.mjs'
|
|
5
|
+
import { goJobId } from './goJobId.mjs'
|
|
6
|
+
|
|
7
|
+
/** Everything the Go conformance checks read, gathered once. */
|
|
8
|
+
export async function loadGoContext(root, versions) {
|
|
9
|
+
const repository = await repositoryRoot(root)
|
|
10
|
+
const workflows = await readWorkflows(repository)
|
|
11
|
+
return {
|
|
12
|
+
root,
|
|
13
|
+
versions,
|
|
14
|
+
workflows,
|
|
15
|
+
jobId: goJobId(relative(repository, root).replaceAll('\\', '/')),
|
|
16
|
+
codealityWorkflow:
|
|
17
|
+
workflows.find((w) => w.name === 'codeality.yml')?.text ?? '',
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { checkActionPins } from '../conformance/checkActionPins.mjs'
|
|
2
|
+
import { checkGoGateJob } from './checkGoGateJob.mjs'
|
|
3
|
+
import { checkGoPin } from './checkGoPin.mjs'
|
|
4
|
+
import { loadGoContext } from './loadGoContext.mjs'
|
|
5
|
+
|
|
6
|
+
const CHECKS = [checkGoGateJob, checkActionPins, checkGoPin]
|
|
7
|
+
|
|
8
|
+
/** Whether a Go module's gate is wired: its job, pinned actions, current release. */
|
|
9
|
+
export async function runGoConformance(root, versions) {
|
|
10
|
+
const context = await loadGoContext(root, versions)
|
|
11
|
+
return { context, findings: CHECKS.flatMap((check) => check(context)) }
|
|
12
|
+
}
|
|
@@ -20,15 +20,15 @@ export const ACTION_PINS = {
|
|
|
20
20
|
tag: 'v7',
|
|
21
21
|
},
|
|
22
22
|
setupPnpm: {
|
|
23
|
-
uses: 'pnpm/action-setup@
|
|
24
|
-
tag: 'v6.1.
|
|
23
|
+
uses: 'pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115',
|
|
24
|
+
tag: 'v6.1.1',
|
|
25
25
|
},
|
|
26
26
|
actionlint: {
|
|
27
27
|
uses: 'raven-actions/actionlint@3d39aea434753780c3b3d4a1a31c854b4dbf49d7',
|
|
28
28
|
tag: 'v2',
|
|
29
29
|
},
|
|
30
30
|
zizmor: {
|
|
31
|
-
uses: 'zizmorcore/zizmor-action@
|
|
32
|
-
tag: 'v0.
|
|
31
|
+
uses: 'zizmorcore/zizmor-action@bd12b495c90993a4301c73398142281a61499af3',
|
|
32
|
+
tag: 'v0.9.0',
|
|
33
33
|
},
|
|
34
34
|
}
|
|
@@ -36,8 +36,12 @@ export function baselineScripts() {
|
|
|
36
36
|
// own when that date passes. Without somewhere to put a judged finding,
|
|
37
37
|
// the only way to silence one is to raise the level for everything.
|
|
38
38
|
'audit:check': 'baseline-audit --level moderate',
|
|
39
|
+
// Prints what the packages upgraded since the last run changed and what
|
|
40
|
+
// must be done about it, once. Always exits 0; it first so the notice is
|
|
41
|
+
// at the top of the gate's output.
|
|
42
|
+
changes: 'baseline-changes',
|
|
39
43
|
'check:ci':
|
|
40
|
-
'pnpm lint:fast && pnpm type-check && pnpm lint && pnpm format:check && pnpm test && pnpm dupes && pnpm knip',
|
|
44
|
+
'pnpm changes && pnpm lint:fast && pnpm type-check && pnpm lint && pnpm format:check && pnpm test && pnpm dupes && pnpm knip',
|
|
41
45
|
'check:quality': 'pnpm deps:graph && pnpm type-coverage',
|
|
42
46
|
'check:security': 'pnpm secrets:check && pnpm audit:check',
|
|
43
47
|
}
|