mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-02-09 13:36:56 +02:00
feat: using archive url to generate brew from source
This commit is contained in:
parent
3c1f856ddf
commit
ff867876b4
@ -3,6 +3,7 @@ package brew
|
||||
import (
|
||||
"bytes"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -93,124 +94,89 @@ func TestSplit(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRunPipe(t *testing.T) {
|
||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||
assert.NoError(t, err)
|
||||
var ctx = &context.Context{
|
||||
Git: context.GitInfo{
|
||||
CurrentTag: "v1.0.1",
|
||||
for name, fn := range map[string]func(ctx *context.Context){
|
||||
"default": func(ctx *context.Context) {},
|
||||
"github_enterprise_url": func(ctx *context.Context) {
|
||||
ctx.Config.GitHubURLs.Download = "http://github.example.org"
|
||||
},
|
||||
Version: "1.0.1",
|
||||
Artifacts: artifact.New(),
|
||||
Config: config.Project{
|
||||
Dist: folder,
|
||||
ProjectName: "run-pipe",
|
||||
Archive: config.Archive{
|
||||
Format: "tar.gz",
|
||||
},
|
||||
Release: config.Release{
|
||||
GitHub: config.Repo{
|
||||
Owner: "test",
|
||||
Name: "test",
|
||||
},
|
||||
},
|
||||
Brew: config.Homebrew{
|
||||
Name: "run-pipe",
|
||||
GitHub: config.Repo{
|
||||
Owner: "test",
|
||||
Name: "test",
|
||||
},
|
||||
Description: "A run pipe test formula",
|
||||
Homepage: "https://github.com/goreleaser",
|
||||
Caveats: "don't do this",
|
||||
Test: "system \"true\"\nsystem \"#{bin}/foo -h\"",
|
||||
Plist: `<xml>whatever</xml>`,
|
||||
Dependencies: []string{"zsh", "bash"},
|
||||
Conflicts: []string{"gtk+", "qt"},
|
||||
Install: `bin.install "foo"`,
|
||||
},
|
||||
"custom_download_strategy": func(ctx *context.Context) {
|
||||
ctx.Config.Brew.DownloadStrategy = "GitHubPrivateRepositoryReleaseDownloadStrategy"
|
||||
},
|
||||
"build_from_source": func(ctx *context.Context) {
|
||||
ctx.Config.Brew.BuildDependencies = []string{"go"}
|
||||
},
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||
assert.NoError(t, err)
|
||||
var ctx = &context.Context{
|
||||
Git: context.GitInfo{
|
||||
CurrentTag: "v1.0.1",
|
||||
},
|
||||
Version: "1.0.1",
|
||||
Artifacts: artifact.New(),
|
||||
Config: config.Project{
|
||||
Dist: folder,
|
||||
ProjectName: name,
|
||||
GitHubURLs: config.GitHubURLs{
|
||||
Download: "https://github.com",
|
||||
},
|
||||
Archive: config.Archive{
|
||||
Format: "tar.gz",
|
||||
},
|
||||
Release: config.Release{
|
||||
GitHub: config.Repo{
|
||||
Owner: "test",
|
||||
Name: "test",
|
||||
},
|
||||
},
|
||||
Brew: config.Homebrew{
|
||||
Name: name,
|
||||
GitHub: config.Repo{
|
||||
Owner: "test",
|
||||
Name: "test",
|
||||
},
|
||||
Description: "A run pipe test formula",
|
||||
Homepage: "https://github.com/goreleaser",
|
||||
Caveats: "don't do this",
|
||||
Test: "system \"true\"\nsystem \"#{bin}/foo -h\"",
|
||||
Plist: `<xml>whatever</xml>`,
|
||||
Dependencies: []string{"zsh", "bash"},
|
||||
Conflicts: []string{"gtk+", "qt"},
|
||||
Install: `bin.install "foo"`,
|
||||
},
|
||||
},
|
||||
}
|
||||
fn(ctx)
|
||||
var path = filepath.Join(folder, "bin.tar.gz")
|
||||
ctx.Artifacts.Add(artifact.Artifact{
|
||||
Name: "bin.tar.gz",
|
||||
Path: path,
|
||||
Goos: "darwin",
|
||||
Goarch: "amd64",
|
||||
Type: artifact.UploadableArchive,
|
||||
})
|
||||
|
||||
_, err = os.Create(path)
|
||||
assert.NoError(t, err)
|
||||
client := &DummyClient{}
|
||||
var distFile = filepath.Join(folder, name+".rb")
|
||||
|
||||
assert.NoError(t, doRun(ctx, client))
|
||||
assert.True(t, client.CreatedFile)
|
||||
var golden = fmt.Sprintf("testdata/%s.rb.golden", name)
|
||||
if *update {
|
||||
ioutil.WriteFile(golden, []byte(client.Content), 0655)
|
||||
}
|
||||
bts, err := ioutil.ReadFile(golden)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, string(bts), client.Content)
|
||||
|
||||
distBts, err := ioutil.ReadFile(distFile)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, string(bts), string(distBts))
|
||||
})
|
||||
}
|
||||
var path = filepath.Join(folder, "bin.tar.gz")
|
||||
ctx.Artifacts.Add(artifact.Artifact{
|
||||
Name: "bin.tar.gz",
|
||||
Path: path,
|
||||
Goos: "darwin",
|
||||
Goarch: "amd64",
|
||||
Type: artifact.UploadableArchive,
|
||||
})
|
||||
client := &DummyClient{}
|
||||
assert.Error(t, doRun(ctx, client))
|
||||
assert.False(t, client.CreatedFile)
|
||||
|
||||
_, err = os.Create(path)
|
||||
assert.NoError(t, err)
|
||||
|
||||
var distFile = filepath.Join(folder, "run-pipe.rb")
|
||||
|
||||
t.Run("default git url", func(tt *testing.T) {
|
||||
ctx.Config.GitHubURLs.Download = "https://github.com"
|
||||
assert.NoError(tt, doRun(ctx, client))
|
||||
assert.True(tt, client.CreatedFile)
|
||||
var golden = "testdata/run_pipe.rb.golden"
|
||||
if *update {
|
||||
ioutil.WriteFile(golden, []byte(client.Content), 0655)
|
||||
}
|
||||
bts, err := ioutil.ReadFile(golden)
|
||||
assert.NoError(tt, err)
|
||||
assert.Equal(tt, string(bts), client.Content)
|
||||
|
||||
distBts, err := ioutil.ReadFile(distFile)
|
||||
assert.NoError(tt, err)
|
||||
assert.Equal(tt, string(bts), string(distBts))
|
||||
})
|
||||
|
||||
t.Run("github enterprise url", func(tt *testing.T) {
|
||||
ctx.Config.GitHubURLs.Download = "http://github.example.org"
|
||||
assert.NoError(tt, doRun(ctx, client))
|
||||
assert.True(tt, client.CreatedFile)
|
||||
var golden = "testdata/run_pipe_enterprise.rb.golden"
|
||||
if *update {
|
||||
ioutil.WriteFile(golden, []byte(client.Content), 0644)
|
||||
}
|
||||
bts, err := ioutil.ReadFile(golden)
|
||||
assert.NoError(tt, err)
|
||||
assert.Equal(tt, string(bts), client.Content)
|
||||
|
||||
distBts, err := ioutil.ReadFile(distFile)
|
||||
assert.NoError(tt, err)
|
||||
assert.Equal(tt, string(bts), string(distBts))
|
||||
})
|
||||
|
||||
t.Run("custom download strategy", func(tt *testing.T) {
|
||||
ctx.Config.Brew.DownloadStrategy = "GitHubPrivateRepositoryReleaseDownloadStrategy"
|
||||
assert.NoError(tt, doRun(ctx, client))
|
||||
assert.True(tt, client.CreatedFile)
|
||||
var golden = "testdata/run_pipe_download_strategy.rb.golden"
|
||||
if *update {
|
||||
ioutil.WriteFile(golden, []byte(client.Content), 0655)
|
||||
}
|
||||
bts, err := ioutil.ReadFile(golden)
|
||||
assert.NoError(tt, err)
|
||||
assert.Equal(tt, string(bts), client.Content)
|
||||
|
||||
distBts, err := ioutil.ReadFile(distFile)
|
||||
assert.NoError(tt, err)
|
||||
assert.Equal(tt, string(bts), string(distBts))
|
||||
})
|
||||
|
||||
t.Run("custom name", func(tt *testing.T) {
|
||||
ctx.Config.Brew.Name = "custom-brew-name"
|
||||
assert.NoError(tt, doRun(ctx, client))
|
||||
assert.True(tt, client.CreatedFile)
|
||||
|
||||
distFile := filepath.Join(folder, "custom-brew-name.rb")
|
||||
_, err := os.Stat(distFile)
|
||||
assert.NoError(t, err)
|
||||
|
||||
distBts, err := ioutil.ReadFile(distFile)
|
||||
assert.NoError(tt, err)
|
||||
assert.Contains(tt, string(distBts), "class CustomBrewName < Formula")
|
||||
})
|
||||
}
|
||||
|
||||
func TestRunPipeNoDarwin64Build(t *testing.T) {
|
||||
|
@ -26,32 +26,36 @@ type templateData struct {
|
||||
const formulaTemplate = `class {{ .Name }} < Formula
|
||||
desc "{{ .Desc }}"
|
||||
homepage "{{ .Homepage }}"
|
||||
{{- if .BuildDependencies }}
|
||||
url "{{ .DownloadURL }}/{{ .Repo.Owner }}/{{ .Repo.Name }}/archive/{{ .Tag }}.tar.gz"
|
||||
{{ else }}
|
||||
url "{{ .DownloadURL }}/{{ .Repo.Owner }}/{{ .Repo.Name }}/releases/download/{{ .Tag }}/{{ .File }}"
|
||||
{{- if .DownloadStrategy }}, :using => {{ .DownloadStrategy }}{{- end }}
|
||||
{{- end }}
|
||||
version "{{ .Version }}"
|
||||
sha256 "{{ .SHA256 }}"
|
||||
head "https://github.com/{{ .Repo.Owner }}/{{ .Repo.Name }}.git"
|
||||
|
||||
{{- if .BuildDependencies }}
|
||||
{{ range $index, $element := .BuildDependencies }}
|
||||
{{- with .BuildDependencies }}
|
||||
{{ range $index, $element := . }}
|
||||
depends_on "{{ . }}" => :build
|
||||
{{- end }}
|
||||
{{- end -}}
|
||||
|
||||
{{- if .Dependencies }}
|
||||
{{ range $index, $element := .Dependencies }}
|
||||
{{- with .Dependencies }}
|
||||
{{ range $index, $element := . }}
|
||||
depends_on "{{ . }}"
|
||||
{{- end }}
|
||||
{{- end -}}
|
||||
|
||||
{{- if .Conflicts }}
|
||||
{{ range $index, $element := .Conflicts }}
|
||||
{{- with .Conflicts }}
|
||||
{{ range $index, $element := . }}
|
||||
conflicts_with "{{ . }}"
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
{{- if .Special }}
|
||||
{{- range $index, $element := .Special }}
|
||||
{{- with .Special }}
|
||||
{{- range $index, $element := . }}
|
||||
{{ . -}}
|
||||
{{- end -}}
|
||||
{{- end }}
|
||||
@ -62,22 +66,22 @@ const formulaTemplate = `class {{ .Name }} < Formula
|
||||
{{- end }}
|
||||
end
|
||||
|
||||
{{- if .Caveats }}
|
||||
{{- with .Caveats }}
|
||||
|
||||
def caveats; <<-EOS.undent
|
||||
{{- range $index, $element := .Caveats }}
|
||||
{{- range $index, $element := . }}
|
||||
{{ . -}}
|
||||
{{- end }}
|
||||
EOS
|
||||
end
|
||||
{{- end -}}
|
||||
|
||||
{{- if .Plist }}
|
||||
{{- with .Plist }}
|
||||
|
||||
plist_options :startup => false
|
||||
|
||||
def plist; <<~EOS
|
||||
{{ .Plist }}
|
||||
{{ . }}
|
||||
EOS
|
||||
end
|
||||
{{- end -}}
|
||||
|
39
pipeline/brew/testdata/build from source.rb.golden
vendored
Normal file
39
pipeline/brew/testdata/build from source.rb.golden
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
class BuildFromSource < Formula
|
||||
desc "A run pipe test formula"
|
||||
homepage "https://github.com/goreleaser"
|
||||
url "https://github.com/test/test/archive/v1.0.1.tar.gz"
|
||||
|
||||
version "1.0.1"
|
||||
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
|
||||
head "https://github.com/test/test.git"
|
||||
|
||||
depends_on "go" => :build
|
||||
|
||||
depends_on "zsh"
|
||||
depends_on "bash"
|
||||
|
||||
conflicts_with "gtk+"
|
||||
conflicts_with "qt"
|
||||
|
||||
|
||||
def install
|
||||
bin.install "foo"
|
||||
end
|
||||
|
||||
def caveats; <<-EOS.undent
|
||||
don't do this
|
||||
EOS
|
||||
end
|
||||
|
||||
plist_options :startup => false
|
||||
|
||||
def plist; <<~EOS
|
||||
<xml>whatever</xml>
|
||||
EOS
|
||||
end
|
||||
|
||||
test do
|
||||
system "true"
|
||||
system "#{bin}/foo -h"
|
||||
end
|
||||
end
|
39
pipeline/brew/testdata/build_from_source.rb.golden
vendored
Normal file
39
pipeline/brew/testdata/build_from_source.rb.golden
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
class BuildFromSource < Formula
|
||||
desc "A run pipe test formula"
|
||||
homepage "https://github.com/goreleaser"
|
||||
url "https://github.com/test/test/archive/v1.0.1.tar.gz"
|
||||
|
||||
version "1.0.1"
|
||||
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
|
||||
head "https://github.com/test/test.git"
|
||||
|
||||
depends_on "go" => :build
|
||||
|
||||
depends_on "zsh"
|
||||
depends_on "bash"
|
||||
|
||||
conflicts_with "gtk+"
|
||||
conflicts_with "qt"
|
||||
|
||||
|
||||
def install
|
||||
bin.install "foo"
|
||||
end
|
||||
|
||||
def caveats; <<-EOS.undent
|
||||
don't do this
|
||||
EOS
|
||||
end
|
||||
|
||||
plist_options :startup => false
|
||||
|
||||
def plist; <<~EOS
|
||||
<xml>whatever</xml>
|
||||
EOS
|
||||
end
|
||||
|
||||
test do
|
||||
system "true"
|
||||
system "#{bin}/foo -h"
|
||||
end
|
||||
end
|
36
pipeline/brew/testdata/custom download strategu.rb.golden
vendored
Normal file
36
pipeline/brew/testdata/custom download strategu.rb.golden
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
class CustomDownloadStrategu < Formula
|
||||
desc "A run pipe test formula"
|
||||
homepage "https://github.com/goreleaser"
|
||||
url "https://github.com/test/test/releases/download/v1.0.1/bin.tar.gz", :using => GitHubPrivateRepositoryReleaseDownloadStrategy
|
||||
version "1.0.1"
|
||||
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
|
||||
head "https://github.com/test/test.git"
|
||||
|
||||
depends_on "zsh"
|
||||
depends_on "bash"
|
||||
|
||||
conflicts_with "gtk+"
|
||||
conflicts_with "qt"
|
||||
|
||||
|
||||
def install
|
||||
bin.install "foo"
|
||||
end
|
||||
|
||||
def caveats; <<-EOS.undent
|
||||
don't do this
|
||||
EOS
|
||||
end
|
||||
|
||||
plist_options :startup => false
|
||||
|
||||
def plist; <<~EOS
|
||||
<xml>whatever</xml>
|
||||
EOS
|
||||
end
|
||||
|
||||
test do
|
||||
system "true"
|
||||
system "#{bin}/foo -h"
|
||||
end
|
||||
end
|
36
pipeline/brew/testdata/custom_download_strategy.rb.golden
vendored
Normal file
36
pipeline/brew/testdata/custom_download_strategy.rb.golden
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
class CustomDownloadStrategy < Formula
|
||||
desc "A run pipe test formula"
|
||||
homepage "https://github.com/goreleaser"
|
||||
url "https://github.com/test/test/releases/download/v1.0.1/bin.tar.gz", :using => GitHubPrivateRepositoryReleaseDownloadStrategy
|
||||
version "1.0.1"
|
||||
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
|
||||
head "https://github.com/test/test.git"
|
||||
|
||||
depends_on "zsh"
|
||||
depends_on "bash"
|
||||
|
||||
conflicts_with "gtk+"
|
||||
conflicts_with "qt"
|
||||
|
||||
|
||||
def install
|
||||
bin.install "foo"
|
||||
end
|
||||
|
||||
def caveats; <<-EOS.undent
|
||||
don't do this
|
||||
EOS
|
||||
end
|
||||
|
||||
plist_options :startup => false
|
||||
|
||||
def plist; <<~EOS
|
||||
<xml>whatever</xml>
|
||||
EOS
|
||||
end
|
||||
|
||||
test do
|
||||
system "true"
|
||||
system "#{bin}/foo -h"
|
||||
end
|
||||
end
|
@ -1,4 +1,4 @@
|
||||
class RunPipe < Formula
|
||||
class Default < Formula
|
||||
desc "A run pipe test formula"
|
||||
homepage "https://github.com/goreleaser"
|
||||
url "https://github.com/test/test/releases/download/v1.0.1/bin.tar.gz"
|
@ -1,4 +1,4 @@
|
||||
class RunPipe < Formula
|
||||
class GithubEnterpriseUrl < Formula
|
||||
desc "A run pipe test formula"
|
||||
homepage "https://github.com/goreleaser"
|
||||
url "http://github.example.org/test/test/releases/download/v1.0.1/bin.tar.gz"
|
@ -1,7 +1,7 @@
|
||||
class RunPipe < Formula
|
||||
class GithubEnterpriseUrl < Formula
|
||||
desc "A run pipe test formula"
|
||||
homepage "https://github.com/goreleaser"
|
||||
url "http://github.example.org/test/test/releases/download/v1.0.1/bin.tar.gz", :using => GitHubPrivateRepositoryReleaseDownloadStrategy
|
||||
url "http://github.example.org/test/test/releases/download/v1.0.1/bin.tar.gz"
|
||||
version "1.0.1"
|
||||
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
|
||||
head "https://github.com/test/test.git"
|
Loading…
x
Reference in New Issue
Block a user