require "language/go" class GitlabRunner < Formula desc "The official GitLab CI runner written in Go" homepage "https://gitlab.com/gitlab-org/gitlab-runner" url "https://gitlab.com/gitlab-org/gitlab-runner.git", :tag => "v10.2.0", :revision => "0a75cdd19694787682d38143b3aaf11d641c3117" head "https://gitlab.com/gitlab-org/gitlab-runner.git" bottle do sha256 "8b75fa67c1a6ecd46c54a284542bcd13f1df90d5f9004f9e93db4adadd524cc8" => :high_sierra sha256 "571cf540bf92dcbfa9b3f8888112a31afcbfaa3daaa96804a969b6a28ce564a8" => :sierra sha256 "f9a1b2ec1f749204c43edfa635d4848cb7bcccf3bce9ceca99f0da51fdaeb4e2" => :el_capitan end depends_on "go" => :build depends_on "docker" => :recommended go_resource "github.com/jteeuwen/go-bindata" do url "https://github.com/jteeuwen/go-bindata.git", :revision => "a0ff2567cfb70903282db057e799fd826784d41d" end resource "prebuilt-x86_64.tar.xz" do url "https://gitlab-runner-downloads.s3.amazonaws.com/v10.2.0/docker/prebuilt-x86_64.tar.xz", :using => :nounzip version "10.2.0" sha256 "e6cee7f8dfc400088ecf8be594705994b1b61e3fbb96e85a3d72473313fc3ea4" end resource "prebuilt-arm.tar.xz" do url "https://gitlab-runner-downloads.s3.amazonaws.com/v10.2.0/docker/prebuilt-arm.tar.xz", :using => :nounzip version "10.2.0" sha256 "d6ea9e81bd20c5cf785f534f9061d76ca9452323cea8d52739bfe8c99dd36ef7" end def install ENV["GOPATH"] = buildpath dir = buildpath/"src/gitlab.com/gitlab-org/gitlab-runner" dir.install buildpath.children ENV.prepend_create_path "PATH", buildpath/"bin" Language::Go.stage_deps resources, buildpath/"src" cd "src/github.com/jteeuwen/go-bindata/go-bindata" do system "go", "install" end cd dir do Pathname.pwd.install resource("prebuilt-x86_64.tar.xz"), resource("prebuilt-arm.tar.xz") system "go-bindata", "-pkg", "docker", "-nocompress", "-nomemcopy", "-nometadata", "-o", "#{dir}/executors/docker/bindata.go", "prebuilt-x86_64.tar.xz", "prebuilt-arm.tar.xz" proj = "gitlab.com/gitlab-org/gitlab-runner" commit = Utils.popen_read("git", "rev-parse", "--short", "HEAD").chomp branch = version.to_s.split(".")[0..1].join("-") + "-stable" built = Time.new.strftime("%Y-%m-%dT%H:%M:%S%:z") system "go", "build", "-ldflags", <<~EOS -X #{proj}/common.NAME=gitlab-runner -X #{proj}/common.VERSION=#{version} -X #{proj}/common.REVISION=#{commit} -X #{proj}/common.BRANCH=#{branch} -X #{proj}/common.BUILT=#{built} EOS bin.install "gitlab-runner" prefix.install_metafiles end end plist_options :manual => "gitlab-runner start" def plist; <<~EOS SessionCreate KeepAlive RunAtLoad Disabled Label #{plist_name} ProgramArguments #{opt_bin}/gitlab-runner run --working-directory #{ENV["HOME"]} --config #{ENV["HOME"]}/.gitlab-runner/config.toml --service gitlab-runner --syslog EOS end test do assert_match version.to_s, shell_output("#{bin}/gitlab-runner --version") end end