-
Notifications
You must be signed in to change notification settings - Fork 474
Add script for tagging all npm packages for a release #8041
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
+120
−1
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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,98 @@ | ||
| #!/usr/bin/env node | ||
| /** | ||
| * Tag a published version of the main ReScript packages with a given dist-tag. | ||
| * | ||
| * Usage: | ||
| * node scripts/npmRelease.js --version 12.0.1 --tag next | ||
| * node scripts/npmRelease.js --version 12.0.1 --tag latest --otp 123456 | ||
| * | ||
| * - Runs `npm dist-tag add` for: rescript, @rescript/runtime, and all platform | ||
| * optional packages, reusing the same OTP so you only get prompted once. | ||
| * - Pass `--dry-run` to see the commands without executing them. | ||
| */ | ||
| import process from "node:process"; | ||
| import readline from "node:readline/promises"; | ||
| import { parseArgs } from "node:util"; | ||
| import { npm } from "../lib_dev/process.js"; | ||
|
|
||
| const packages = [ | ||
| "rescript", | ||
| "@rescript/runtime", | ||
| "@rescript/darwin-arm64", | ||
| "@rescript/darwin-x64", | ||
| "@rescript/linux-arm64", | ||
| "@rescript/linux-x64", | ||
| "@rescript/win32-x64", | ||
| ]; | ||
|
|
||
| async function promptForOtp(existingOtp) { | ||
| if (existingOtp) { | ||
| return existingOtp; | ||
| } | ||
| const rl = readline.createInterface({ | ||
| input: process.stdin, | ||
| output: process.stdout, | ||
| }); | ||
| const answer = await rl.question("npm one-time password: "); | ||
| rl.close(); | ||
| return answer.trim(); | ||
| } | ||
|
|
||
| async function runDistTag(pkg, version, tag, otp, dryRun) { | ||
| const spec = `${pkg}@${version}`; | ||
| const args = ["dist-tag", "add", spec, tag, "--otp", otp]; | ||
| if (dryRun) { | ||
| console.log(`[dry-run] npm ${args.join(" ")}`); | ||
| return; | ||
| } | ||
| console.log(`Tagging ${spec} as ${tag}...`); | ||
| await npm("dist-tag", ["add", spec, tag, "--otp", otp], { | ||
| stdio: "inherit", | ||
| throwOnFail: true, | ||
| }); | ||
| } | ||
|
|
||
| async function main() { | ||
| try { | ||
| const { values } = parseArgs({ | ||
| args: process.argv.slice(2), | ||
| strict: true, | ||
| options: { | ||
| version: { type: "string", short: "v" }, | ||
| tag: { type: "string", short: "t" }, | ||
| otp: { type: "string" }, | ||
| "dry-run": { type: "boolean" }, | ||
| }, | ||
| }); | ||
| if (!values.version || !values.tag) { | ||
| console.error( | ||
| "Usage: node scripts/npmRelease.js --version <version> --tag <tag> [--otp <code>] [--dry-run]", | ||
| ); | ||
| process.exitCode = 1; | ||
| return; | ||
| } | ||
| const otp = await promptForOtp(values.otp); | ||
| if (!otp) { | ||
| throw new Error("OTP is required to publish dist-tags."); | ||
| } | ||
| for (const pkg of packages) { | ||
| await runDistTag( | ||
| pkg, | ||
| values.version, | ||
| values.tag, | ||
| otp, | ||
| Boolean(values["dry-run"]), | ||
| ); | ||
| } | ||
| if (values["dry-run"]) { | ||
| console.log("Dry run complete."); | ||
| } else { | ||
| console.log("All packages tagged successfully."); | ||
| } | ||
| } catch (error) { | ||
| console.error(error.message || error); | ||
| process.exitCode = 1; | ||
| } | ||
| } | ||
|
|
||
| await main(); |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the lore here that this is such a labor intensive process?
Just curious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Labor intensive, well, you should have seen how these processes worked in earlier times. 🙈
The current procedure allows one to test the finished packages for a final time using
npm install rescript@ci, and then decide manually which tag to set.Ideas for further simplification/automation are of course welcome. If the final tag
latest/nextis to be set by CI automatically on a tag build (instead of just thecitag), it needs to know 100% when to use what, and especially avoid publishing versions from maintenance branches asnext/latest.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, I could be wrong, but that sounds like a bit of conditional logic in a script?
npm view rescript --jsoncan show the current latest, ci, next tags.If a maintenance branch needs to publish another 11, it can detect that a higher major exists. Stuff like that.
Again, I'm unfamiliar with what we are trying to achieve in the first place.