-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# frozen_string_literal: true | ||
|
||
require "tap_auditor" | ||
|
||
RSpec.describe Homebrew::TapAuditor do | ||
subject(:tap_auditor) { described_class.new(tap) } | ||
|
||
let(:tap) { Tap.fetch("user", "repo") } | ||
let(:ruby_files) { [] } | ||
|
||
before do | ||
tap.path.mkpath | ||
|
||
ruby_files.each do |ruby_file| | ||
ruby_file.dirname.mkpath | ||
FileUtils.touch ruby_file | ||
end | ||
end | ||
|
||
after do | ||
tap.path.dirname.rmtree | ||
end | ||
|
||
context "when Ruby files are in a wrong location" do | ||
let(:ruby_files) do | ||
[ | ||
tap.path/"wrong"/"file.rb", | ||
] | ||
end | ||
|
||
it "fails" do | ||
tap_auditor.audit | ||
expect(tap_auditor.problems.first[:message]).to match "Ruby files in wrong location" | ||
end | ||
end | ||
|
||
context "when formula files are in homebrew/cask" do | ||
let(:tap) { CoreCaskTap.instance } | ||
let(:ruby_files) do | ||
[ | ||
tap.path/"Formula"/"formula.rb", | ||
] | ||
end | ||
|
||
it "fails" do | ||
tap_auditor.audit | ||
expect(tap_auditor.problems.first[:message]).to match "Ruby files in wrong location" | ||
end | ||
end | ||
|
||
context "when cask files are in homebrew/core" do | ||
let(:tap) { CoreTap.instance } | ||
let(:ruby_files) do | ||
[ | ||
tap.path/"Casks"/"cask.rb", | ||
] | ||
end | ||
|
||
it "fails" do | ||
tap_auditor.audit | ||
expect(tap_auditor.problems.first[:message]).to match "Ruby files in wrong location" | ||
end | ||
end | ||
|
||
context "when Ruby files are in correct locations" do | ||
let(:ruby_files) do | ||
[ | ||
tap.path/"cmd"/"cmd.rb", | ||
tap.path/"Formula"/"formula.rb", | ||
tap.path/"Casks"/"cask.rb", | ||
] | ||
end | ||
|
||
it "passes" do | ||
tap_auditor.audit | ||
expect(tap_auditor.problems).to be_empty | ||
end | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct would be
*.rb
(ifFormula/
doesn't exist),cmd/**/*.rb
,Formula/**/*.rb
andCasks/**/*.rb
, anything else incorrect.Additionally,
Formula/**/*.rb
is incorrect inhomebrew/cask
andcask/**/*.rb
is incorrect inhomebrew/core
.There was a problem hiding this comment.
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
andspec/**/*.rb
.Homebrew/portable-ruby has
Abstract/*.rb
.Stray files detection here seems somewhat far reaching.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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?
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See Homebrew/homebrew-cask#177890.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I think either:
class .+ < Formula
orcask ".+" do
that aren't inpotential_formula_dirs
brew/Library/Homebrew/tap.rb
Lines 655 to 658 in 9f58612
cask_dir
brew/Library/Homebrew/tap.rb
Lines 668 to 671 in 9f58612
There was a problem hiding this comment.
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 theAbstract/*.rb
mentioned above. Then again, I'm not a fan of subclassingFormula
that way in the first place.There was a problem hiding this comment.
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.