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.4.0", :revision => "857480b64b013d8edffaf70e4b7ea43ee1c66a9e" head "https://gitlab.com/gitlab-org/gitlab-runner.git" bottle do sha256 "21886f4f36c3ce1a810166f6b4a3b29813f60f43c4ff3d06dfbac0d541913981" => :high_sierra sha256 "7acad56cc8784144d6120510d70e93f397e6c515b900208a742c34dba2eea44c" => :sierra sha256 "cdc63301f3b82c014cdba21da6428517a023a733a53ce988002c4c4f74f4d8df" => :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.4.0/docker/prebuilt-x86_64.tar.xz", :using => :nounzip version "10.4.0" sha256 "aa8bccad577923276f2828b69577ad032acd2ffb4818bb5418483e5e436c8d39" end resource "prebuilt-arm.tar.xz" do url "https://gitlab-runner-downloads.s3.amazonaws.com/v10.4.0/docker/prebuilt-arm.tar.xz", :using => :nounzip version "10.4.0" sha256 "a470da06463aca65972151967d5be22d420fd347e0fd3972f958d72f531c93fe" 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