-
Notifications
You must be signed in to change notification settings - Fork 3
ci: test builds and suites across Node and Bun #180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0b836bd
ci: test builds and suites across Node and Bun
mynameistito 92b2e6c
ci: remove unsupported Node 20 test target
mynameistito 2a706e1
ci: enforce coverage thresholds in Node tests
mynameistito f4bd992
ci: continue Node checks after package failures
mynameistito 77752f4
fix(ci): preserve Node resolution and root tests
mynameistito File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| import { spawnSync } from "node:child_process"; | ||
| import { existsSync, readdirSync, readFileSync } from "node:fs"; | ||
| import path from "node:path"; | ||
| import { fileURLToPath } from "node:url"; | ||
|
|
||
| const rootDirectory = fileURLToPath(new URL("../", import.meta.url)); | ||
| const nodeModulesDirectory = "node_modules"; | ||
| const packageManifestFile = "package.json"; | ||
| const packageDirectories = ["packages", "apps"] | ||
| .flatMap((parent) => { | ||
| const parentPath = path.join(rootDirectory, parent); | ||
| return readdirSync(parentPath, { withFileTypes: true }) | ||
| .filter( | ||
| (entry) => | ||
| entry.isDirectory() && | ||
| readdirSync(path.join(parentPath, entry.name)).includes( | ||
| packageManifestFile | ||
| ) | ||
| ) | ||
| .map((entry) => path.join(parent, entry.name)); | ||
| }) | ||
| .toSorted(); | ||
|
|
||
| let hasFailedTask = false; | ||
| const run = (command, args, cwd = rootDirectory) => { | ||
| const result = spawnSync(command, args, { | ||
| cwd, | ||
| stdio: "inherit", | ||
| }); | ||
| if (result.error) { | ||
| throw result.error; | ||
| } | ||
| if (result.status !== 0) { | ||
| hasFailedTask = true; | ||
| } | ||
| }; | ||
|
|
||
| const vitestCli = path.join(rootDirectory, "node_modules/vitest/vitest.mjs"); | ||
| const coverageScript = path.join(rootDirectory, "scripts/check-coverage.ts"); | ||
| const runPackageCli = (script, packagePath) => { | ||
| if (/[\n\r"'`;&|<>]/u.test(script)) { | ||
| throw new Error(`Unsupported shell syntax in package script: ${script}`); | ||
| } | ||
| const [command, ...args] = script.split(/\s+/u); | ||
| const manifestPath = [ | ||
| path.join(packagePath, nodeModulesDirectory, command, packageManifestFile), | ||
| path.join( | ||
| rootDirectory, | ||
| nodeModulesDirectory, | ||
| command, | ||
| packageManifestFile | ||
| ), | ||
| ].find(existsSync); | ||
| if (!manifestPath) { | ||
| throw new Error(`Could not resolve package manifest for ${command}.`); | ||
| } | ||
| const cliManifest = JSON.parse(readFileSync(manifestPath, "utf-8")); | ||
| const bin = cliManifest.bin?.[command] ?? cliManifest.bin; | ||
| if (!bin) { | ||
| throw new Error(`Could not resolve executable for ${command}.`); | ||
| } | ||
| run( | ||
| process.execPath, | ||
| [path.resolve(path.dirname(manifestPath), bin), ...args], | ||
| packagePath | ||
| ); | ||
| }; | ||
|
|
||
| for (const packageDirectory of packageDirectories) { | ||
| const packagePath = path.join(rootDirectory, packageDirectory); | ||
| const manifest = JSON.parse( | ||
| readFileSync(path.join(packagePath, packageManifestFile), "utf-8") | ||
| ); | ||
| if (manifest.scripts?.build) { | ||
| console.log(`\n==> ${packageDirectory} build (Node)`); | ||
| runPackageCli(manifest.scripts.build, packagePath); | ||
| } | ||
| if (manifest.scripts?.test) { | ||
| console.log(`\n==> ${packageDirectory} test (Node)`); | ||
| if (existsSync(path.join(packagePath, "vitest.config.ts"))) { | ||
| const coverageThreshold = manifest.scripts.test.match( | ||
| /check-coverage\.ts\s+coverage\/lcov\.info\s+(?<threshold>\S+)/u | ||
| )?.groups?.threshold; | ||
| if (!coverageThreshold) { | ||
| throw new Error( | ||
| `Could not resolve coverage threshold for ${packageDirectory}.` | ||
| ); | ||
| } | ||
| const result = spawnSync( | ||
|
mynameistito marked this conversation as resolved.
|
||
| process.execPath, | ||
| [ | ||
| vitestCli, | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
|
||
| "run", | ||
| "--coverage", | ||
| "--config", | ||
| path.join(packagePath, "vitest.config.ts"), | ||
| ], | ||
|
mynameistito marked this conversation as resolved.
|
||
| { | ||
| cwd: packagePath, | ||
| env: { ...process.env, NODE_COMPAT: "true" }, | ||
| stdio: "inherit", | ||
| } | ||
| ); | ||
| if (result.error) { | ||
| throw result.error; | ||
| } | ||
| if (result.status === 0) { | ||
| run( | ||
| "bun", | ||
| [ | ||
| coverageScript, | ||
| path.join(packagePath, "coverage/lcov.info"), | ||
| coverageThreshold, | ||
| ], | ||
| packagePath | ||
| ); | ||
| } else { | ||
| hasFailedTask = true; | ||
| } | ||
| } else { | ||
| runPackageCli(manifest.scripts.test, packagePath); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| console.log("\n==> scripts/__tests__ (Node)"); | ||
| const rootTestResult = spawnSync( | ||
| process.execPath, | ||
| [vitestCli, "run", "scripts/__tests__"], | ||
| { cwd: rootDirectory, stdio: "inherit" } | ||
| ); | ||
| if (rootTestResult.error) { | ||
| throw rootTestResult.error; | ||
| } | ||
| if (rootTestResult.status !== 0) { | ||
| hasFailedTask = true; | ||
| } | ||
|
|
||
| if (hasFailedTask) { | ||
| process.exitCode = 1; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.