github.com/wader/devd@v0.0.0-20221031103345-441c7e455249/scripts/mkbrew (about)

     1  #!/usr/bin/env python2
     2  import subprocess
     3  import sys
     4  import requests
     5  import hashlib
     6  
     7  TEMPLATE = """
     8  require "language/go"
     9  
    10  class Devd < Formula
    11    desc "Local webserver for developers"
    12    homepage "https://github.com/cortesi/devd"
    13    url "https://github.com/cortesi/devd/archive/{version}.tar.gz"
    14    sha256 "{hash}"
    15    head "https://github.com/cortesi/devd.git"
    16  
    17    bottle do
    18      cellar :any_skip_relocation
    19      sha256 "3b7c357c44ec47b77d5ad89ff929b38447cb87b1b5698e0efa1d558cb22c7b26" => :el_capitan
    20      sha256 "3a91f99b6136a401cd5551d0ed2c06e100bb80e7a844478096fff9ee944934b3" => :yosemite
    21      sha256 "6e160b2d36c713c3dce3342f30c7ea2e81b6ec449719e01781c4ca5b21bf3e9e" => :mavericks
    22    end
    23  
    24    depends_on "go" => :build
    25    {resources}
    26  
    27    def install
    28      ENV["GOOS"] = "darwin"
    29      ENV["GOARCH"] = MacOS.prefer_64_bit? ? "amd64" : "386"
    30      ENV["GOPATH"] = buildpath
    31      (buildpath/"src/github.com/cortesi/devd").install buildpath.children
    32      Language::Go.stage_deps resources, buildpath/"src"
    33      cd "src/github.com/cortesi/devd" do
    34        system "go", "build", "-o", bin/"devd", ".../cmd/devd"
    35        prefix.install_metafiles
    36      end
    37    end
    38  
    39    test do
    40      begin
    41        io = IO.popen("#{{bin}}/devd #{{testpath}}")
    42        sleep 2
    43      ensure
    44        Process.kill("SIGINT", io.pid)
    45        Process.wait(io.pid)
    46      end
    47  
    48      assert_match "Listening on http://devd.io", io.read
    49    end
    50  end
    51  """
    52  
    53  
    54  def main(version):
    55      url = "https://github.com/cortesi/devd/archive/%s.tar.gz"%version
    56      print >> sys.stderr, "Calculating hash from %s..."%url
    57      resp = requests.get(url)
    58      if resp.status_code != 200:
    59          print "ERROR"
    60          return
    61  
    62      hash = hashlib.sha256(resp.content).hexdigest()
    63  
    64      print >> sys.stderr, "Generating external resources"
    65      goresources = subprocess.check_output(
    66          ["homebrew-go-resources", "./cmd/devd"]
    67      )
    68      print TEMPLATE.format(
    69          resources=goresources,
    70          version=version,
    71          hash=hash
    72      )
    73  
    74  
    75  if __name__ == "__main__":
    76      if len(sys.argv) != 2:
    77          print >> sys.stderr, "Please specify version"
    78          sys.exit(1)
    79      main(sys.argv[1])