@decohere/ci-tools 0.0.1-dev.20261123.370 → 0.0.1-dev.20261123.379
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/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# @decohere/ci-tools
|
|
2
|
+
|
|
3
|
+
Node scripts the repo's GitHub workflows and root `package.json` scripts run. Plain `.mjs`, run from source with `node`. One folder per job, under `src/`:
|
|
4
|
+
|
|
5
|
+
- `audit/`: summarize `npm audit`, fail on findings (`enforce`), and open or close the audit issue (`upsert-issue`). Run by CI (`ci.yml`) and the nightly `npm-audit.yml`.
|
|
6
|
+
- `badges/`: the CI status badge (`ci-status`). Run by `pages.yml`, `bench.yml` and `clear-benchmark-history.yml`.
|
|
7
|
+
- `bench/`: build benchmarks (`pnpm bench`, `pnpm bench:save`, `pnpm perf:trace`), and the nightly run and its regression issues. Run by `bench.yml`.
|
|
8
|
+
- `changeset/`: changeset status and changelog scripts behind `pnpm changeset:check` and `pnpm version:aggregate`. No workflow runs them.
|
|
9
|
+
- `coverage/`: the coverage report (`pnpm test:coverage:report`) and its badge, run by `pages.yml`.
|
|
10
|
+
- `github/`: GitHub and npm checks (`ensure-metadata` is used by `publish-verify`): `first-publish-check` (CI), `publish-verify` (`publish.yml`), `failure-report` (the `failure-report` action, used by `ci.yml` and `clear-benchmark-history.yml`), and `npm-bootstrap` (`pnpm npm:bootstrap`, run by hand).
|
|
11
|
+
- `lib/`: what the scripts share: SVG badges, LCOV parsing, GitHub issues, the workspace's packages. Nothing runs it directly.
|
|
12
|
+
- `pages/`: the GitHub Pages site (badges, bench history, the artifact). Run by `pages.yml`, `bench.yml` and `clear-benchmark-history.yml`.
|
|
13
|
+
- `release/`: publishing: `check-patch-release`, `find-publish-base` and `restamp-build` (`publish.yml`), `promote-latest` (`promote-latest.yml`, the "Promote to latest" workflow), and `publish-to-temporary-registry` (the `verify-release` action).
|
|
14
|
+
|
|
15
|
+
## Working on this package
|
|
16
|
+
|
|
17
|
+
Tests are in `tests/`, in folders named like the `src/` folders they test: `*.test.mjs` and, under `release/`, `*.spec.ts`. `pnpm test` runs both. `tests/github/ci-workflow.test.mjs` and `publish-workflow.test.mjs` check the workflow files themselves. There is no canonical suite for ci-tools in the [testing table](../../docs/contributing/testing/README.md#canonical-suite-ownership).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decohere/ci-tools",
|
|
3
|
-
"version": "0.0.1-dev.20261123.
|
|
3
|
+
"version": "0.0.1-dev.20261123.379",
|
|
4
4
|
"description": "CI utility scripts for badge generation, coverage reporting, pages artifact assembly, and GitHub API tooling",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -103,18 +103,20 @@ export class CodeDesign {
|
|
|
103
103
|
if (BANNED.test(base)) add("bannedNames", rel);
|
|
104
104
|
const role = base.split(".");
|
|
105
105
|
if (base !== "index" && (role.length < 2 || !ROLES.has(role.at(-1)))) add("noRole", rel);
|
|
106
|
-
const env = text.match(/process\.env\b/g)?.length ?? 0;
|
|
107
|
-
if (env > 0 && name !== "config" && !bins.has(relative(this.root, file))) {
|
|
108
|
-
for (let i = 0; i < env; i++) add("envReads", rel);
|
|
109
|
-
}
|
|
110
106
|
const source = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true);
|
|
107
|
+
const isPluginFile = role.at(-1) === "plugin";
|
|
108
|
+
if (name !== "config" && !bins.has(relative(this.root, file))) {
|
|
109
|
+
for (let i = countEnvReads(source); i > 0; i--) add("envReads", rel);
|
|
110
|
+
}
|
|
111
111
|
let classes = 0;
|
|
112
112
|
for (const statement of source.statements) {
|
|
113
113
|
if (ts.isClassDeclaration(statement)) classes++;
|
|
114
114
|
if (!isExported(statement)) continue;
|
|
115
115
|
if (ts.isFunctionDeclaration(statement)) {
|
|
116
116
|
const fn = statement.name?.text ?? "default";
|
|
117
|
-
|
|
117
|
+
// A .plugin.ts file holds a plugin factory, whatever writer or module it returns.
|
|
118
|
+
if (!isPluginFile && !isAllowedFunction(fn, statement))
|
|
119
|
+
add("looseFunctions", `${rel}: ${fn}`);
|
|
118
120
|
}
|
|
119
121
|
if (ts.isVariableStatement(statement)) {
|
|
120
122
|
for (const declaration of statement.declarationList.declarations) {
|
|
@@ -195,6 +197,28 @@ export class CodeDesign {
|
|
|
195
197
|
}
|
|
196
198
|
|
|
197
199
|
/** @param {ts.Statement} statement */
|
|
200
|
+
/**
|
|
201
|
+
* `process.env` in code: a property read, so the words in a string (a template for generated
|
|
202
|
+
* code) or a comment don't count.
|
|
203
|
+
*
|
|
204
|
+
* @param {ts.Node} node
|
|
205
|
+
* @returns {number}
|
|
206
|
+
*/
|
|
207
|
+
function countEnvReads(node) {
|
|
208
|
+
const here =
|
|
209
|
+
ts.isPropertyAccessExpression(node) &&
|
|
210
|
+
node.name.text === "env" &&
|
|
211
|
+
ts.isIdentifier(node.expression) &&
|
|
212
|
+
node.expression.text === "process"
|
|
213
|
+
? 1
|
|
214
|
+
: 0;
|
|
215
|
+
let below = 0;
|
|
216
|
+
node.forEachChild((child) => {
|
|
217
|
+
below += countEnvReads(child);
|
|
218
|
+
});
|
|
219
|
+
return here + below;
|
|
220
|
+
}
|
|
221
|
+
|
|
198
222
|
function isExported(statement) {
|
|
199
223
|
return (
|
|
200
224
|
ts.canHaveModifiers(statement) &&
|
|
@@ -57,7 +57,9 @@ export function runDesignCheck(options = {}) {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
log(
|
|
60
|
+
log(
|
|
61
|
+
`design: ${total(counts)} breaks of ADR 0027 (docs/contributing/adr/0027-code-design.md).`,
|
|
62
|
+
);
|
|
61
63
|
if (rose.length > 0) {
|
|
62
64
|
log(rose.join("\n"));
|
|
63
65
|
log(
|
|
@@ -43,7 +43,7 @@ export function promoteLatest(options) {
|
|
|
43
43
|
}
|
|
44
44
|
log(`Promoting ${version} to latest on ${packages.length} packages`);
|
|
45
45
|
|
|
46
|
-
// Once a stable version is out, latest belongs to releases: see "Stable release" in docs/ci.
|
|
46
|
+
// Once a stable version is out, latest belongs to releases: see "Stable release" in docs/contributing/ci.
|
|
47
47
|
const current = /^latest: (.+)$/m.exec(npm("dist-tag", "ls", LAUNCH_PACKAGE).stdout)?.[1];
|
|
48
48
|
if (current != null && !current.includes("-") && version.includes("-")) {
|
|
49
49
|
log(`latest is the stable ${current}, and ${version} is a dev version. Nothing moved.`);
|
|
@@ -75,6 +75,27 @@ describe("design:check", () => {
|
|
|
75
75
|
});
|
|
76
76
|
});
|
|
77
77
|
|
|
78
|
+
it("counts environment reads in code, not the words in a string or a comment", () => {
|
|
79
|
+
seed({
|
|
80
|
+
"src/app.service.ts":
|
|
81
|
+
"// reads process.env.PORT\nexport class AppService {\n" +
|
|
82
|
+
'\tpublic readonly text = "const port = process.env.PORT;";\n' +
|
|
83
|
+
"\tpublic readonly port = process.env.PORT;\n}\n",
|
|
84
|
+
});
|
|
85
|
+
expect(run(["--update"]).code).toBe(0);
|
|
86
|
+
expect(JSON.parse(vol.readFileSync(`${root}/${BASELINE}`, "utf8"))).toEqual({
|
|
87
|
+
http: { envReads: 1 },
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("keeps the factory in a .plugin.ts file, whatever it returns", () => {
|
|
92
|
+
seed({
|
|
93
|
+
"src/pino.plugin.ts":
|
|
94
|
+
"export function pino(): PinoAdapter {\n\treturn new PinoAdapter();\n}\n",
|
|
95
|
+
});
|
|
96
|
+
expect(run()).toEqual({ code: 0, output: expect.stringContaining("design: 0 breaks") });
|
|
97
|
+
});
|
|
98
|
+
|
|
78
99
|
it("keeps plugin factories, decorators, define helpers and predicates", () => {
|
|
79
100
|
seed({
|
|
80
101
|
...CLEAN,
|