Skip to content

Commit 53d2d82

Browse files
authored
CI: don't run npm pack twice (#6923)
* CI: don't run npm pack twice * Add typedefs for PackOutput * Update comments
1 parent 789443f commit 53d2d82

File tree

4 files changed

+86
-66
lines changed

4 files changed

+86
-66
lines changed

.github/workflows/ci.yml

+2-5
Original file line numberDiff line numberDiff line change
@@ -432,11 +432,8 @@ jobs:
432432
- name: Move artifacts
433433
run: ./scripts/moveArtifacts.sh
434434

435-
- name: Check artifact list
436-
run: node ./scripts/makeArtifactList.js -check
437-
438-
- name: npm pack (rescript)
439-
run: npm pack
435+
- name: npm pack (rescript) + check artifact list
436+
run: node ./scripts/npmPack.js
440437

441438
- name: Copy JS files to stdlib package
442439
run: mkdir -p packages/std/lib && cp -R lib/es6 lib/js packages/std/lib

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ lib: build node_modules/.bin/semver
5656
./scripts/prebuilt.js
5757

5858
artifacts: lib
59-
./scripts/makeArtifactList.js
59+
./scripts/npmPack.js -updateArtifactList
6060

6161
# Builds the core playground bundle (without the relevant cmijs files for the runtime)
6262
playground:

scripts/makeArtifactList.js

-60
This file was deleted.

scripts/npmPack.js

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/usr/bin/env node
2+
// @ts-check
3+
4+
// This performs `npm pack` and retrieves the list of artifact files from the output.
5+
//
6+
// In local dev, invoke it with `-updateArtifactList` to perform a dry run of `npm pack`
7+
// and recreate `packages/artifacts.txt`.
8+
// The exes for all platforms will then be included in the list, even if not present locally.
9+
//
10+
// In CI, the scripts is invoked without options. It then performs `npm pack` for real,
11+
// recreates the artifact list and verifies that it has no changes compared to the committed state.
12+
13+
/**
14+
* @typedef {{
15+
* path: string,
16+
* size: number,
17+
* mode: number,
18+
* }} PackOutputFile
19+
*
20+
* @typedef {{
21+
* files: PackOutputFile[],
22+
* entryCount: number,
23+
* bundled: unknown[],
24+
* }} PackOutputEntry
25+
*
26+
* @typedef {[PackOutputEntry]} PackOutput
27+
*/
28+
29+
const { spawnSync, execSync } = require("child_process");
30+
const path = require("path");
31+
const fs = require("fs");
32+
33+
const mode = process.argv.includes("-updateArtifactList")
34+
? "updateArtifactList"
35+
: "package";
36+
37+
const rootPath = path.join(__dirname, "..");
38+
const fileListPath = path.join(rootPath, "packages", "artifacts.txt");
39+
40+
const output = spawnSync(
41+
"npm pack --json" + (mode === "updateArtifactList" ? " --dry-run" : ""),
42+
{
43+
cwd: rootPath,
44+
encoding: "utf8",
45+
shell: true,
46+
},
47+
).stdout;
48+
49+
/** @type {PackOutput} */
50+
const parsedOutput = JSON.parse(output);
51+
let filePaths = parsedOutput[0].files.map(file => file.path);
52+
53+
if (mode === "updateArtifactList") {
54+
filePaths = Array.from(new Set(filePaths.concat(getFilesAddedByCI())));
55+
}
56+
57+
filePaths.sort();
58+
fs.writeFileSync(fileListPath, filePaths.join("\n"));
59+
60+
if (mode === "package") {
61+
execSync(`git diff --exit-code ${fileListPath}`, { stdio: "inherit" });
62+
}
63+
64+
function getFilesAddedByCI() {
65+
const platforms = ["darwin", "darwinarm64", "linux", "linuxarm64", "win32"];
66+
const exes = [
67+
"bsb_helper.exe",
68+
"bsc.exe",
69+
"ninja.exe",
70+
"rescript.exe",
71+
"rewatch.exe",
72+
];
73+
74+
const files = ["ninja.COPYING"];
75+
76+
for (let platform of platforms) {
77+
for (let exe of exes) {
78+
files.push(`${platform}/${exe}`);
79+
}
80+
}
81+
82+
return files;
83+
}

0 commit comments

Comments
 (0)