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

Run Dependency Group updates #7075

Merged
merged 29 commits into from
Apr 18, 2023
Merged

Run Dependency Group updates #7075

merged 29 commits into from
Apr 18, 2023

Conversation

Nishnha
Copy link
Member

@Nishnha Nishnha commented Apr 13, 2023

This PR is stacked on top of #7074

I have tried to make each commit represent a single file change for this PR.

Things to note:

The main contribution of this PR is that it introduces a new class, the DependencyGroupEngine, which registers DependencyGroups based on values passed in from an Update Job.

The engine is not called directly, but dependency groups are made available to the Updater through 2 methods:

  • DependencySnapshot#groups
  • DependencySnapshot#ungrouped_dependencies

Here is what the job summary for 2 dependency groups looks like:

+------------------------------------------------------------------------------------------------------------------------------------+
|                                                Changes to Dependabot Pull Requests                                                 |
+---------+--------------------------------------------------------------------------------------------------------------------------+
| created | @emotion/react ( from 11.10.5 to 11.10.6 ), @emotion/styled ( from 11.10.5 to 11.10.6 )                                  |
| created | gatsby ( from 5.6.0 to 5.8.1 ), gatsby-cli ( from 5.6.0 to 5.8.0 ), gatsby-plugin-emotion ( from 8.6.0 to 8.8.0 ), ga... |
+---------+--------------------------------------------------------------------------------------------------------------------------+

This implementation will only run dependencies that belong to a dependency group. It does not try to generate any PRs for ungrouped dependencies.

@Nishnha Nishnha requested a review from a team as a code owner April 13, 2023 04:34
Copy link
Contributor

@brrygrdn brrygrdn left a comment

Choose a reason for hiding this comment

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

This looks great! I really like the split out responsibilities between DependencyGroup and the DependencyGroupEngine.

I have a few minor notes, but my longer thought on making the DependencyGroupEngine an instance rather than a 'singleton-like' class is probably worth doing separately. Ruby class variables have a lot of gotchas so while they work it's generally not the preferred idiom and I think we get a side benefit that when we start to do more rule validation we can throw any parsing errors at a nice and clear point in the code later.

common/lib/dependabot/dependency_group.rb Outdated Show resolved Hide resolved
updater/lib/dependabot/dependency_snapshot.rb Show resolved Hide resolved
updater/lib/dependabot/dependency_snapshot.rb Show resolved Hide resolved
updater/lib/dependabot/job.rb Outdated Show resolved Hide resolved
common/spec/dependabot/dependency_group_spec.rb Outdated Show resolved Hide resolved
common/lib/dependabot/dependency_group.rb Show resolved Hide resolved
updater/lib/dependabot/dependency_change.rb Outdated Show resolved Hide resolved
@Nishnha Nishnha force-pushed the nishnha/dependency-group-rename branch from 6754830 to 7557850 Compare April 13, 2023 15:49
Base automatically changed from nishnha/dependency-group-rename to main April 13, 2023 16:02
@Nishnha
Copy link
Member Author

Nishnha commented Apr 13, 2023

This PR is in kind of a weird state because I had it stacked on top of https://github.com/dependabot/dependabot-core/pull/7074/commits which I then squashed into main.

The merge commit brings this branch back up to date with main, but there are a couple of commits, namely ff792bc and e8a2b4b, that were also present in the stacked PR that I squashed.

So those 2 commits are kind of unnecessary? If you diff them with main they look (mostly) empty.

Anyhow, I'm going to continue rolling forward with commits on this branch. If we want to have a cleaner history I'd be happy to re-open this branch as a new PR but I don't want to rebase and lose @brrygrdn's comments here.

Nishnha and others added 3 commits April 13, 2023 16:15
Co-authored-by: Barry Gordon <896971+brrygrdn@users.noreply.github.com>
This is an artifact from an earlier iteration that skipped over ungrouped_dependencies

Co-authored-by: Barry Gordon <896971+brrygrdn@users.noreply.github.com>
since we are adding to an instance variable, we can just use each here

Co-authored-by: Barry Gordon <896971+brrygrdn@users.noreply.github.com>
@Nishnha
Copy link
Member Author

Nishnha commented Apr 13, 2023

Based on some of the comments from @brrygrdn, after this PR lands I'm going to follow up with a refactor of the DependencyGroupEngine with the goals being:

  • make DependencyGroupEngine a class that is instantiated by a DependencySnapshot
  • time how long dependency group rules checking takes and attempts a more performant check
  • handle errors that result during dependency group rules checks

