Skip to content

Commit

Permalink
fix(cli-integ-tests): integ workflow is not usable in status checks (#…
Browse files Browse the repository at this point in the history
…785)

* fix(cli-integ-tests): integ workflow is not usable in status checks

* typo fixup
  • Loading branch information
mrgrain authored Feb 17, 2025
1 parent a53c4e2 commit 10bce89
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 92 deletions.
33 changes: 29 additions & 4 deletions src/cdk-cli-integ-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class CdkCliIntegTestsWorkflow extends Component {
super(repo);

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

runTestsWorkflow.addJob('integ', {
// We create a matrix job for the test.
// This job will run all the different test suites in parallel.
const JOB_INTEG_MATRIX = 'integ_matrix';
runTestsWorkflow.addJob(JOB_INTEG_MATRIX, {
environment: props.testEnvironment,
runsOn: [props.testRunsOn],
needs: ['build'],
needs: ['prepare'],
permissions: {
contents: github.workflows.JobPermission.READ,
idToken: github.workflows.JobPermission.WRITE,
Expand Down Expand Up @@ -331,5 +334,27 @@ export class CdkCliIntegTestsWorkflow extends Component {
},
],
});

// Add a job that collates all matrix jobs into a single status
// This is required so that we can setup required status checks
// and if we ever change the test matrix, we don't need to update
// the status check configuration.
runTestsWorkflow.addJob('integ', {
permissions: {},
runsOn: [props.testRunsOn],
needs: [JOB_INTEG_MATRIX],
if: 'always()',
steps: [
{
name: 'Integ test result',
run: `echo \${{ needs.${JOB_INTEG_MATRIX}.result }}`,
},
{
if: `\${{ needs.${JOB_INTEG_MATRIX}.result != 'success' }}`,
name: 'Set status based on matrix job',
run: 'exit 1',
},
],
});
}
}
187 changes: 99 additions & 88 deletions test/__snapshots__/cdk-cli-integ-tests.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 10bce89

Please sign in to comment.