Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore brew fix formula generation #71

Merged
merged 2 commits into from
Oct 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

### Not released yet

DIST:

* homebrew: Approriate harp version can be installed according to your platform architecture and OS [#71](https://github.com/elastic/harp/pull/71)

CHANGES:

* core/vault: Replace json encoded metadata in secret data by a JSON object. [#68](https://github.com/elastic/harp/pull/68)
Expand Down
60 changes: 36 additions & 24 deletions build/mage/release/formula.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,39 @@ import (
"github.com/elastic/harp/build/artifact"
)

var formulaTemplate = strings.TrimSpace(`# Code generated by Harp build tool
var formulaTemplate = strings.TrimSpace(`# typed: false
# frozen_string_literal: true

# Code generated by Harp build tool
class {{ .Formula }} < Formula
desc "{{ .Description }}"
homepage "https://{{ .Repository }}"
license "Apache-2.0"
bottle :unneeded

# Stable build
stable do
if OS.mac? && Hardware::CPU.arm?
url "https://{{ .Repository }}/releases/download/cmd%2F{{ .Bin }}%2F{{ .Release }}/{{ .Bin }}-darwin-arm64-{{ .Release }}.tar.xz"
sha256 "{{ sha256file (printf "dist/%s-darwin-arm64-%s.tar.xz" .Bin .Release) }}"
elsif OS.mac?
url "https://{{ .Repository }}/releases/download/cmd%2F{{ .Bin }}%2F{{ .Release }}/{{ .Bin }}-darwin-amd64-{{ .Release }}.tar.xz"
sha256 "{{ sha256file (printf "dist/%s-darwin-amd64-%s.tar.xz" .Bin .Release) }}"
elsif OS.linux?
url "https://{{ .Repository }}/releases/download/cmd%2F{{ .Bin }}%2F{{ .Release }}/{{ .Bin }}-linux-amd64-{{ .Release }}.tar.xz"
sha256 "{{ sha256file (printf "dist/%s-linux-amd64-%s.tar.xz" .Bin .Release) }}"
on_macos do
if Hardware::CPU.intel?
url "https://{{ .Repository }}/releases/download/cmd%2F{{ .Bin }}%2F{{ .Release }}/{{ .Bin }}-darwin-amd64-{{ .Release }}.tar.xz"
sha256 "{{ sha256file (printf "dist/%s-darwin-amd64-%s.tar.xz" .Bin .Release) }}"
elsif Hardware::CPU.arm?
url "https://{{ .Repository }}/releases/download/cmd%2F{{ .Bin }}%2F{{ .Release }}/{{ .Bin }}-darwin-arm64-{{ .Release }}.tar.xz"
sha256 "{{ sha256file (printf "dist/%s-darwin-arm64-%s.tar.xz" .Bin .Release) }}"
end
end
on_linux do
if Hardware::CPU.intel?
if Hardware::CPU.is_64_bit?
url "https://{{ .Repository }}/releases/download/cmd%2F{{ .Bin }}%2F{{ .Release }}/{{ .Bin }}-linux-amd64-{{ .Release }}.tar.xz"
sha256 "{{ sha256file (printf "dist/%s-linux-amd64-%s.tar.xz" .Bin .Release) }}"
end
elsif Hardware::CPU.arm?
if Hardware::CPU.is_64_bit?
url "https://{{ .Repository }}/releases/download/cmd%2F{{ .Bin }}%2F{{ .Release }}/{{ .Bin }}-linux-arm64-{{ .Release }}.tar.xz"
sha256 "{{ sha256file (printf "dist/%s-linux-arm64-%s.tar.xz" .Bin .Release) }}"
else
url "https://{{ .Repository }}/releases/download/cmd%2F{{ .Bin }}%2F{{ .Release }}/{{ .Bin }}-linux-arm7-{{ .Release }}.tar.xz"
sha256 "{{ sha256file (printf "dist/%s-linux-arm7-%s.tar.xz" .Bin .Release) }}"
end
end
end
end

Expand All @@ -62,16 +77,7 @@ class {{ .Formula }} < Formula
def install
ENV.deparallelize

unless build.head?
# Install binaries
if OS.mac? && Hardware::CPU.arm?
bin.install "{{ .Bin }}-darwin-arm64" => "{{ .Bin }}"
elsif OS.mac?
bin.install "{{ .Bin }}-darwin-amd64" => "{{ .Bin }}"
elsif OS.linux?
bin.install "{{ .Bin }}-linux-amd64" => "{{ .Bin }}"
end
else
if build.head?
# Prepare build environment
ENV["GOPATH"] = buildpath
(buildpath/"src/{{ .Repository }}").install Dir["{*,.git,.gitignore}"]
Expand All @@ -96,6 +102,13 @@ class {{ .Formula }} < Formula
bin.install "{{ .Bin }}-linux-amd64" => "{{ .Bin }}"
end
end
elsif OS.mac? && Hardware::CPU.arm?
# Install binaries
bin.install "{{ .Bin }}-darwin-arm64" => "{{ .Bin }}"
elsif OS.mac?
bin.install "{{ .Bin }}-darwin-amd64" => "{{ .Bin }}"
elsif OS.linux?
bin.install "{{ .Bin }}-linux-amd64" => "{{ .Bin }}"
end

# Final message
Expand All @@ -114,7 +127,6 @@ class {{ .Formula }} < Formula
assert_match version.to_s, shell_output("#{bin}/{{ .Bin }} version")
end
end

`)

type formulaModel struct {
Expand Down