Skip to content

Commit 4bce213

Browse files
AndrewKushnirjosephperrott
authored andcommitted
feat(dev-infra): add a command to verify NgBot YAML config syntax (angular#39071)
This commit adds a new command to the `ng-dev` suite, which verifies that the NgBot YAML config is correct. It also adds this command to the `lint` CircleCI job so that we execute this check while running CI. This should help prevent syntax errors similar to the one introduced in: angular@393ce55 PR Close angular#39071
1 parent 6205ed0 commit 4bce213

File tree

6 files changed

+73
-0
lines changed

6 files changed

+73
-0
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ jobs:
273273
- run: yarn -s ng-dev format changed $CI_GIT_BASE_REVISION --check
274274
- run: yarn -s ts-circular-deps:check
275275
- run: yarn -s ng-dev pullapprove verify
276+
- run: yarn -s ng-dev ngbot verify
276277
- run: yarn -s ng-dev commit-message validate-range --range $CI_COMMIT_RANGE
277278

278279
test:

dev-infra/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ ts_library(
1111
"//dev-infra/caretaker",
1212
"//dev-infra/commit-message",
1313
"//dev-infra/format",
14+
"//dev-infra/ngbot",
1415
"//dev-infra/pr",
1516
"//dev-infra/pullapprove",
1617
"//dev-infra/release",

dev-infra/cli.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {buildReleaseParser} from './release/cli';
1515
import {buildPrParser} from './pr/cli';
1616
import {captureLogOutputForCommand} from './utils/console';
1717
import {buildCaretakerParser} from './caretaker/cli';
18+
import {buildNgbotParser} from './ngbot/cli';
1819

1920
yargs.scriptName('ng-dev')
2021
.middleware(captureLogOutputForCommand)
@@ -27,6 +28,7 @@ yargs.scriptName('ng-dev')
2728
.command('release <command>', '', buildReleaseParser)
2829
.command('ts-circular-deps <command>', '', tsCircularDependenciesBuilder)
2930
.command('caretaker <command>', '', buildCaretakerParser)
31+
.command('ngbot <command>', false, buildNgbotParser)
3032
.wrap(120)
3133
.strict()
3234
.parse();

dev-infra/ngbot/BUILD.bazel

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
load("@npm_bazel_typescript//:index.bzl", "ts_library")
2+
3+
ts_library(
4+
name = "ngbot",
5+
srcs = [
6+
"cli.ts",
7+
"verify.ts",
8+
],
9+
module_name = "@angular/dev-infra-private/ngbot",
10+
visibility = ["//dev-infra:__subpackages__"],
11+
deps = [
12+
"//dev-infra/utils",
13+
"@npm//@types/node",
14+
"@npm//@types/yaml",
15+
"@npm//@types/yargs",
16+
"@npm//yaml",
17+
"@npm//yargs",
18+
],
19+
)

dev-infra/ngbot/cli.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
import * as yargs from 'yargs';
9+
import {verify} from './verify';
10+
11+
/** Build the parser for the NgBot commands. */
12+
export function buildNgbotParser(localYargs: yargs.Argv) {
13+
return localYargs.help().strict().demandCommand().command(
14+
'verify', 'Verify the NgBot config', {}, () => verify());
15+
}
16+
17+
if (require.main === module) {
18+
buildNgbotParser(yargs).parse();
19+
}

dev-infra/ngbot/verify.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
import {readFileSync} from 'fs';
9+
import {resolve} from 'path';
10+
import {parse as parseYaml} from 'yaml';
11+
12+
import {getRepoBaseDir} from '../utils/config';
13+
import {error, green, info, red} from '../utils/console';
14+
15+
export function verify() {
16+
/** Full path to NgBot config file */
17+
const NGBOT_CONFIG_YAML_PATH = resolve(getRepoBaseDir(), '.github/angular-robot.yml');
18+
19+
/** The NgBot config file */
20+
const ngBotYaml = readFileSync(NGBOT_CONFIG_YAML_PATH, 'utf8');
21+
22+
try {
23+
// Try parsing the config file to verify that the syntax is correct.
24+
parseYaml(ngBotYaml);
25+
info(`${green('√')} Valid NgBot YAML config`);
26+
} catch (e) {
27+
error(`${red('!')} Invalid NgBot YAML config`);
28+
error(e);
29+
process.exitCode = 1;
30+
}
31+
}

0 commit comments

Comments
 (0)