|
2 | 2 | const shell = require('shelljs') |
3 | 3 |
|
4 | 4 | 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 |
7 | 23 |
|
8 | 24 | // create the release branch |
9 | | -const releaseBranchCreate = shell.exec(`git branch ${releaseBranchName}`, silent) |
| 25 | +const releaseBranchCreate = shell.exec(`git branch ${RELEASE_BRANCH_NAME}`, silent) |
10 | 26 | if (releaseBranchCreate.code === 0) { |
11 | | - shell.echo(`Created ${releaseBranchName} branch`) |
| 27 | + shell.echo(`Created ${RELEASE_BRANCH_NAME} branch`) |
12 | 28 | } else { |
13 | | - shell.echo(`Error: Could not create ${releaseBranchName} branch.`) |
| 29 | + shell.echo(`Error: Could not create ${RELEASE_BRANCH_NAME} branch.`) |
14 | 30 | console.log(releaseBranchCreate.stderr || releaseBranchCreate.stdout) |
15 | 31 | shell.exit(1) |
16 | 32 | } |
17 | 33 |
|
18 | 34 | // checkout the release branch |
19 | | -const releaseBranchCheckout = shell.exec(`git checkout ${releaseBranchName}`, silent) |
| 35 | +const releaseBranchCheckout = shell.exec(`git checkout ${RELEASE_BRANCH_NAME}`, silent) |
20 | 36 | if (releaseBranchCheckout.code === 0) { |
21 | | - shell.echo(`Checked out the ${releaseBranchName} branch.`) |
| 37 | + shell.echo(`Checked out the ${RELEASE_BRANCH_NAME} branch.`) |
22 | 38 | } else { |
23 | | - shell.echo(`Error: Could not checkout the ${releaseBranchName} branch.`) |
| 39 | + shell.echo(`Error: Could not checkout the ${RELEASE_BRANCH_NAME} branch.`) |
24 | 40 | console.log(releaseBranchCheckout.stderr || releaseBranchCheckout.stdout) |
25 | 41 | shell.exit(1) |
26 | 42 | } |
@@ -110,25 +126,35 @@ if (commitChanges.code === 0) { |
110 | 126 | shell.exit(1) |
111 | 127 | } |
112 | 128 |
|
| 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 | + |
113 | 139 | // checkout the master branch |
114 | | -const masterCheckout = shell.exec(`git checkout ${masterBranchName}`, silent) |
| 140 | +const masterCheckout = shell.exec(`git checkout ${MASTER_BRANCH_NAME}`, silent) |
115 | 141 | if (masterCheckout.code === 0) { |
116 | | - shell.echo(`Checked out the ${masterBranchName} branch`) |
| 142 | + shell.echo(`Checked out the ${MASTER_BRANCH_NAME} branch`) |
117 | 143 | } else { |
118 | | - shell.echo(`Error: Could not checkout the ${masterBranchName} branch.`) |
| 144 | + shell.echo(`Error: Could not checkout the ${MASTER_BRANCH_NAME} branch.`) |
119 | 145 | console.log(masterCheckout.stderr || masterCheckout.stdout) |
120 | 146 | shell.exit(1) |
121 | 147 | } |
122 | 148 |
|
123 | 149 | // 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 | +} |
132 | 158 |
|
133 | 159 | // install vendor deps back |
134 | 160 | const vendorInstallAll = shell.exec('composer install', silent) |
|
0 commit comments