@Nishnha Nishnha force-pushed the nishnha/plumb-dependency-groups branch from 8d98717 to 0b9675f Compare April 13, 2023 20:39
DependencyGroups have a name and rules, where a rule is a Hash that
currently accepts one key, "patterns". Other keys may be supported in
the future, but for now we can just pass in `group["rules]["patterns"]`
directly
@Nishnha
Copy link
Member Author

Nishnha commented Apr 17, 2023

I see this test failure in the updater spec but I can't recreate it locally ☹️

Failures:

  1) Dependabot::Updater#run with the grouped experiment enabled updates multiple dependencies in a single PR correctly
     Failure/Error:
       expect(service).to receive(:create_pull_request) do |dependency_change, base_commit_sha|
         expect(dependency_change.updated_dependencies.first).to have_attributes(name: "dummy-pkg-b")
         expect(dependency_change.updated_dependency_files_hash).to eql(
           [
             {
               "name" => "Gemfile",
               "content" => fixture("bundler/updated/Gemfile"),
               "directory" => "/",
               "type" => "file",
               "mode" => "100644",

       (#<Dependabot::Service:0x00007ff524fb8d28 @client=#<InstanceDouble(Dependabot::ApiClient) (anonymous)>, @pull_requests=[], @errors=[]>).create_pull_request(*(any args))
           expected: 1 time with any arguments
           received: 2 times with any arguments
     # ./spec/dependabot/updater_spec.rb:2206:in `block (3 levels) in <top (required)>'
     # ./vendor/ruby/3.1.0/gems/webmock-3.18.1/lib/webmock/rspec.rb:37:in `block (2 levels) in <top (required)>'

I was thinking of changing the test to be expect(service).to receive(:create_pull_request).at_least(:once) do ... but I'm not sure why :create_pull_request is getting called more than once in the first place?

Comment on lines +95 to +99
def register_all_dependencies_group
all_dependencies_group = { "name" => "group-all", "rules" => { "patterns" => ["*"] } }
Dependabot::DependencyGroupEngine.register(all_dependencies_group["name"],
all_dependencies_group["rules"]["patterns"])
end
Copy link
Contributor

Choose a reason for hiding this comment

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

👍🏻

Comment on lines +110 to +112
# FIXME: rules are actually a hash but for the purposes of this pass we can leave it as a list
# Once this is refactored we should create a DependencyGroup like so
# Dependabot::DependencyGroup.new(name: "dummy-pkg-*", rules: { "patterns" => ["dummy-pkg-*"] })
Copy link
Contributor

Choose a reason for hiding this comment

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

👍🏻

@brrygrdn
Copy link
Contributor

I was thinking of changing the test to be expect(service).to receive(:create_pull_request).at_least(:once) do ... but I'm not sure why :create_pull_request is getting called more than once in the first place?

Yeah, that's odd - it seems like it should only be called once. It might be worth just adding a puts statement to throw out the dependency_group name/identity at the start of the Service#create_pull_request method just in case there is a mystery guest in the test setup?

I'm thinking that due to the DependencyGroupEngine being a singleton, it might mean that rules declared in other tests are leaking when ran in CI as part of a full suite? We could also put a before to reset the group rule engine to check?

@Nishnha
Copy link
Member Author

Nishnha commented Apr 18, 2023

I'm thinking that due to the DependencyGroupEngine being a singleton, it might mean that rules declared in other tests are leaking when ran in CI as part of a full suite?

Looks like it was a leaky dependency group! I fixed this in 9ac2f7e by no longer registering a DependencyGroup for the job spec.
The test checks whether the :register_dependency_groups method was called on job creation, but we don't actually need to have a dependency group registered for this test to pass.

@brrygrdn brrygrdn self-assigned this Apr 18, 2023
@Nishnha Nishnha force-pushed the nishnha/plumb-dependency-groups branch from 015f0cf to 9ac2f7e Compare April 18, 2023 14:44
Copy link
Contributor

@brrygrdn brrygrdn left a comment

Choose a reason for hiding this comment

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

Nice, let's 🚀

@Nishnha Nishnha force-pushed the nishnha/plumb-dependency-groups branch from 7e241c2 to 9ac2f7e Compare April 18, 2023 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants