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

feat(codebuild): adds report group type property #20178

Merged
merged 15 commits into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from 8 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
27 changes: 26 additions & 1 deletion packages/@aws-cdk/aws-codebuild/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,32 @@ const project = new codebuild.Project(this, 'Project', {
});
```

If you do that, you need to grant the project's role permissions to write reports to that report group:
For a code coverage report, you can specify a report group with the code coverage report group type.

```ts
declare const source: codebuild.Source;

// create a new ReportGroup
const reportGroup = new codebuild.ReportGroup(this, 'ReportGroup', {
type: ReportGroupType.CODE_COVERAGE
daschaa marked this conversation as resolved.
Show resolved Hide resolved
});

const project = new codebuild.Project(this, 'Project', {
source,
buildSpec: codebuild.BuildSpec.fromObject({
// ...
reports: {
[reportGroup.reportGroupArn]: {
files: '**/*',
'base-directory': 'build/coverage-report.xml',
'file-format': 'JACOCOXML'
},
},
}),
});
```

If you specify a report group, you need to grant the project's role permissions to write reports to that report group:

```ts
declare const project: codebuild.Project;
Expand Down
26 changes: 25 additions & 1 deletion packages/@aws-cdk/aws-codebuild/lib/report-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ abstract class ReportGroupBase extends cdk.Resource implements IReportGroup {
}
}

/**
* The type of reports in the report group.
*/
export enum ReportGroupType {
/**
* The report group contains test reports.
*/
TEST = 'TEST',
/**
* The report group contains code coverage reports.
*/
CODE_COVERAGE = 'CODE_COVERAGE'
}

/**
* Construction properties for {@link ReportGroup}.
*/
Expand Down Expand Up @@ -93,6 +107,16 @@ export interface ReportGroupProps {
* @default RemovalPolicy.RETAIN
*/
readonly removalPolicy?: cdk.RemovalPolicy;

/**
* The type of report group. This can be one of the following values:
*
* - **TEST** - The report group contains test reports.
* - **CODE_COVERAGE** - The report group contains code coverage reports.
*
* @default - TEST
daschaa marked this conversation as resolved.
Show resolved Hide resolved
*/
readonly type?: ReportGroupType
}

/**
Expand Down Expand Up @@ -125,7 +149,7 @@ export class ReportGroup extends ReportGroupBase {
});

const resource = new CfnReportGroup(this, 'Resource', {
type: 'TEST',
type: props.type ? props.type : ReportGroupType.TEST,
exportConfig: {
exportConfigType: props.exportBucket ? 'S3' : 'NO_EXPORT',
s3Destination: props.exportBucket
Expand Down
13 changes: 13 additions & 0 deletions packages/@aws-cdk/aws-codebuild/test/report-group.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as kms from '@aws-cdk/aws-kms';
import * as s3 from '@aws-cdk/aws-s3';
import * as cdk from '@aws-cdk/core';
import * as codebuild from '../lib';
import { ReportGroupType } from '../lib';

/* eslint-disable quote-props */
/* eslint-disable quotes */
Expand Down Expand Up @@ -142,4 +143,16 @@ describe('Test Reports Groups', () => {
"UpdateReplacePolicy": "Delete",
});
});

test('can be created with type=CODE_COVERAGE', () => {
daschaa marked this conversation as resolved.
Show resolved Hide resolved
const stack = new cdk.Stack();

new codebuild.ReportGroup(stack, 'ReportGroup', {
type: ReportGroupType.CODE_COVERAGE,
});

Template.fromStack(stack).hasResourceProperties('AWS::CodeBuild::ReportGroup', {
"Type": "CODE_COVERAGE",
});
});
});