Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,21 @@ jobs:
touch persist.dat
npx --no-install stryker run mutation/stryker.config.json
node mutation/stryker_check.js

production-quality:
name: Production quality
runs-on: ubuntu-latest

steps:
- name: Check out repository
uses: actions/checkout@v5
with:
fetch-depth: 0

- name: Set up Node.js
uses: actions/setup-node@v5
with:
node-version: 22

- name: Run aggregate production quality gate
run: npm run quality:production
37 changes: 36 additions & 1 deletion scripts/messcript.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { spawnSync } from "node:child_process";
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
import { dirname, join } from "node:path";
import process from "node:process";
import { fileURLToPath } from "node:url";
import { fileURLToPath, pathToFileURL } from "node:url";

const projectRoot = join(dirname(fileURLToPath(import.meta.url)), "..");
const messcriptRepository = "https://github.com/quality-gates/messcript.git";
Expand All @@ -21,6 +21,10 @@ const productionUnits = new Map([
["http-handler", ["src/handler.ts"]],
["entrypoint", ["main.ts"]],
]);
const requiredComplexityRules = [
"CyclomaticComplexity",
"NPathComplexity",
];

function run(command, args, cwd) {
const result = spawnSync(command, args, {
Expand Down Expand Up @@ -133,6 +137,34 @@ function requestedPaths(unitName) {
return paths;
}

async function reportAggregatePolicy() {
const rulesets = await import(
pathToFileURL(join(toolRoot, "dist", "rulesets.js")).href
);
const selectedRules = new Set(
rulesets.loadRulesets(["typescript"]).selections.map(
(selection) => selection.name,
),
);
const missingRules = requiredComplexityRules.filter(
(ruleName) => !selectedRules.has(ruleName),
);
if (missingRules.length > 0) {
throw new Error(
`typescript policy is missing required rules: ${missingRules.join(", ")}`,
);
}

console.log(
`Production quality scope (${productionUnits.size}): ${
[...productionUnits.keys()].join(", ")
}`,
);
console.log(
`Required complexity rules: ${requiredComplexityRules.join(", ")}`,
);
}

const unitName = process.argv[2] ?? "all";

try {
Expand All @@ -141,6 +173,9 @@ try {
if (acquireExit !== 0) {
process.exitCode = acquireExit;
} else {
if (unitName === "all") {
await reportAggregatePolicy();
}
process.exitCode = run(
"node",
[messcriptCli, paths.join(","), "text", "typescript", "--color=never"],
Expand Down