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 audit for Ruby files in taps. #17574

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

reitermarkus
Copy link
Member

@reitermarkus reitermarkus commented Jun 27, 2024

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

Replaces the same logic in the homebrew/cask CI workflow with an audit in TapAuditor.

See Homebrew/homebrew-cask#177890 (comment).

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

There seems to be a bunch of changes here and I don't fully understand which ones are stylistic and which ones change behaviour. Can you elaborate a bit more on what this is doing, how and why?

@reitermarkus
Copy link
Member Author

reitermarkus commented Jun 27, 2024

Most of the changes are caused by moving Homebrew.with_no_api_env from TapAuditor#initialize to TapAuditor#audit to avoid duplicating every Tap instance variable.

Apart from that, the only thing that's new is the TapAuditor#audit_ruby_files method.


return if stray_ruby_files.none?

problem "Ruby files in wrong location:\n#{stray_ruby_files.map(&:to_s).join("\n")}"
Copy link
Member

Choose a reason for hiding this comment

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

This should say what location they should be in. Even from reading the code: I don't really understand what would be the right/wrong location here. Can you elaborate?

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct would be *.rb (if Formula/ doesn't exist), cmd/**/*.rb, Formula/**/*.rb and Casks/**/*.rb, anything else incorrect.

Additionally, Formula/**/*.rb is incorrect in homebrew/cask and cask/**/*.rb is incorrect in homebrew/core.

Copy link
Member

@Bo98 Bo98 Jun 27, 2024

Choose a reason for hiding this comment

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

Homebrew/test-bot is a tap with formulae but also uses lib/**/*.rb and spec/**/*.rb.
Homebrew/portable-ruby has Abstract/*.rb.

Stray files detection here seems somewhat far reaching.

Copy link
Member

Choose a reason for hiding this comment

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

Additionally, Formula/**/*.rb is incorrect in homebrew/cask and cask/**/*.rb is incorrect in homebrew/core.

This seems reasonable and a good add. Could also look for Ruby files that look like formulae or casks that aren't in a directory that Homebrew will ever find

Correct would be *.rb (if Formula/ doesn't exist), cmd/**/*.rb, Formula/**/*.rb and Casks/**/*.rb, anything else incorrect.

Agreed with @Bo98: this does not and feels like it's going to blow up on a lot of taps, official and otherwise.

What's the motivation here?

Copy link
Member Author

@reitermarkus reitermarkus Jun 27, 2024

Choose a reason for hiding this comment

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

The motivation is to move the logic from the cask CI workflow into brew audit. I'm also fine with simly removing this check altogether.

Copy link
Member

Choose a reason for hiding this comment

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

Which part of the cask CI currently checks this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Personally I think either:

  • this check can be removed entirely
  • if we want it to be in Homebrew/brew: it should check for files than e.g. contain class .+ < Formula or cask ".+" do that aren't in potential_formula_dirs
    sig { returns(T::Array[Pathname]) }
    def potential_formula_dirs
    @potential_formula_dirs ||= [path/"Formula", path/"HomebrewFormula", path].freeze
    end
    or cask_dir
    sig { returns(Pathname) }
    def cask_dir
    @cask_dir ||= path/"Casks"
    end
    and leave all other random Ruby files alone

Copy link
Member Author

Choose a reason for hiding this comment

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

Matching class .+ < Formula would still include the Abstract/*.rb mentioned above. Then again, I'm not a fan of subclassing Formula that way in the first place.

Copy link
Member

Choose a reason for hiding this comment

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

Then: remove it entirely, I think.

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.

None yet

3 participants