Skip to content

Commit 4576863

Browse files
authored
chore: make publish version+branch check support minor and patch (#12910)
1 parent 59f401d commit 4576863

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

tools/gulp/tasks/publish/branch-check.ts

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,34 @@
1-
import {bold} from 'chalk';
21
import {spawnSync} from 'child_process';
32
import {buildConfig} from 'material2-build-tools';
43

54
/** Regular expression that matches version names and the individual version segments. */
65
export const versionNameRegex = /^(\d+)\.(\d+)\.(\d+)(?:-(alpha|beta|rc)\.(\d)+)?/;
76

8-
/** Regular expression that matches publish branch names and their Semver digits. */
9-
const publishBranchNameRegex = /^([0-9]+)\.([x0-9]+)(?:\.([x0-9]+))?$/;
10-
117
/** Checks if the specified version can be released from the current Git branch. */
128
export function checkPublishBranch(version: string) {
139
const versionType = getSemverVersionType(version);
1410
const branchName = spawnSync('git', ['symbolic-ref', '--short', 'HEAD'],
1511
{cwd: buildConfig.projectDir}).stdout.toString().trim();
1612

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-
}
2513

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('.');
2819

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`;
3127
}
3228

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.`;
3531
}
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")`;
3932
}
4033

4134
/**

0 commit comments

Comments
 (0)