|
1 |
| -import {bold} from 'chalk'; |
2 | 1 | import {spawnSync} from 'child_process';
|
3 | 2 | import {buildConfig} from 'material2-build-tools';
|
4 | 3 |
|
5 | 4 | /** Regular expression that matches version names and the individual version segments. */
|
6 | 5 | export const versionNameRegex = /^(\d+)\.(\d+)\.(\d+)(?:-(alpha|beta|rc)\.(\d)+)?/;
|
7 | 6 |
|
8 |
| -/** Regular expression that matches publish branch names and their Semver digits. */ |
9 |
| -const publishBranchNameRegex = /^([0-9]+)\.([x0-9]+)(?:\.([x0-9]+))?$/; |
10 |
| - |
11 | 7 | /** Checks if the specified version can be released from the current Git branch. */
|
12 | 8 | export function checkPublishBranch(version: string) {
|
13 | 9 | const versionType = getSemverVersionType(version);
|
14 | 10 | const branchName = spawnSync('git', ['symbolic-ref', '--short', 'HEAD'],
|
15 | 11 | {cwd: buildConfig.projectDir}).stdout.toString().trim();
|
16 | 12 |
|
17 |
| - if (branchName === 'master') { |
18 |
| - if (versionType === 'major') { |
19 |
| - return; |
20 |
| - } |
21 |
| - |
22 |
| - throw `Publishing of "${versionType}" releases should not happen inside of the ` + |
23 |
| - `${bold('master')} branch.`; |
24 |
| - } |
25 | 13 |
|
26 |
| - const branchNameMatch = branchName.match(publishBranchNameRegex) || []; |
27 |
| - const branchDigits = branchNameMatch.slice(1, 4); |
| 14 | + // TODO(devversion): also check the the local branch's HEAD sha matches upstream. |
| 15 | + // TODO(devversion): also check that the version is a single increment of the previous release. |
| 16 | + // TODO(devversion): minor releases can also be published from master if there isn't a minor |
| 17 | + // branch for that major range yet. |
| 18 | + const [major, minor] = version.split('.'); |
28 | 19 |
|
29 |
| - if (branchDigits[2] === 'x' && versionType !== 'patch') { |
30 |
| - throw `Cannot publish a "${versionType}" release inside of a patch branch (${branchName})`; |
| 20 | + let expectedBranch = ''; |
| 21 | + if (versionType === 'major') { |
| 22 | + expectedBranch = 'master'; |
| 23 | + } else if (versionType === 'minor') { |
| 24 | + expectedBranch = `${major}.x`; |
| 25 | + } else if (versionType === 'patch') { |
| 26 | + expectedBranch = `${major}.${minor}.x`; |
31 | 27 | }
|
32 | 28 |
|
33 |
| - if (branchDigits[1] === 'x' && versionType !== 'minor') { |
34 |
| - throw `Cannot publish a "${versionType}" release inside of a minor branch (${branchName})`; |
| 29 | + if (branchName !== expectedBranch) { |
| 30 | + throw `A ${versionType} release must be done from the ${expectedBranch} branch.`; |
35 | 31 | }
|
36 |
| - |
37 |
| - throw `Cannot publish a "${versionType}" release from branch: "${branchName}". Releases should ` |
38 |
| - + `be published from "master" or the according publish branch (e.g. "6.x", "6.4.x")`; |
39 | 32 | }
|
40 | 33 |
|
41 | 34 | /**
|
|
0 commit comments