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

pin cdk versions for create amplify #2535

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

rtpascual
Copy link
Contributor

@rtpascual rtpascual commented Feb 21, 2025

Problem

We are not pinning to versions of CDK being used in our repo for create amplify.
We also don't have an automated way to update these pinned versions.

Issue number, if available:

Changes

  • Pin versions of CDK for create amplify taken from package-lock.json
  • Moved create amplify dependencies to a separate file to contain changes
  • Add git hook and command to run update create amplify dependencies script
  • Add new job that runs a check which attempts to update create amplify dependencies to match what is in package-lock.json, then if there is any git diff it fails.

Corresponding docs PR, if applicable:

Validation

Unit tests and #2534, which is a PR built on top of this one that has changes to CDK versions in package-lock.json.

Checklist

  • If this PR includes a functional change to the runtime behavior of the code, I have added or updated automated test coverage for this change.
  • If this PR requires a change to the Project Architecture README, I have included that update in this PR.
  • If this PR requires a docs update, I have linked to that docs PR above.
  • If this PR modifies E2E tests, makes changes to resource provisioning, or makes SDK calls, I have run the PR checks with the run-e2e label set.

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

@rtpascual rtpascual requested review from a team as code owners February 21, 2025 22:48
Copy link

changeset-bot bot commented Feb 21, 2025

🦋 Changeset detected

Latest commit: 94ff772

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
create-amplify Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Member

@sobolk sobolk left a comment

Choose a reason for hiding this comment

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

overall looking good, please see comments.

Comment on lines 1 to 12
export const defaultDevPackages = [
'@aws-amplify/backend',
'@aws-amplify/backend-cli',
'[email protected]',
'[email protected]',
'constructs@^10.0.0',
'typescript@^5.0.0',
'tsx',
'esbuild',
];

export const defaultProdPackages = ['aws-amplify'];
Copy link
Member

Choose a reason for hiding this comment

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

could this be plain JSON file ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right this can be a plain JSON and will remove the need for regex

Comment on lines 31 to 38
// taken from lodash escapeRegExp and used to sanitize dep.name before using it in RegExp
// can be replaced by RegExp.escape once it is available
const safeDepName = dep.name.replace(/[\\^$.*+?()[\]{}|]/g, '\\$&');
const depRegex = new RegExp(`'${safeDepName}.*'`);
defaultPackagesContent = defaultPackagesContent.replace(
depRegex,
`'${dep.name}@${dep.version}'`
);
Copy link
Member

Choose a reason for hiding this comment

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

if we make default_packages.json we could get rid of regexes

Comment on lines 321 to 323
update_create_amplify_deps:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
Copy link
Member

Choose a reason for hiding this comment

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

The automation for this is great idea.

In addition to this we should have:

  1. A check that asserts that some of default_packages.ts are matching package.lock content. The check should block PR merges. This would be a gate to stop inconsistency, therefore this is a mandatory addition to have I would think.
  2. Git hook to short circuit feedback loop to local machine that either does validation or upgrade or both. This is nice to have.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. I agree there may be inconsistencies in the beginning, but won't the automation and this new check be redundant? Since each time package.lock is updated automation will update cdk versions in default_packages.ts accordingly
  2. That's a great idea for some nice QOL, I'll look into adding this

Copy link
Member

Choose a reason for hiding this comment

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

  1. If we were to craft extremely minimalistic automation, then the check would be automated and updates would be left manual. The goal of check is to prevent inconsistency, the goal of update is to reduce operational load on operators, those are different goals. But to your point about redundancy - if this job can be made is such a way that it update_and_checks_create_amplify_desp i.e. it either updates and early exists or asserts that versions are in sync as last step then it would fulfill the need for "check".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I see what you mean. What I currently have for update does have some checks but the idea of check being automated and updates left manual is growing on me and would be similar to check_api_changes.ts and the npm run update:api script.

Only problem I can think of is dependabot version updates but like with fixing any failing check we would go into the PR and make manual changes anyways (plus it'll only be for a subset of dependency updates).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the automated check and the not-so-manual update that runs on git hook and can be run manually for tighter feedback loop.


if (!ghContext.payload.pull_request) {
// event is not a pull request, return early
process.exit();
Copy link
Member

Choose a reason for hiding this comment

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

can we use throw and return instead of process exists ?

Comment on lines 321 to 323
update_create_amplify_deps:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
Copy link
Member

Choose a reason for hiding this comment

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

  1. If we were to craft extremely minimalistic automation, then the check would be automated and updates would be left manual. The goal of check is to prevent inconsistency, the goal of update is to reduce operational load on operators, those are different goals. But to your point about redundancy - if this job can be made is such a way that it update_and_checks_create_amplify_desp i.e. it either updates and early exists or asserts that versions are in sync as last step then it would fulfill the need for "check".

@rtpascual rtpascual requested a review from a team as a code owner February 26, 2025 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants