How do I add multiple versions to a formula on GitHub?


#1

I have a formula that is hosted on GitHub, which users can install using:

brew install --HEAD org/repo/package

The formula is quite simple. It clones another GitHub repository, runs a build script, then marks a directory as bin.

The source repository has tags for versioning. I would like to add these tags as versions in the Homebrew formula, but all of the examples I have seen are using hashed zips.

The end result should be that --HEAD still works, but by default running brew install org/repo/package will just install the latest version.

What is the syntax for adding these versions to my formula?


(Mike McQuaid) #2

Can you be more specific on what you’re asking and provide the current formula and what version you would like HEAD and non-HEAD to install? Thanks!


#3

The current formula looks like this:

require 'formula'

class Buckaroo < Formula
  homepage 'https://github.com/loopperfect/buckaroo'
  head 'https://github.com/LoopPerfect/buckaroo.git', :using => :git
  depends_on :java => "1.8+"
  depends_on 'buck'
  def install
    system 'buck', 'build', ':buckaroo-cli'
    libexec.install Dir["buck-out/gen/*"]
    bin.write_jar_script libexec + "buckaroo-cli.jar", "buckaroo"
  end
  def caveats
    "Anonymous usage statistics are enabled by default. \n" +
    "For more information and instructions for disabling analytics, visit: \n" +
    "https://buckaroo.readthedocs.io/"
  end
end

If the user installs with --HEAD it should install the latest commit on master. If the user installs without --HEAD, it should install the latest tag. I don’t know how to add Git tags to the formula.

Additionally, I would like old tags to be in the formula. If the latest tag is v2.0.0, then it should still be possible to switch to v1.0.0, for example.


(Mike McQuaid) #4

Add url "https://github.com/LoopPerfect/buckaroo/archive/v0.1.0.tar.gz" and a sha256. You’ll need to update that on each release, we don’t support formulae automatically installing the latest tags (because they might not work).

Some other advice would be to do bin.write_jar_script "#{libexec}/buckaroo-cli.jar", "buckaroo", add more newlines for readability, use EOS.undent for the caveats to be easier to follow and remove :using => :git which should be automatically detected.


#5

Thanks for the pointers.

Can I add multiple url entries?

I would like to express something like this:

{
  "v0.1.0": {
    "url": "https://github.com/LoopPerfect/buckaroo/archive/v0.1.0.tar.gz", 
    "sha256": "..."
   }, 
   "v0.2.0": {
    "url": "https://github.com/LoopPerfect/buckaroo/archive/v0.2.0.tar.gz", 
    "sha256": "..."
   }
}

The idea is that I can update the formula to add more versions as they get released.


(Mike McQuaid) #6

You can add a stable do url (a url outside stable do is implied to be stable), devel do url and your head URL as you currently have. Formulae do not support multiple versions. For your system you would need to have multiple formulae e.g. buckaroo and buckaroo@0.1


#7

So for example:

If I have a formula (myFormula) with 3 versions (3.0.0, 2.0.0, 1.0.0) then I would create the following files:

myFormula.rb           # The formula of the latest version (3.0.0)
myFormula2.0.0.rb      # The formula of version 2.0.0
myFormula1.0.0.rb      # The formula of version 1.0.0

Then when version 4.0.0 is released, I would create myFormula3.0.0.rb and update myFormula.rb to point to 4.0.0 .

  • Is this the recommended approach?
  • Will Homebrew understand the version suffixes?

(Mike McQuaid) #8

buckaroo.rb, buckaroo@0.1.rb, buckaroo@0.2.rb and an alias from buckaroo.rb to buckaroo@0.3. The formula names need to be e.g. BuckarooAT01.


#9

OK, makes sense.

What do you mean by alias? Is there an example of a formula that is an alias for another somewhere? How do I express that in a formula file?


#10

Ah, figured it out. For people who stumble on this:

For each version:

  • Create a formula named myFormula@version.rb.
  • Inside, ensure that the class name is myFormulaATversion

For example, myFormula@1.0.0.rb should contain class myFormulaAT100 < Formula.

Then, in the root of your Homebrew repository, create a folder called Aliases. In here, create a symlink with the name of your formula to the current latest version.

For example, Aliases/myFormula would be a symlink to ../myFormula@1.0.0.rb.