Skip to content

Commit d2c8a90

Browse files
committed
Add release level options to release script.
1 parent 436c7aa commit d2c8a90

File tree

2 files changed

+48
-20
lines changed

2 files changed

+48
-20
lines changed

bin/release.js

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,41 @@
22
const shell = require('shelljs')
33

44
const silent = { silent: true }
5-
const releaseBranchName = 'release'
6-
const masterBranchName = 'ci'
5+
const RELEASE_BRANCH_NAME = 'release'
6+
const MASTER_BRANCH_NAME = 'ci'
7+
8+
const RELEASE_MAJOR = 'major'
9+
const RELEASE_MINOR = 'minor'
10+
const RELEASE_PATCH = 'patch'
11+
12+
const releaseLevel = process.argv[2]
13+
if (
14+
releaseLevel !== RELEASE_MAJOR &&
15+
releaseLevel !== RELEASE_MINOR &&
16+
releaseLevel !== RELEASE_PATCH
17+
) {
18+
shell.echo(`Error: The provided release level is incorrect: ${releaseLevel}. Allowed: ${RELEASE_MAJOR}, ${RELEASE_MINOR}, ${RELEASE_PATCH}`)
19+
shell.exit(1)
20+
}
21+
22+
return
723

824
// create the release branch
9-
const releaseBranchCreate = shell.exec(`git branch ${releaseBranchName}`, silent)
25+
const releaseBranchCreate = shell.exec(`git branch ${RELEASE_BRANCH_NAME}`, silent)
1026
if (releaseBranchCreate.code === 0) {
11-
shell.echo(`Created ${releaseBranchName} branch`)
27+
shell.echo(`Created ${RELEASE_BRANCH_NAME} branch`)
1228
} else {
13-
shell.echo(`Error: Could not create ${releaseBranchName} branch.`)
29+
shell.echo(`Error: Could not create ${RELEASE_BRANCH_NAME} branch.`)
1430
console.log(releaseBranchCreate.stderr || releaseBranchCreate.stdout)
1531
shell.exit(1)
1632
}
1733

1834
// checkout the release branch
19-
const releaseBranchCheckout = shell.exec(`git checkout ${releaseBranchName}`, silent)
35+
const releaseBranchCheckout = shell.exec(`git checkout ${RELEASE_BRANCH_NAME}`, silent)
2036
if (releaseBranchCheckout.code === 0) {
21-
shell.echo(`Checked out the ${releaseBranchName} branch.`)
37+
shell.echo(`Checked out the ${RELEASE_BRANCH_NAME} branch.`)
2238
} else {
23-
shell.echo(`Error: Could not checkout the ${releaseBranchName} branch.`)
39+
shell.echo(`Error: Could not checkout the ${RELEASE_BRANCH_NAME} branch.`)
2440
console.log(releaseBranchCheckout.stderr || releaseBranchCheckout.stdout)
2541
shell.exit(1)
2642
}
@@ -110,25 +126,35 @@ if (commitChanges.code === 0) {
110126
shell.exit(1)
111127
}
112128

129+
// tag the release
130+
const releaseTagging = shell.exec(`npm version ${releaseLevel}`)
131+
if (releaseTagging.code === 0) {
132+
shell.echo('Tag the release.')
133+
} else {
134+
shell.echo('Error: Could not tag the release.')
135+
console.log(releaseTagging.stderr)
136+
shell.exit(1)
137+
}
138+
113139
// checkout the master branch
114-
const masterCheckout = shell.exec(`git checkout ${masterBranchName}`, silent)
140+
const masterCheckout = shell.exec(`git checkout ${MASTER_BRANCH_NAME}`, silent)
115141
if (masterCheckout.code === 0) {
116-
shell.echo(`Checked out the ${masterBranchName} branch`)
142+
shell.echo(`Checked out the ${MASTER_BRANCH_NAME} branch`)
117143
} else {
118-
shell.echo(`Error: Could not checkout the ${masterBranchName} branch.`)
144+
shell.echo(`Error: Could not checkout the ${MASTER_BRANCH_NAME} branch.`)
119145
console.log(masterCheckout.stderr || masterCheckout.stdout)
120146
shell.exit(1)
121147
}
122148

123149
// delete the release branch
124-
// const releaseBranchDelete = shell.exec(`git branch -D ${releaseBranchName}`, silent)
125-
// if (releaseBranchDelete.code === 0) {
126-
// shell.echo(`Deleted ${releaseBranchName} branch.`)
127-
// } else {
128-
// shell.echo(`Error: Could not delete ${releaseBranchName} branch.`)
129-
// console.log(releaseBranchDelete.stderr || releaseBranchDelete.stdout)
130-
// shell.exit(1)
131-
// }
150+
const releaseBranchDelete = shell.exec(`git branch -D ${RELEASE_BRANCH_NAME}`, silent)
151+
if (releaseBranchDelete.code === 0) {
152+
shell.echo(`Deleted ${RELEASE_BRANCH_NAME} branch.`)
153+
} else {
154+
shell.echo(`Error: Could not delete ${RELEASE_BRANCH_NAME} branch.`)
155+
console.log(releaseBranchDelete.stderr || releaseBranchDelete.stdout)
156+
shell.exit(1)
157+
}
132158

133159
// install vendor deps back
134160
const vendorInstallAll = shell.exec('composer install', silent)

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
},
1212
"scripts": {
1313
"test": "echo \"Error: no test specified\" && exit 1",
14-
"release-patch": "bin-release"
14+
"release-patch": "bin-release patch",
15+
"release-minor": "bin-release minor",
16+
"release-major": "bin-release major"
1517
},
1618
"repository": {
1719
"type": "git",

0 commit comments

Comments
 (0)