homebrew-core/Formula/faas-cli.rb

94 lines
3.3 KiB
Ruby

class FaasCli < Formula
desc "CLI for templating and/or deploying FaaS functions"
homepage "https://www.openfaas.com/"
url "https://github.com/openfaas/faas-cli.git",
tag: "0.14.7",
revision: "0451db85faebbc4b2c9c69c8af64686ff6617825"
license "MIT"
head "https://github.com/openfaas/faas-cli.git", branch: "master"
livecheck do
url :stable
strategy :github_latest
end
bottle do
sha256 cellar: :any_skip_relocation, arm64_monterey: "3814557a999c90b023d686b7c1c6b971081c24bb23de2315fe60df3b8ddcf7bf"
sha256 cellar: :any_skip_relocation, arm64_big_sur: "1a1061de2ac2e9b3dbfae2746f196f6b6bbd950b634590fdb4e4fed7348e04b5"
sha256 cellar: :any_skip_relocation, monterey: "3195c194d2c9d635dc48811383c035685e3c85ba597a302fbf486828681d9043"
sha256 cellar: :any_skip_relocation, big_sur: "15ed9aabab9aa47f950f3718af39f6f4349d53fcb7e5701d6cb6e8687cf72f07"
sha256 cellar: :any_skip_relocation, catalina: "23e1ef15a1202e6188874bdbc69a103a4a91863d56e5fc379c4e7f8bb39e9d8a"
sha256 cellar: :any_skip_relocation, x86_64_linux: "acda2168fc7bb427469eddc7c426b9d16f0fe30300352d1d1331cbf86b950aae"
end
depends_on "go" => :build
def install
ENV["XC_OS"] = OS.kernel_name.downcase
ENV["XC_ARCH"] = Hardware::CPU.intel? ? "amd64" : Hardware::CPU.arch.to_s
project = "github.com/openfaas/faas-cli"
ldflags = %W[
-s -w
-X #{project}/version.GitCommit=#{Utils.git_head}
-X #{project}/version.Version=#{version}
]
system "go", "build", *std_go_args(ldflags: ldflags), "-a", "-installsuffix", "cgo"
bin.install_symlink "faas-cli" => "faas"
generate_completions_from_executable(bin/"faas-cli", "completion", "--shell", shells: [:bash, :zsh])
# make zsh completions also work for `faas` symlink
inreplace zsh_completion/"_faas-cli", "#compdef faas-cli", "#compdef faas-cli\ncompdef faas=faas-cli"
end
test do
require "socket"
server = TCPServer.new("localhost", 0)
port = server.addr[1]
pid = fork do
loop do
socket = server.accept
response = "OK"
socket.print "HTTP/1.1 200 OK\r\n" \
"Content-Length: #{response.bytesize}\r\n" \
"Connection: close\r\n"
socket.print "\r\n"
socket.print response
socket.close
end
end
(testpath/"test.yml").write <<~EOS
provider:
name: openfaas
gateway: https://localhost:#{port}
network: "func_functions"
functions:
dummy_function:
lang: python
handler: ./dummy_function
image: dummy_image
EOS
begin
output = shell_output("#{bin}/faas-cli deploy --tls-no-verify -yaml test.yml 2>&1", 1)
assert_match "stat ./template/python/template.yml", output
assert_match "ruby", shell_output("#{bin}/faas-cli template pull 2>&1")
assert_match "node", shell_output("#{bin}/faas-cli new --list")
output = shell_output("#{bin}/faas-cli deploy --tls-no-verify -yaml test.yml", 1)
assert_match "Deploying: dummy_function.", output
commit_regex = /[a-f0-9]{40}/
faas_cli_version = shell_output("#{bin}/faas-cli version")
assert_match commit_regex, faas_cli_version
assert_match version.to_s, faas_cli_version
ensure
Process.kill("TERM", pid)
Process.wait(pid)
end
end
end