Skip to content

Commit d8e40bf

Browse files
committed
Convert check-js.sh to TypeScript
1 parent fccc166 commit d8e40bf

4 files changed

Lines changed: 71 additions & 34 deletions

File tree

.github/workflows/pr-checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
npm ci
5656
5757
- name: Verify compiled JS up to date
58-
run: .github/workflows/script/check-js.sh
58+
run: npx tsx pr-checks/check-js.ts
5959

6060
- name: Run unit tests
6161
if: always()

.github/workflows/script/check-js.sh

Lines changed: 0 additions & 33 deletions
This file was deleted.

pr-checks/check-js.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env npx tsx
2+
3+
import * as fs from "node:fs";
4+
import * as path from "node:path";
5+
6+
import * as core from "@actions/core";
7+
8+
import { runCommand, runGit } from "./command";
9+
import { LIB_ROOT, PR_CHECKS_DIR, REPO_ROOT } from "./config";
10+
import { getErrorMessage } from "./util";
11+
12+
function main() {
13+
// Sanity check that repo is clean to start with
14+
try {
15+
runGit(["diff", "--exit-code"], { allowNonZeroExitCode: false });
16+
console.info("Repository is clean.");
17+
} catch (err) {
18+
// If we get a fail here then this workflow needs attention...
19+
console.error(getErrorMessage(err));
20+
console.error("Failed: Repo should be clean before testing!");
21+
return -1;
22+
}
23+
24+
// Wipe the lib directory in case there are extra unnecessary files in there
25+
console.info(`Removing ${LIB_ROOT}...`);
26+
fs.rmSync(LIB_ROOT, { recursive: true, force: true });
27+
28+
// Generate the JavaScript files
29+
runCommand("npm", ["run", "build"], { execOptions: { cwd: REPO_ROOT } });
30+
31+
// Check that repo is still clean
32+
try {
33+
runGit(["diff", "--exit-code"], { allowNonZeroExitCode: false });
34+
console.info("Repository is clean.");
35+
} catch (err) {
36+
// If we get a fail here then the PR needs attention
37+
console.error(getErrorMessage(err));
38+
console.error("Failed: JavaScript files are not up to date.");
39+
console.error("Run 'rm -rf lib && npm run build' to update.");
40+
41+
const diffFile = path.join(
42+
process.env["RUNNER_TEMP"] ?? PR_CHECKS_DIR,
43+
"js.diff",
44+
);
45+
runCommand("git", ["status"], { execOptions: { cwd: REPO_ROOT } });
46+
runCommand("git", ["diff", `--output=${diffFile}`], {
47+
execOptions: { cwd: REPO_ROOT },
48+
});
49+
50+
core.summary.addHeading("Transpiled JS diff", 3);
51+
core.summary.addCodeBlock(fs.readFileSync(diffFile, "utf-8"), "diff");
52+
53+
fs.rmSync(diffFile);
54+
55+
// Reset bundled files to allow other checks to test for changes
56+
runCommand("git", ["checkout", "lib"], { execOptions: { cwd: REPO_ROOT } });
57+
58+
return 1;
59+
}
60+
61+
console.info("Success: JavaScript files are up to date");
62+
return 0;
63+
}
64+
65+
if (require.main === module) {
66+
process.exit(main());
67+
}

pr-checks/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ export const BUNDLE_METADATA_FILE = path.join(REPO_ROOT, "meta.json");
2424
/** The `src` directory. */
2525
export const SOURCE_ROOT = path.join(REPO_ROOT, "src");
2626

27+
/** The `src` directory. */
28+
export const LIB_ROOT = path.join(REPO_ROOT, "lib");
29+
2730
/** The path to `defaults.json`. */
2831
export const DEFAULTS_FILE = path.join(SOURCE_ROOT, "defaults.json");
2932

0 commit comments

Comments
 (0)