Skip to content
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
9 changes: 7 additions & 2 deletions .github/workflows/release-prebuilt-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ on:
required: true
default: false
type: boolean
npm_tag:
description: npm dist-tag to publish under (for example latest or beta)
required: true
default: latest
type: string
push:
tags:
- "v*"
Expand Down Expand Up @@ -95,7 +100,7 @@ jobs:
run: bun run check:prebuilt-pack

- name: Dry-run npm publish order
run: bun run publish:prebuilt:npm -- --dry-run
run: bun run publish:prebuilt:npm -- --dry-run --tag "${{ github.event_name == 'workflow_dispatch' && inputs.npm_tag || 'latest' }}"

- name: Upload staged npm release
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -146,4 +151,4 @@ jobs:
- name: Publish packages
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: bun run publish:prebuilt:npm
run: bun run publish:prebuilt:npm -- --tag "${{ github.event_name == 'workflow_dispatch' && inputs.npm_tag || 'latest' }}"
39 changes: 34 additions & 5 deletions scripts/publish-prebuilt-npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,33 @@ type PackageJson = {
};

function parseArgs(argv: string[]) {
let dryRun = false;
let npmTag = "latest";

for (let index = 0; index < argv.length; index += 1) {
const argument = argv[index];

if (argument === "--dry-run") {
dryRun = true;
continue;
}

if (argument === "--tag") {
const value = argv[index + 1];
if (!value) {
throw new Error("Missing value for --tag");
}
npmTag = value;
index += 1;
continue;
}

throw new Error(`Unknown argument: ${argument}`);
}

return {
dryRun: argv.includes("--dry-run"),
dryRun,
npmTag,
};
}

Expand All @@ -26,7 +51,7 @@ function npmViewExists(name: string, version: string) {
return proc.exitCode === 0;
}

function publishDirectory(directory: string, dryRun: boolean) {
function publishDirectory(directory: string, dryRun: boolean, npmTag: string) {
const packageJson = JSON.parse(readFileSync(path.join(directory, "package.json"), "utf8")) as PackageJson;

if (npmViewExists(packageJson.name, packageJson.version)) {
Expand All @@ -38,7 +63,7 @@ function publishDirectory(directory: string, dryRun: boolean) {
return;
}

const args = ["publish", "--access", "public"];
const args = ["publish", "--access", "public", "--tag", npmTag];
if (dryRun) {
args.push("--dry-run");
}
Expand Down Expand Up @@ -79,7 +104,11 @@ if (directories.length === 0) {
}

for (const directory of directories) {
publishDirectory(directory, options.dryRun);
publishDirectory(directory, options.dryRun, options.npmTag);
}

console.log(options.dryRun ? "Completed npm publish dry-run for staged prebuilt packages." : "Published staged prebuilt packages to npm.");
console.log(
options.dryRun
? `Completed npm publish dry-run for staged prebuilt packages with dist-tag \"${options.npmTag}\".`
: `Published staged prebuilt packages to npm with dist-tag \"${options.npmTag}\".`,
);
Loading