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

feat(codebuild): improve merging of BuildSpecs #15332

Merged
merged 5 commits into from
Jul 1, 2021
Merged

feat(codebuild): improve merging of BuildSpecs #15332

merged 5 commits into from
Jul 1, 2021

Conversation

hoegertn
Copy link
Contributor

@hoegertn hoegertn commented Jun 28, 2021

First steps for #15169


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

@gitpod-io
Copy link

gitpod-io bot commented Jun 28, 2021

@hoegertn hoegertn marked this pull request as draft June 28, 2021 21:46
@hoegertn
Copy link
Contributor Author

@rix0rrr for visibility

@ericzbeard ericzbeard added this to the [GA] CDK Pipelines milestone Jun 29, 2021
@rix0rrr rix0rrr changed the title feat(pipelines): enable full control over bildSpec feat(pipelines): enable full control over BuildSpec Jun 30, 2021
}

function mergeDeep(lhs: any, rhs: any): any {
lhs = JSON.parse(JSON.stringify(lhs));
Copy link
Contributor

@rix0rrr rix0rrr Jun 30, 2021

Choose a reason for hiding this comment

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

I'd prefer doing a fully recursive function here that type-analyzes, of the form:

function mergeDeep(lhs, rhs) {

  if (Array.isArray(lhs) && Array.isArray(rhs)) {
    return [...lhs, ...rhs];
  }
  if (Array.isArray(lhs) || Array.isArray(rhs)) { return rhs; }

  if (isObject(lhs) && isObject(rhs)) {
    const ret: any = {...lhs};
    for (const k of Object.keys(rhs)) {
      ret[k] = k in lhs ? mergeDeep(lhs[k], rhs[k]) : rhs[k];
    }
    return ret;
  }

  return rhs;
}

This will take care to create new objects instead of mutating when necessary, and otherwise structurally reuse when not.

If you MUST, I would accept a single parse(stringify(x)) on both structures at the start, to make sure nobody is holding "illegal" references to the starting structures that would be structure-shared in the final result. But we don't need to parse(stringify(x)) at every level of the recursion.

@hoegertn hoegertn changed the title feat(pipelines): enable full control over BuildSpec feat(codebuild): improve merging of BuildSpecs Jun 30, 2021
@hoegertn hoegertn marked this pull request as ready for review June 30, 2021 22:43
@rix0rrr rix0rrr self-assigned this Jul 1, 2021
@rix0rrr rix0rrr added the pr-linter/exempt-readme The PR linter will not require README changes label Jul 1, 2021
Copy link
Contributor

@rix0rrr rix0rrr left a comment

Choose a reason for hiding this comment

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

Sweet, thanks!

@mergify
Copy link
Contributor

mergify bot commented Jul 1, 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: 0a05edc
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@mergify mergify bot merged commit e68087d into aws:master Jul 1, 2021
@mergify
Copy link
Contributor

mergify bot commented Jul 1, 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).

@hoegertn hoegertn deleted the hoegertn-buildspec-merge branch July 17, 2021 16:31
hollanddd pushed a commit to hollanddd/aws-cdk that referenced this pull request Aug 26, 2021
First steps for aws#15169 

----

*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
pr-linter/exempt-readme The PR linter will not require README changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants