-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.js
More file actions
78 lines (67 loc) · 2.26 KB
/
release.js
File metadata and controls
78 lines (67 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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)
}