Skip to content

Conversation

@cho-m
Copy link
Member

@cho-m cho-m commented Sep 16, 2025

This expands prior logic for :parent resources to also allow autobumping livecheck-defined resources.

Only works for some standard formats so can't deal with on_system blocks within resources, comments, etc. yet.

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

This expands prior logic for `:parent` resources to also allow
autobumping livecheck-defined resources.

Only works for some standard formats so can't deal with on_system blocks
within resources, comments, etc. yet.
MikeMcQuaid
MikeMcQuaid previously approved these changes Sep 16, 2025
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.

Looks good when 🟢 and @samford is 👍🏻

@github-actions
Copy link

github-actions bot commented Oct 7, 2025

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@github-actions github-actions bot added the stale No recent activity label Oct 7, 2025
@samford
Copy link
Member

samford commented Oct 7, 2025

Apologies for the delay, I'll try to review this tonight. The notification ended up being buried in my inbox until stalebot reminded me.

@samford samford removed the stale No recent activity label Oct 7, 2025
Copy link
Member

@samford samford left a comment

Choose a reason for hiding this comment

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

I haven't manually tested this but allowing bump-formula-pr to update any resources with a livecheck block (beyond those using formula :parent) makes sense to me as the next step in gradually expanding support. Figuring out if a new version is appropriate for the formula's software is the hard part when it comes to updating resources but resource livecheck blocks should be accounting for that, at least in theory. I haven't checked the existing resource livecheck blocks recently but it would be a good idea to confirm that's still true before merging this (I can probably take a look tomorrow when I have a moment).

My review comments here only ended up being stylistic tweaks, as it looks reasonable otherwise (granted, it's late and my brain is tired, so take that with a grain of salt 😆).

Comment on lines +572 to +574
new_version = formula_version

if resource.livecheck.formula != :parent
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
new_version = formula_version
if resource.livecheck.formula != :parent
if resource.livecheck.formula == :parent
new_version = formula_version
else

We only want to set new_version to formula_version when the livecheck block uses formula :parent, so an if/else setup may make this more explicit. The existing logic works but I think this suggestion is easier to follow.

verbose: args.verbose?)
new_version = version_info.dig(:version, :latest)
odie "Resource \"#{resource.name}\" livecheck failed to get latest version!" if new_version.blank?
next if old_version == new_version
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
next if old_version == new_version
next if new_version == old_version

This may just be me but with comparisons, I prefer to put the variable that I'm interested in first. In this case, this suggestion would read as, "Don't proceed if the new version is the same as the old version" and I think that's easy to follow and makes it clear what we're interested in.

Copy link
Member Author

@cho-m cho-m Oct 8, 2025

Choose a reason for hiding this comment

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

Sure, can update to this.

Unrelated but GitHub batch apply is suddenly not working so may have to apply each suggestion individually.

new_version
elsif (old_tag = resource.specs[:tag])
new_tag = old_tag.gsub(old_version, new_version)
odie "Resource \"#{resource.name}\" tag could not be updated!" if old_tag == new_tag
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
odie "Resource \"#{resource.name}\" tag could not be updated!" if old_tag == new_tag
odie "Resource \"#{resource.name}\" tag could not be updated!" if new_tag == old_tag

Same here, if you agree with the previous comment.

EOS
end
# Allow skipping different tags on same revision
next if old_revision == new_revision
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
next if old_revision == new_revision
next if new_revision == old_revision

Comment on lines +606 to +609
^(?<ws>[ ]+)resource\ "#{resource.name}"\ do\s+
url\ "#{Regexp.escape(old_url)}",\s+
(using:[ ]+.*,\s+)?
(tag:[ ]+.*,\s+)?
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
^(?<ws>[ ]+)resource\ "#{resource.name}"\ do\s+
url\ "#{Regexp.escape(old_url)}",\s+
(using:[ ]+.*,\s+)?
(tag:[ ]+.*,\s+)?
^(?<ws> +)resource\ "#{resource.name}"\ do\s+
url\ "#{Regexp.escape(old_url)}",\s+
(using: +.*,\s+)?
(tag: +.*,\s+)?

Unless I'm overlooking something, I believe you should be able to use + here instead of [ ]+. The previous regex was using [ ]+ because the space was at the very start of the line but that's not the case here.

Copy link
Member Author

@cho-m cho-m Oct 8, 2025

Choose a reason for hiding this comment

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

Extended mode (x) so either need \ or [ ]. Could switch to former as it is used it in other parts of regexp.

Copy link
Member

Choose a reason for hiding this comment

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

I really don't think we should add more regexp for this when we have AST logic already. They will be brittle and error-prone. Ideally we'd move away from the existing regexp in bump* too because they predate our vendored AST logic.

Copy link
Member Author

Choose a reason for hiding this comment

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

I really don't think we should add more regexp for this when we have AST logic already. They will be brittle and error-prone. Ideally we'd move away from the existing regexp in bump* too because they predate our vendored AST logic.

Sounds reasonable.

Won't have time to look into this so will close PR for now in case anyone else wants to work on it.

new_resource_block += "\\k<ws> version \"#{new_version}\"\n" if forced_version
else
new_url = update_url(old_url, old_version, new_version)
if old_url == new_url
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if old_url == new_url
if new_url == old_url


# Capture old_url to avoid possible HEAD resources
inreplace_regex = /
^(?<ws>[ ]+)resource\ "#{resource.name}"\ do\s+
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
^(?<ws>[ ]+)resource\ "#{resource.name}"\ do\s+
^(?<ws> +)resource\ "#{resource.name}"\ do\s+

@cho-m cho-m added the in progress Maintainers are working on this label Oct 8, 2025
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.

Pulling ✅, sorry.

Comment on lines +606 to +609
^(?<ws>[ ]+)resource\ "#{resource.name}"\ do\s+
url\ "#{Regexp.escape(old_url)}",\s+
(using:[ ]+.*,\s+)?
(tag:[ ]+.*,\s+)?
Copy link
Member

Choose a reason for hiding this comment

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

I really don't think we should add more regexp for this when we have AST logic already. They will be brittle and error-prone. Ideally we'd move away from the existing regexp in bump* too because they predate our vendored AST logic.

@MikeMcQuaid MikeMcQuaid dismissed their stale review October 8, 2025 18:23

Removing ✅

@cho-m cho-m closed this Oct 8, 2025
@cho-m cho-m removed the in progress Maintainers are working on this label Oct 8, 2025
@MikeMcQuaid MikeMcQuaid reopened this Oct 9, 2025
@MikeMcQuaid
Copy link
Member

@cho-m Ok, fine to merge this approach as-is as long as we create at least a # TODO and ideally a issue to cleanup this/these regexes after. Deal?

@cho-m
Copy link
Member Author

cho-m commented Oct 12, 2025

I won't have time to finish up PR for a couple weeks. I can update PR when I am available assuming no one has superseded it.

@MikeMcQuaid
Copy link
Member

@cho-m Ok, closing until then. When you reopen can we try the AST approach please.

@p-linnane p-linnane deleted the bump-formula-pr-resources branch November 5, 2025 16:37
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.

4 participants