@@ -36,79 +36,72 @@ var formulaTemplate = strings.TrimSpace(`# typed: false
3636class {{ .Formula }} < Formula
3737 desc "{{ .Description }}"
3838 homepage "https://{{ .Repository }}"
39+ version "{{ .Version }}"
3940 license "Apache-2.0"
40- stable do
41- on_macos do
42- if Hardware::CPU.intel?
43- url "https://{{ .Repository }}/releases/download/cmd%2F{{ .Bin }}%2F{{ .Release }}/{{ .Bin }}-darwin-amd64-{{ .Release }}.tar.gz"
44- sha256 "{{ sha256file (printf "dist/%s-darwin-amd64-%s.tar.gz" .Bin .Release) }}"
45- elsif Hardware::CPU.arm?
46- url "https://{{ .Repository }}/releases/download/cmd%2F{{ .Bin }}%2F{{ .Release }}/{{ .Bin }}-darwin-arm64-{{ .Release }}.tar.gz"
47- sha256 "{{ sha256file (printf "dist/%s-darwin-arm64-%s.tar.gz" .Bin .Release) }}"
48- end
41+
42+ on_macos do
43+ if Hardware::CPU.intel?
44+ url "https://{{ .Repository }}/releases/download/{{ .Release }}/{{ .Bin }}-darwin-amd64-v1.tar.gz"
45+ sha256 "{{ sha256file (printf "dist/%s-darwin-amd64-v1.tar.gz" .Bin) }}"
46+ elsif Hardware::CPU.arm?
47+ url "https://{{ .Repository }}/releases/download/{{ .Release }}/{{ .Bin }}-darwin-arm64-v8.0.tar.gz"
48+ sha256 "{{ sha256file (printf "dist/%s-darwin-arm64-v8.0.tar.gz" .Bin) }}"
4949 end
50- on_linux do
51- if Hardware::CPU.intel?
52- if Hardware::CPU.is_64_bit?
53- url "https://{{ .Repository }}/releases/download/cmd%2F{{ .Bin }}%2F{{ .Release }}/{{ .Bin }}-linux-amd64-{{ .Release }}.tar.gz"
54- sha256 "{{ sha256file (printf "dist/%s-linux-amd64-%s.tar.gz" .Bin .Release) }}"
55- end
56- elsif Hardware::CPU.arm?
57- if Hardware::CPU.is_64_bit?
58- url "https://{{ .Repository }}/releases/download/cmd%2F{{ .Bin }}%2F{{ .Release }}/{{ .Bin }}-linux-arm64-{{ .Release }}.tar.gz"
59- sha256 "{{ sha256file (printf "dist/%s-linux-arm64-%s.tar.gz" .Bin .Release) }}"
60- else
61- url "https://{{ .Repository }}/releases/download/cmd%2F{{ .Bin }}%2F{{ .Release }}/{{ .Bin }}-linux-arm7-{{ .Release }}.tar.gz"
62- sha256 "{{ sha256file (printf "dist/%s-linux-arm7-%s.tar.gz" .Bin .Release) }}"
63- end
50+ end
51+
52+ on_linux do
53+ if Hardware::CPU.intel?
54+ if Hardware::CPU.is_64_bit?
55+ url "https://{{ .Repository }}/releases/download/{{ .Release }}/{{ .Bin }}-linux-amd64-v1.tar.gz"
56+ sha256 "{{ sha256file (printf "dist/%s-linux-amd64-v1.tar.gz" .Bin) }}"
57+ end
58+ elsif Hardware::CPU.arm?
59+ if Hardware::CPU.is_64_bit?
60+ url "https://{{ .Repository }}/releases/download/{{ .Release }}/{{ .Bin }}-linux-arm64-v8.0.tar.gz"
61+ sha256 "{{ sha256file (printf "dist/%s-linux-arm64-v8.0.tar.gz" .Bin) }}"
62+ else
63+ url "https://{{ .Repository }}/releases/download/{{ .Release }}/{{ .Bin }}-linux-arm-6.tar.gz"
64+ sha256 "{{ sha256file (printf "dist/%s-linux-arm-6.tar.gz" .Bin) }}"
6465 end
6566 end
6667 end
6768
68- # Source definition
69- head do
70- url "https://{{ .Repository }}.git", :branch => "main"
71-
72- # build dependencies
73- depends_on "go" => :build
74- depends_on "mage" => :build
75- end
69+ conflicts_with "{{ .Bin }}-fips", because: "{{ .Bin }}-fips also ships a '{{ .Bin }}' binary"
7670
7771 def install
7872 ENV.deparallelize
7973
80- if build.head?
81- # Prepare build environment
82- ENV["GOPATH"] = buildpath
83- (buildpath/"src/{{ .Repository }}").install Dir["{*,.git,.gitignore}"]
84-
85- # Mage tools
86- ENV.prepend_path "PATH", buildpath/"tools/bin"
87-
88- # In {{ .Repository }} command
89- cd "src/{{ .Repository }}/cmd/{{ .Bin }}" do
90- system "go", "mod", "vendor"
91- system "mage", "compile"
74+ # Install binaries
75+ if OS.mac?
76+ if Hardware::CPU.arm?
77+ bin.install "{{ .Bin }}-darwin-arm64-v8.0" => "{{ .Bin }}"
78+ else
79+ bin.install "{{ .Bin }}-darwin-amd64-v1" => "{{ .Bin }}"
9280 end
93-
94- # Install builded command
95- cd "src/{{ .Repository }}/cmd/{{ .Bin }}/bin" do
96- # Install binaries
97- if OS.mac? && Hardware::CPU.arm?
98- bin.install "{{ .Bin }}-darwin-arm64 " => "{{ .Bin }}"
99- elsif OS.mac?
100- bin.install "{{ .Bin }}-darwin-amd64" => "{{ .Bin }}"
101- elsif OS.linux ?
102- bin.install "{{ .Bin }}-linux-amd64" => "{{ .Bin }}"
81+ elsif OS.linux?
82+ if Hardware::CPU.arm?
83+ if Hardware::CPU.is_64_bit?
84+ bin.install "{{ .Bin }}-linux-arm64-v8.0" => "{{ .Bin }}"
85+ else
86+ bin.install "{{ .Bin }}-linux-arm-6 " => "{{ .Bin }}"
87+ end
88+ else
89+ if Hardware::CPU.is_64_bit ?
90+ bin.install "{{ .Bin }}-linux-amd64-v1 " => "{{ .Bin }}"
10391 end
10492 end
105- elsif OS.mac? && Hardware::CPU.arm?
106- # Install binaries
107- bin.install "{{ .Bin }}-darwin-arm64" => "{{ .Bin }}"
108- elsif OS.mac?
109- bin.install "{{ .Bin }}-darwin-amd64" => "{{ .Bin }}"
110- elsif OS.linux?
111- bin.install "{{ .Bin }}-linux-amd64" => "{{ .Bin }}"
93+ end
94+
95+ # Exclude from Gatekeeper quarantine on macOS Catalina+
96+ if OS.mac? && MacOS.version >= :catalina && /com.apple.quarantine/.match?(Utils.safe_popen_read("xattr", "#{bin}/{{ .Bin }}"))
97+ (bin/"{{ .Bin }}").chmod 0755
98+ begin
99+ system "xattr", "-d",
100+ "com.apple.quarantine",
101+ bin/"{{ .Bin }}"
102+ ensure
103+ (bin/"{{ .Bin }}").chmod 0555
104+ end
112105 end
113106
114107 # Final message
@@ -124,6 +117,7 @@ class {{ .Formula }} < Formula
124117 end
125118
126119 test do
120+ assert_predicate bin/"{{ .Bin }}", :exist?
127121 assert_match version.to_s, shell_output("#{bin}/{{ .Bin }} version")
128122 end
129123end
@@ -135,6 +129,7 @@ type formulaModel struct {
135129 Formula string
136130 Description string
137131 Release string
132+ Version string
138133}
139134
140135// HomebrewFormula generates HomeBrew formula for given command.
@@ -145,6 +140,7 @@ func HomebrewFormula(cmd *artifact.Command) func() error {
145140 if err != nil {
146141 return "" , err
147142 }
143+ defer f .Close ()
148144
149145 // Prepare hasher
150146 h := sha256 .New ()
@@ -157,7 +153,7 @@ func HomebrewFormula(cmd *artifact.Command) func() error {
157153 }
158154 return func () error {
159155 // Compile template
160- formulaTpl , err := template .New ("Formula" ).Funcs (map [string ]interface {} {
156+ formulaTpl , err := template .New ("Formula" ).Funcs (map [string ]any {
161157 "sha256file" : sha256sum ,
162158 }).Parse (formulaTemplate )
163159 if err != nil {
@@ -166,12 +162,15 @@ func HomebrewFormula(cmd *artifact.Command) func() error {
166162
167163 // Merge data
168164 var buf bytes.Buffer
165+ release := os .Getenv ("RELEASE" )
166+ version := strings .TrimPrefix (release , "v" )
169167 if errTmpl := formulaTpl .Execute (& buf , & formulaModel {
170168 Repository : cmd .Package ,
171169 Bin : cmd .Kebab (),
172170 Formula : cmd .Camel (),
173171 Description : cmd .Description ,
174- Release : os .Getenv ("RELEASE" ),
172+ Release : release ,
173+ Version : version ,
175174 }); errTmpl != nil {
176175 return errTmpl
177176 }
0 commit comments