From 15bcc3c5feb36f069538d89d7e6c36a2671bb2c5 Mon Sep 17 00:00:00 2001 From: Joshua Weber <57131123+daschaa@users.noreply.github.com> Date: Sat, 4 Jun 2022 01:14:21 +0200 Subject: [PATCH] feat(codebuild): adds report group type property (#20178) fixes #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* --- packages/@aws-cdk/aws-codebuild/README.md | 27 ++++++++++++++++++- .../aws-codebuild/lib/report-group.ts | 26 +++++++++++++++++- .../aws-codebuild/test/report-group.test.ts | 23 ++++++++++++++++ 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/aws-codebuild/README.md b/packages/@aws-cdk/aws-codebuild/README.md index be8e057f50cb0..ec69c84714529 100644 --- a/packages/@aws-cdk/aws-codebuild/README.md +++ b/packages/@aws-cdk/aws-codebuild/README.md @@ -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; diff --git a/packages/@aws-cdk/aws-codebuild/lib/report-group.ts b/packages/@aws-cdk/aws-codebuild/lib/report-group.ts index 6dfaa34752d0c..1cf148cc0c133 100644 --- a/packages/@aws-cdk/aws-codebuild/lib/report-group.ts +++ b/packages/@aws-cdk/aws-codebuild/lib/report-group.ts @@ -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}. */ @@ -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 } /** @@ -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 diff --git a/packages/@aws-cdk/aws-codebuild/test/report-group.test.ts b/packages/@aws-cdk/aws-codebuild/test/report-group.test.ts index 6e653d891f3fb..387b5d5b65fa4 100644 --- a/packages/@aws-cdk/aws-codebuild/test/report-group.test.ts +++ b/packages/@aws-cdk/aws-codebuild/test/report-group.test.ts @@ -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 */ @@ -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", + }); + }); });