-
Notifications
You must be signed in to change notification settings - Fork 4k
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
(CodeBuild Report Group): Defining the report type in CDK #14279
Comments
Thanks for the feature request @CodeEngineTechnology! |
Is there a chance to solve this? |
@kostiantyn-lab PRs are always welcome! In the meantime, you can probably use escape hatches to work around this problem. |
The escape hatch approach seems to have some limitations. When I use it like so: const unitTestCoverageGroup = new ReportGroup(this, 'CoverageReportGroup', {
removalPolicy: cdk.RemovalPolicy.RETAIN
})
const cfnUnitTestCoverageGroup = unitTestCoverageGroup.node.defaultChild as CfnReportGroup
cfnUnitTestCoverageGroup.type = 'CODE_COVERAGE'
// ...
unitTestCoverageGroup.grantWrite(buildStep.grantPrincipal) The
EDIT: I see the issue. The This problem is made worse by the fact that the IAM docs for CodeBuild don't mention the existence of this operation at all. The workaround ends up being to have the following: import { BuildSpec, ReportGroup, CfnReportGroup } from '@aws-cdk/aws-codebuild'
import * as cdk from '@aws-cdk/core'
import * as pipelines from '@aws-cdk/pipelines'
import * as iam from '@aws-cdk/aws-iam'
interface SomePipelineProps extends cdk.StackProps {
// ...
}
export class SomePipeline extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props: SomePipelineProps) {
super(scope, id, props)
const repo = 'Your Repo here'
const branch = 'Your branch here'
const codeStarConnection = pipelines.CodePipelineSource.connection(repo, branch, {
connectionArn: 'Your CodeStar connection ARN here',
triggerOnPush: true
})
const jestReportGroup = new ReportGroup(this, 'JestReportGroup', {})
const unitTestCoverageGroup = new ReportGroup(this, 'CoverageReportGroup', {})
const cfnUnitTestCoverageGroup = unitTestCoverageGroup.node.defaultChild as CfnReportGroup
cfnUnitTestCoverageGroup.type = 'CODE_COVERAGE'
const customSynthStep = new pipelines.CodeBuildStep('ExperimentalSynth', {
input: codeStarConnection,
env: {
CI: 'true'
},
installCommands: ['npm ci'],
commands: ['npm run build', 'npm test', 'npx cdk synth'],
partialBuildSpec: BuildSpec.fromObject({
version: '0.2',
// Make sure your jest config outputs to locations that match what's here
reports: {
[jestReportGroup.reportGroupArn]: {
files: ['jest-results.xml'],
'file-format': 'JUNITXML',
'base-directory': 'build/reports/unit-test'
},
[unitTestCoverageGroup.reportGroupArn]: {
files: ['clover.xml'],
'file-format': 'CLOVERXML',
'base-directory': 'build/reports/coverage'
}
}
}),
primaryOutputDirectory: 'cdk.out'
})
const pipeline = new pipelines.CodePipeline(this, 'SomePipeline', {
pipelineName: 'SomePipeline',
synth: customSynthStep
})
// Do whatever else you want on your pipeline
// ...
// Granting access here has to happen after calling buildPipeline so the CloudAssembly references resolve
// All of this is only necessary becasue of limitations discussed in https://github.com/aws/aws-cdk/issues/10464
pipeline.buildPipeline()
jestReportGroup.grantWrite(customSynthStep.grantPrincipal)
unitTestCoverageGroup.grantWrite(customSynthStep.grantPrincipal)
// This next grant is necessary because the grantWrite command won't add the permission needed for coverage reports
// https://github.com/aws/aws-cdk/issues/14279
iam.Grant.addToPrincipal({
grantee: customSynthStep.grantPrincipal,
actions: ['codebuild:BatchPutCodeCoverages'],
resourceArns: [unitTestCoverageGroup.reportGroupArn]
})
}
} |
Thanks for posting that @bilalq! Will be super useful when implementing this feature. |
I'm considering working on a PR to address both this and #10464. My thoughts on the approach:
Would you have objections/concerns with any of the above @skinny85? |
No, that sounds great @bilalq! The only possible comment I have is to think whether it's better to introduce a property to I would lean towards having a separate Something to consider! |
I don't really feel strongly either way. The only reason I suggested using an adjustment on the existing class was that it mirrors the underlying CFN resource more that way. I suppose a better implementation here would be to have Another option would be to make ReportGroup take a property like I suggested earlier and have two subclasses while preserving the existing behavior as the default. Thoughts? Today, they don't have different properties, but they do have different valid combinations with the buildspec property on the related CodeBuild project object. The It's worth calling out that buildspecs can be imported from files, so compile time guarantees can't be made without additional runtime checking. |
Yep, that actually sounds pretty fantastic! |
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*
|
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*
When you create a new Report Group you should be able to select the report type (e,g,. Coverage)
There is no way to change the report type from Test to Coverage in props
new ReportGroup(this.scope, 'test-coverage', {reportGroupName: 'test-coverage'});
Use Case
Proposed Solution
Other
This is a 🚀 Feature Request
The text was updated successfully, but these errors were encountered: