Skip to content

Commit 37f7a2a

Browse files
committed
Fix beta npm dist-tag
Change-Id: I5e3e201d94cdbe7a239f23a7dbd4d8fd89726b80
1 parent 480e050 commit 37f7a2a

4 files changed

Lines changed: 24 additions & 5 deletions

File tree

.github/workflows/release.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ jobs:
3333
outputs:
3434
channel: ${{ steps.release.outputs.channel }}
3535
version: ${{ steps.release.outputs.version }}
36+
dist-tag: ${{ steps.release.outputs.dist-tag }}
3637
permissions:
3738
contents: read
3839
steps:
@@ -113,7 +114,8 @@ jobs:
113114
- name: Publish packages with npm Trusted Publishing
114115
env:
115116
NPM_CONFIG_PROVENANCE: "true"
116-
run: bun run release:publish
117+
NPM_DIST_TAG: ${{ needs.preflight.outputs.dist-tag }}
118+
run: bun run release:publish -- --tag "$NPM_DIST_TAG"
117119

118120
- name: Create immutable Git tag
119121
env:

scripts/open-source.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ describe("open-source repository invariants", () => {
145145
expect(workflow).toContain("environment: npm-release");
146146
expect(workflow).toContain("vars.NPM_RELEASE_ENABLED == 'true'");
147147
expect(workflow).toContain("inputs.confirm == 'PUBLISH'");
148+
expect(workflow).toContain(["dist-tag: $", "{{ steps.release.outputs.dist-tag }}"].join(""));
149+
expect(workflow).toContain('bun run release:publish -- --tag "$NPM_DIST_TAG"');
148150
expect(workflow).toContain("id-token: write");
149151
expect(workflow).toContain("cancel-in-progress: false");
150152
expect(workflow).toContain("workflow_dispatch:");

scripts/release/publish.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ describe("release publish recovery", () => {
2828

2929
test("derives a safe npm dist-tag from prerelease versions", () => {
3030
expect(inferDistTag("1.0.1-beta.5")).toBe("beta");
31+
expect(inferDistTag("1.0.1-beta-a1b2c3d-20260720")).toBe("beta");
3132
expect(inferDistTag("2.0.0-rc.1")).toBe("rc");
3233
expect(inferDistTag("1.0.1")).toBeUndefined();
3334
});
@@ -44,6 +45,15 @@ describe("release publish recovery", () => {
4445
"--tag",
4546
"beta",
4647
]);
48+
expect(publishCommand(false, "1.2.3-beta-a1b2c3d-20260720", "beta")).toEqual([
49+
"npm",
50+
"publish",
51+
"--access",
52+
"public",
53+
"--provenance",
54+
"--tag",
55+
"beta",
56+
]);
4757
});
4858

4959
test("allows real publishing only inside GitHub Actions", () => {

scripts/release/publish.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ export function assertPublishEnvironment(
5353
}
5454

5555
export function inferDistTag(version: string): string | undefined {
56-
const prerelease = version.match(/^[0-9]+\.[0-9]+\.[0-9]+-([0-9A-Za-z-]+)(?:\.|$)/);
56+
const prerelease = version.match(/^[0-9]+\.[0-9]+\.[0-9]+-([0-9A-Za-z]+)(?:[.-]|$)/);
5757
return prerelease?.[1];
5858
}
5959

60-
export function publishCommand(dryRun: boolean, version: string): string[] {
60+
export function publishCommand(dryRun: boolean, version: string, distTag?: string): string[] {
6161
if (dryRun) return ["npm", "pack", "--dry-run"];
6262
const command = ["npm", "publish", "--access", "public", "--provenance"];
63-
const publishTag = inferDistTag(version);
63+
const publishTag = distTag ?? inferDistTag(version);
6464
if (publishTag) command.push("--tag", publishTag);
6565
return command;
6666
}
@@ -149,6 +149,11 @@ function trackedFileContents(path: string): string | undefined {
149149
function main(): number {
150150
const args = process.argv.slice(2);
151151
const dryRun = args.includes("--dry-run");
152+
const tagIndex = args.indexOf("--tag");
153+
const distTag = tagIndex === -1 ? undefined : args[tagIndex + 1];
154+
if (tagIndex !== -1 && (!distTag || !/^[a-z][a-z0-9-]*$/.test(distTag))) {
155+
throw new Error("--tag must be a lowercase npm dist-tag");
156+
}
152157
assertPublishEnvironment(dryRun);
153158

154159
console.log(`Publishing packages${dryRun ? " (dry-run)" : ""}...\n`);
@@ -166,7 +171,7 @@ function main(): number {
166171
continue;
167172
}
168173

169-
const cmd = publishCommand(dryRun, manifest.version);
174+
const cmd = publishCommand(dryRun, manifest.version, distTag);
170175

171176
console.log(`\n--- Publishing ${manifest.name} ---`);
172177
let originalLicense: string | undefined;

0 commit comments

Comments
 (0)