Skip to content

Commit 70e4081

Browse files
rix0rrrmrgrain
andauthored
chore: add CodeCov workflow (#79)
--- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license --------- Co-authored-by: Momo Kornher <[email protected]>
1 parent 1b91afb commit 70e4081

File tree

7 files changed

+104
-2
lines changed

7 files changed

+104
-2
lines changed

.gitattributes

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/codecov.yml

+33
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.gitignore

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projen/files.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projenrc.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Stability } from 'projen/lib/cdk';
44
import { BundleCli } from './projenrc/bundle';
55
import { ESLINT_RULES } from './projenrc/eslint';
66
import { JsiiBuild } from './projenrc/jsii';
7+
import { CodeCovWorkflow } from './projenrc/codecov';
78

89
// 5.7 sometimes gives a weird error in `ts-jest` in `@aws-cdk/cli-lib-alpha`
910
// https://github.com/microsoft/TypeScript/issues/60159
@@ -1093,7 +1094,7 @@ const toolkitLib = configureProject(
10931094
coverageThreshold: {
10941095
// this is very sad but we will get better
10951096
statements: 85,
1096-
branches: 77,
1097+
branches: 76,
10971098
functions: 77,
10981099
lines: 85,
10991100
},
@@ -1278,4 +1279,9 @@ new CdkCliIntegTestsWorkflow(repo, {
12781279
],
12791280
});
12801281

1282+
new CodeCovWorkflow(repo, {
1283+
restrictToRepos: ['aws-cdk-cli/aws-cdk-cli'],
1284+
packages: [cli.name],
1285+
});
1286+
12811287
repo.synth();

packages/@aws-cdk/toolkit-lib/jest.config.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

projenrc/codecov.ts

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { Component, github } from "projen";
2+
import { JobPermission } from "projen/lib/github/workflows-model";
3+
import { TypeScriptProject } from "projen/lib/typescript";
4+
5+
export interface CodeCovWorkflowProps {
6+
readonly restrictToRepos: string[];
7+
readonly packages: string[];
8+
}
9+
10+
export class CodeCovWorkflow extends Component {
11+
public readonly workflow: github.GithubWorkflow;
12+
13+
constructor(repo: TypeScriptProject, props: CodeCovWorkflowProps) {
14+
super(repo);
15+
16+
if (!repo.github) {
17+
throw new Error('Given repository does not have a GitHub component');
18+
}
19+
20+
this.workflow = repo.github.addWorkflow('codecov');
21+
this.workflow.on({
22+
push: { branches: ['main'] },
23+
pullRequest: { branches: ['main'] },
24+
});
25+
26+
this.workflow.addJob('collect', {
27+
permissions: { idToken: JobPermission.WRITE },
28+
if: props.restrictToRepos.map(r => `github.repository == '${r}'`).join(' || '),
29+
steps: [
30+
github.WorkflowSteps.checkout(),
31+
{
32+
name: 'Set up Node',
33+
uses: 'actions/setup-node@v4',
34+
with: {
35+
'node-version': 'lts/*',
36+
},
37+
},
38+
{
39+
name: 'Install dependencies',
40+
run: 'yarn install',
41+
},
42+
{
43+
name: 'Build and test CLI',
44+
// The 'build' job includes running tests
45+
run: `yarn nx run ${props.packages.map(p => `${p}:build`).join(' ')}`,
46+
},
47+
{
48+
name: 'Upload results to Codecov',
49+
uses: 'codecov/codecov-action@v5',
50+
with: {
51+
files: props.packages.map(p => `packages/${p}/coverage/cobertura-coverage.xml`).join(','),
52+
fail_ci_if_error: true,
53+
flags: 'suite.unit',
54+
use_oidc: true
55+
},
56+
},
57+
],
58+
});
59+
}
60+
}

0 commit comments

Comments
 (0)