-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
fix(codebuild): Fixed build spec file format to return yaml #13445
Conversation
Hi 👋 First of all, I wanted to check what breaking compatibilities this could have. I'm using amplify and as it recommends I create my build file using the codebuild class. But I noticed that it is creating a json instead of a yaml, it works fine but I would prefer to keep it consistent CodeBuild: I'm not familiar with code-build, but in the console, it seems to work with yaml, could you confirm if this can break somehow? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution @janario !
Your build is failing on linter rules:
@aws-cdk/aws-codebuild: /codebuild/output/src641264259/src/github.com/aws/aws-cdk/packages/@aws-cdk/aws-codebuild/lib/build-spec.ts
@aws-cdk/aws-codebuild: 2:8 error A space is required after '{' object-curly-spacing
@aws-cdk/aws-codebuild: 2:15 error A space is required before '}' object-curly-spacing
@aws-cdk/aws-codebuild: 2:22 error Strings must use singlequote quotes
@aws-cdk/aws-codebuild: ✖ 3 problems (3 errors, 0 warnings)
@aws-cdk/aws-codebuild: 3 errors and 0 warnings potentially fixable with the `--fix` option.
@aws-cdk/aws-codebuild: Error: /codebuild/output/src641264259/src/github.com/aws/aws-cdk/node_modules/eslint/bin/eslint.js . --ext=.ts --resolve-plugins-relative-to=/codebuild/output/src641264259/src/github.com/aws/aws-cdk/tools/cdk-build-tools/lib exited with error code 1
@aws-cdk/aws-codebuild: Build failed.!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
(You can see the log of your build in a comment submitted to the PR, like this one: #13445 (comment) ).
May I suggest something? Instead of changing the existing fromObject()
method, that will result in many, many changes to existing templates (both inside this repository in the various tests, and also for customers of the CodeBuild library), how about you create a new static factory method on the BuildSpec
class, called something like yamlFromObject()
, and make only that one result in rendering YAML? You can then describe in the ReadMe of the package how to use that new method.
Thoughts on this idea?
Thanks,
Adam
Perfect, yeah I realized that many test would be broke and compatibility could be affected, I wanted to bring for discussion first I'll try to create a new yamlFromObject and see how it goes, will update this PR soon, for now changing it to draft |
ce45f8e
to
2ec91bc
Compare
@skinny85 Changed to be a new method and added some test, as well as changed the doc of amplify. Let me know your opinion 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great @janario!
A few minor comments. I apologize for the churn of the name of this method, but I think we can come up with something better than yamlFromObject
(which I didn't spend enough time thinking on before suggesting it, for which I'm sorry).
@@ -38,7 +38,7 @@ const amplifyApp = new amplify.App(this, 'MyApp', { | |||
repository: '<repo>', | |||
oauthToken: cdk.SecretValue.secretsManager('my-github-token') | |||
}), | |||
buildSpec: codebuild.BuildSpec.fromObject({ // Alternatively add a `amplify.yml` to the repo | |||
buildSpec: codebuild.BuildSpec.yamlFromObject({ // Alternatively add a `amplify.yml` to the repo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need to update the ReadMe of the CodeBuild module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the readme, but here I have some doubts
I'm not familiar with codebuild, so they might be a bit stupid :-) .
Is buildSpec
from codebuild expected to be a yaml?
The old json function goes over until the function tokenAwareStringify.
Is there something that codebuild would expect from this token function that the yaml would not cover yet? Not sure if it is more general for cloudformation or if codebuild needs something from it.
Stack.of(ctx.scope).toJsonString(this.spec, 2),
> CloudFormationLang.toJSON(obj, space).toString();
>> tokenAwareStringify()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@janario this looks fantastic! I have one last comment to the ReadMe, and then we can merge this in!
Thanks for the contribution!
@@ -583,7 +583,7 @@ For example: | |||
|
|||
```ts | |||
new codebuild.Project(stack, 'MyProject', { | |||
buildSpec: codebuild.BuildSpec.fromObject({ | |||
buildSpec: codebuild.BuildSpec.fromObjectToYaml({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of changing these, can you just add a paragraph in the ReadMe saying something like "If you'd prefer your buildspec to be rendered as YAML in the template, use the fromObjectToYaml()
method instead", and a simple example snippet of code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done 👍
9cac563
to
cbaefe1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work @janario, thanks so much for the contribution!
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license