Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"package": "npx ncc build src/index.ts -o dist --source-map --license licenses.txt",
"package:watch": "npm run package -- --watch",
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules npx jest",
"release": "node script/release.js",
"all": "npm run format:write && npm run lint && npm run test && npm run coverage && npm run package"
},
"license": "MIT",
Expand Down
64 changes: 0 additions & 64 deletions script/release

This file was deleted.

78 changes: 78 additions & 0 deletions script/release.js
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
Copy link
Contributor

@matejchalk matejchalk Mar 4, 2025

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.


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)
}
Loading