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

fix: improving URLs on linuxbrew #1900

Merged
merged 6 commits into from Nov 16, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions internal/pipe/brew/brew.go
Expand Up @@ -310,21 +310,21 @@ func dataFor(ctx *context.Context, cfg config.Homebrew, cl client.Client, artifa
result.MacOS = down
} else if artifact.Goos == "linux" {
switch artifact.Goarch {
case "386", "amd64":
if result.Linux.DownloadURL != "" {
case "amd64":
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we never include i386 builds, so this part of the switch was useless

if result.LinuxAmd64.DownloadURL != "" {
return result, ErrMultipleArchivesSameOS
}
result.Linux = down
result.LinuxAmd64 = down
case "arm":
if result.Arm.DownloadURL != "" {
if result.LinuxArm.DownloadURL != "" {
return result, ErrMultipleArchivesSameOS
}
result.Arm = down
result.LinuxArm = down
case "arm64":
if result.Arm64.DownloadURL != "" {
if result.LinuxArm64.DownloadURL != "" {
return result, ErrMultipleArchivesSameOS
}
result.Arm64 = down
result.LinuxArm64 = down
}
}
}
Expand Down
27 changes: 23 additions & 4 deletions internal/pipe/brew/brew_test.go
Expand Up @@ -45,15 +45,15 @@ var defaultTemplateData = templateData{
DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_x86_64.tar.gz",
SHA256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68",
},
Linux: downloadable{
LinuxAmd64: downloadable{
DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_x86_64.tar.gz",
SHA256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67",
},
Arm: downloadable{
LinuxArm: downloadable{
DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm6.tar.gz",
SHA256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67",
},
Arm64: downloadable{
LinuxArm64: downloadable{
DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm64.tar.gz",
SHA256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67",
},
Expand Down Expand Up @@ -95,6 +95,25 @@ func TestFullFormulae(t *testing.T) {
require.Equal(t, string(bts), formulae)
}

func TestFullFormulaeLinuxOnly(t *testing.T) {
data := defaultTemplateData
data.MacOS = downloadable{}
data.Install = []string{`bin.install "test"`}
formulae, err := doBuildFormula(context.New(config.Project{
ProjectName: "foo",
}), data)
require.NoError(t, err)

var golden = "testdata/test_linux_only.rb.golden"
if *update {
err := ioutil.WriteFile(golden, []byte(formulae), 0655)
require.NoError(t, err)
}
bts, err := ioutil.ReadFile(golden)
require.NoError(t, err)
require.Equal(t, string(bts), formulae)
}

func TestFormulaeSimple(t *testing.T) {
formulae, err := doBuildFormula(context.New(config.Project{}), defaultTemplateData)
require.NoError(t, err)
Expand Down Expand Up @@ -504,7 +523,7 @@ func TestRunPipeForMultipleArmVersions(t *testing.T) {
}
}

func TestRunPipeNoDarwin64Build(t *testing.T) {
func TestRunPipeNoBuilds(t *testing.T) {
var ctx = &context.Context{
TokenType: context.TokenTypeGitHub,
Config: config.Project{
Expand Down
64 changes: 33 additions & 31 deletions internal/pipe/brew/template.go
Expand Up @@ -18,9 +18,9 @@ type templateData struct {
CustomRequire string
CustomBlock []string
MacOS downloadable
Linux downloadable
Arm downloadable
Arm64 downloadable
LinuxAmd64 downloadable
LinuxArm downloadable
LinuxArm64 downloadable
}

type downloadable struct {
Expand All @@ -37,39 +37,41 @@ class {{ .Name }} < Formula
homepage "{{ .Homepage }}"
version "{{ .Version }}"
bottle :unneeded

{{- if and (not .MacOS.DownloadURL) (or .LinuxAmd64.DownloadURL .LinuxArm.DownloadURL .LinuxArm64.DownloadURL) }}
depends_on :linux
{{- end }}
{{- printf "\n" }}
{{- if .MacOS.DownloadURL }}
if OS.mac?
{{- if .MacOS.DownloadURL }}
url "{{ .MacOS.DownloadURL }}"
{{- if .DownloadStrategy }}, :using => {{ .DownloadStrategy }}{{- end }}
sha256 "{{ .MacOS.SHA256 }}"
{{- end }}
elsif OS.linux?
{{- if .Linux.DownloadURL }}
if Hardware::CPU.intel?
url "{{ .Linux.DownloadURL }}"
{{- if .DownloadStrategy }}, :using => {{ .DownloadStrategy }}{{- end }}
sha256 "{{ .Linux.SHA256 }}"
end
{{- end }}
{{- if or .Arm.DownloadURL .Arm64.DownloadURL }}
if Hardware::CPU.arm?
if Hardware::CPU.is_64_bit?
{{- if .Arm64.DownloadURL }}
url "{{ .Arm64.DownloadURL }}"
{{- if .DownloadStrategy }}, :using => {{ .DownloadStrategy }}{{- end }}
sha256 "{{ .Arm64.SHA256 }}"
{{- end }}
else
{{- if .Arm.DownloadURL }}
url "{{ .Arm.DownloadURL }}"
{{- if .DownloadStrategy }}, :using => {{ .DownloadStrategy }}{{- end }}
sha256 "{{ .Arm.SHA256 }}"
{{- end }}
end
end
{{- end }}
end
{{- end }}

{{- if .LinuxAmd64.DownloadURL }}
if OS.linux? && Hardware::CPU.intel?
url "{{ .LinuxAmd64.DownloadURL }}"
{{- if .DownloadStrategy }}, :using => {{ .DownloadStrategy }}{{- end }}
sha256 "{{ .LinuxAmd64.SHA256 }}"
end
{{- end }}

{{- if .LinuxArm.DownloadURL }}
if OS.linux? && Hardware::CPU.arm? && !Hardware::CPU.is_64_bit?
url "{{ .LinuxArm.DownloadURL }}"
{{- if .DownloadStrategy }}, :using => {{ .DownloadStrategy }}{{- end }}
sha256 "{{ .LinuxArm.SHA256 }}"
end
{{- end }}

{{- if .LinuxArm64.DownloadURL }}
if OS.linux? && Hardware::CPU.arm? && Hardware::CPU.is_64_bit?
url "{{ .LinuxArm64.DownloadURL }}"
{{- if .DownloadStrategy }}, :using => {{ .DownloadStrategy }}{{- end }}
sha256 "{{ .LinuxArm64.SHA256 }}"
end
{{- end }}

{{- with .CustomBlock }}
{{ range $index, $element := . }}
Expand Down
1 change: 0 additions & 1 deletion internal/pipe/brew/testdata/custom_block.rb.golden
Expand Up @@ -8,7 +8,6 @@ class CustomBlock < Formula
if OS.mac?
url "https://dummyhost/download/v1.0.1/bin.tar.gz"
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
elsif OS.linux?
end

head "https://github.com/caarlos0/test.git"
Expand Down
Expand Up @@ -8,7 +8,6 @@ class CustomDownloadStrategy < Formula
if OS.mac?
url "https://dummyhost/download/v1.0.1/bin.tar.gz", :using => GitHubPrivateRepositoryReleaseDownloadStrategy
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
elsif OS.linux?
end

depends_on "zsh" => :optional
Expand Down
1 change: 0 additions & 1 deletion internal/pipe/brew/testdata/custom_require.rb.golden
Expand Up @@ -9,7 +9,6 @@ class CustomRequire < Formula
if OS.mac?
url "https://dummyhost/download/v1.0.1/bin.tar.gz", :using => CustomDownloadStrategy
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
elsif OS.linux?
end

depends_on "zsh" => :optional
Expand Down
1 change: 0 additions & 1 deletion internal/pipe/brew/testdata/default.rb.golden
Expand Up @@ -8,7 +8,6 @@ class Default < Formula
if OS.mac?
url "https://dummyhost/download/v1.0.1/bin.tar.gz"
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
elsif OS.linux?
end

depends_on "zsh" => :optional
Expand Down
1 change: 0 additions & 1 deletion internal/pipe/brew/testdata/default_gitlab.rb.golden
Expand Up @@ -8,7 +8,6 @@ class DefaultGitlab < Formula
if OS.mac?
url "https://dummyhost/download/v1.0.1/bin.tar.gz"
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
elsif OS.linux?
end

depends_on "zsh" => :optional
Expand Down
1 change: 0 additions & 1 deletion internal/pipe/brew/testdata/foo_is_bar.rb.golden
Expand Up @@ -8,7 +8,6 @@ class FooIsBar < Formula
if OS.mac?
url "https://dummyhost/download/v1.0.1/bin.tar.gz"
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
elsif OS.linux?
end

def install
Expand Down
18 changes: 8 additions & 10 deletions internal/pipe/brew/testdata/multiple_armv5.rb.golden
Expand Up @@ -8,16 +8,14 @@ class MultipleArmv5 < Formula
if OS.mac?
url "https://dummyhost/download/v1.0.1/bin.tar.gz"
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
elsif OS.linux?
if Hardware::CPU.arm?
if Hardware::CPU.is_64_bit?
url "https://dummyhost/download/v1.0.1/arm64.tar.gz"
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
else
url "https://dummyhost/download/v1.0.1/armv5.tar.gz"
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
end
end
end
if OS.linux? && Hardware::CPU.arm? && !Hardware::CPU.is_64_bit?
url "https://dummyhost/download/v1.0.1/armv5.tar.gz"
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
end
if OS.linux? && Hardware::CPU.arm? && Hardware::CPU.is_64_bit?
url "https://dummyhost/download/v1.0.1/arm64.tar.gz"
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
end

depends_on "zsh"
Expand Down
18 changes: 8 additions & 10 deletions internal/pipe/brew/testdata/multiple_armv6.rb.golden
Expand Up @@ -8,16 +8,14 @@ class MultipleArmv6 < Formula
if OS.mac?
url "https://dummyhost/download/v1.0.1/bin.tar.gz"
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
elsif OS.linux?
if Hardware::CPU.arm?
if Hardware::CPU.is_64_bit?
url "https://dummyhost/download/v1.0.1/arm64.tar.gz"
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
else
url "https://dummyhost/download/v1.0.1/armv6.tar.gz"
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
end
end
end
if OS.linux? && Hardware::CPU.arm? && !Hardware::CPU.is_64_bit?
url "https://dummyhost/download/v1.0.1/armv6.tar.gz"
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
end
if OS.linux? && Hardware::CPU.arm? && Hardware::CPU.is_64_bit?
url "https://dummyhost/download/v1.0.1/arm64.tar.gz"
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
end

depends_on "zsh"
Expand Down
18 changes: 8 additions & 10 deletions internal/pipe/brew/testdata/multiple_armv7.rb.golden
Expand Up @@ -8,16 +8,14 @@ class MultipleArmv7 < Formula
if OS.mac?
url "https://dummyhost/download/v1.0.1/bin.tar.gz"
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
elsif OS.linux?
if Hardware::CPU.arm?
if Hardware::CPU.is_64_bit?
url "https://dummyhost/download/v1.0.1/arm64.tar.gz"
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
else
url "https://dummyhost/download/v1.0.1/armv7.tar.gz"
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
end
end
end
if OS.linux? && Hardware::CPU.arm? && !Hardware::CPU.is_64_bit?
url "https://dummyhost/download/v1.0.1/armv7.tar.gz"
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
end
if OS.linux? && Hardware::CPU.arm? && Hardware::CPU.is_64_bit?
url "https://dummyhost/download/v1.0.1/arm64.tar.gz"
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
end

depends_on "zsh"
Expand Down
26 changes: 12 additions & 14 deletions internal/pipe/brew/testdata/test.rb.golden
Expand Up @@ -8,20 +8,18 @@ class Test < Formula
if OS.mac?
url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_x86_64.tar.gz"
sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68"
elsif OS.linux?
if Hardware::CPU.intel?
url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_x86_64.tar.gz"
sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67"
end
if Hardware::CPU.arm?
if Hardware::CPU.is_64_bit?
url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm64.tar.gz"
sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67"
else
url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm6.tar.gz"
sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67"
end
end
end
if OS.linux? && Hardware::CPU.intel?
url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_x86_64.tar.gz"
sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67"
end
if OS.linux? && Hardware::CPU.arm? && !Hardware::CPU.is_64_bit?
url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm6.tar.gz"
sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67"
end
if OS.linux? && Hardware::CPU.arm? && Hardware::CPU.is_64_bit?
url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm64.tar.gz"
sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67"
end

devel do
Expand Down
25 changes: 25 additions & 0 deletions internal/pipe/brew/testdata/test_linux_only.rb.golden
@@ -0,0 +1,25 @@
# This file was generated by GoReleaser. DO NOT EDIT.
class Test < Formula
desc "Some desc"
homepage "https://google.com"
version "0.1.3"
bottle :unneeded
depends_on :linux

if OS.linux? && Hardware::CPU.intel?
url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_x86_64.tar.gz"
sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67"
end
if OS.linux? && Hardware::CPU.arm? && !Hardware::CPU.is_64_bit?
url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm6.tar.gz"
sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67"
end
if OS.linux? && Hardware::CPU.arm? && Hardware::CPU.is_64_bit?
url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm64.tar.gz"
sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67"
end

def install
bin.install "test"
end
end
20 changes: 10 additions & 10 deletions www/docs/customization/homebrew.md
Expand Up @@ -146,18 +146,18 @@ class Program < Formula
if os.Mac?
url "https://github.com/user/repo/releases/download/v1.2.3/program_v1.2.3_macOs_64bit.zip"
sha256 "9ee30fc358fae8d248a2d7538957089885da321dca3f09e3296fe2058e7fff74"
elsif os.Linux?
end
if OS.linux? && Hardware::CPU.intel?
url "https://github.com/user/repo/releases/download/v1.2.3/program_v1.2.3_Linux_64bit.zip"
sha256 "b41bebd25fd7bb1a67dc2cd5ee12c9f67073094567fdf7b3871f05fd74a45fdd"
if Hardware::CPU.arm?
if Hardware::CPU.is_64_bit?
url "https://github.com/user/repo/releases/download/v1.2.3/program_v1.2.3_Linux_arm64.zip"
sha256 "97cadca3c3c3f36388a4a601acf878dd356d6275a976bee516798b72bfdbeecf"
else
url "https://github.com/user/repo/releases/download/v1.2.3/program_v1.2.3_Linux_armv7.zip"
sha256 "78f31239430eaaec01df783e2a3443753a8126c325292ed8ddb1658ddd2b401d"
end
end
end
if OS.linux? && Hardware::CPU.arm? && !Hardware::CPU.is_64_bit?
url "https://github.com/user/repo/releases/download/v1.2.3/program_v1.2.3_Linux_armv7.zip"
sha256 "78f31239430eaaec01df783e2a3443753a8126c325292ed8ddb1658ddd2b401d"
end
if OS.linux? && Hardware::CPU.arm? && Hardware::CPU.is_64_bit?
url "https://github.com/user/repo/releases/download/v1.2.3/program_v1.2.3_Linux_arm64.zip"
sha256 "97cadca3c3c3f36388a4a601acf878dd356d6275a976bee516798b72bfdbeecf"
end

depends_on "git"
Expand Down