-
Notifications
You must be signed in to change notification settings - Fork 16
Add npm run test:build script #189
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#! /usr/bin/env node | ||
|
||
import commandLineArgs from "command-line-args"; | ||
import fs from "fs"; | ||
import { fileURLToPath } from "url"; | ||
import path from "path"; | ||
|
||
import { logError, logCommand, printHelp, runTest, sh } from "./helper.mjs"; | ||
|
||
const optionDefinitions = [ | ||
{ name: "help", alias: "h", description: "Print this help text." }, | ||
]; | ||
|
||
const options = commandLineArgs(optionDefinitions); | ||
|
||
if ("help" in options) | ||
printHelp(optionDefinitions); | ||
|
||
const FILE_PATH = fileURLToPath(import.meta.url); | ||
const SRC_DIR = path.dirname(path.dirname(FILE_PATH)); | ||
|
||
async function findPackageJsonFiles(dir, accumulator=[]) { | ||
const dirEntries = fs.readdirSync(dir, { withFileTypes: true }); | ||
for (const dirent of dirEntries) { | ||
if (dirent.name === "node_modules" || dirent.name === ".git") | ||
continue; | ||
const fullPath = path.join(dir, dirent.name); | ||
if (dirent.isDirectory()) | ||
findPackageJsonFiles(fullPath, accumulator); | ||
else if (dirent.name === "package.json") | ||
accumulator.push(fullPath) | ||
} | ||
return accumulator; | ||
} | ||
|
||
async function runBuilds() { | ||
const packageJsonFiles = await findPackageJsonFiles(SRC_DIR); | ||
let success = true; | ||
|
||
for (const file of packageJsonFiles) { | ||
const content = fs.readFileSync(file, "utf-8"); | ||
const packageJson = JSON.parse(content); | ||
if (!packageJson.scripts?.build) { | ||
continue; | ||
} | ||
|
||
const dir = path.dirname(file); | ||
const relativeDir = path.relative(SRC_DIR, dir); | ||
const testName = `Building ${relativeDir}`; | ||
|
||
const buildTask = async () => { | ||
const oldCWD = process.cwd(); | ||
try { | ||
logCommand("cd", dir); | ||
process.chdir(dir); | ||
await sh("npm", "ci"); | ||
await sh("npm", "run", "build"); | ||
} finally { | ||
process.chdir(oldCWD); | ||
// await sh("git", "reset", "--hard"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: remove or add a comment maybe? Otherwise it looks like it's potentially forgotten/accidentally committed code. |
||
} | ||
}; | ||
|
||
success &&= await runTest(testName, buildTask); | ||
} | ||
|
||
if (!success) { | ||
logError("One or more builds failed."); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
setImmediate(runBuilds); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: add newline |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ordering question: is there a particular reason to have this after the
Run Tests
step? Logically it seems to make sense to have build before test, so that we always run the freshly rebuilt workloads, right?