From 36be9bfb351869594575071c503ca5833511c5bd Mon Sep 17 00:00:00 2001 From: Ben Vinegar Date: Sat, 21 Mar 2026 11:26:59 -0400 Subject: [PATCH] feat: support beta tags for prebuilt releases --- .github/workflows/release-prebuilt-npm.yml | 9 +++-- scripts/publish-prebuilt-npm.ts | 39 +++++++++++++++++++--- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release-prebuilt-npm.yml b/.github/workflows/release-prebuilt-npm.yml index b2a671e..0fb120d 100644 --- a/.github/workflows/release-prebuilt-npm.yml +++ b/.github/workflows/release-prebuilt-npm.yml @@ -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*" @@ -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 @@ -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' }}" diff --git a/scripts/publish-prebuilt-npm.ts b/scripts/publish-prebuilt-npm.ts index 6c7173e..e166cb4 100644 --- a/scripts/publish-prebuilt-npm.ts +++ b/scripts/publish-prebuilt-npm.ts @@ -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, }; } @@ -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)) { @@ -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"); } @@ -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}\".`, +);