Skip to content

CI: don't run npm pack twice #6923

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

Merged
merged 3 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -432,11 +432,8 @@ jobs:
- name: Move artifacts
run: ./scripts/moveArtifacts.sh

- name: Check artifact list
run: node ./scripts/makeArtifactList.js -check

- name: npm pack (rescript)
run: npm pack
- name: npm pack (rescript) + check artifact list
run: node ./scripts/npmPack.js

- name: Copy JS files to stdlib package
run: mkdir -p packages/std/lib && cp -R lib/es6 lib/js packages/std/lib
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ lib: build node_modules/.bin/semver
./scripts/prebuilt.js

artifacts: lib
./scripts/makeArtifactList.js
./scripts/npmPack.js -updateArtifactList

# Builds the core playground bundle (without the relevant cmijs files for the runtime)
playground:
Expand Down
60 changes: 0 additions & 60 deletions scripts/makeArtifactList.js

This file was deleted.

83 changes: 83 additions & 0 deletions scripts/npmPack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env node
// @ts-check

// This performs `npm pack` and retrieves the list of artifact files from the output.
//
// In local dev, invoke it with `-updateArtifactList` to perform a dry run of `npm pack`
// and recreate `packages/artifacts.txt`.
// The exes for all platforms will then be included in the list, even if not present locally.
//
// In CI, the scripts is invoked without options. It then performs `npm pack` for real,
// recreates the artifact list and verifies that it has no changes compared to the committed state.

/**
* @typedef {{
* path: string,
* size: number,
* mode: number,
* }} PackOutputFile
*
* @typedef {{
* files: PackOutputFile[],
* entryCount: number,
* bundled: unknown[],
* }} PackOutputEntry
*
* @typedef {[PackOutputEntry]} PackOutput
*/

const { spawnSync, execSync } = require("child_process");
const path = require("path");
const fs = require("fs");

const mode = process.argv.includes("-updateArtifactList")
? "updateArtifactList"
: "package";

const rootPath = path.join(__dirname, "..");
const fileListPath = path.join(rootPath, "packages", "artifacts.txt");

const output = spawnSync(
"npm pack --json" + (mode === "updateArtifactList" ? " --dry-run" : ""),
{
cwd: rootPath,
encoding: "utf8",
shell: true,
},
).stdout;

/** @type {PackOutput} */
const parsedOutput = JSON.parse(output);
let filePaths = parsedOutput[0].files.map(file => file.path);

if (mode === "updateArtifactList") {
filePaths = Array.from(new Set(filePaths.concat(getFilesAddedByCI())));
}

filePaths.sort();
fs.writeFileSync(fileListPath, filePaths.join("\n"));

if (mode === "package") {
execSync(`git diff --exit-code ${fileListPath}`, { stdio: "inherit" });
}

function getFilesAddedByCI() {
const platforms = ["darwin", "darwinarm64", "linux", "linuxarm64", "win32"];
const exes = [
"bsb_helper.exe",
"bsc.exe",
"ninja.exe",
"rescript.exe",
"rewatch.exe",
];

const files = ["ninja.COPYING"];

for (let platform of platforms) {
for (let exe of exes) {
files.push(`${platform}/${exe}`);
}
}

return files;
}