1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-11-06 09:09:29 +02:00

feat(brew): allow to set headers in the url (#4648)

closes  #4647

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
Carlos Alexandro Becker
2024-02-26 17:22:12 -03:00
committed by GitHub
parent bd0c985398
commit 4d2bcfdc46
9 changed files with 237 additions and 0 deletions

View File

@@ -310,6 +310,13 @@ func doBuildFormula(ctx *context.Context, data templateData) (string, error) {
pad := strings.Repeat(" ", spaces)
return pad + strings.ReplaceAll(v, "\n", "\n"+pad)
},
"join": func(in []string) string {
items := make([]string, 0, len(in))
for _, i := range in {
items = append(items, fmt.Sprintf(`"%s"`, i))
}
return strings.Join(items, ",\n")
},
}).ParseFS(formulaTemplate, "templates/*.rb")
if err != nil {
return "", err
@@ -437,6 +444,7 @@ func dataFor(ctx *context.Context, cfg config.Homebrew, cl client.ReleaseURLTemp
OS: art.Goos,
Arch: art.Goarch,
DownloadStrategy: cfg.DownloadStrategy,
Headers: cfg.URLHeaders,
Install: install,
}

View File

@@ -177,6 +177,29 @@ func TestFullPipe(t *testing.T) {
ctx.Config.Brews[0].Homepage = "https://github.com/goreleaser"
},
},
"with_header": {
prepare: func(ctx *context.Context) {
ctx.TokenType = context.TokenTypeGitHub
ctx.Config.Brews[0].Repository.Owner = "test"
ctx.Config.Brews[0].Repository.Name = "test"
ctx.Config.Brews[0].Homepage = "https://github.com/goreleaser"
ctx.Config.Brews[0].URLHeaders = []string{
`Authorization: bearer #{ENV["HOMEBREW_GITHUB_API_TOKEN"]}`,
}
},
},
"with_many_headers": {
prepare: func(ctx *context.Context) {
ctx.TokenType = context.TokenTypeGitHub
ctx.Config.Brews[0].Repository.Owner = "test"
ctx.Config.Brews[0].Repository.Name = "test"
ctx.Config.Brews[0].Homepage = "https://github.com/goreleaser"
ctx.Config.Brews[0].URLHeaders = []string{
"Accept: application/octet-stream",
`Authorization: bearer #{ENV["HOMEBREW_GITHUB_API_TOKEN"]}`,
}
},
},
"git_remote": {
prepare: func(ctx *context.Context) {
ctx.TokenType = context.TokenTypeGitHub

View File

@@ -33,6 +33,7 @@ type releasePackage struct {
Arch string
DownloadStrategy string
Install []string
Headers []string
}
//go:embed templates

View File

@@ -11,6 +11,11 @@
{{- end }}
url "{{ $element.DownloadURL }}"
{{- if .DownloadStrategy }}, using: {{ .DownloadStrategy }}{{- end }}
{{- if .Headers }},
headers: [{{ printf "\n" }}
{{- join .Headers | indent 10 }}
]
{{- end }}
sha256 "{{ $element.SHA256 }}"
def install

View File

@@ -3,6 +3,11 @@
{{- if eq $element.Arch "all" }}
url "{{ $element.DownloadURL }}"
{{- if .DownloadStrategy }}, using: {{ .DownloadStrategy }}{{- end }}
{{- if .Headers }},
headers: [{{ printf "\n" }}
{{- join .Headers | indent 8 }}
]
{{- end }}
sha256 "{{ $element.SHA256 }}"
def install
@@ -13,6 +18,11 @@
{{- else if $.HasOnlyAmd64MacOsPkg }}
url "{{ $element.DownloadURL }}"
{{- if .DownloadStrategy }}, using: {{ .DownloadStrategy }}{{- end }}
{{- if .Headers }},
headers: [{{ printf "\n" }}
{{- join .Headers | indent 8 }}
]
{{- end }}
sha256 "{{ $element.SHA256 }}"
def install
@@ -39,6 +49,11 @@
{{- end}}
url "{{ $element.DownloadURL }}"
{{- if .DownloadStrategy }}, using: {{ .DownloadStrategy }}{{- end }}
{{- if .Headers }},
headers: [{{ printf "\n" }}
{{- join .Headers | indent 8 }}
]
{{- end }}
sha256 "{{ $element.SHA256 }}"
def install

View File

@@ -0,0 +1,86 @@
# typed: false
# frozen_string_literal: true
# This file was generated by GoReleaser. DO NOT EDIT.
class WithHeader < Formula
desc "Run pipe test formula and FOO=foo_is_bar"
homepage "https://github.com/goreleaser"
version "1.0.1"
depends_on "ash" => "1.0.0" if OS.linux?
depends_on "bash" => "3.2.57"
depends_on "fish" => :optional
depends_on "powershell" => :optional if OS.mac?
depends_on "zsh" => :optional
on_macos do
if Hardware::CPU.intel?
url "https://dummyhost/download/v1.0.1/bin.tar.gz",
headers: [
"Authorization: bearer #{ENV["HOMEBREW_GITHUB_API_TOKEN"]}"
]
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
def install
bin.install "with_header_darwin_amd64 => with_header"
end
end
if Hardware::CPU.arm?
url "https://dummyhost/download/v1.0.1/bin.tar.gz",
headers: [
"Authorization: bearer #{ENV["HOMEBREW_GITHUB_API_TOKEN"]}"
]
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
def install
bin.install "with_header_darwin_arm64 => with_header"
end
end
end
on_linux do
if Hardware::CPU.intel?
url "https://dummyhost/download/v1.0.1/bin.tar.gz",
headers: [
"Authorization: bearer #{ENV["HOMEBREW_GITHUB_API_TOKEN"]}"
]
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
def install
bin.install "with_header_linux_amd64 => with_header"
end
end
end
conflicts_with "gtk+"
conflicts_with "qt"
def post_install
system "echo"
touch "/tmp/hi"
end
def caveats
<<~EOS
don't do this with_header
EOS
end
plist_options startup: false
def plist
<<~EOS
<xml>whatever</xml>
EOS
end
service do
run foo/bar
keep_alive true
end
test do
system "true"
system "#{bin}/foo", "-h"
end
end

View File

@@ -0,0 +1,89 @@
# typed: false
# frozen_string_literal: true
# This file was generated by GoReleaser. DO NOT EDIT.
class WithManyHeaders < Formula
desc "Run pipe test formula and FOO=foo_is_bar"
homepage "https://github.com/goreleaser"
version "1.0.1"
depends_on "ash" => "1.0.0" if OS.linux?
depends_on "bash" => "3.2.57"
depends_on "fish" => :optional
depends_on "powershell" => :optional if OS.mac?
depends_on "zsh" => :optional
on_macos do
if Hardware::CPU.intel?
url "https://dummyhost/download/v1.0.1/bin.tar.gz",
headers: [
"Accept: application/octet-stream",
"Authorization: bearer #{ENV["HOMEBREW_GITHUB_API_TOKEN"]}"
]
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
def install
bin.install "with_many_headers_darwin_amd64 => with_many_headers"
end
end
if Hardware::CPU.arm?
url "https://dummyhost/download/v1.0.1/bin.tar.gz",
headers: [
"Accept: application/octet-stream",
"Authorization: bearer #{ENV["HOMEBREW_GITHUB_API_TOKEN"]}"
]
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
def install
bin.install "with_many_headers_darwin_arm64 => with_many_headers"
end
end
end
on_linux do
if Hardware::CPU.intel?
url "https://dummyhost/download/v1.0.1/bin.tar.gz",
headers: [
"Accept: application/octet-stream",
"Authorization: bearer #{ENV["HOMEBREW_GITHUB_API_TOKEN"]}"
]
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
def install
bin.install "with_many_headers_linux_amd64 => with_many_headers"
end
end
end
conflicts_with "gtk+"
conflicts_with "qt"
def post_install
system "echo"
touch "/tmp/hi"
end
def caveats
<<~EOS
don't do this with_many_headers
EOS
end
plist_options startup: false
def plist
<<~EOS
<xml>whatever</xml>
EOS
end
service do
run foo/bar
keep_alive true
end
test do
system "true"
system "#{bin}/foo", "-h"
end
end