@maniumek/suwgate 0.1.0 → 0.2.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/README.md +38 -11
- package/dist/eslint/index.d.ts +1 -0
- package/dist/eslint/index.js +5 -1
- package/dist/gate/check.js +5 -1
- package/dist/gate/config.d.ts +1 -0
- package/dist/gate/config.js +1 -0
- package/dist/gate/report.js +1 -1
- package/dist/guards/comments/eslint.d.ts +1 -0
- package/dist/guards/comments/eslint.js +4 -2
- package/dist/guards/repository/configContents.d.ts +3 -0
- package/dist/guards/repository/configContents.js +330 -0
- package/dist/guards/repository/docsPaths.d.ts +2 -0
- package/dist/guards/repository/docsPaths.js +30 -6
- package/dist/guards/repository/forbiddenNames.js +5 -2
- package/dist/guards/repository/index.js +2 -0
- package/dist/guards/repository/noRawColors.js +3 -2
- package/dist/guards/repository/repositoryLayout.js +20 -2
- package/dist/guards/repository/requiredFiles.js +46 -9
- package/dist/guards/repository/text.d.ts +1 -0
- package/dist/guards/repository/text.js +38 -0
- package/dist/guards/repository/vsCodeSettings.js +1 -1
- package/dist/profiles/contract.d.ts +1 -0
- package/dist/profiles/contract.js +6 -5
- package/dist/profiles/database.js +2 -2
- package/dist/profiles/dotnet.d.ts +2 -0
- package/dist/profiles/dotnet.js +18 -8
- package/dist/profiles/node.js +1 -1
- package/dist/profiles/shell.d.ts +3 -0
- package/dist/profiles/shell.js +17 -0
- package/dist/profiles/web.js +19 -3
- package/dist/session/guardEdit.js +2 -0
- package/package.json +1 -1
- package/schema/suwgate.schema.json +12 -0
package/README.md
CHANGED
|
@@ -34,12 +34,16 @@ exceptions:
|
|
|
34
34
|
guards run only with `database`.
|
|
35
35
|
- `steps.add` runs more (`name`, `run`, optionally `title`, `quick`, `after`, `limitSeconds`); `steps.skip` leaves a step out,
|
|
36
36
|
always with a `reason`.
|
|
37
|
+
- `quick.limitSeconds` is the budget of `suwgate check --quick` (default 20): the quick gate fails above it. A machine that is slow
|
|
38
|
+
across the board overrides it with `SUWGATE_QUICK_LIMIT=<seconds>`.
|
|
37
39
|
- `exceptions` let one target through one guard, always with a `reason`; `suwgate check` counts them in its report, and an
|
|
38
40
|
exception that no longer matches anything fails the gate until it is deleted.
|
|
39
41
|
- The schema is in the package, `schema/suwgate.schema.json`. VS Code checks the file as you type with
|
|
40
42
|
`"yaml.schemas": { "./node_modules/@maniumek/suwgate/schema/suwgate.schema.json": "suwgate.yml" }` in `.vscode/settings.json`.
|
|
41
|
-
- `settings` configure a guard by its id, for example `dependency-direction: { applications: [Myapp.*] }
|
|
42
|
-
`agents-file: { acronyms: [NUGET] }
|
|
43
|
+
- `settings` configure a guard by its id, for example `dependency-direction: { applications: [Myapp.*] }`,
|
|
44
|
+
`agents-file: { acronyms: [NUGET] }` or `docs-paths: { ignore: [Myapp.Web/node_modules/], skip: [docs/notes/**] }` (`ignore`: names the
|
|
45
|
+
docs may mention that are not paths here; `skip`: documents, by glob, that docs-paths does not read at all); the schema of each
|
|
46
|
+
guard's settings is in its source, and `suwgate check` validates them.
|
|
43
47
|
|
|
44
48
|
## Hooks
|
|
45
49
|
|
|
@@ -86,9 +90,9 @@ Each step looks where its profile lives (`directories`) and passes with nothing
|
|
|
86
90
|
| Profile | Steps |
|
|
87
91
|
| :--------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
88
92
|
| `web`, `library` | `pnpm-install` (only without `node_modules`), `typecheck` (every `tsconfig*.json` but `tsconfig.build.json`), `lint`, `unit-tests` (the Vitest project `unit` when the config names one), `format`, `knip` |
|
|
89
|
-
| `web` | `e2e`: `playwright test -c e2e/playwright.config.ts`, after the build, the database and the .NET tests
|
|
93
|
+
| `web` | `e2e`: `playwright test -c e2e/playwright.config.ts`, after the build, the database and the .NET tests; with a `dev` section, first the checkout's variables (`suwgate dev checkout-env`) and a fresh, empty `E2E_DATABASE` (`dev db up`, then drop and create it); Playwright's `webServer` starts and stops the server and the web app |
|
|
90
94
|
| `library` | `stories` (with `.storybook/`), `publint`, `attw`, `consumer-app` (packs the library into a copy of `gate/consumer/app`, builds it, runs `gate/consumer/playwright.config.ts`), `visual` (`visual/playwright.config.ts` in the Playwright image of the installed `@playwright/test`), `changeset` |
|
|
91
|
-
| `dotnet` | `dotnet-build`, `dotnet-format`, `dotnet-test` (`--quick`: only the test projects that use `Suwgate.Architecture` or `Suwgate.Database`)
|
|
95
|
+
| `dotnet` | `dotnet-build`, `dotnet-format`, `dotnet-test` (with a `dev` section, under the checkout's variables, so two worktrees never share a test database; `--quick`: only the test projects that use `Suwgate.Architecture` or `Suwgate.Database`); every .NET step leaves no idle MSBuild worker or build server behind |
|
|
92
96
|
| `dotnet`, `web` | with `contract/openapi.json`: `api-contract` (the contract and `src/api/openapi.d.ts` of the web app regenerated from the server's project, the one that references `Microsoft.Extensions.ApiDescription.Server`), `api-version` (oasdiff against master; a break needs a new major version in `contract/package.json`), `contract-pins` (every test tagged `contract <name>@<version>` names a version) |
|
|
93
97
|
| `database` | `database-up`: `docker compose --profile db up -d --wait db`, not in CI |
|
|
94
98
|
| every repository | `compose` (with a compose file), `criteria`, `shellcheck`, `gitleaks` |
|
|
@@ -117,13 +121,36 @@ adds the repository's own (`{ "kinds": [{ "kind", "paths", "how" }] }`, optional
|
|
|
117
121
|
|
|
118
122
|
The configs of the tools the steps run extend suwgate's, so an application keeps only its own paths:
|
|
119
123
|
|
|
120
|
-
| Tool | The application's file
|
|
121
|
-
| :--------- |
|
|
122
|
-
| Prettier | `.prettierrc.json`: `"@maniumek/suwgate/prettier"` (with a plugin: spread it in `prettier.config.js`)
|
|
123
|
-
| TypeScript | `{ "extends": "@maniumek/suwgate/tsconfig/browser", "include": ["src"] }`; `tsconfig/node` for the configs, scripts and tests run by Node; `tsconfig/strict` for the options alone
|
|
124
|
-
| knip | `knip.config.ts`: `export { default } from "@maniumek/suwgate/knip"`, or `knip({ entry: [...] })`; it ignores the tools the steps run and the generated API types, and reads the steps' Playwright configs
|
|
125
|
-
| Vitest | `unitTests({ environment: "jsdom" })` and `storyTests({ plugin, provider })` from `@maniumek/suwgate/vitest`: the projects `unit` and `stories` the steps run
|
|
126
|
-
| Playwright | `defineConfig(e2eTests({ use: { baseURL }, webServer }))` or `defineConfig(visualTests())` from `@maniumek/suwgate/playwright`
|
|
124
|
+
| Tool | The application's file |
|
|
125
|
+
| :--------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
126
|
+
| Prettier | `.prettierrc.json`: `"@maniumek/suwgate/prettier"` (with a plugin: spread it in `prettier.config.js`) |
|
|
127
|
+
| TypeScript | `{ "extends": "@maniumek/suwgate/tsconfig/browser", "include": ["src"] }`; `tsconfig/node` for the configs, scripts and tests run by Node; `tsconfig/strict` for the options alone |
|
|
128
|
+
| knip | `knip.config.ts`: `export { default } from "@maniumek/suwgate/knip"`, or `knip({ entry: [...] })`; it ignores the tools the steps run and the generated API types, and reads the steps' Playwright configs |
|
|
129
|
+
| Vitest | `unitTests({ environment: "jsdom" })` and `storyTests({ plugin, provider })` from `@maniumek/suwgate/vitest`: the projects `unit` and `stories` the steps run |
|
|
130
|
+
| Playwright | `defineConfig(e2eTests({ use: { baseURL }, webServer }))` or `defineConfig(visualTests())` from `@maniumek/suwgate/playwright` |
|
|
131
|
+
| ESLint | `app({ root, features, shared, sharedImports, storage })` from `@maniumek/suwgate/eslint`: a feature imports itself and the shared folders, a shared folder only itself and what `sharedImports` allows it (`[["design", "api"]]`: design may import api) |
|
|
132
|
+
|
|
133
|
+
### What the config files must say
|
|
134
|
+
|
|
135
|
+
`required-files` asks for the files; `config-contents` checks that they say what the gate relies on, each where its profile lives
|
|
136
|
+
(`directories`), and only when the profile is on and the file is there:
|
|
137
|
+
|
|
138
|
+
| File | Profile | Must contain |
|
|
139
|
+
| :---------------------------------------------------------------------------- | :--------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
140
|
+
| `global.json` | `dotnet` | an exact `sdk.version` (`10.0.100`), a `sdk.rollForward` other than `major` and `latestMajor`, `test.runner` `Microsoft.Testing.Platform` |
|
|
141
|
+
| `.editorconfig` (the root's, then the dotnet directory's) | `dotnet` | `max_line_length = 140` for `*.cs`, `*.csproj`, `*.props` and `*.targets`: CSharpier's width; a `.csharpierrc*` anywhere must go, it would win over it |
|
|
142
|
+
| `Directory.Packages.props` | `dotnet` | `<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>` |
|
|
143
|
+
| `tsconfig*.json` (not `tsconfig.build.json`, which the typecheck step skips) | `web`, `library` | `extends` `@maniumek/suwgate/tsconfig/...`, directly or through another tsconfig of the repository |
|
|
144
|
+
| `eslint.config.js`, `knip.config.ts`, the Vitest config | `web`, `library` | an import of `@maniumek/suwgate/eslint`, `/knip`, `/vitest` |
|
|
145
|
+
| `.prettierrc.json` or `prettier.config.js` | `web`, `library` | exactly `"@maniumek/suwgate/prettier"`, or an import of it |
|
|
146
|
+
| `e2e/playwright.config.ts`, `visual/playwright.config.ts` | `web`, `library` | an import of `@maniumek/suwgate/playwright` |
|
|
147
|
+
| `package.json` that installs suwgate (the root or a web or library directory) | every | `@maniumek/suwgate` at an exact version: no `^`, `~`, range or tag |
|
|
148
|
+
| `pnpm-workspace.yaml` (web, library, and where suwgate is installed) | every | no `minimumReleaseAge` of 0 (pnpm waits 1440 minutes by default); `minimumReleaseAgeExclude` is fine |
|
|
149
|
+
| `.vscode/settings.json` | every | `yaml.schemas` mapping `./node_modules/@maniumek/suwgate/schema/suwgate.schema.json` (or under a profile's directory) to `suwgate.yml` |
|
|
150
|
+
| `.github/workflows/*.yml` | every | a job with `uses: Manomenu/suwgate/.github/workflows/gate.yml@<full 40-character commit sha>` |
|
|
151
|
+
|
|
152
|
+
`required-files` also asks the `dotnet` profile for exactly one `*.slnx` in its directory, and for `Directory.Build.rsp`
|
|
153
|
+
(`-nodeReuse:false`, so no idle MSBuild worker stays behind).
|
|
127
154
|
|
|
128
155
|
### The .NET guards
|
|
129
156
|
|
package/dist/eslint/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export interface StrictOptions {
|
|
|
10
10
|
export interface AppOptions extends StrictOptions {
|
|
11
11
|
features: readonly string[];
|
|
12
12
|
shared?: readonly string[];
|
|
13
|
+
sharedImports?: readonly (readonly [from: string, to: string])[];
|
|
13
14
|
storage?: readonly string[];
|
|
14
15
|
}
|
|
15
16
|
export declare const plugin: ESLint.Plugin;
|
package/dist/eslint/index.js
CHANGED
|
@@ -10,7 +10,7 @@ const CODE = ["**/*.{ts,tsx,js,jsx,mjs,cjs,mts,cts}"];
|
|
|
10
10
|
const SOURCES = ["src/**/*.{ts,tsx}"];
|
|
11
11
|
const BROWSER_STORAGE = ["localStorage", "sessionStorage", "indexedDB"];
|
|
12
12
|
const BROWSER_STORAGE_FIX = "Keep the state on the server, in the address or in React; browser storage is allowed only in the files that storage of app() names in eslint.config.js.";
|
|
13
|
-
const BOUNDARIES_FIX = "A feature of src/ imports only itself and the shared folders, a shared folder only itself, a file directly in src/ anything; a new folder of src/ goes into features or shared of app() in eslint.config.js.";
|
|
13
|
+
const BOUNDARIES_FIX = "A feature of src/ imports only itself and the shared folders, a shared folder only itself (and the shared folders sharedImports of app() lets it), a file directly in src/ anything; a new folder of src/ goes into features or shared of app() in eslint.config.js.";
|
|
14
14
|
export const plugin = {
|
|
15
15
|
meta: { name: "@maniumek/suwgate" },
|
|
16
16
|
rules: { "no-comments": noComments },
|
|
@@ -67,6 +67,10 @@ function featureBoundaries(options) {
|
|
|
67
67
|
allow: { to: [{ file: { categories: "entry" } }, { element: { types: { anyOf: ["feature", "shared"] } } }] },
|
|
68
68
|
},
|
|
69
69
|
{ from: { element: { type: "feature" } }, allow: { to: { element: { type: "shared" } } } },
|
|
70
|
+
...(options.sharedImports ?? []).map(([from, to]) => ({
|
|
71
|
+
from: { element: { type: "shared", path: `src/${from}/**` } },
|
|
72
|
+
allow: { to: { element: { type: "shared", path: `src/${to}/**` } } },
|
|
73
|
+
})),
|
|
70
74
|
],
|
|
71
75
|
},
|
|
72
76
|
],
|
package/dist/gate/check.js
CHANGED
|
@@ -40,7 +40,11 @@ export async function check(options) {
|
|
|
40
40
|
results,
|
|
41
41
|
command,
|
|
42
42
|
totalSeconds,
|
|
43
|
-
quickLimit: options.quick
|
|
43
|
+
quickLimit: options.quick
|
|
44
|
+
? typeof quickLimit === "number"
|
|
45
|
+
? quickLimit
|
|
46
|
+
: (loaded.config.quickLimitSeconds ?? DEFAULT_QUICK_LIMIT_SECONDS)
|
|
47
|
+
: null,
|
|
44
48
|
ci: (options.env["CI"] ?? "") !== "",
|
|
45
49
|
exceptions: loaded.config.exceptions.length,
|
|
46
50
|
verbose: options.verbose,
|
package/dist/gate/config.d.ts
CHANGED
package/dist/gate/config.js
CHANGED
|
@@ -158,6 +158,7 @@ export function parseConfig(text, catalog) {
|
|
|
158
158
|
skip: data.steps?.skip ?? [],
|
|
159
159
|
exceptions: data.exceptions ?? [],
|
|
160
160
|
settings: data.settings ?? {},
|
|
161
|
+
...(data.quick?.limitSeconds === undefined ? {} : { quickLimitSeconds: data.quick.limitSeconds }),
|
|
161
162
|
},
|
|
162
163
|
};
|
|
163
164
|
}
|
package/dist/gate/report.js
CHANGED
|
@@ -41,7 +41,7 @@ export function report(input) {
|
|
|
41
41
|
}
|
|
42
42
|
if (input.quickLimit !== null && input.totalSeconds > input.quickLimit) {
|
|
43
43
|
failed = true;
|
|
44
|
-
rows.push(row("FAIL", input.totalSeconds, `the quick gate is over its budget of ${input.quickLimit}s: move the slow step to the full gate or speed it up; a machine that is slow across the board runs with SUWGATE_QUICK_LIMIT=<seconds>`));
|
|
44
|
+
rows.push(row("FAIL", input.totalSeconds, `the quick gate is over its budget of ${input.quickLimit}s: move the slow step to the full gate or speed it up; a repository whose quick gate is rightly longer sets quick.limitSeconds in suwgate.yml, and a machine that is slow across the board runs with SUWGATE_QUICK_LIMIT=<seconds>`));
|
|
45
45
|
}
|
|
46
46
|
const extras = [
|
|
47
47
|
`${input.exceptions} exception${input.exceptions === 1 ? "" : "s"} in suwgate.yml`,
|
|
@@ -13,6 +13,7 @@ import { pathToFileURL } from "node:url";
|
|
|
13
13
|
import { isScanned } from "./scan.js";
|
|
14
14
|
const RULE = "suwgate/no-comments";
|
|
15
15
|
const CODE = /\.(ts|tsx|js|jsx|mjs|cjs|mts|cts)$/;
|
|
16
|
+
export const GENERATED_API_TYPES = "src/api/openapi.d.ts";
|
|
16
17
|
const LINTED_PROFILES = ["web", "library"];
|
|
17
18
|
const USE_THE_PRESET = `extend strict() or app() of @maniumek/suwgate/eslint in eslint.config.js, or switch ${RULE} on as an error for every TypeScript and JavaScript file`;
|
|
18
19
|
function lintedDirectories(context) {
|
|
@@ -53,7 +54,8 @@ function findingOf(file, verdict) {
|
|
|
53
54
|
return [];
|
|
54
55
|
}
|
|
55
56
|
async function findingsIn(context, directory) {
|
|
56
|
-
const
|
|
57
|
+
const generated = context.profiles.includes("web") ? path.posix.join(context.directories.web ?? ".", GENERATED_API_TYPES) : null;
|
|
58
|
+
const files = context.files.filter((file) => CODE.test(file) && isScanned(file) && inDirectory(file, directory) && file !== generated);
|
|
57
59
|
if (files.length === 0)
|
|
58
60
|
return [];
|
|
59
61
|
const cwd = path.join(context.root, directory);
|
|
@@ -75,7 +77,7 @@ async function findingsIn(context, directory) {
|
|
|
75
77
|
}
|
|
76
78
|
export const commentsEslint = {
|
|
77
79
|
id: "comments-eslint",
|
|
78
|
-
description: `ESLint lints every TypeScript and JavaScript file and refuses its comments with ${RULE} as an error`,
|
|
80
|
+
description: `ESLint lints every TypeScript and JavaScript file but the web app's generated API types and refuses its comments with ${RULE} as an error`,
|
|
79
81
|
profiles: LINTED_PROFILES,
|
|
80
82
|
check: async (context) => (await Promise.all(lintedDirectories(context).map((directory) => findingsIn(context, directory)))).flat(),
|
|
81
83
|
};
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { parse as parseYaml } from "yaml";
|
|
3
|
+
import { npmDependencies } from "./packageManifests.js";
|
|
4
|
+
import { baseName, inProfileDirectory, isRecord, lineAt, numberedLines, parseJson, parseJsonc } from "./text.js";
|
|
5
|
+
const SUWGATE = "@maniumek/suwgate";
|
|
6
|
+
const NODE_PROFILES = ["web", "library"];
|
|
7
|
+
const EXACT_VERSION = /^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/;
|
|
8
|
+
const ROLL_FORWARD_ALLOWED = ["patch", "feature", "minor", "latestPatch", "latestFeature", "latestMinor", "disable"];
|
|
9
|
+
const ROLL_FORWARD_MAJOR = ["major", "latestMajor"];
|
|
10
|
+
const TEST_RUNNER = "Microsoft.Testing.Platform";
|
|
11
|
+
const LINE_LENGTH = "140";
|
|
12
|
+
const CSHARPIER_FILES = [".cs", ".csproj", ".props", ".targets"];
|
|
13
|
+
const CSHARPIER_CONFIGS = [".csharpierrc", ".csharpierrc.json", ".csharpierrc.yaml", ".csharpierrc.yml"];
|
|
14
|
+
const TSCONFIG = /^tsconfig(\..+)?\.json$/;
|
|
15
|
+
const ESLINT_CONFIGS = ["eslint.config.js", "eslint.config.mjs", "eslint.config.ts", "eslint.config.mts"];
|
|
16
|
+
const VITEST_CONFIGS = ["vitest.config.ts", "vitest.config.mts", "vitest.config.js", "vitest.config.mjs"];
|
|
17
|
+
const PLAYWRIGHT_CONFIGS = [
|
|
18
|
+
["web", "e2e/playwright.config.ts"],
|
|
19
|
+
["library", "visual/playwright.config.ts"],
|
|
20
|
+
];
|
|
21
|
+
const SCHEMA_PATH = `node_modules/${SUWGATE}/schema/suwgate.schema.json`;
|
|
22
|
+
const WORKFLOW = /^\.github\/workflows\/[^/]+\.ya?ml$/;
|
|
23
|
+
const GATE_CALL = /^\s*(?:-\s+)?uses:\s*["']?manomenu\/suwgate\/\.github\/workflows\/gate\.ya?ml@([^\s"'#]+)/i;
|
|
24
|
+
const FULL_SHA = /^[0-9a-f]{40}$/;
|
|
25
|
+
const GATE_USES = "uses: Manomenu/suwgate/.github/workflows/gate.yml@<full 40-character commit sha>";
|
|
26
|
+
function directoryOf(context, profile) {
|
|
27
|
+
return (context.directories[profile] ?? "").replace(/\/+$/, "");
|
|
28
|
+
}
|
|
29
|
+
function joined(directory, file) {
|
|
30
|
+
return directory === "" ? file : `${directory}/${file}`;
|
|
31
|
+
}
|
|
32
|
+
function present(context, file) {
|
|
33
|
+
return context.files.includes(file);
|
|
34
|
+
}
|
|
35
|
+
function nodeDirectories(context) {
|
|
36
|
+
return [...new Set(NODE_PROFILES.filter((profile) => context.profiles.includes(profile)).map((p) => directoryOf(context, p)))];
|
|
37
|
+
}
|
|
38
|
+
function imports(text, module) {
|
|
39
|
+
const escaped = module.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
|
|
40
|
+
return new RegExp(`(?:\\bfrom\\s*|\\bimport\\s*\\(\\s*|\\bimport\\s+|\\brequire\\s*\\(\\s*)["']${escaped}["']`).test(text);
|
|
41
|
+
}
|
|
42
|
+
function globalJson(context) {
|
|
43
|
+
const file = inProfileDirectory(context.directories, "dotnet", "global.json");
|
|
44
|
+
if (!present(context, file))
|
|
45
|
+
return [];
|
|
46
|
+
const parsed = parseJsonc(context.read(file));
|
|
47
|
+
if (!isRecord(parsed))
|
|
48
|
+
return [{ target: file, message: "not valid JSON: fix the file so the dotnet CLI can read it" }];
|
|
49
|
+
const sdk = isRecord(parsed["sdk"]) ? parsed["sdk"] : {};
|
|
50
|
+
const test = isRecord(parsed["test"]) ? parsed["test"] : {};
|
|
51
|
+
const version = sdk["version"];
|
|
52
|
+
const rollForward = sdk["rollForward"];
|
|
53
|
+
const allowed = ROLL_FORWARD_ALLOWED.join(", ");
|
|
54
|
+
const findings = [];
|
|
55
|
+
if (typeof version !== "string" || !EXACT_VERSION.test(version)) {
|
|
56
|
+
findings.push(`sdk.version is ${JSON.stringify(version ?? null)}: set the exact SDK version, such as "10.0.100" (major.minor.patch, no wildcard or range), so every machine and CI build with the same SDK`);
|
|
57
|
+
}
|
|
58
|
+
if (typeof rollForward !== "string") {
|
|
59
|
+
findings.push(`sdk.rollForward is not set: set it, for example "latestFeature" (allowed: ${allowed}), so it is written down how far the SDK may move`);
|
|
60
|
+
}
|
|
61
|
+
else if (ROLL_FORWARD_MAJOR.includes(rollForward)) {
|
|
62
|
+
findings.push(`sdk.rollForward is "${rollForward}", which lets a new major SDK build the code with other analyzers and defaults: set it to one of ${allowed}`);
|
|
63
|
+
}
|
|
64
|
+
else if (!ROLL_FORWARD_ALLOWED.includes(rollForward)) {
|
|
65
|
+
findings.push(`sdk.rollForward "${rollForward}" is not a value .NET knows: set it to one of ${allowed}`);
|
|
66
|
+
}
|
|
67
|
+
if (test["runner"] !== TEST_RUNNER) {
|
|
68
|
+
findings.push(`test.runner is ${JSON.stringify(test["runner"] ?? null)}: set "test": { "runner": "${TEST_RUNNER}" }, the runner the dotnet-test step's dotnet test options are written for`);
|
|
69
|
+
}
|
|
70
|
+
return findings.map((message) => ({ target: file, message }));
|
|
71
|
+
}
|
|
72
|
+
function expandBraces(glob) {
|
|
73
|
+
const match = /\{([^{}]*)\}/.exec(glob);
|
|
74
|
+
if (match?.[1]?.includes(",") !== true)
|
|
75
|
+
return [glob];
|
|
76
|
+
const before = glob.slice(0, match.index);
|
|
77
|
+
const after = glob.slice(match.index + match[0].length);
|
|
78
|
+
return match[1].split(",").flatMap((option) => expandBraces(`${before}${option}${after}`));
|
|
79
|
+
}
|
|
80
|
+
function globPattern(glob) {
|
|
81
|
+
const source = glob
|
|
82
|
+
.replace(/[.+^${}()|\\]/g, "\\$&")
|
|
83
|
+
.replaceAll("**", "\u0000")
|
|
84
|
+
.replaceAll("*", "[^/]*")
|
|
85
|
+
.replaceAll("?", "[^/]")
|
|
86
|
+
.replaceAll("[!", "[^")
|
|
87
|
+
.replaceAll("\u0000", ".*");
|
|
88
|
+
return new RegExp(`^${source}$`);
|
|
89
|
+
}
|
|
90
|
+
export function appliesToEvery(glob, extension) {
|
|
91
|
+
return !glob.includes("/") && expandBraces(glob).some((single) => globPattern(single).test(`Any${extension}`));
|
|
92
|
+
}
|
|
93
|
+
function editorConfig(text) {
|
|
94
|
+
let glob = null;
|
|
95
|
+
let root = false;
|
|
96
|
+
const widths = [];
|
|
97
|
+
for (const { text: line } of numberedLines(text)) {
|
|
98
|
+
const trimmed = line.trim();
|
|
99
|
+
const header = /^\[(.*)\]$/.exec(trimmed);
|
|
100
|
+
const property = /^([^=#;]+?)\s*=\s*(.*)$/.exec(trimmed);
|
|
101
|
+
const key = property?.[1]?.toLowerCase();
|
|
102
|
+
const value = property?.[2]?.trim() ?? "";
|
|
103
|
+
if (header)
|
|
104
|
+
glob = header[1] ?? "";
|
|
105
|
+
else if (glob === null && key === "root")
|
|
106
|
+
root = value.toLowerCase() === "true";
|
|
107
|
+
else if (glob !== null && key === "max_line_length")
|
|
108
|
+
widths.push({ glob, width: value });
|
|
109
|
+
}
|
|
110
|
+
return { root, widths };
|
|
111
|
+
}
|
|
112
|
+
function widthFor(configs, extension) {
|
|
113
|
+
let width;
|
|
114
|
+
for (const config of configs) {
|
|
115
|
+
if (config.root)
|
|
116
|
+
width = undefined;
|
|
117
|
+
for (const section of config.widths)
|
|
118
|
+
if (appliesToEvery(section.glob, extension))
|
|
119
|
+
width = section.width;
|
|
120
|
+
}
|
|
121
|
+
return width;
|
|
122
|
+
}
|
|
123
|
+
function lineLength(context) {
|
|
124
|
+
const chain = [...new Set([".editorconfig", joined(directoryOf(context, "dotnet"), ".editorconfig")])].filter((file) => present(context, file));
|
|
125
|
+
const nearest = chain.at(-1);
|
|
126
|
+
if (nearest === undefined)
|
|
127
|
+
return [];
|
|
128
|
+
const configs = chain.map((file) => editorConfig(context.read(file)));
|
|
129
|
+
const wrong = CSHARPIER_FILES.map((extension) => ({ extension, width: widthFor(configs, extension) })).filter(({ width }) => width !== LINE_LENGTH);
|
|
130
|
+
if (wrong.length === 0)
|
|
131
|
+
return [];
|
|
132
|
+
const now = wrong.map(({ extension, width }) => `*${extension}: ${width ?? "not set"}`).join(", ");
|
|
133
|
+
return [
|
|
134
|
+
{
|
|
135
|
+
target: nearest,
|
|
136
|
+
message: `max_line_length is not ${LINE_LENGTH} for every file CSharpier formats (${now}): set max_line_length = ${LINE_LENGTH} in a section such as [*.{cs,csproj,props,targets}], the width CSharpier reads from .editorconfig`,
|
|
137
|
+
},
|
|
138
|
+
];
|
|
139
|
+
}
|
|
140
|
+
function csharpierConfigs(context) {
|
|
141
|
+
return context.files
|
|
142
|
+
.filter((file) => CSHARPIER_CONFIGS.includes(baseName(file)))
|
|
143
|
+
.map((file) => ({
|
|
144
|
+
target: file,
|
|
145
|
+
message: `delete it: CSharpier takes a .csharpierrc over .editorconfig, and the width is max_line_length = ${LINE_LENGTH} in .editorconfig`,
|
|
146
|
+
}));
|
|
147
|
+
}
|
|
148
|
+
function centralPackages(context) {
|
|
149
|
+
const file = inProfileDirectory(context.directories, "dotnet", "Directory.Packages.props");
|
|
150
|
+
if (!present(context, file))
|
|
151
|
+
return [];
|
|
152
|
+
if (/<ManagePackageVersionsCentrally>\s*true\s*<\/ManagePackageVersionsCentrally>/i.test(context.read(file)))
|
|
153
|
+
return [];
|
|
154
|
+
return [
|
|
155
|
+
{
|
|
156
|
+
target: file,
|
|
157
|
+
message: "add <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally> to a PropertyGroup, so the versions in this file are the only ones and no project pins its own",
|
|
158
|
+
},
|
|
159
|
+
];
|
|
160
|
+
}
|
|
161
|
+
function extendsSuwgate(context, file, seen) {
|
|
162
|
+
if (seen.has(file) || !present(context, file))
|
|
163
|
+
return false;
|
|
164
|
+
seen.add(file);
|
|
165
|
+
const parsed = parseJsonc(context.read(file));
|
|
166
|
+
const value = isRecord(parsed) ? parsed["extends"] : undefined;
|
|
167
|
+
const bases = (Array.isArray(value) ? value : [value]).filter((base) => typeof base === "string");
|
|
168
|
+
return bases.some((base) => {
|
|
169
|
+
if (base.startsWith(`${SUWGATE}/tsconfig/`))
|
|
170
|
+
return true;
|
|
171
|
+
if (!base.startsWith("."))
|
|
172
|
+
return false;
|
|
173
|
+
const resolved = path.posix.normalize(path.posix.join(path.posix.dirname(file), base));
|
|
174
|
+
return extendsSuwgate(context, resolved.endsWith(".json") ? resolved : `${resolved}.json`, seen);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
function tsconfigs(context, directory) {
|
|
178
|
+
return context.files
|
|
179
|
+
.filter((file) => path.posix.dirname(file) === (directory === "" ? "." : directory))
|
|
180
|
+
.filter((file) => TSCONFIG.test(baseName(file)) && baseName(file) !== "tsconfig.build.json")
|
|
181
|
+
.filter((file) => !extendsSuwgate(context, file, new Set()))
|
|
182
|
+
.map((file) => ({
|
|
183
|
+
target: file,
|
|
184
|
+
message: `extends no ${SUWGATE}/tsconfig preset: set "extends": "${SUWGATE}/tsconfig/browser" (app code) or "${SUWGATE}/tsconfig/node" (configs, scripts, Node tests), directly or through another tsconfig of the repository that does`,
|
|
185
|
+
}));
|
|
186
|
+
}
|
|
187
|
+
function importing(context, file, module, fix) {
|
|
188
|
+
if (!present(context, file) || imports(context.read(file), module))
|
|
189
|
+
return [];
|
|
190
|
+
return [{ target: file, message: `does not import ${module}: ${fix}` }];
|
|
191
|
+
}
|
|
192
|
+
function prettier(context, directory) {
|
|
193
|
+
const json = joined(directory, ".prettierrc.json");
|
|
194
|
+
const preset = `${SUWGATE}/prettier`;
|
|
195
|
+
const findings = importing(context, joined(directory, "prettier.config.js"), preset, `spread the preset: import preset from "${preset}"; export default { ...preset, plugins: [...] }`);
|
|
196
|
+
if (present(context, json) && parseJson(context.read(json)) !== preset) {
|
|
197
|
+
findings.push({
|
|
198
|
+
target: json,
|
|
199
|
+
message: `does not use the preset: make the whole file "${preset}" (with a plugin, spread the preset in prettier.config.js instead)`,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
return findings;
|
|
203
|
+
}
|
|
204
|
+
function nodeTools(context, directory) {
|
|
205
|
+
const eslint = ESLINT_CONFIGS.map((file) => joined(directory, file)).find((file) => present(context, file));
|
|
206
|
+
const vitest = VITEST_CONFIGS.map((file) => joined(directory, file)).filter((file) => present(context, file));
|
|
207
|
+
return [
|
|
208
|
+
...tsconfigs(context, directory),
|
|
209
|
+
...(eslint === undefined
|
|
210
|
+
? []
|
|
211
|
+
: importing(context, eslint, `${SUWGATE}/eslint`, `build the config from strict() or app() of ${SUWGATE}/eslint`)),
|
|
212
|
+
...prettier(context, directory),
|
|
213
|
+
...importing(context, joined(directory, "knip.config.ts"), `${SUWGATE}/knip`, `export { default } from "${SUWGATE}/knip", or build it with knip({ entry: [...] }) from there`),
|
|
214
|
+
...vitest.flatMap((file) => importing(context, file, `${SUWGATE}/vitest`, `build the projects with unitTests() or storyTests() of ${SUWGATE}/vitest, the projects unit and stories the steps run`)),
|
|
215
|
+
];
|
|
216
|
+
}
|
|
217
|
+
function playwright(context) {
|
|
218
|
+
return PLAYWRIGHT_CONFIGS.filter(([profile]) => context.profiles.includes(profile)).flatMap(([profile, config]) => importing(context, joined(directoryOf(context, profile), config), `${SUWGATE}/playwright`, `build it with defineConfig(e2eTests({ ... })) or defineConfig(visualTests()) of ${SUWGATE}/playwright`));
|
|
219
|
+
}
|
|
220
|
+
function installDirectories(context) {
|
|
221
|
+
const candidates = new Set(["package.json", ...nodeDirectories(context).map((directory) => joined(directory, "package.json"))]);
|
|
222
|
+
const installs = new Map();
|
|
223
|
+
for (const dependency of npmDependencies(context)) {
|
|
224
|
+
if (dependency.name !== SUWGATE || !candidates.has(dependency.manifest))
|
|
225
|
+
continue;
|
|
226
|
+
const findings = EXACT_VERSION.test(dependency.version)
|
|
227
|
+
? []
|
|
228
|
+
: [
|
|
229
|
+
{
|
|
230
|
+
target: dependency.manifest,
|
|
231
|
+
line: dependency.line,
|
|
232
|
+
message: `${SUWGATE} is "${dependency.version}": pin it to an exact version, such as "0.1.2" (no ^, ~, range or tag), so the gate changes only when the repository updates it`,
|
|
233
|
+
},
|
|
234
|
+
];
|
|
235
|
+
installs.set(path.posix.dirname(dependency.manifest).replace(/^\.$/, ""), findings);
|
|
236
|
+
}
|
|
237
|
+
return installs;
|
|
238
|
+
}
|
|
239
|
+
function releaseAge(context, directories) {
|
|
240
|
+
return [...new Set(directories)]
|
|
241
|
+
.map((directory) => joined(directory, "pnpm-workspace.yaml"))
|
|
242
|
+
.filter((file) => present(context, file))
|
|
243
|
+
.flatMap((file) => {
|
|
244
|
+
const text = context.read(file);
|
|
245
|
+
let parsed;
|
|
246
|
+
try {
|
|
247
|
+
parsed = parseYaml(text);
|
|
248
|
+
}
|
|
249
|
+
catch {
|
|
250
|
+
return [{ target: file, message: "not valid YAML: fix the file so pnpm can read it" }];
|
|
251
|
+
}
|
|
252
|
+
if (!isRecord(parsed) || !("minimumReleaseAge" in parsed))
|
|
253
|
+
return [];
|
|
254
|
+
const age = parsed["minimumReleaseAge"];
|
|
255
|
+
if (typeof age === "number" && age > 0)
|
|
256
|
+
return [];
|
|
257
|
+
return [
|
|
258
|
+
{
|
|
259
|
+
target: file,
|
|
260
|
+
line: lineAt(text, Math.max(0, text.indexOf("minimumReleaseAge:"))),
|
|
261
|
+
message: `minimumReleaseAge is ${JSON.stringify(age)}, so pnpm installs a release minutes after it is published: delete the line (pnpm waits 1440 minutes by default) or set more minutes, and put a package needed sooner into minimumReleaseAgeExclude`,
|
|
262
|
+
},
|
|
263
|
+
];
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
function schemaMapped(schemas, directories) {
|
|
267
|
+
const accepted = new Set(directories.flatMap((directory) => [joined(directory, SCHEMA_PATH), `./${joined(directory, SCHEMA_PATH)}`]));
|
|
268
|
+
return Object.entries(schemas).some(([schema, targets]) => accepted.has(schema) && (Array.isArray(targets) ? targets : [targets]).includes("suwgate.yml"));
|
|
269
|
+
}
|
|
270
|
+
function yamlSchemas(context, installs) {
|
|
271
|
+
const file = ".vscode/settings.json";
|
|
272
|
+
if (!present(context, file))
|
|
273
|
+
return [];
|
|
274
|
+
const settings = parseJson(context.read(file));
|
|
275
|
+
if (!isRecord(settings))
|
|
276
|
+
return [];
|
|
277
|
+
const schemas = isRecord(settings["yaml.schemas"]) ? settings["yaml.schemas"] : {};
|
|
278
|
+
const profileDirectories = Object.values(context.directories).map((directory) => directory.replace(/\/+$/, ""));
|
|
279
|
+
if (schemaMapped(schemas, ["", ...installs, ...profileDirectories]))
|
|
280
|
+
return [];
|
|
281
|
+
const schema = `./${joined(installs[0] ?? "", SCHEMA_PATH)}`;
|
|
282
|
+
return [
|
|
283
|
+
{
|
|
284
|
+
target: file,
|
|
285
|
+
message: `yaml.schemas does not map suwgate's schema to suwgate.yml: add "yaml.schemas": { "${schema}": "suwgate.yml" }, so VS Code checks suwgate.yml as you type`,
|
|
286
|
+
},
|
|
287
|
+
];
|
|
288
|
+
}
|
|
289
|
+
function gateWorkflow(context) {
|
|
290
|
+
const workflows = context.files.filter((file) => WORKFLOW.test(file));
|
|
291
|
+
if (workflows.length === 0)
|
|
292
|
+
return [];
|
|
293
|
+
const calls = workflows.flatMap((file) => numberedLines(context.read(file)).flatMap(({ line, text }) => {
|
|
294
|
+
const ref = GATE_CALL.exec(text)?.[1];
|
|
295
|
+
return ref === undefined ? [] : [{ file, line, ref }];
|
|
296
|
+
}));
|
|
297
|
+
if (calls.length === 0) {
|
|
298
|
+
return [
|
|
299
|
+
{
|
|
300
|
+
target: ".github/workflows",
|
|
301
|
+
message: `no job calls suwgate's gate: add a job with ${GATE_USES}, so CI runs the same gate as suwgate check`,
|
|
302
|
+
},
|
|
303
|
+
];
|
|
304
|
+
}
|
|
305
|
+
return calls
|
|
306
|
+
.filter(({ ref }) => !FULL_SHA.test(ref))
|
|
307
|
+
.map(({ file, line, ref }) => ({
|
|
308
|
+
target: file,
|
|
309
|
+
line,
|
|
310
|
+
message: `the gate is called at ${ref}, which can move: pin it by the commit, ${GATE_USES}`,
|
|
311
|
+
}));
|
|
312
|
+
}
|
|
313
|
+
export const configContents = {
|
|
314
|
+
id: "config-contents",
|
|
315
|
+
description: "The config files suwgate relies on say what it needs: the SDK and test runner, the C# line width, the tool presets, an exact suwgate version, pnpm's release age, the schema in VS Code and the pinned gate workflow",
|
|
316
|
+
profiles: "every",
|
|
317
|
+
check(context) {
|
|
318
|
+
const dotnet = context.profiles.includes("dotnet");
|
|
319
|
+
const installs = installDirectories(context);
|
|
320
|
+
return [
|
|
321
|
+
...(dotnet ? [...globalJson(context), ...lineLength(context), ...csharpierConfigs(context), ...centralPackages(context)] : []),
|
|
322
|
+
...nodeDirectories(context).flatMap((directory) => nodeTools(context, directory)),
|
|
323
|
+
...playwright(context),
|
|
324
|
+
...[...installs.values()].flat(),
|
|
325
|
+
...releaseAge(context, [...nodeDirectories(context), ...installs.keys()]),
|
|
326
|
+
...yamlSchemas(context, [...installs.keys()]),
|
|
327
|
+
...gateWorkflow(context),
|
|
328
|
+
];
|
|
329
|
+
},
|
|
330
|
+
};
|
|
@@ -4,8 +4,24 @@ const MENTION = /`([\w.\-/@]+)`|\]\(([\w.\-/]+)(?:#[\w-]*)?\)/g;
|
|
|
4
4
|
const FILE_NAME = /[\w-]\.(cs|csproj|css|json|md|props|sh|slnx|sql|ts|tsx|txt|yaml|yml)$/;
|
|
5
5
|
const NOT_IN_THE_REPOSITORY = ["CLAUDE.local.md", "dist/"];
|
|
6
6
|
const NOT_READ = ["docs/visual/**", ".changeset/**"];
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
export const DOTNET_GUARD_IDS = [
|
|
8
|
+
"architecture/build-settings",
|
|
9
|
+
"architecture/endpoints",
|
|
10
|
+
"architecture/every-project-guarded",
|
|
11
|
+
"architecture/forbidden-type-names",
|
|
12
|
+
"architecture/interfaces-have-two-implementations",
|
|
13
|
+
"architecture/layers",
|
|
14
|
+
"architecture/no-escape-hatches",
|
|
15
|
+
"architecture/no-fixture-in-field",
|
|
16
|
+
"architecture/no-unused-types",
|
|
17
|
+
"architecture/nothing-obsolete",
|
|
18
|
+
"architecture/one-type-per-file",
|
|
19
|
+
"architecture/project-references",
|
|
20
|
+
"architecture/unique-type-names",
|
|
21
|
+
"database/migration-script-names",
|
|
22
|
+
];
|
|
23
|
+
export function isPath(mention) {
|
|
24
|
+
return !/^(https?:|\/|@|~)/.test(mention) && (mention.includes("/") || FILE_NAME.test(mention)) && !DOTNET_GUARD_IDS.includes(mention);
|
|
9
25
|
}
|
|
10
26
|
function existsLoosely(mention, files) {
|
|
11
27
|
const name = mention.replace(/^(\.\.?\/)+/, "");
|
|
@@ -34,21 +50,29 @@ function stale(document, text, files, ignored) {
|
|
|
34
50
|
{
|
|
35
51
|
target: document,
|
|
36
52
|
line: lineAt(text, match.index),
|
|
37
|
-
message: `${mention} is not a path in this repository: fix the path, or say what the code does instead of where it is (a name meant to be outside the repository, or a pattern of names, goes into settings.docs-paths.ignore
|
|
53
|
+
message: `${mention} is not a path in this repository: fix the path, or say what the code does instead of where it is (a name meant to be outside the repository, or a pattern of names, goes into settings.docs-paths.ignore, a folder there ends with /; a whole document that is not about this repository goes into settings.docs-paths.skip as a glob)`,
|
|
38
54
|
},
|
|
39
55
|
];
|
|
40
56
|
});
|
|
41
57
|
}
|
|
42
58
|
export const docsPaths = {
|
|
43
59
|
id: "docs-paths",
|
|
44
|
-
description: "Every file and folder the Markdown docs name, in backticks or as a link, exists in the repository",
|
|
60
|
+
description: "Every file and folder the Markdown docs name, in backticks or as a link, exists in the repository (a .NET guard id is not a path)",
|
|
45
61
|
profiles: "every",
|
|
46
|
-
settingsSchema: {
|
|
62
|
+
settingsSchema: {
|
|
63
|
+
type: "object",
|
|
64
|
+
additionalProperties: false,
|
|
65
|
+
properties: {
|
|
66
|
+
ignore: { ...stringList, description: "Names the docs may mention that are not paths here; a folder ends with /." },
|
|
67
|
+
skip: { ...stringList, description: "Globs of documents not read at all, such as docs/notes/**." },
|
|
68
|
+
},
|
|
69
|
+
},
|
|
47
70
|
check(context) {
|
|
48
71
|
const settings = (context.settings ?? {});
|
|
49
72
|
const ignored = [...NOT_IN_THE_REPOSITORY, ...(settings.ignore ?? [])];
|
|
73
|
+
const notRead = [...NOT_READ, ...(settings.skip ?? [])];
|
|
50
74
|
return context.files
|
|
51
|
-
.filter((file) => file.endsWith(".md") && baseName(file) !== "CHANGELOG.md" && !matchesAny(file,
|
|
75
|
+
.filter((file) => file.endsWith(".md") && baseName(file) !== "CHANGELOG.md" && !matchesAny(file, notRead))
|
|
52
76
|
.flatMap((document) => stale(document, context.read(document), context.files, ignored));
|
|
53
77
|
},
|
|
54
78
|
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { PROFILES } from "../../gate/contract.js";
|
|
2
2
|
import { matchesAny, stringList } from "./text.js";
|
|
3
3
|
const EVERY_REPOSITORY = [
|
|
4
|
-
"base",
|
|
5
4
|
"common",
|
|
6
5
|
"core",
|
|
7
6
|
"helper",
|
|
@@ -22,6 +21,7 @@ export const FORBIDDEN_BY_PROFILE = {
|
|
|
22
21
|
dotnet: ["application", "controllers", "domain", "dtos", "infrastructure", "interfaces", "models", "repositories", "services"],
|
|
23
22
|
database: [],
|
|
24
23
|
};
|
|
24
|
+
const FOLDERS_ONLY = ["base"];
|
|
25
25
|
const NOT_READ = ["docs/visual/**"];
|
|
26
26
|
function words(name) {
|
|
27
27
|
return name
|
|
@@ -51,7 +51,10 @@ export const forbiddenNames = {
|
|
|
51
51
|
check(context) {
|
|
52
52
|
const settings = (context.settings ?? {});
|
|
53
53
|
const vague = [...EVERY_REPOSITORY, ...(settings.words ?? []).map((word) => word.toLowerCase())];
|
|
54
|
-
const byKind =
|
|
54
|
+
const byKind = [
|
|
55
|
+
...FOLDERS_ONLY,
|
|
56
|
+
...PROFILES.filter((profile) => context.profiles.includes(profile)).flatMap((profile) => FORBIDDEN_BY_PROFILE[profile]),
|
|
57
|
+
];
|
|
55
58
|
const ignored = [...NOT_READ, ...(settings.ignore ?? [])];
|
|
56
59
|
return namedPaths(context.files.filter((file) => !matchesAny(file, ignored))).flatMap(({ named, isFolderOrProject }) => {
|
|
57
60
|
const name = named.split("/").at(-1) ?? named;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { agentsFile } from "./agentsFile.js";
|
|
2
2
|
import { bannedNpmPackages } from "./bannedNpmPackages.js";
|
|
3
3
|
import { composePorts } from "./composePorts.js";
|
|
4
|
+
import { configContents } from "./configContents.js";
|
|
4
5
|
import { dependencyDirection } from "./dependencyDirection.js";
|
|
5
6
|
import { docsPaths } from "./docsPaths.js";
|
|
6
7
|
import { forbiddenNames } from "./forbiddenNames.js";
|
|
@@ -15,6 +16,7 @@ import { scriptsHelp } from "./scriptsHelp.js";
|
|
|
15
16
|
import { vsCodeSettings } from "./vsCodeSettings.js";
|
|
16
17
|
export const repositoryGuards = [
|
|
17
18
|
requiredFiles,
|
|
19
|
+
configContents,
|
|
18
20
|
agentsFile,
|
|
19
21
|
docsPaths,
|
|
20
22
|
forbiddenNames,
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { inProfileDirectory, numberedLines, stringList } from "./text.js";
|
|
2
2
|
const RAW_COLOR = /#[0-9a-fA-F]{3,8}\b|\b(rgb|rgba|hsl|hsla|oklch|oklab)\(|\[#/;
|
|
3
3
|
const CODE_FILE = /\.(ts|tsx|js|jsx)$/;
|
|
4
|
+
const TEST_FILE = /\.(test|spec|e2e)\.(ts|tsx|js|jsx)$/;
|
|
4
5
|
export const noRawColors = {
|
|
5
6
|
id: "no-raw-colors",
|
|
6
|
-
description: "Components use the theme's tokens, never a colour value of their own; it reads the src/ folder of a web app, and the folders settings name",
|
|
7
|
+
description: "Components use the theme's tokens, never a colour value of their own; it reads the src/ folder of a web app, and the folders settings name, but not the tests",
|
|
7
8
|
profiles: ["web", "library"],
|
|
8
9
|
settingsSchema: {
|
|
9
10
|
type: "object",
|
|
@@ -17,7 +18,7 @@ export const noRawColors = {
|
|
|
17
18
|
const defaults = context.profiles.includes("web") ? [inProfileDirectory(context.directories, "web", "src/")] : [];
|
|
18
19
|
const folders = (settings.folders ?? defaults).map((folder) => `${folder.replace(/\/+$/, "")}/`);
|
|
19
20
|
return context.files
|
|
20
|
-
.filter((file) => CODE_FILE.test(file) && folders.some((folder) => file.startsWith(folder)))
|
|
21
|
+
.filter((file) => CODE_FILE.test(file) && !TEST_FILE.test(file) && folders.some((folder) => file.startsWith(folder)))
|
|
21
22
|
.flatMap((file) => numberedLines(context.read(file))
|
|
22
23
|
.filter(({ text }) => RAW_COLOR.test(text))
|
|
23
24
|
.map(({ line }) => ({
|
|
@@ -5,8 +5,26 @@ import { numberedLines } from "./text.js";
|
|
|
5
5
|
const MAP = "docs/architecture.md";
|
|
6
6
|
export const MAX_MAP_LINE_LENGTH = 300;
|
|
7
7
|
const MAP_ENTRY = /^- `([^`]+)`/;
|
|
8
|
+
const MAP_HEADING = "## The map";
|
|
9
|
+
function mapSection(text) {
|
|
10
|
+
const lines = numberedLines(text);
|
|
11
|
+
const start = lines.findIndex(({ text: line }) => line.trim() === MAP_HEADING);
|
|
12
|
+
if (start === -1)
|
|
13
|
+
return null;
|
|
14
|
+
const end = lines.findIndex(({ text: line }, index) => index > start && /^#{1,2} /.test(line));
|
|
15
|
+
return lines.slice(start + 1, end === -1 ? undefined : end);
|
|
16
|
+
}
|
|
8
17
|
function mapFindings(context) {
|
|
9
|
-
const
|
|
18
|
+
const section = mapSection(context.read(MAP));
|
|
19
|
+
if (section === null) {
|
|
20
|
+
return [
|
|
21
|
+
{
|
|
22
|
+
target: MAP,
|
|
23
|
+
message: `no "${MAP_HEADING}" section: add it, with one line per top-level folder (- \`folder/\` — what it holds)`,
|
|
24
|
+
},
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
const entries = section.filter(({ text }) => MAP_ENTRY.test(text));
|
|
10
28
|
const folders = new Set(context.files.filter((file) => file.includes("/")).map((file) => file.split("/")[0] ?? ""));
|
|
11
29
|
const described = new Map(entries.map(({ line, text }) => [(MAP_ENTRY.exec(text)?.[1] ?? "").split("/")[0] ?? "", line]));
|
|
12
30
|
const missing = [...folders]
|
|
@@ -63,7 +81,7 @@ function notExecutable(root) {
|
|
|
63
81
|
}
|
|
64
82
|
export const repositoryLayout = {
|
|
65
83
|
id: "repository-layout",
|
|
66
|
-
description: "Every top-level folder has a short line in the map of docs/architecture.md, no two files differ only in letter case, and every shell script is executable in git",
|
|
84
|
+
description: "Every top-level folder has a short line in the map (the section ## The map) of docs/architecture.md, no two files differ only in letter case, and every shell script is executable in git",
|
|
67
85
|
profiles: "every",
|
|
68
86
|
check(context) {
|
|
69
87
|
return [
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import path from "node:path";
|
|
1
2
|
import { PROFILES } from "../../gate/contract.js";
|
|
2
|
-
import { inProfileDirectory, stringList } from "./text.js";
|
|
3
|
+
import { baseName, inProfileDirectory, stringList } from "./text.js";
|
|
3
4
|
export const EVERY_REPOSITORY = {
|
|
4
5
|
"suwgate.yml": "the repository's gate: its profiles, the steps it adds or skips, and the exceptions with their reasons",
|
|
5
6
|
"README.md": "what the project is and how to use it, for people",
|
|
@@ -23,7 +24,7 @@ export const REQUIRED_BY_PROFILE = {
|
|
|
23
24
|
"pnpm-workspace.yaml": "pnpm's settings, such as the minimum age of a new release",
|
|
24
25
|
"tsconfig.json": "the strict TypeScript options the typecheck step uses",
|
|
25
26
|
"eslint.config.js": "the lint rules, including no comments and the feature boundaries",
|
|
26
|
-
".prettierrc.json": "the formatting the format step checks",
|
|
27
|
+
".prettierrc.json": "the formatting the format step checks (prettier.config.js instead, when a plugin needs the preset spread)",
|
|
27
28
|
"knip.config.ts": "knip's config, one line that extends @maniumek/suwgate/knip, so dead code is found",
|
|
28
29
|
},
|
|
29
30
|
library: {
|
|
@@ -37,6 +38,7 @@ export const REQUIRED_BY_PROFILE = {
|
|
|
37
38
|
"nuget.config": "the package sources, so a restore never reaches an unexpected feed",
|
|
38
39
|
"Directory.Build.props": "the build settings of every project (warnings as errors, analyzers, nullable, lock files)",
|
|
39
40
|
"Directory.Packages.props": "the one place that pins the version of every NuGet package",
|
|
41
|
+
"Directory.Build.rsp": "the MSBuild switches of every build, -nodeReuse:false among them, so no idle MSBuild worker stays behind",
|
|
40
42
|
".config/dotnet-tools.json": "the .NET tools at pinned versions, such as CSharpier for the format step",
|
|
41
43
|
"layers.json": "the layers of the server and which project may reference which, read by Suwgate.Architecture",
|
|
42
44
|
},
|
|
@@ -44,6 +46,14 @@ export const REQUIRED_BY_PROFILE = {
|
|
|
44
46
|
"compose.yaml": "the local PostgreSQL the server and its tests run against",
|
|
45
47
|
},
|
|
46
48
|
};
|
|
49
|
+
const ALTERNATIVES = {
|
|
50
|
+
".prettierrc.json": ["prettier.config.js"],
|
|
51
|
+
};
|
|
52
|
+
function isPresent(file, present) {
|
|
53
|
+
const directory = file.slice(0, file.lastIndexOf("/") + 1);
|
|
54
|
+
const name = file.slice(directory.length);
|
|
55
|
+
return [name, ...(ALTERNATIVES[name] ?? [])].some((candidate) => present.has(directory + candidate));
|
|
56
|
+
}
|
|
47
57
|
function required(context, settings) {
|
|
48
58
|
const files = new Map();
|
|
49
59
|
for (const [file, purpose] of Object.entries(EVERY_REPOSITORY))
|
|
@@ -61,18 +71,45 @@ function required(context, settings) {
|
|
|
61
71
|
}
|
|
62
72
|
return files;
|
|
63
73
|
}
|
|
74
|
+
function solutionFindings(context) {
|
|
75
|
+
if (!context.profiles.includes("dotnet"))
|
|
76
|
+
return [];
|
|
77
|
+
const directory = (context.directories.dotnet ?? "").replace(/\/+$/, "");
|
|
78
|
+
const inDirectory = context.files.filter((file) => path.posix.dirname(file) === (directory === "" ? "." : directory));
|
|
79
|
+
const solutions = inDirectory.filter((file) => file.endsWith(".slnx"));
|
|
80
|
+
const target = inProfileDirectory(context.directories, "dotnet", "*.slnx");
|
|
81
|
+
if (solutions.length === 1)
|
|
82
|
+
return [];
|
|
83
|
+
if (solutions.length === 0) {
|
|
84
|
+
return [
|
|
85
|
+
{
|
|
86
|
+
target,
|
|
87
|
+
message: "missing: the one solution file that dotnet build and dotnet test find in the dotnet profile's directory. Add it with dotnet new sln --format slnx (an old .sln: dotnet sln migrate, then delete the .sln), or add an exception with the reason it does not apply",
|
|
88
|
+
},
|
|
89
|
+
];
|
|
90
|
+
}
|
|
91
|
+
return [
|
|
92
|
+
{
|
|
93
|
+
target,
|
|
94
|
+
message: `${solutions.length} solution files (${solutions.map(baseName).join(", ")}): keep one, because dotnet build and dotnet test refuse to choose between them`,
|
|
95
|
+
},
|
|
96
|
+
];
|
|
97
|
+
}
|
|
64
98
|
export const requiredFiles = {
|
|
65
99
|
id: "required-files",
|
|
66
|
-
description: "Every file a repository of these profiles needs is there (the gate, the agent rules, the editor and git settings, the hooks, each profile's tool configs)",
|
|
100
|
+
description: "Every file a repository of these profiles needs is there (the gate, the agent rules, the editor and git settings, the hooks, each profile's tool configs, one .slnx for .NET)",
|
|
67
101
|
profiles: "every",
|
|
68
102
|
settingsSchema: { type: "object", additionalProperties: false, properties: { files: stringList } },
|
|
69
103
|
check(context) {
|
|
70
104
|
const present = new Set(context.files);
|
|
71
|
-
return [
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
105
|
+
return [
|
|
106
|
+
...[...required(context, (context.settings ?? {}))]
|
|
107
|
+
.filter(([file]) => !isPresent(file, present))
|
|
108
|
+
.map(([file, purpose]) => ({
|
|
109
|
+
target: file,
|
|
110
|
+
message: `missing: ${purpose}, or add an exception with the reason it does not apply`,
|
|
111
|
+
})),
|
|
112
|
+
...solutionFindings(context),
|
|
113
|
+
];
|
|
77
114
|
},
|
|
78
115
|
};
|
|
@@ -31,3 +31,41 @@ export function isRecord(value) {
|
|
|
31
31
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
32
32
|
}
|
|
33
33
|
export const stringList = { type: "array", uniqueItems: true, items: { type: "string", minLength: 1 } };
|
|
34
|
+
function withoutComments(text) {
|
|
35
|
+
let kept = "";
|
|
36
|
+
let index = 0;
|
|
37
|
+
let inString = false;
|
|
38
|
+
while (index < text.length) {
|
|
39
|
+
const character = text.charAt(index);
|
|
40
|
+
const next = text.charAt(index + 1);
|
|
41
|
+
if (inString) {
|
|
42
|
+
kept += character;
|
|
43
|
+
if (character === "\\") {
|
|
44
|
+
kept += next;
|
|
45
|
+
index += 2;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (character === '"')
|
|
49
|
+
inString = false;
|
|
50
|
+
index++;
|
|
51
|
+
}
|
|
52
|
+
else if (character === "/" && next === "/") {
|
|
53
|
+
while (index < text.length && text.charAt(index) !== "\n")
|
|
54
|
+
index++;
|
|
55
|
+
}
|
|
56
|
+
else if (character === "/" && next === "*") {
|
|
57
|
+
const end = text.indexOf("*/", index + 2);
|
|
58
|
+
index = end === -1 ? text.length : end + 2;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
if (character === '"')
|
|
62
|
+
inString = true;
|
|
63
|
+
kept += character;
|
|
64
|
+
index++;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return kept;
|
|
68
|
+
}
|
|
69
|
+
export function parseJsonc(text) {
|
|
70
|
+
return parseJson(withoutComments(text).replace(/,(\s*[}\]])/g, "$1"));
|
|
71
|
+
}
|
|
@@ -21,7 +21,7 @@ function settingsFindings(text) {
|
|
|
21
21
|
.filter(isStyleKey)
|
|
22
22
|
.map((key) => ({
|
|
23
23
|
target: SETTINGS,
|
|
24
|
-
message: `${key} is a style rule only VS Code reads: move it to .editorconfig
|
|
24
|
+
message: `${key} is a style rule only VS Code reads: move it to .editorconfig (C# width: max_line_length) or the Prettier config so every editor and the gate use it`,
|
|
25
25
|
}));
|
|
26
26
|
}
|
|
27
27
|
function extensionFindings(text) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Step, StepContext } from "../gate/contract.ts";
|
|
2
|
+
export declare const API_TYPES = "src/api/openapi.d.ts";
|
|
2
3
|
export declare const API_CONTRACT = "api-contract";
|
|
3
4
|
export declare function apiContract(context: StepContext): string | null;
|
|
4
5
|
export declare function contractPins(context: StepContext): string | null;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { DOTNET_TEST } from "./dotnet.js";
|
|
3
|
+
import { DOTNET_TEST, NO_IDLE_BUILD_PROCESSES } from "./dotnet.js";
|
|
4
4
|
import { PNPM_INSTALL } from "./node.js";
|
|
5
5
|
import { has, quoted, read, script, tracked } from "./shell.js";
|
|
6
6
|
const CONTRACT = "contract/openapi.json";
|
|
7
7
|
const CONTRACT_VERSION = "contract/package.json";
|
|
8
|
-
const
|
|
8
|
+
export const API_TYPES = "src/api/openapi.d.ts";
|
|
9
9
|
export const API_CONTRACT = "api-contract";
|
|
10
10
|
const GENERATOR = "Microsoft.Extensions.ApiDescription.Server";
|
|
11
11
|
const TAGGED = ["*.cs", "*.test.ts", "*.test.tsx", "*.e2e.ts"];
|
|
@@ -19,7 +19,7 @@ function webApp(context) {
|
|
|
19
19
|
if (!context.profiles.includes("web"))
|
|
20
20
|
return null;
|
|
21
21
|
const directory = path.join(context.root, context.directories.web ?? "");
|
|
22
|
-
return existsSync(path.join(directory,
|
|
22
|
+
return existsSync(path.join(directory, API_TYPES)) ? directory : null;
|
|
23
23
|
}
|
|
24
24
|
export function apiContract(context) {
|
|
25
25
|
if (!has(context, CONTRACT))
|
|
@@ -33,8 +33,9 @@ export function apiContract(context) {
|
|
|
33
33
|
const name = path.basename(server, ".csproj");
|
|
34
34
|
const document = `"$work"/${quoted(`${name}.json`)}`;
|
|
35
35
|
const web = webApp(context);
|
|
36
|
-
const types = web === null ? "" : path.join(web,
|
|
36
|
+
const types = web === null ? "" : path.join(web, API_TYPES);
|
|
37
37
|
return script([
|
|
38
|
+
NO_IDLE_BUILD_PROCESSES,
|
|
38
39
|
'work="$(mktemp -d)"',
|
|
39
40
|
"trap 'rm -rf \"$work\"' EXIT",
|
|
40
41
|
`rm -f ${quoted(path.join(path.dirname(server), "obj", `${name}.OpenApiFiles.cache`))}`,
|
|
@@ -99,7 +100,7 @@ export function contractPins(context) {
|
|
|
99
100
|
export const contractSteps = [
|
|
100
101
|
{
|
|
101
102
|
id: API_CONTRACT,
|
|
102
|
-
title: `the API contract and the web app's types up to date with the server (${CONTRACT}, ${
|
|
103
|
+
title: `the API contract and the web app's types up to date with the server (${CONTRACT}, ${API_TYPES}, openapi-typescript)`,
|
|
103
104
|
profile: "dotnet",
|
|
104
105
|
needs: ["dotnet"],
|
|
105
106
|
after: [DOTNET_TEST, PNPM_INSTALL],
|
|
@@ -2,7 +2,7 @@ import { has, script } from "./shell.js";
|
|
|
2
2
|
export const DATABASE_UP = "database-up";
|
|
3
3
|
const COMPOSE_FILES = ["compose.yaml", "compose.yml", "docker-compose.yaml", "docker-compose.yml"];
|
|
4
4
|
const UP = script([
|
|
5
|
-
'if [ -n "${CI:-}" ]; then echo "CI: the workflow
|
|
5
|
+
'if [ -n "${CI:-}" ]; then echo "CI: the workflow starts the database (database: true of the reusable gate workflow)"; exit 0; fi',
|
|
6
6
|
"docker compose --profile db up -d --wait db >/dev/null 2>&1 || {",
|
|
7
7
|
' echo "postgres did not start — see: docker compose --profile db logs db" >&2',
|
|
8
8
|
" exit 1",
|
|
@@ -14,7 +14,7 @@ export function composeFile(context) {
|
|
|
14
14
|
export const databaseSteps = [
|
|
15
15
|
{
|
|
16
16
|
id: DATABASE_UP,
|
|
17
|
-
title: "the local database for the tests (docker compose --profile db up --wait db; CI
|
|
17
|
+
title: "the local database for the tests (docker compose --profile db up --wait db; in CI the workflow starts it)",
|
|
18
18
|
profile: "database",
|
|
19
19
|
needs: ["docker"],
|
|
20
20
|
run: (context) => (composeFile(context) ? UP : null),
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { Step, StepContext } from "../gate/contract.ts";
|
|
2
|
+
export declare const NO_IDLE_BUILD_PROCESSES = "export MSBUILDDISABLENODEREUSE=1 DOTNET_CLI_USE_MSBUILD_SERVER=0";
|
|
2
3
|
export declare const DOTNET_BUILD = "dotnet-build";
|
|
3
4
|
export declare const DOTNET_TEST = "dotnet-test";
|
|
5
|
+
export declare function inCheckoutEnv(context: StepContext, command: string): string;
|
|
4
6
|
export declare function guardTests(context: StepContext): string | null;
|
|
5
7
|
export declare const dotnetSteps: readonly Step[];
|
package/dist/profiles/dotnet.js
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import { DATABASE_UP } from "./database.js";
|
|
2
|
-
import { changedIn, quoted, read, tracked, withChanged } from "./shell.js";
|
|
2
|
+
import { CHECKOUT_ENV, changedIn, hasDevSection, quoted, read, tracked, withChanged } from "./shell.js";
|
|
3
3
|
const DOTNET_INPUT = /\.(cs|csproj|props|targets|slnx|sln|rsp)$|(^|\/)(\.editorconfig|BannedSymbols\.txt|global\.json|packages\.lock\.json|nuget\.config)$/;
|
|
4
|
-
const GUARD_PACKAGE = /<(PackageReference|ProjectReference)\b[^>]*Include="[^"]*Suwgate\.(Architecture|Database)\b/;
|
|
4
|
+
const GUARD_PACKAGE = /<(PackageReference|ProjectReference)\b[^>]*(?:Include|Update)="[^"]*Suwgate\.(Architecture|Database)\b/;
|
|
5
5
|
const TEST_PROJECT = /<PackageReference\b[^>]*Include="xunit\.v3"|<IsTestProject>true<\/IsTestProject>/;
|
|
6
|
-
const
|
|
6
|
+
export const NO_IDLE_BUILD_PROCESSES = "export MSBUILDDISABLENODEREUSE=1 DOTNET_CLI_USE_MSBUILD_SERVER=0";
|
|
7
|
+
const BUILD = `${NO_IDLE_BUILD_PROCESSES} && dotnet build --nologo -v quiet`;
|
|
7
8
|
const TEST = "dotnet test --no-build --no-progress";
|
|
9
|
+
const FORMAT = `${NO_IDLE_BUILD_PROCESSES} && dotnet tool restore >/dev/null`;
|
|
8
10
|
export const DOTNET_BUILD = "dotnet-build";
|
|
9
11
|
export const DOTNET_TEST = "dotnet-test";
|
|
10
12
|
function dotnetChanged(context) {
|
|
11
13
|
return changedIn(context, DOTNET_INPUT).length > 0;
|
|
12
14
|
}
|
|
15
|
+
export function inCheckoutEnv(context, command) {
|
|
16
|
+
if (!hasDevSection(context))
|
|
17
|
+
return `${NO_IDLE_BUILD_PROCESSES} && ${command}`;
|
|
18
|
+
return [...CHECKOUT_ENV, command].join(" && ");
|
|
19
|
+
}
|
|
13
20
|
export function guardTests(context) {
|
|
14
21
|
if (!dotnetChanged(context))
|
|
15
22
|
return null;
|
|
@@ -36,21 +43,24 @@ export const dotnetSteps = [
|
|
|
36
43
|
title: "format C# (csharpier check)",
|
|
37
44
|
profile: "dotnet",
|
|
38
45
|
needs: ["dotnet"],
|
|
39
|
-
run:
|
|
46
|
+
run: `${FORMAT} && dotnet csharpier check .`,
|
|
40
47
|
quick: (context) => {
|
|
41
48
|
const command = withChanged(context, /\.cs$/, "dotnet csharpier check");
|
|
42
|
-
return command === null ? null :
|
|
49
|
+
return command === null ? null : `${FORMAT} && ${command}`;
|
|
43
50
|
},
|
|
44
51
|
limitSeconds: 120,
|
|
45
52
|
},
|
|
46
53
|
{
|
|
47
54
|
id: DOTNET_TEST,
|
|
48
|
-
title: "tests (dotnet test, xUnit v3; --quick: the projects that test with Suwgate.Architecture or Suwgate.Database)",
|
|
55
|
+
title: "tests (dotnet test, xUnit v3, with the checkout's databases when suwgate.yml has dev; --quick: the projects that test with Suwgate.Architecture or Suwgate.Database)",
|
|
49
56
|
profile: "dotnet",
|
|
50
57
|
needs: ["dotnet"],
|
|
51
58
|
after: [DOTNET_BUILD, DATABASE_UP],
|
|
52
|
-
run: TEST,
|
|
53
|
-
quick:
|
|
59
|
+
run: (context) => inCheckoutEnv(context, TEST),
|
|
60
|
+
quick: (context) => {
|
|
61
|
+
const command = guardTests(context);
|
|
62
|
+
return command === null ? null : inCheckoutEnv(context, command);
|
|
63
|
+
},
|
|
54
64
|
limitSeconds: 600,
|
|
55
65
|
},
|
|
56
66
|
];
|
package/dist/profiles/node.js
CHANGED
|
@@ -2,7 +2,7 @@ import { changedIn, filesIn, has, read, withChanged } from "./shell.js";
|
|
|
2
2
|
const CODE = /\.(ts|tsx|js|jsx|mjs|cjs|mts|cts)$/;
|
|
3
3
|
const TSCONFIG = /^tsconfig(\..+)?\.json$/;
|
|
4
4
|
const VITEST_CONFIG = /^vitest\.config\.(ts|mts|js|mjs)$/;
|
|
5
|
-
const UNIT_PROJECT = /\bname:\s*["'`]unit["'`]/;
|
|
5
|
+
const UNIT_PROJECT = /\bname:\s*["'`]unit["'`]|\bunitTests\(/;
|
|
6
6
|
export const PNPM_INSTALL = "pnpm-install";
|
|
7
7
|
function install(context) {
|
|
8
8
|
return has(context, "node_modules") ? null : "pnpm install --frozen-lockfile --silent";
|
package/dist/profiles/shell.d.ts
CHANGED
|
@@ -8,3 +8,6 @@ export declare function read(context: StepContext, file: string): string | null;
|
|
|
8
8
|
export declare function tracked(context: StepContext, pathspecs: readonly string[]): string[];
|
|
9
9
|
export declare function script(lines: readonly string[]): string;
|
|
10
10
|
export declare function onPath(tool: string): boolean;
|
|
11
|
+
export declare function suwgate(args: string): string;
|
|
12
|
+
export declare function hasDevSection(context: StepContext): boolean;
|
|
13
|
+
export declare const CHECKOUT_ENV: string[];
|
package/dist/profiles/shell.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { execFileSync } from "node:child_process";
|
|
2
2
|
import { accessSync, constants, existsSync, readdirSync, readFileSync } from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { parse as parseYaml } from "yaml";
|
|
6
|
+
const HERE = fileURLToPath(import.meta.url);
|
|
7
|
+
const CLI = path.join(path.dirname(HERE), "..", `cli${path.extname(HERE)}`);
|
|
4
8
|
export function quoted(argument) {
|
|
5
9
|
return `'${argument.replaceAll("'", `'"'"'`)}'`;
|
|
6
10
|
}
|
|
@@ -60,3 +64,16 @@ export function onPath(tool) {
|
|
|
60
64
|
}
|
|
61
65
|
});
|
|
62
66
|
}
|
|
67
|
+
export function suwgate(args) {
|
|
68
|
+
return `${quoted(process.execPath)} ${quoted(CLI)} ${args}`;
|
|
69
|
+
}
|
|
70
|
+
export function hasDevSection(context) {
|
|
71
|
+
try {
|
|
72
|
+
const parsed = parseYaml(readFileSync(path.join(context.root, "suwgate.yml"), "utf8"));
|
|
73
|
+
return typeof parsed === "object" && parsed !== null && "dev" in parsed;
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export const CHECKOUT_ENV = [`variables="$(${suwgate("dev checkout-env")})"`, 'eval "$variables"'];
|
package/dist/profiles/web.js
CHANGED
|
@@ -2,16 +2,32 @@ import { API_CONTRACT } from "./contract.js";
|
|
|
2
2
|
import { DATABASE_UP } from "./database.js";
|
|
3
3
|
import { DOTNET_BUILD, DOTNET_TEST } from "./dotnet.js";
|
|
4
4
|
import { PNPM_INSTALL } from "./node.js";
|
|
5
|
-
import { has } from "./shell.js";
|
|
5
|
+
import { CHECKOUT_ENV, has, hasDevSection, quoted, script, suwgate } from "./shell.js";
|
|
6
6
|
const E2E_CONFIG = "e2e/playwright.config.ts";
|
|
7
|
+
const PLAYWRIGHT = `pnpm exec playwright test -c ${E2E_CONFIG}`;
|
|
8
|
+
function e2e(context) {
|
|
9
|
+
if (!has(context, E2E_CONFIG))
|
|
10
|
+
return null;
|
|
11
|
+
if (!hasDevSection(context))
|
|
12
|
+
return PLAYWRIGHT;
|
|
13
|
+
return script([
|
|
14
|
+
"set -euo pipefail",
|
|
15
|
+
...CHECKOUT_ENV,
|
|
16
|
+
'case "$E2E_DATABASE" in *e2e*) ;; *) echo "E2E_DATABASE is \\"$E2E_DATABASE\\": the e2e step drops and recreates it, so its name must contain e2e; never point it at the development database" >&2; exit 2 ;; esac',
|
|
17
|
+
`${suwgate("dev db up")} >/dev/null`,
|
|
18
|
+
`${suwgate("dev db psql")} -q -d postgres -c "DROP DATABASE IF EXISTS $E2E_DATABASE WITH (FORCE)" -c "CREATE DATABASE $E2E_DATABASE"`,
|
|
19
|
+
`mkdir -p ${quoted(`${context.root}/.artifacts/logs`)}`,
|
|
20
|
+
PLAYWRIGHT,
|
|
21
|
+
]);
|
|
22
|
+
}
|
|
7
23
|
export const webSteps = [
|
|
8
24
|
{
|
|
9
25
|
id: "e2e",
|
|
10
|
-
title: `browser tests against the real server and database (playwright, ${E2E_CONFIG})`,
|
|
26
|
+
title: `browser tests against the real server and a fresh database of this checkout (playwright, ${E2E_CONFIG})`,
|
|
11
27
|
profile: "web",
|
|
12
28
|
needs: ["pnpm"],
|
|
13
29
|
after: [PNPM_INSTALL, DOTNET_BUILD, DATABASE_UP, DOTNET_TEST, API_CONTRACT],
|
|
14
|
-
run:
|
|
30
|
+
run: e2e,
|
|
15
31
|
limitSeconds: 600,
|
|
16
32
|
},
|
|
17
33
|
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maniumek/suwgate",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "One quality gate for every repository: suwgate check runs the steps of the repository's profiles and its guards, configured in suwgate.yml",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Manomenu",
|
|
@@ -23,6 +23,18 @@
|
|
|
23
23
|
"^": { "$ref": "#/$defs/relativePath" }
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
|
+
"quick": {
|
|
27
|
+
"description": "The quick gate (suwgate check --quick).",
|
|
28
|
+
"type": "object",
|
|
29
|
+
"additionalProperties": false,
|
|
30
|
+
"properties": {
|
|
31
|
+
"limitSeconds": {
|
|
32
|
+
"type": "integer",
|
|
33
|
+
"minimum": 1,
|
|
34
|
+
"description": "The quick gate fails when it takes longer (default 20). SUWGATE_QUICK_LIMIT on a machine overrides it."
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
},
|
|
26
38
|
"steps": {
|
|
27
39
|
"type": "object",
|
|
28
40
|
"additionalProperties": false,
|