Skip to content

Commit f9ad7d8

Browse files
committed
refactor(ng-dev): allow for perf workflows to be run for individual workflows (#2460)
Allow individual workflows to be run, and fan out CI job to multiple jobs via matrix. PR Close #2460
1 parent 81dd606 commit f9ad7d8

File tree

4 files changed

+50
-14
lines changed

4 files changed

+50
-14
lines changed

.github/workflows/perf.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ defaults:
1212
shell: bash
1313

1414
jobs:
15-
workflow-perf:
15+
list:
1616
timeout-minutes: 30
1717
runs-on: ubuntu-latest
18+
outputs:
19+
workflows: ${{ steps.workflows.outputs.workflows }}
1820
steps:
1921
# Because the checkout and setup node action is contained in the dev-infra repo, we must
2022
# checkout the repo to be able to run the action we have created. Other repos will skip
@@ -23,4 +25,22 @@ jobs:
2325
- uses: ./github-actions/npm/checkout-and-setup-node
2426
- uses: ./github-actions/bazel/setup
2527
- run: yarn install --immutable
26-
- run: yarn ng-dev perf workflows --json
28+
- id: workflows
29+
run: echo "workflows=$(yarn ng-dev perf workflows --list)" >> "$GITHUB_OUTPUT"
30+
31+
workflow:
32+
timeout-minutes: 30
33+
runs-on: ubuntu-latest
34+
needs: list
35+
strategy:
36+
matrix:
37+
workflow: ${{ fromJSON(needs.list.outputs.workflows) }}
38+
steps:
39+
# Because the checkout and setup node action is contained in the dev-infra repo, we must
40+
# checkout the repo to be able to run the action we have created. Other repos will skip
41+
# this step.
42+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
43+
- uses: ./github-actions/npm/checkout-and-setup-node
44+
- uses: ./github-actions/bazel/setup
45+
- run: yarn install --immutable
46+
- run: yarn ng-dev perf workflows --name ${{ matrix.workflow }}

.ng-dev/dx-perf-workflows.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
workflows:
2-
- name: Rerun a test
2+
rerun:
3+
name: Rerun a test
34
prepare:
45
- bazel clean;
56
- bazel build //ng-dev/utils/test;
@@ -10,7 +11,8 @@ workflows:
1011
cleanup:
1112
- git apply -R .ng-dev/perf-tests/test-rerun.diff;
1213

13-
- name: Build Everything
14+
build-everything:
15+
name: Build Everything
1416
prepare:
1517
- bazel clean;
1618
workflow:

ng-dev/perf/workflow/cli.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import {determineRepoBaseDirFromCwd} from '../../utils/repo-directory.js';
1414

1515
interface WorkflowsParams {
1616
configFile: string;
17-
json: boolean;
17+
list: boolean;
18+
name?: string;
1819
}
1920

2021
/** Builds the checkout pull request command. */
@@ -25,25 +26,38 @@ function builder(yargs: Argv) {
2526
type: 'string',
2627
description: 'The path to the workflow definitions in a yml file',
2728
})
28-
.option('json', {
29+
.option('list', {
2930
default: false,
3031
type: 'boolean',
31-
description: 'Whether to output the results as a json object',
32+
description: 'Whether to get back a list of workflows that can be executed',
33+
})
34+
.option('name', {
35+
type: 'string',
36+
description: 'A specific workflow to run by name',
3237
});
3338
}
3439

3540
/** Handles the checkout pull request command. */
36-
async function handler({configFile, json}: WorkflowsParams) {
41+
async function handler({configFile, list, name}: WorkflowsParams) {
3742
const workflows = await loadWorkflows(join(determineRepoBaseDirFromCwd(), configFile));
43+
44+
if (list) {
45+
process.stdout.write(JSON.stringify(Object.keys(workflows)));
46+
return;
47+
}
48+
49+
if (name) {
50+
const {duration} = await measureWorkflow(workflows[name]);
51+
process.stdout.write(JSON.stringify({[name]: duration}));
52+
return;
53+
}
54+
3855
const results: {[key: string]: number} = {};
39-
for (const workflow of workflows) {
56+
for (const workflow of Object.values(workflows)) {
4057
const {name, duration} = await measureWorkflow(workflow);
4158
results[name] = duration;
4259
}
43-
44-
if (json) {
45-
process.stdout.write(JSON.stringify(results));
46-
}
60+
process.stdout.write(JSON.stringify(results));
4761
}
4862

4963
/** yargs command module for checking out a PR. */

ng-dev/perf/workflow/loader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ export interface Workflow {
1010

1111
export async function loadWorkflows(src: string) {
1212
const rawWorkflows = await readFile(src, {encoding: 'utf-8'});
13-
return parse(rawWorkflows).workflows as Workflow[];
13+
return parse(rawWorkflows).workflows as {[key: string]: Workflow};
1414
}

0 commit comments

Comments
 (0)