Skip to content

Commit bb56f80

Browse files
committed
ci: publish script now checks that master has next tag
1 parent 3d27986 commit bb56f80

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

scripts/publish.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
// tslint:disable:no-implicit-dependencies
9-
import { logging } from '@angular-devkit/core';
9+
import { logging, tags } from '@angular-devkit/core';
1010
import { spawnSync } from 'child_process';
1111
import { packages } from '../lib/packages';
1212
import build from './build';
1313

1414

15+
export interface PublishArgs {
16+
tag?: string;
17+
branchCheck?: boolean;
18+
}
19+
20+
1521
function _exec(command: string, args: string[], opts: { cwd?: string }, logger: logging.Logger) {
1622
const { status, error, stderr, stdout } = spawnSync(command, args, { ...opts });
1723

@@ -29,7 +35,28 @@ function _exec(command: string, args: string[], opts: { cwd?: string }, logger:
2935
}
3036

3137

32-
export default async function (args: { tag?: string }, logger: logging.Logger) {
38+
function _branchCheck(args: PublishArgs, logger: logging.Logger) {
39+
logger.info('Checking branch...');
40+
const ref = _exec('git', ['symbolic-ref', 'HEAD'], {}, logger);
41+
const branch = ref.trim().replace(/^refs\/heads\//, '');
42+
43+
switch (branch) {
44+
case 'master':
45+
if (args.tag !== 'next') {
46+
throw new Error(tags.oneLine`
47+
Releasing from master requires a next tag. Use --branchCheck=false to skip this check.
48+
`);
49+
}
50+
}
51+
}
52+
53+
54+
export default async function (args: PublishArgs, logger: logging.Logger) {
55+
if (args.branchCheck === undefined || args.branchCheck === true) {
56+
_branchCheck(args, logger);
57+
}
58+
59+
3360
logger.info('Building...');
3461
await build({}, logger.createChild('build'));
3562

0 commit comments

Comments
 (0)