-
Notifications
You must be signed in to change notification settings - Fork 0
fix(ci): make release publish step idempotent #20
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| #!/usr/bin/env node | ||
| // scripts/publish-if-new.mjs | ||
| // Idempotent npm publish: skip if the current version is already on the registry. | ||
| // | ||
| // Why: release.yml runs on every push to main. changesets/action only opens a | ||
| // "Version Packages" PR when there are pending changesets — on pushes that | ||
| // merge non-changeset PRs (e.g. CI tweaks), the action falls through to the | ||
| // publish step. Without this guard, `npm publish` errors out with | ||
| // "You cannot publish over the previously published versions" and fails the | ||
| // release job for every infra-only merge. | ||
| // | ||
| // Direct `npm publish` (rather than `changeset publish`) is intentional — | ||
| // the project uses npm 11.5.1+ trusted publishing with provenance, which | ||
| // `changeset publish` doesn't pass through cleanly. | ||
|
|
||
| import { execFileSync, spawnSync } from 'node:child_process'; | ||
| import { readFileSync } from 'node:fs'; | ||
| import { dirname, resolve } from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
|
|
||
| const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
| const pkgPath = resolve(__dirname, '../packages/whisper/package.json'); | ||
| const pkg = JSON.parse(readFileSync(pkgPath, 'utf8')); | ||
| const { name, version } = pkg; | ||
|
|
||
| let published = ''; | ||
| try { | ||
| published = execFileSync('npm', ['view', `${name}@${version}`, 'version'], { | ||
| encoding: 'utf8', | ||
| stdio: ['ignore', 'pipe', 'pipe'], | ||
| }).trim(); | ||
| } catch (err) { | ||
| // E404 from `npm view` means the version is not published — that's the | ||
| // happy "publish me" path. Anything else is a real registry/network error. | ||
| const stderr = err.stderr?.toString() ?? ''; | ||
| if (!stderr.includes('E404') && !stderr.includes('code E404')) { | ||
| process.stderr.write(stderr); | ||
| process.exit(err.status ?? 1); | ||
| } | ||
| } | ||
|
|
||
| if (published === version) { | ||
| console.log(`publish-if-new: ${name}@${version} already on registry — skipping publish.`); | ||
| process.exit(0); | ||
| } | ||
|
|
||
| console.log(`publish-if-new: publishing ${name}@${version}...`); | ||
| const result = spawnSync('npm', ['publish', '--access', 'public', '--provenance'], { | ||
| cwd: resolve(__dirname, '../packages/whisper'), | ||
| stdio: 'inherit', | ||
| }); | ||
| process.exit(result.status ?? 1); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.