Skip to content
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

Merged
merged 7 commits into from
Mar 22, 2021

Conversation

janario
Copy link
Contributor

@janario janario commented Mar 6, 2021


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added the @aws-cdk/aws-codebuild Related to AWS CodeBuild label Mar 6, 2021
@janario
Copy link
Contributor Author

janario commented Mar 6, 2021

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

json:
image

yaml (after):
image


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?

image

@gitpod-io
Copy link

gitpod-io bot commented Mar 6, 2021

Copy link
Contributor

@skinny85 skinny85 left a 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

packages/@aws-cdk/aws-codebuild/lib/build-spec.ts Outdated Show resolved Hide resolved
@janario
Copy link
Contributor Author

janario commented Mar 9, 2021

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
#13445 (comment)

I'll try to create a new yamlFromObject and see how it goes, will update this PR soon, for now changing it to draft

@janario janario marked this pull request as draft March 9, 2021 08:06
@mergify mergify bot dismissed skinny85’s stale review March 13, 2021 13:30

Pull request has been modified.

@janario janario marked this pull request as ready for review March 13, 2021 14:07
@janario
Copy link
Contributor Author

janario commented Mar 13, 2021

@skinny85 Changed to be a new method and added some test, as well as changed the doc of amplify.

Let me know your opinion 👍

Copy link
Contributor

@skinny85 skinny85 left a 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
Copy link
Contributor

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.

Copy link
Contributor Author

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()

packages/@aws-cdk/aws-amplify/test/app.test.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-codebuild/lib/build-spec.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-codebuild/lib/build-spec.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-codebuild/lib/build-spec.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-codebuild/lib/build-spec.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-codebuild/test/test.project.ts Outdated Show resolved Hide resolved
@mergify mergify bot dismissed skinny85’s stale review March 17, 2021 20:40

Pull request has been modified.

Copy link
Contributor

@skinny85 skinny85 left a 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({
Copy link
Contributor

@skinny85 skinny85 Mar 18, 2021

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done 👍

@mergify mergify bot dismissed skinny85’s stale review March 21, 2021 09:13

Pull request has been modified.

Copy link
Contributor

@skinny85 skinny85 left a 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!

@mergify
Copy link
Contributor

mergify bot commented Mar 22, 2021

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-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 333fefc
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented Mar 22, 2021

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).

@mergify mergify bot merged commit fab93c6 into aws:master Mar 22, 2021
eladb pushed a commit that referenced this pull request Mar 24, 2021
----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
hollanddd pushed a commit to hollanddd/aws-cdk that referenced this pull request Aug 26, 2021
----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-codebuild Related to AWS CodeBuild
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants