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

[Grouped Updates] The VendorUpdater class watermarks DependencyFile objects it creates #7433

Merged
merged 8 commits into from
Jun 16, 2023

Conversation

brrygrdn
Copy link
Contributor

Groundwork to fix #7319

Grouped Updates need to manage the aggregation of DependencyFile objects return from updaters in two ways:

  • They need the maintain an overall list of every file that changed during each step to create the PR
  • The need to maintain a list of the manifest files to pass into subsequent updaters so the changes are performed iteratively

In the case of vendor files, we need them to be present in the overall file list for (1), but we do not want them to be passed into subsequent updaters as their interface does not expect to have to filter them out and retrofitting this filtering across all our ecosystems isn't the most practical approach.

The Changes

This PR does the following

  • Adds a vendored_file attribute to Dependabot::DependencyFile which is false by default
  • Splits out a base class from the VendorUpdater class to provide support for managing arbitrary files within an Updater that don't fall within the remit of the FileUpdater itself, i.e. they are not a manifest file, nor are they a vendor file
  • Use this new base class to manage .pnp.* and install state files for yarn berry within our NPM library
  • Updater the concrete VendorUpdater to set vendored_file: true on any DependecyFile objects it creates

Rationale

This change introduces the vendor_file watermarking without changing any behaviour or modifying the Group Update processes to use it to isolate and de-risk this from the larger effort to handle grouped updates + vendoring.

@brrygrdn brrygrdn marked this pull request as ready for review June 14, 2023 17:39
@brrygrdn brrygrdn requested a review from a team as a code owner June 14, 2023 17:39
@brrygrdn brrygrdn requested a review from pavera June 14, 2023 17:39
@brrygrdn
Copy link
Contributor Author

👋🏻 @pavera I just wanted to check that my changes around the npm file updater made sense for the yarn files being managed

module Dependabot
module FileUpdaters
class VendorUpdater
class VendorUpdater < ArtifactUpdater
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 considered an alternative approach of adding a new argument to VendorUpdater rather than creating a 'generic' ArtifactUpdater, something like

def initialise(repo_contents_path:, vendor_dir:, create_vendored_files: true)

Although this would work had result in less churn to the API, I felt this didn't make the intent that vendor files need some special handling clear enough and it would extremely easy for a subtle bug if we were to develop a new use for this utility class similar to the calls in the NPM FileUpdater.

The split of 'utility class to grab any artefact outside the manifest files' and 'specific class to manage vendored dependencies' seemed like a safer, more intentional interface.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for explaining your thought process. Seems well-reasoned to me and straightforward inheritance like this seems preferable to weaving in switching logic 👍

Comment on lines +67 to +68
pnp_updater.updated_files(base_directory: base_dir, only_paths: [".pnp.cjs", ".pnp.data.json"]).each do |file|
updated_files << file
Copy link
Contributor Author

@brrygrdn brrygrdn Jun 14, 2023

Choose a reason for hiding this comment

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

This was an opportunistic change to allow us to optimise very slightly to avoid reading any files we don't plan on using I've made in passing.

I'm ok with backing this out as it is scope creep, but it was a fairly quick thing to add on.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the callout 👍 I don't see any issue with it, especially given its size/impact.

Copy link
Contributor

@bdragon bdragon 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!

common/lib/dependabot/file_updaters/artifact_updater.rb Outdated Show resolved Hide resolved
encoding = `#{command}`.strip

!TEXT_ENCODINGS.include?(encoding)
def create_dependency_file(parameters)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a private method in the base class, so it feels a little sneaky for this subclass to know it should override it, but then again this is ruby so nbd.

Comment on lines +67 to +68
pnp_updater.updated_files(base_directory: base_dir, only_paths: [".pnp.cjs", ".pnp.data.json"]).each do |file|
updated_files << file
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the callout 👍 I don't see any issue with it, especially given its size/impact.

module Dependabot
module FileUpdaters
class VendorUpdater
class VendorUpdater < ArtifactUpdater
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for explaining your thought process. Seems well-reasoned to me and straightforward inheritance like this seems preferable to weaving in switching logic 👍

@brrygrdn brrygrdn force-pushed the brrygrdn/watermark-vendor-files branch from 206fddb to 32f3c89 Compare June 16, 2023 10:27
@brrygrdn brrygrdn force-pushed the brrygrdn/watermark-vendor-files branch from 32f3c89 to 1da6c28 Compare June 16, 2023 12:48
@brrygrdn brrygrdn merged commit 5ae8305 into main Jun 16, 2023
@brrygrdn brrygrdn deleted the brrygrdn/watermark-vendor-files branch June 16, 2023 13:48
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.

Grouped bundler update fails with "undefined method `force_encoding' for nil:NilClass"
2 participants