Skip to content

Commit

Permalink
feat(codebuild): adds report group type property (aws#20178)
Browse files Browse the repository at this point in the history
fixes aws#14279.
Introduces optional property to the ReportGroup to define the type of the report group (either 'TEST' or 'CODE_COVERAGE'). It just passes down the property to the underlying CfnReportGroup.

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [x] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)?
	* [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
daschaa authored Jun 3, 2022
1 parent 4537b3f commit 15bcc3c
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
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: codebuild.ReportGroupType.CODE_COVERAGE
});

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
*/
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
23 changes: 23 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,26 @@ describe('Test Reports Groups', () => {
"UpdateReplacePolicy": "Delete",
});
});

test('can be created with type=CODE_COVERAGE', () => {
const stack = new cdk.Stack();

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

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

test('defaults to report group type=TEST when not specified explicitly', () => {
const stack = new cdk.Stack();

new codebuild.ReportGroup(stack, 'ReportGroup', {});

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

0 comments on commit 15bcc3c

Please sign in to comment.