-
-
Notifications
You must be signed in to change notification settings - Fork 530
/
beta-release.js
77 lines (56 loc) · 2.3 KB
/
beta-release.js
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
/* eslint-disable @typescript-eslint/no-var-requires */
const util = require('util')
const exec = util.promisify(require('child_process').exec)
const package = require('./package.json')
const args = require('minimist')(process.argv.slice(2))
const issueNumber = args['issue']
console.log(issueNumber)
const runCommand = async (command) => {
return new Promise((resolve) => {
exec(command, (error, stdout, stderr) => {
resolve({ error, stdout, stderr })
})
})
}
const AutoBetaRelease = async () => {
// get all the versions of the package from npm
const { stdout } = await runCommand(`npm view . versions --json`)
// show npm published versions of this package
console.log(stdout)
// check if there is a beta release with the same issue number on published versions
const arrayOfBetaReleases = JSON.parse(stdout).filter((version) =>
version.includes(`${package.version}-beta.${issueNumber}`),
)
let fullLastBetaRelease = null
// if yes, get the latest beta release. Output: 1.0.0-beta.1.rc.0
if (arrayOfBetaReleases.length) {
fullLastBetaRelease = arrayOfBetaReleases[arrayOfBetaReleases.length - 1]
}
console.log('Last Beta Release: ', fullLastBetaRelease)
let nextBetaReleaseVersion = 0
if (fullLastBetaRelease) {
const lastBetaReleaseRCVersionArray = fullLastBetaRelease.match(/rc.+[0-9]+/g)
const lastBetaReleaseRCVersion =
lastBetaReleaseRCVersionArray && lastBetaReleaseRCVersionArray.length
? lastBetaReleaseRCVersionArray[0]
: null
const lastBetaReleaseVersion = lastBetaReleaseRCVersion
? lastBetaReleaseRCVersion.split('.')[1]
: 0
nextBetaReleaseVersion = parseInt(lastBetaReleaseVersion, 10) + 1
}
// next beta release version. Output: 1.0.0-beta.1.rc.1
const nextBetaReleaseVesionFull = `${package.version}-beta.${issueNumber}.rc.${nextBetaReleaseVersion}`
// update the beta version on package.json
const { error } = await runCommand(
`npm version ${nextBetaReleaseVesionFull} --no-git-tag-version`,
)
if (error) {
console.error(error)
return
}
// the beta version is already updated on package.json on the next line
console.log('Next Beta version: ', `${nextBetaReleaseVesionFull}`)
await runCommand(`echo "NEW_VERSION=${nextBetaReleaseVesionFull}" >> $GITHUB_ENV`)
}
AutoBetaRelease()