From c19c1b1ffd920a6c8a8a88ebbe7bf2e5f509eb0c Mon Sep 17 00:00:00 2001 From: Kevin Stillhammer Date: Tue, 27 May 2025 18:25:00 +0200 Subject: [PATCH] Check that all jobs are in all-tests-passed.needs (#432) --- .../scripts/check-all-tests-passed-needs.ts | 35 +++++++++++++++++++ .github/workflows/test.yml | 9 +++++ package-lock.json | 14 ++++++++ package.json | 1 + 4 files changed, 59 insertions(+) create mode 100644 .github/scripts/check-all-tests-passed-needs.ts diff --git a/.github/scripts/check-all-tests-passed-needs.ts b/.github/scripts/check-all-tests-passed-needs.ts new file mode 100644 index 0000000..f21bdb6 --- /dev/null +++ b/.github/scripts/check-all-tests-passed-needs.ts @@ -0,0 +1,35 @@ +import * as fs from "node:fs"; +import * as yaml from "js-yaml"; + +interface WorkflowJob { + needs?: string[]; + [key: string]: unknown; +} + +interface Workflow { + jobs: Record; + [key: string]: unknown; +} + +const workflow = yaml.load( + fs.readFileSync("../workflows/test.yml", "utf8"), +) as Workflow; +const jobs = Object.keys(workflow.jobs); +const allTestsPassed = workflow.jobs["all-tests-passed"]; +const needs: string[] = allTestsPassed.needs || []; + +const expectedNeeds = jobs.filter((j) => j !== "all-tests-passed"); +const missing = expectedNeeds.filter((j) => !needs.includes(j)); + +if (missing.length > 0) { + console.error( + `Missing jobs in all-tests-passed needs: ${missing.join(", ")}`, + ); + console.info( + "Please add the missing jobs to the needs section of all-tests-passed in test.yml.", + ); + process.exit(1); +} +console.log( + "All jobs in test.yml are in the needs section of all-tests-passed.", +); diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8ddf39b..760bf4b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,6 +29,11 @@ jobs: npm install - run: | npm run all + - name: Check all jobs are in all-tests-passed.needs + run: | + tsc check-all-tests-passed-needs.ts + node check-all-tests-passed-needs.js + working-directory: .github/scripts - name: Make sure no changes from linters are detected run: | git diff --exit-code || (echo "::error::Please run 'npm run all' to fix the issues" && exit 1) @@ -548,9 +553,13 @@ jobs: - test-activate-environment - test-musl - test-cache-local + - test-setup-cache - test-restore-cache + - test-setup-cache-requirements-txt - test-restore-cache-requirements-txt + - test-setup-cache-dependency-glob - test-restore-cache-dependency-glob + - test-setup-cache-local - test-restore-cache-local - test-tilde-expansion-cache-local-path - test-tilde-expansion-cache-dependency-glob diff --git a/package-lock.json b/package-lock.json index b2d6e2b..31ce7c2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,6 +24,7 @@ }, "devDependencies": { "@biomejs/biome": "1.9.4", + "@types/js-yaml": "^4.0.9", "@types/node": "^22.15.21", "@types/semver": "^7.7.0", "@vercel/ncc": "^0.38.3", @@ -1825,6 +1826,13 @@ "@types/istanbul-lib-report": "*" } }, + "node_modules/@types/js-yaml": { + "version": "4.0.9", + "resolved": "https://registry.npmjs.org/@types/js-yaml/-/js-yaml-4.0.9.tgz", + "integrity": "sha512-k4MGaQl5TGo/iipqb2UDG2UwjXziSWkh0uysQelTlJpX1qGlpUZYm8PnO4DxG1qBomtJUdYJ6qR6xdIah10JLg==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/node": { "version": "22.15.21", "resolved": "https://registry.npmjs.org/@types/node/-/node-22.15.21.tgz", @@ -6082,6 +6090,12 @@ "@types/istanbul-lib-report": "*" } }, + "@types/js-yaml": { + "version": "4.0.9", + "resolved": "https://registry.npmjs.org/@types/js-yaml/-/js-yaml-4.0.9.tgz", + "integrity": "sha512-k4MGaQl5TGo/iipqb2UDG2UwjXziSWkh0uysQelTlJpX1qGlpUZYm8PnO4DxG1qBomtJUdYJ6qR6xdIah10JLg==", + "dev": true + }, "@types/node": { "version": "22.15.21", "resolved": "https://registry.npmjs.org/@types/node/-/node-22.15.21.tgz", diff --git a/package.json b/package.json index e9daf75..be30693 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ }, "devDependencies": { "@biomejs/biome": "1.9.4", + "@types/js-yaml": "^4.0.9", "@types/node": "^22.15.21", "@types/semver": "^7.7.0", "@vercel/ncc": "^0.38.3",