Skip to content

tap_auditor: ensure lists of packages are in sorted order #19972

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

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

Conversation

botantony
Copy link
Contributor

  • 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?

It would be nice to check if lists of formulae/casks in files (f.e. autobump.txt or formula_renames) are in sorted order

@botantony botantony force-pushed the tap_auditor branch 5 times, most recently from a1c1a11 to eead40c Compare May 19, 2025 11:04
@botantony botantony marked this pull request as draft May 19, 2025 11:16
list_without_versions = if list_file == ".github/autobump.txt"
list
else
# Allow versioned packages not to follow the strict order
Copy link
Member

Choose a reason for hiding this comment

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

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because sometimes we want to arrange versioned in different order. Instead of ["package@1.10", "package@1.11", "package@1.9"] I'd prefer ["package@1.9", "package@1.10", "package@1.11"]

Copy link
Member

Choose a reason for hiding this comment

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

It would be nice to enforce that ordering.

list.map { |s| s.split("@", 2).first }
end

sorted = list_without_versions.each_cons(2).all? do |a, b|
Copy link
Member

Choose a reason for hiding this comment

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

Why the 2?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's no built-in method to check if an array is sorted so I had to implement it on my own, see similar question on StackOverflow
https://stackoverflow.com/questions/8015775/check-to-see-if-an-array-is-already-sorted

Copy link
Member

Choose a reason for hiding this comment

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

Generally comparing the array and array.sort is an easy way to verify this.

a <= b
end

sorted = true if list_file == "formula_renames" # Skip sort check for renames
Copy link
Member

Choose a reason for hiding this comment

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

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fromula_renames audit works with values of the keys, not the keys themselves.
In JSON like

{
  "amtk": "libgedit-amtk",
  "annie": "lux",
  "ark": "velero",
  "arm": "nyx",
  "asciigen": "glyph"
}

it checks if array ["libgedit-amtk", "lux", "velero", "nyx", "glyph"] is sorted

Copy link
Member

Choose a reason for hiding this comment

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

do we check both keys and values are sorted elsewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The check is performed only on values, keys are not checked at all

Copy link
Member

Choose a reason for hiding this comment

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

Feels like it'd be desirable to sort both keys and values.

Signed-off-by: botantony <antonsm21@gmail.com>
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.

2 participants