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 2 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
62 changes: 32 additions & 30 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 :LinuxAmd64
{{- end }}

{{- 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.LinuxAmd64? && Hardware::CPU.intel?
url "{{ .LinuxAmd64.DownloadURL }}"
{{- if .DownloadStrategy }}, :using => {{ .DownloadStrategy }}{{- end }}
sha256 "{{ .LinuxAmd64.SHA256 }}"
end
{{- end }}

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

{{- if .LinuxArm64.DownloadURL }}
if OS.LinuxAmd64? && Hardware::CPU.LinuxArm? && 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
2 changes: 0 additions & 2 deletions internal/pipe/brew/testdata/custom_block.rb.golden
Expand Up @@ -4,11 +4,9 @@ class CustomBlock < Formula
homepage "https://github.com/goreleaser"
version "1.0.1"
bottle :unneeded

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 @@ -4,11 +4,9 @@ class CustomDownloadStrategy < Formula
homepage "https://github.com/goreleaser"
version "1.0.1"
bottle :unneeded

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
2 changes: 0 additions & 2 deletions internal/pipe/brew/testdata/custom_require.rb.golden
Expand Up @@ -5,11 +5,9 @@ class CustomRequire < Formula
homepage "https://github.com/goreleaser"
version "1.0.1"
bottle :unneeded

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
2 changes: 0 additions & 2 deletions internal/pipe/brew/testdata/default.rb.golden
Expand Up @@ -4,11 +4,9 @@ class Default < Formula
homepage "https://github.com/goreleaser"
version "1.0.1"
bottle :unneeded

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
2 changes: 0 additions & 2 deletions internal/pipe/brew/testdata/default_gitlab.rb.golden
Expand Up @@ -4,11 +4,9 @@ class DefaultGitlab < Formula
homepage "https://gitlab.com/goreleaser"
version "1.0.1"
bottle :unneeded

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
2 changes: 0 additions & 2 deletions internal/pipe/brew/testdata/foo_is_bar.rb.golden
Expand Up @@ -4,11 +4,9 @@ class FooIsBar < Formula
homepage ""
version "1.0.1"
bottle :unneeded

if OS.mac?
url "https://dummyhost/download/v1.0.1/bin.tar.gz"
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
elsif OS.linux?
end

def install
Expand Down
19 changes: 8 additions & 11 deletions internal/pipe/brew/testdata/multiple_armv5.rb.golden
Expand Up @@ -4,20 +4,17 @@ class MultipleArmv5 < Formula
homepage "https://github.com/goreleaser"
version "1.0.1"
bottle :unneeded

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
19 changes: 8 additions & 11 deletions internal/pipe/brew/testdata/multiple_armv6.rb.golden
Expand Up @@ -4,20 +4,17 @@ class MultipleArmv6 < Formula
homepage "https://github.com/goreleaser"
version "1.0.1"
bottle :unneeded

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
19 changes: 8 additions & 11 deletions internal/pipe/brew/testdata/multiple_armv7.rb.golden
Expand Up @@ -4,20 +4,17 @@ class MultipleArmv7 < Formula
homepage "https://github.com/goreleaser"
version "1.0.1"
bottle :unneeded

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
27 changes: 12 additions & 15 deletions internal/pipe/brew/testdata/test.rb.golden
Expand Up @@ -4,24 +4,21 @@ class Test < Formula
homepage "https://google.com"
version "0.1.3"
bottle :unneeded

Copy link
Member

Choose a reason for hiding this comment

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

I think that extra space was actually useful from grouping perspective.

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
24 changes: 24 additions & 0 deletions internal/pipe/brew/testdata/test_linux_only.rb.golden
@@ -0,0 +1,24 @@
# 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