generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: make release script OS-agnostic by migrating from bash to node #148
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 was deleted.
Oops, something went wrong.
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,78 @@ | ||
| /** | ||
| * This is a helper script to tag and push a new release. GitHub Actions use | ||
| * release tags to allow users to select a specific version of the action to use. | ||
| * | ||
| * See: https://github.com/actions/typescript-action#publishing-a-new-release | ||
| * | ||
| * This script will do the following: | ||
| * | ||
| * 1. Get the latest release tag | ||
| * 2. Prompt the user for a new release tag | ||
| * 3. Tag the new release | ||
| * 4. Push the new tag to the remote | ||
| * | ||
| * Usage: node script/release.js | ||
| */ | ||
|
|
||
| import readline from 'node:readline/promises' | ||
| import { stdin as input, stdout as output } from 'node:process' | ||
| import { simpleGit } from 'simple-git' | ||
|
|
||
| // Terminal colors | ||
| const OFF = '\x1B[0m' | ||
| const RED = '\x1B[0;31m' | ||
| const GREEN = '\x1B[0;32m' | ||
| const BLUE = '\x1B[0;34m' | ||
|
|
||
| const git = simpleGit() | ||
|
|
||
| try { | ||
| // Get the latest release tag | ||
| let latestTag = (await git.tags()).latest | ||
|
|
||
| if (!latestTag) { | ||
| // There are no existing release tags | ||
| console.log( | ||
| 'No tags found (yet) - Continue to create and push your first tag' | ||
| ) | ||
| latestTag = '[unknown]' | ||
| } | ||
|
|
||
| // Display the latest release tag | ||
| console.log(`The latest release tag is: ${BLUE}${latestTag}${OFF}`) | ||
|
|
||
| // Prompt the user for the new release tag | ||
| const rl = readline.createInterface({ input, output }) | ||
| const newTag = ( | ||
| await rl.question('Enter a new release tag (vX.X.X format): ') | ||
| ).trim() | ||
| rl.close() | ||
|
|
||
| // Validate if the new release tag is in the format vX.X.X | ||
| const tagRegex = /^v\d+\.\d+\.\d+$/ | ||
| if (tagRegex.test(newTag)) { | ||
| console.log(`Tag: ${BLUE}${newTag}${OFF} is valid`) | ||
| } else { | ||
| console.error( | ||
| `Tag: ${BLUE}${newTag}${OFF} is ${RED}not valid${OFF} (must be in vX.X.X format)` | ||
| ) | ||
| process.exit(1) | ||
| } | ||
|
|
||
| // Tag the new release | ||
| await git.addAnnotatedTag(newTag, `${newTag} Release`) | ||
| console.log(`${GREEN}Tagged: ${newTag}${OFF}`) | ||
|
|
||
| // Tag major version (extract the "vX" from "vX.X.X") | ||
| const newMajorTag = newTag.split('.')[0] | ||
| await git.tag(['-fa', newMajorTag, '-m', `Update ${newMajorTag} tag`]) | ||
| console.log(`${GREEN}Tagged: ${newMajorTag}${OFF}`) | ||
|
|
||
| // Push the new tag to the remote | ||
| await git.push(['--tags', '--force']) | ||
| console.log(`${GREEN}Release tag pushed to remote${OFF}`) | ||
| console.log(`${GREEN}Done!${OFF}`) | ||
| } catch (error) { | ||
| console.error(`${RED}Error:${OFF} ${error}`) | ||
| process.exit(1) | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
This is a little different than the original bash command -
git describe --tags --match='v*.*.*' "$(git rev-list --tags --max-count=1)". I guess non-version tags might cause issues. But it's probably an edge case, and the latest tag is only informative anyway, so not a blocker.