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

add dependabot.yml #2353

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

add dependabot.yml #2353

wants to merge 18 commits into from

Conversation

rtpascual
Copy link
Contributor

Problem

We can be more proactive in keeping our dependencies up to date so we can avoid problem statements like in #2303.

Issue number, if available:

Changes

Adds dependabot.yml which will trigger Dependabot to check for version updates of our dependencies.

Corresponding docs PR, if applicable:

Validation

Forked the repo and used dependabot.yml to create PRs to update dependencies, see https://github.com/rtpascual/amplify-backend-fork/pulls.

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 December 18, 2024 23:32
Copy link

changeset-bot bot commented Dec 18, 2024

🦋 Changeset detected

Latest commit: a79bfee

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

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

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

sobolk
sobolk previously approved these changes Dec 19, 2024
.github/dependabot.yml Outdated Show resolved Hide resolved
sobolk
sobolk previously approved these changes Dec 19, 2024
Comment on lines +13 to +14
# Runs every Monday
interval: 'weekly'
Copy link
Contributor

Choose a reason for hiding this comment

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

why weekly and not say daily?

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 was thinking weekly to start so we aren't constantly bombarded with version update PRs, especially since we are using increase-if-necessary the PRs will most likely be for new MVs so we need to be thorough on checking for breaking changes.

Or we make sure E2E runs on these PRs and we assume if E2E passes then there are no breaks, in that case I'm fine with changing it to daily.

# Runs every Monday
interval: 'weekly'
# Update package.json files if new version is outside of version range specified there. Otherwise lock file only.
versioning-strategy: increase-if-necessary
Copy link
Contributor

Choose a reason for hiding this comment

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

If this strategy can update package.json files, how will we accommodate changesets in those PRs?

Copy link
Member

Choose a reason for hiding this comment

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

That's a good point. Best if this could be automated.

If it can't:
PR won't pass checks until changeset is added (if our check works)
Maintainer adds changeset (this is doable using UI here #2353 (comment) +/- quotes style but we could exclude changeset files from prettier.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point on changesets, I'll see if I can automate it.

Copy link
Contributor Author

@rtpascual rtpascual Dec 20, 2024

Choose a reason for hiding this comment

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

With change in d826612, I used the new script locally for this PR rtpascual#20 and this is the resulting changeset file that will be force pushed to the PR (had to do it locally to simulate health_checks running on PR):
Screenshot 2024-12-19 at 5 18 28 PM

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.

The idea for automation looks good.

# Update package.json files if new version is outside of version range specified there. Otherwise lock file only.
versioning-strategy: increase-if-necessary
labels:
- 'dependency'
Copy link
Member

Choose a reason for hiding this comment

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

What's the purpose of dependency label?

Copy link
Contributor Author

@rtpascual rtpascual Dec 20, 2024

Choose a reason for hiding this comment

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

Just keeping that label from past dependabot PRs, I'll remove the labels here since we will be adding it through the script

Comment on lines 23 to 44
const getVersionUpdates = async (files: string[]) => {
const updates = new Map<string, string>();
for (const file of files) {
const changes = await gitClient.getFileChanges(file);
for (const change of changes.split(EOL)) {
if (!change.startsWith('+ ')) {
continue;
}
// This will capture lines in git diff like:
// + "<dependency>": "^<version>"
const match = change.match(/"(.*)": "(.*)"/);

if (!match) {
continue;
}
// Add dependency name (match[1]) and new version (match[2]) to Map
updates.set(match[1].replace(/"/g, ''), match[2].replace(/"/g, ''));
}
}

return updates;
};
Copy link
Member

Choose a reason for hiding this comment

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

One other source to consider is parse PR title or description. I'm not sure if this will be any simple - please evaluate and adopt or reject this suggestion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sometimes dependabot will group version updates together so the title can be something like Bump the npm_and_yarn group across 1 directory with 3 updates.

I think description will be best, since it gives us the version dependabot updated from since there will be a line like Updates/Bumps <dependency> from <old-version> to <new-version>.

Comment on lines 67 to 75
// Get modified package.json files that we care about for changesets
const packageJsonFiles = changedFiles.filter(
(changedFile) =>
changedFile.startsWith('packages/') &&
!['packages/integration-tests', 'packages/eslint-rules'].some(
(packageName) => changedFile.startsWith(packageName)
) &&
changedFile.endsWith('package.json')
);
Copy link
Member

Choose a reason for hiding this comment

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

You can use private instead of names, see

Comment on lines 92 to 93
await gitClient.commitAllChanges('add changeset');
await gitClient.push({ force: true });
Copy link
Member

Choose a reason for hiding this comment

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

How does the stop condition work?
I.e. this will presumably push a change to PR and trigger new workflow. Would that trigger this script again or not ? If this is handled already - please drop a comment somewhere - it's not easy to catch this detail.

Other thing is e2e tests.
In case script adds extra commit then we'll be kicking off 2 e2e runs next to each other. If possible we should kick off one.
For example this script could add run-e2e label before pushing. And always commit something (even if it's only pacakge-lock update).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch I don't have anything in place to stop pushing the changeset from triggering the script again, I'll see where I can handle that (possibly using the fact that the script may be adding the run-e2e label?).

That's a good idea on the script adding the run-e2e label to prevent the initial e2e run, then we can push an empty commit or empty changeset (in case of only package-lock update).

@@ -0,0 +1,93 @@
import fsp from 'fs/promises';
Copy link
Member

Choose a reason for hiding this comment

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

I'd rename this script to dependabot_handle_version_update or something like this.
It's doing a bit more than generating changeset (i.e. it's also pushing it to repo).

Also - consider writing a happy case test case for this.
Something like https://github.com/aws-amplify/amplify-backend/blob/main/scripts/components/release_lifecycle.test.ts .

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.

3 participants