Skip to content

Commit 10bce89

Browse files
authored
fix(cli-integ-tests): integ workflow is not usable in status checks (#785)
* fix(cli-integ-tests): integ workflow is not usable in status checks * typo fixup
1 parent a53c4e2 commit 10bce89

File tree

2 files changed

+128
-92
lines changed

2 files changed

+128
-92
lines changed

src/cdk-cli-integ-tests.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class CdkCliIntegTestsWorkflow extends Component {
7777
super(repo);
7878

7979
const buildWorkflow = repo.buildWorkflow;
80-
const runTestsWorkflow = repo.github?.addWorkflow('build-and-integ');
80+
const runTestsWorkflow = repo.github?.addWorkflow('integ');
8181
if (!buildWorkflow || !runTestsWorkflow) {
8282
throw new Error('Expected build and run tests workflow');
8383
}
@@ -98,7 +98,7 @@ export class CdkCliIntegTestsWorkflow extends Component {
9898
// - The build job is only one job, versus the tests which are a matrix build.
9999
// If the matrix test job needs approval, the Pull Request timeline gets spammed
100100
// with an approval request for every individual run.
101-
runTestsWorkflow.addJob('build', {
101+
runTestsWorkflow.addJob('prepare', {
102102
environment: props.approvalEnvironment,
103103
runsOn: [props.buildRunsOn],
104104
permissions: {
@@ -178,10 +178,13 @@ export class CdkCliIntegTestsWorkflow extends Component {
178178
proxy: 'npmjs',
179179
};
180180

181-
runTestsWorkflow.addJob('integ', {
181+
// We create a matrix job for the test.
182+
// This job will run all the different test suites in parallel.
183+
const JOB_INTEG_MATRIX = 'integ_matrix';
184+
runTestsWorkflow.addJob(JOB_INTEG_MATRIX, {
182185
environment: props.testEnvironment,
183186
runsOn: [props.testRunsOn],
184-
needs: ['build'],
187+
needs: ['prepare'],
185188
permissions: {
186189
contents: github.workflows.JobPermission.READ,
187190
idToken: github.workflows.JobPermission.WRITE,
@@ -331,5 +334,27 @@ export class CdkCliIntegTestsWorkflow extends Component {
331334
},
332335
],
333336
});
337+
338+
// Add a job that collates all matrix jobs into a single status
339+
// This is required so that we can setup required status checks
340+
// and if we ever change the test matrix, we don't need to update
341+
// the status check configuration.
342+
runTestsWorkflow.addJob('integ', {
343+
permissions: {},
344+
runsOn: [props.testRunsOn],
345+
needs: [JOB_INTEG_MATRIX],
346+
if: 'always()',
347+
steps: [
348+
{
349+
name: 'Integ test result',
350+
run: `echo \${{ needs.${JOB_INTEG_MATRIX}.result }}`,
351+
},
352+
{
353+
if: `\${{ needs.${JOB_INTEG_MATRIX}.result != 'success' }}`,
354+
name: 'Set status based on matrix job',
355+
run: 'exit 1',
356+
},
357+
],
358+
});
334359
}
335360
}

test/__snapshots__/cdk-cli-integ-tests.test.ts.snap

Lines changed: 99 additions & 88 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)