Skip to content
Merged
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
15 changes: 13 additions & 2 deletions scripts/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { join } from "node:path";

// Bun cannot perform npm OIDC publishing. Pack with Bun to resolve `workspace:*`,
// then publish the tarball with npm for OIDC authentication and provenance.
// `New tag: <name>@<version>` is consumed by changesets/action.
// Create an annotated git tag, then print `New tag: <name>@<version>` so
// changesets/action can push the tag and open a GitHub Release.
// Existing registry versions are skipped so partial releases can be retried.
import { $ } from "bun";

Expand All @@ -19,6 +20,14 @@ async function isAlreadyPublished(
return res.exitCode === 0;
}

async function ensureReleaseTag(tag: string): Promise<void> {
const exists = await $`git rev-parse -q --verify ${`refs/tags/${tag}`}`
.quiet()
.nothrow();
if (exists.exitCode === 0) return;
await $`git tag -a ${tag} -m ${tag}`;
}

let published = 0;
for (const entry of readdirSync(PACKAGES_DIR, { withFileTypes: true })) {
if (!entry.isDirectory()) continue;
Expand Down Expand Up @@ -48,7 +57,9 @@ for (const entry of readdirSync(PACKAGES_DIR, { withFileTypes: true })) {
}

await $`npm publish ${tarball} --provenance --access public`.cwd(dir);
console.log(`New tag: ${pkg.name}@${pkg.version}`);
const tag = `${pkg.name}@${pkg.version}`;
await ensureReleaseTag(tag);
console.log(`New tag: ${tag}`);
published++;
}

Expand Down
Loading