-
Notifications
You must be signed in to change notification settings - Fork 4.4k
feat(codebuild): add support for test reports #7691
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import * as cdk from '@aws-cdk/core'; | ||
|
|
||
| // this file contains a bunch of functions shared | ||
| // between Project and ResourceGroup, | ||
| // which we don't want to make part of the public API of this module | ||
|
|
||
| export function renderReportGroupArn(scope: cdk.Construct, reportGroupName: string): string { | ||
| return cdk.Stack.of(scope).formatArn(reportGroupArnComponents(reportGroupName)); | ||
| } | ||
|
|
||
| export function reportGroupArnComponents(reportGroupName: string): cdk.ArnComponents { | ||
| return { | ||
| service: 'codebuild', | ||
| resource: 'report-group', | ||
| resourceName: reportGroupName, | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| import * as iam from '@aws-cdk/aws-iam'; | ||
| import * as s3 from '@aws-cdk/aws-s3'; | ||
| import * as cdk from '@aws-cdk/core'; | ||
| import { CfnReportGroup } from './codebuild.generated'; | ||
| import { renderReportGroupArn, reportGroupArnComponents } from './report-group-utils'; | ||
|
|
||
| /** | ||
| * The interface representing the ReportGroup resource - | ||
| * either an existing one, imported using the | ||
| * {@link ReportGroup.fromReportGroupName} method, | ||
| * or a new one, created with the {@link ReportGroup} class. | ||
| */ | ||
| export interface IReportGroup extends cdk.IResource { | ||
| /** | ||
| * The ARN of the ReportGroup. | ||
| * | ||
| * @attribute | ||
| */ | ||
| readonly reportGroupArn: string; | ||
|
|
||
| /** | ||
| * The name of the ReportGroup. | ||
| * | ||
| * @attribute | ||
| */ | ||
| readonly reportGroupName: string; | ||
|
|
||
| /** | ||
| * Grants the given entity permissions to write | ||
| * (that is, upload reports to) | ||
| * this report group. | ||
| */ | ||
| grantWrite(identity: iam.IGrantable): iam.Grant; | ||
| } | ||
|
|
||
| abstract class ReportGroupBase extends cdk.Resource implements IReportGroup { | ||
| public abstract readonly reportGroupArn: string; | ||
| public abstract readonly reportGroupName: string; | ||
| protected abstract readonly exportBucket?: s3.IBucket; | ||
|
|
||
| public grantWrite(identity: iam.IGrantable): iam.Grant { | ||
| const ret = iam.Grant.addToPrincipal({ | ||
| grantee: identity, | ||
| actions: [ | ||
| 'codebuild:CreateReport', | ||
| 'codebuild:UpdateReport', | ||
| 'codebuild:BatchPutTestCases', | ||
| ], | ||
| resourceArns: [this.reportGroupArn], | ||
| }); | ||
|
|
||
| if (this.exportBucket) { | ||
| this.exportBucket.grantWrite(identity); | ||
| } | ||
|
|
||
| return ret; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Construction properties for {@link ReportGroup}. | ||
| */ | ||
| export interface ReportGroupProps { | ||
| /** | ||
| * The physical name of the report group. | ||
| * | ||
| * @default - CloudFormation-generated name | ||
| */ | ||
| readonly reportGroupName?: string; | ||
|
|
||
| /** | ||
| * An optional S3 bucket to export the reports to. | ||
| * | ||
| * @default - the reports will not be exported | ||
| */ | ||
| readonly exportBucket?: s3.IBucket; | ||
|
|
||
| /** | ||
| * Whether to output the report files into the export bucket as-is, | ||
| * or create a ZIP from them before doing the export. | ||
| * Ignored if {@link exportBucket} has not been provided. | ||
| * | ||
| * @default - false (the files will not be ZIPped) | ||
| */ | ||
| readonly zipExport?: boolean; | ||
|
|
||
| /** | ||
| * What to do when this resource is deleted from a stack. | ||
| * As CodeBuild does not allow deleting a ResourceGroup that has reports inside of it, | ||
| * this is set to retain the resource by default. | ||
| * | ||
| * @default RemovalPolicy.RETAIN | ||
| */ | ||
| readonly removalPolicy?: cdk.RemovalPolicy; | ||
| } | ||
|
|
||
| /** | ||
| * The ReportGroup resource class. | ||
| */ | ||
| export class ReportGroup extends ReportGroupBase { | ||
|
|
||
| /** | ||
| * Reference an existing ReportGroup, | ||
| * defined outside of the CDK code, | ||
| * by name. | ||
| */ | ||
| public static fromReportGroupName(scope: cdk.Construct, id: string, reportGroupName: string): IReportGroup { | ||
| class Import extends ReportGroupBase { | ||
| public readonly reportGroupName = reportGroupName; | ||
| public readonly reportGroupArn = renderReportGroupArn(scope, reportGroupName); | ||
| protected readonly exportBucket = undefined; | ||
| } | ||
|
|
||
| return new Import(scope, id); | ||
| } | ||
|
|
||
| public readonly reportGroupArn: string; | ||
| public readonly reportGroupName: string; | ||
| protected readonly exportBucket?: s3.IBucket; | ||
|
|
||
| constructor(scope: cdk.Construct, id: string, props: ReportGroupProps = {}) { | ||
| super(scope, id, { | ||
| physicalName: props.reportGroupName, | ||
| }); | ||
|
|
||
| const resource = new CfnReportGroup(this, 'Resource', { | ||
| type: 'TEST', | ||
| exportConfig: { | ||
| exportConfigType: props.exportBucket ? 'S3' : 'NO_EXPORT', | ||
| s3Destination: props.exportBucket | ||
| ? { | ||
| bucket: props.exportBucket.bucketName, | ||
| encryptionDisabled: props.exportBucket.encryptionKey ? false : undefined, | ||
| encryptionKey: props.exportBucket.encryptionKey?.keyArn, | ||
| packaging: props.zipExport ? 'ZIP' : undefined, | ||
| } | ||
| : undefined, | ||
| }, | ||
| }); | ||
| resource.applyRemovalPolicy(props.removalPolicy, { | ||
| default: cdk.RemovalPolicy.RETAIN, | ||
| }); | ||
| this.reportGroupArn = this.getResourceArnAttribute(resource.attrArn, | ||
| reportGroupArnComponents(this.physicalName)); | ||
| this.reportGroupName = this.getResourceNameAttribute( | ||
| // there is no separate name attribute, | ||
| // so use Fn::Select + Fn::Split to make one | ||
| cdk.Fn.select(1, cdk.Fn.split('/', resource.ref)), | ||
| ); | ||
| this.exportBucket = props.exportBucket; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.