Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add CodeCov workflow #79

Merged
merged 4 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes

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

33 changes: 33 additions & 0 deletions .github/workflows/codecov.yml

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

1 change: 1 addition & 0 deletions .gitignore

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

1 change: 1 addition & 0 deletions .projen/files.json

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

8 changes: 7 additions & 1 deletion .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Stability } from 'projen/lib/cdk';
import { BundleCli } from './projenrc/bundle';
import { ESLINT_RULES } from './projenrc/eslint';
import { JsiiBuild } from './projenrc/jsii';
import { CodeCovWorkflow } from './projenrc/codecov';

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

new CodeCovWorkflow(repo, {
restrictToRepos: ['aws-cdk-cli/aws-cdk-cli'],
packages: [cli.name],
});

repo.synth();
2 changes: 1 addition & 1 deletion packages/@aws-cdk/toolkit-lib/jest.config.json

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

60 changes: 60 additions & 0 deletions projenrc/codecov.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { Component, github } from "projen";
import { JobPermission } from "projen/lib/github/workflows-model";
import { TypeScriptProject } from "projen/lib/typescript";

export interface CodeCovWorkflowProps {
readonly restrictToRepos: string[];
readonly packages: string[];
}

export class CodeCovWorkflow extends Component {
public readonly workflow: github.GithubWorkflow;

constructor(repo: TypeScriptProject, props: CodeCovWorkflowProps) {
super(repo);

if (!repo.github) {
throw new Error('Given repository does not have a GitHub component');
}

this.workflow = repo.github.addWorkflow('codecov');
this.workflow.on({
push: { branches: ['main'] },
pullRequest: { branches: ['main'] },
});

this.workflow.addJob('collect', {
permissions: { idToken: JobPermission.WRITE },
if: props.restrictToRepos.map(r => `github.repository == '${r}'`).join(' || '),
steps: [
github.WorkflowSteps.checkout(),
{
name: 'Set up Node',
uses: 'actions/setup-node@v4',
with: {
'node-version': 'lts/*',
},
},
{
name: 'Install dependencies',
run: 'yarn install',
},
{
name: 'Build and test CLI',
// The 'build' job includes running tests
run: `yarn nx run ${props.packages.map(p => `${p}:build`).join(' ')}`,
},
{
name: 'Upload results to Codecov',
uses: 'codecov/codecov-action@v5',
with: {
files: props.packages.map(p => `packages/${p}/coverage/cobertura-coverage.xml`).join(','),
fail_ci_if_error: true,
flags: 'suite.unit',
use_oidc: true
},
},
],
});
}
}
Loading