mislav / bump-homebrew-formula-action

Automatically bump Homebrew formula after a release
The Unlicense
165 stars 32 forks source link

Support for Homebrew Cask #42

Open MWin123 opened 1 year ago

MWin123 commented 1 year ago

Hi,

are there any plans to add support for Homebrew casks?

According to How to Open a Homebrew Pull Request there is a cask version of brew bump-formula-pr as well, i.e., brew bump-cask-pr.

mislav commented 1 year ago

Hi, I don't have experience with updating casks. I'm not opposed to the feature.

What fields do you typically need updated when bumping a cask formula?

MWin123 commented 1 year ago

Great! It seems like currently there is no working GitHub Action to update casks.

I don't have that much experience with Homebrew formulas or casks, but I believe that version, sha256 (generated) & url are the most important fields to update.

In my cask repo we just update version & sha256 because the url contains #{version}.

mislav commented 1 year ago

@MWin123 This Action should already have the ability to update those fields in a file in theory. You can also use the formula-path input parameter to override the file path to be edited to something like Casks/mycask.rb. Could you try that? https://github.com/mislav/bump-homebrew-formula-action/blob/dfea670072c2c0bb96924bcafd8dd9c0397c073f/src/main.ts#L76

MWin123 commented 1 year ago

Thanks, I just tested the action with formula-path: Casks/mycask.rb, and it worked! It created a PR for the cask with an updated version, sha256 & url.

Unfortunately, there was one problem. brew audit fails now.

brew audit --tap=mwin123/esque
==> FAILED
Full audit --tap=mwin123/esque output
  audit for kafkaesque: failed
   - Use `sha256 :no_check` when URL is unversioned.
  Error: 1 problem in 1 cask detected
  Error: Use `sha256 :no_check` when URL is unversioned.

Currently, it uses the following url in the cask definition where the url references the version field.

version "2.4.0"
sha256 "..."
url "https://github.com/patschuh/KafkaEsque/releases/download/v#{version}/kafkaesque-#{version}.dmg"

This solution passes brew audit, so it seems like it would be best to keep the current, "versioned" url.

Is it possible to just update the version and sha256 fields, and leave the url field unchanged? If I change the url in the action to the one in the cask definition, the download fails, and it can't generate the hash.

Sorry my late reply.

Edit: I forked this repo, and commented out the following line.

https://github.com/mislav/bump-homebrew-formula-action/blob/ab7aa3933be49444f6e147c7aadbf9d250d923b0/src/main.ts#L99

With the forked action it works as expected. It doesn't replace the url field, and brew audit is successful.

If you decided to add explicit support for Homebrew casks, a feature toggle could be used to disable the url replacement for casks.

mislav commented 1 year ago

@MWin123 Thanks for the deep dive into this and for sharing your solution.

I think you could set addition parameters to get around your problem:

formula-path: Casks/mycask.rb
download-url: https://github.com/patschuh/KafkaEsque/releases/download/v#{version}/kafkaesque-#{version}.dmg
download-sha256: <CHECKSUM>

assuming that the #{...} syntax will not be expanded by either GitHub Actions nor YAML processing, when "CHECKSUM" value is the sha256 of the .dmg file being released, it should all come together and work for your case in theory.

If embedding #{version} in download URLs for Homebrew is commonpractice, I could consider a change to support that interpolation in this action. By having that feature, the download-sha256 param would again become optional as it can be calculated on the fly.

MWin123 commented 1 year ago

I'm not sure if I'm missing something but where would I get the checksum from?

If embedding #{version} in download URLs for Homebrew is commonpractice

I randomly clicked on a few casks in the official cask repo, and they all had a version parameter in the URL. If brew audit fails otherwise, it's probably mandatory for official casks.

p-linnane commented 1 year ago

I sometimes see this action when I'm merging cask PR's: https://github.com/macauley/action-homebrew-bump-cask

Might be good for inspiration 😄