1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-07-15 01:34:21 +02:00

fix: brew tmpl (#1057)

* fix: brew tmpl

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: compile

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: compile

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
This commit is contained in:
Carlos Alexandro Becker
2019-06-26 14:12:33 -03:00
committed by GitHub
parent c9546ec81b
commit ef6e13a61b
12 changed files with 47 additions and 48 deletions

View File

@ -2,7 +2,6 @@
package client package client
import ( import (
"bytes"
"os" "os"
"github.com/goreleaser/goreleaser/pkg/config" "github.com/goreleaser/goreleaser/pkg/config"
@ -19,6 +18,6 @@ type Info struct {
// Client interface // Client interface
type Client interface { type Client interface {
CreateRelease(ctx *context.Context, body string) (releaseID int64, err error) CreateRelease(ctx *context.Context, body string) (releaseID int64, err error)
CreateFile(ctx *context.Context, commitAuthor config.CommitAuthor, repo config.Repo, content bytes.Buffer, path, message string) (err error) CreateFile(ctx *context.Context, commitAuthor config.CommitAuthor, repo config.Repo, content []byte, path, message string) (err error)
Upload(ctx *context.Context, releaseID int64, name string, file *os.File) (err error) Upload(ctx *context.Context, releaseID int64, name string, file *os.File) (err error)
} }

View File

@ -1,7 +1,6 @@
package client package client
import ( import (
"bytes"
"crypto/tls" "crypto/tls"
"net/http" "net/http"
"net/url" "net/url"
@ -56,7 +55,7 @@ func (c *githubClient) CreateFile(
ctx *context.Context, ctx *context.Context,
commitAuthor config.CommitAuthor, commitAuthor config.CommitAuthor,
repo config.Repo, repo config.Repo,
content bytes.Buffer, content []byte,
path, path,
message string, message string,
) error { ) error {
@ -65,7 +64,7 @@ func (c *githubClient) CreateFile(
Name: github.String(commitAuthor.Name), Name: github.String(commitAuthor.Name),
Email: github.String(commitAuthor.Email), Email: github.String(commitAuthor.Email),
}, },
Content: content.Bytes(), Content: content,
Message: github.String(message), Message: github.String(message),
} }

View File

@ -141,7 +141,7 @@ func doRun(ctx *context.Context, brew config.Homebrew, client client.Client) err
var filename = brew.Name + ".rb" var filename = brew.Name + ".rb"
var path = filepath.Join(ctx.Config.Dist, filename) var path = filepath.Join(ctx.Config.Dist, filename)
log.WithField("formula", path).Info("writing") log.WithField("formula", path).Info("writing")
if err := ioutil.WriteFile(path, content.Bytes(), 0644); err != nil { if err := ioutil.WriteFile(path, []byte(content), 0644); err != nil {
return err return err
} }
@ -164,28 +164,31 @@ func doRun(ctx *context.Context, brew config.Homebrew, client client.Client) err
Info("pushing") Info("pushing")
var msg = fmt.Sprintf("Brew formula update for %s version %s", ctx.Config.ProjectName, ctx.Git.CurrentTag) var msg = fmt.Sprintf("Brew formula update for %s version %s", ctx.Config.ProjectName, ctx.Git.CurrentTag)
return client.CreateFile(ctx, brew.CommitAuthor, brew.GitHub, content, gpath, msg) return client.CreateFile(ctx, brew.CommitAuthor, brew.GitHub, []byte(content), gpath, msg)
} }
func ghFormulaPath(folder, filename string) string { func ghFormulaPath(folder, filename string) string {
return path.Join(folder, filename) return path.Join(folder, filename)
} }
func buildFormula(ctx *context.Context, brew config.Homebrew, artifacts []artifact.Artifact) (bytes.Buffer, error) { func buildFormula(ctx *context.Context, brew config.Homebrew, artifacts []artifact.Artifact) (string, error) {
data, err := dataFor(ctx, brew, artifacts) data, err := dataFor(ctx, brew, artifacts)
if err != nil { if err != nil {
return bytes.Buffer{}, err return "", err
} }
return doBuildFormula(data) return doBuildFormula(ctx, data)
} }
func doBuildFormula(data templateData) (out bytes.Buffer, err error) { func doBuildFormula(ctx *context.Context, data templateData) (string, error) {
t, err := template.New(data.Name).Parse(formulaTemplate) t, err := template.New(data.Name).Parse(formulaTemplate)
if err != nil { if err != nil {
return out, err return "", err
} }
err = t.Execute(&out, data) var out bytes.Buffer
return if err := t.Execute(&out, data); err != nil {
return "", err
}
return tmpl.New(ctx).Apply(out.String())
} }
func dataFor(ctx *context.Context, cfg config.Homebrew, artifacts []artifact.Artifact) (templateData, error) { func dataFor(ctx *context.Context, cfg config.Homebrew, artifacts []artifact.Artifact) (templateData, error) {

View File

@ -1,7 +1,6 @@
package brew package brew
import ( import (
"bytes"
"flag" "flag"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
@ -66,10 +65,11 @@ func TestFullFormulae(t *testing.T) {
data.Plist = "it works" data.Plist = "it works"
data.CustomBlock = []string{"devel do", ` url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_x86_64.tar.gz"`, ` sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68"`, "end"} data.CustomBlock = []string{"devel do", ` url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_x86_64.tar.gz"`, ` sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68"`, "end"}
data.Install = []string{"custom install script", "another install script"} data.Install = []string{"custom install script", "another install script"}
data.Tests = []string{`system "#{bin}/foo -version"`} data.Tests = []string{`system "#{bin}/{{.ProjectName}} -version"`}
out, err := doBuildFormula(data) formulae, err := doBuildFormula(context.New(config.Project{
ProjectName: "foo",
}), data)
assert.NoError(t, err) assert.NoError(t, err)
formulae := out.String()
var golden = "testdata/test.rb.golden" var golden = "testdata/test.rb.golden"
if *update { if *update {
@ -82,9 +82,8 @@ func TestFullFormulae(t *testing.T) {
} }
func TestFormulaeSimple(t *testing.T) { func TestFormulaeSimple(t *testing.T) {
out, err := doBuildFormula(defaultTemplateData) formulae, err := doBuildFormula(context.New(config.Project{}), defaultTemplateData)
assert.NoError(t, err) assert.NoError(t, err)
formulae := out.String()
assertDefaultTemplateData(t, formulae) assertDefaultTemplateData(t, formulae)
assert.NotContains(t, formulae, "def caveats") assert.NotContains(t, formulae, "def caveats")
assert.NotContains(t, formulae, "depends_on") assert.NotContains(t, formulae, "depends_on")
@ -126,6 +125,9 @@ func TestRunPipe(t *testing.T) {
}, },
Version: "1.0.1", Version: "1.0.1",
Artifacts: artifact.New(), Artifacts: artifact.New(),
Env: map[string]string{
"FOO": "foo_is_bar",
},
Config: config.Project{ Config: config.Project{
Dist: folder, Dist: folder,
ProjectName: name, ProjectName: name,
@ -148,14 +150,14 @@ func TestRunPipe(t *testing.T) {
IDs: []string{ IDs: []string{
"foo", "foo",
}, },
Description: "A run pipe test formula", Description: "A run pipe test formula and FOO={{ .Env.FOO }}",
Homepage: "https://github.com/goreleaser", Homepage: "https://github.com/goreleaser",
Caveats: "don't do this", Caveats: "don't do this {{ .ProjectName }}",
Test: "system \"true\"\nsystem \"#{bin}/foo -h\"", Test: "system \"true\"\nsystem \"#{bin}/foo -h\"",
Plist: `<xml>whatever</xml>`, Plist: `<xml>whatever</xml>`,
Dependencies: []string{"zsh", "bash"}, Dependencies: []string{"zsh", "bash"},
Conflicts: []string{"gtk+", "qt"}, Conflicts: []string{"gtk+", "qt"},
Install: `bin.install "foo"`, Install: `bin.install "{{ .ProjectName }}"`,
}, },
}, },
}, },
@ -423,10 +425,9 @@ func (client *DummyClient) CreateRelease(ctx *context.Context, body string) (rel
return return
} }
func (client *DummyClient) CreateFile(ctx *context.Context, commitAuthor config.CommitAuthor, repo config.Repo, content bytes.Buffer, path, msg string) (err error) { func (client *DummyClient) CreateFile(ctx *context.Context, commitAuthor config.CommitAuthor, repo config.Repo, content []byte, path, msg string) (err error) {
client.CreatedFile = true client.CreatedFile = true
bts, _ := ioutil.ReadAll(&content) client.Content = string(content)
client.Content = string(bts)
return return
} }

View File

@ -1,6 +1,6 @@
# This file was generated by GoReleaser. DO NOT EDIT. # This file was generated by GoReleaser. DO NOT EDIT.
class CustomBlock < Formula class CustomBlock < Formula
desc "A run pipe test formula" desc "A run pipe test formula and FOO=foo_is_bar"
homepage "https://github.com/goreleaser" homepage "https://github.com/goreleaser"
version "1.0.1" version "1.0.1"
@ -19,11 +19,11 @@ class CustomBlock < Formula
conflicts_with "qt" conflicts_with "qt"
def install def install
bin.install "foo" bin.install "custom_block"
end end
def caveats; <<~EOS def caveats; <<~EOS
don't do this don't do this custom_block
EOS EOS
end end

View File

@ -1,6 +1,6 @@
# This file was generated by GoReleaser. DO NOT EDIT. # This file was generated by GoReleaser. DO NOT EDIT.
class CustomDownloadStrategy < Formula class CustomDownloadStrategy < Formula
desc "A run pipe test formula" desc "A run pipe test formula and FOO=foo_is_bar"
homepage "https://github.com/goreleaser" homepage "https://github.com/goreleaser"
version "1.0.1" version "1.0.1"
@ -17,11 +17,11 @@ class CustomDownloadStrategy < Formula
conflicts_with "qt" conflicts_with "qt"
def install def install
bin.install "foo" bin.install "custom_download_strategy"
end end
def caveats; <<~EOS def caveats; <<~EOS
don't do this don't do this custom_download_strategy
EOS EOS
end end

View File

@ -1,7 +1,7 @@
# This file was generated by GoReleaser. DO NOT EDIT. # This file was generated by GoReleaser. DO NOT EDIT.
require_relative "custom_download_strategy" require_relative "custom_download_strategy"
class CustomRequire < Formula class CustomRequire < Formula
desc "A run pipe test formula" desc "A run pipe test formula and FOO=foo_is_bar"
homepage "https://github.com/goreleaser" homepage "https://github.com/goreleaser"
version "1.0.1" version "1.0.1"
@ -18,11 +18,11 @@ class CustomRequire < Formula
conflicts_with "qt" conflicts_with "qt"
def install def install
bin.install "foo" bin.install "custom_require"
end end
def caveats; <<~EOS def caveats; <<~EOS
don't do this don't do this custom_require
EOS EOS
end end

View File

@ -1,6 +1,6 @@
# This file was generated by GoReleaser. DO NOT EDIT. # This file was generated by GoReleaser. DO NOT EDIT.
class Default < Formula class Default < Formula
desc "A run pipe test formula" desc "A run pipe test formula and FOO=foo_is_bar"
homepage "https://github.com/goreleaser" homepage "https://github.com/goreleaser"
version "1.0.1" version "1.0.1"
@ -17,11 +17,11 @@ class Default < Formula
conflicts_with "qt" conflicts_with "qt"
def install def install
bin.install "foo" bin.install "default"
end end
def caveats; <<~EOS def caveats; <<~EOS
don't do this don't do this default
EOS EOS
end end

View File

@ -1,6 +1,6 @@
# This file was generated by GoReleaser. DO NOT EDIT. # This file was generated by GoReleaser. DO NOT EDIT.
class GithubEnterpriseUrl < Formula class GithubEnterpriseUrl < Formula
desc "A run pipe test formula" desc "A run pipe test formula and FOO=foo_is_bar"
homepage "https://github.com/goreleaser" homepage "https://github.com/goreleaser"
version "1.0.1" version "1.0.1"
@ -17,11 +17,11 @@ class GithubEnterpriseUrl < Formula
conflicts_with "qt" conflicts_with "qt"
def install def install
bin.install "foo" bin.install "github_enterprise_url"
end end
def caveats; <<~EOS def caveats; <<~EOS
don't do this don't do this github_enterprise_url
EOS EOS
end end

View File

@ -1,7 +1,6 @@
package release package release
import ( import (
"bytes"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@ -332,7 +331,7 @@ func (client *DummyClient) CreateRelease(ctx *context.Context, body string) (rel
return return
} }
func (client *DummyClient) CreateFile(ctx *context.Context, commitAuthor config.CommitAuthor, repo config.Repo, content bytes.Buffer, path, msg string) (err error) { func (client *DummyClient) CreateFile(ctx *context.Context, commitAuthor config.CommitAuthor, repo config.Repo, content []byte, path, msg string) (err error) {
return return
} }

View File

@ -90,7 +90,7 @@ func doRun(ctx *context.Context, client client.Client) error {
ctx, ctx,
ctx.Config.Scoop.CommitAuthor, ctx.Config.Scoop.CommitAuthor,
ctx.Config.Scoop.Bucket, ctx.Config.Scoop.Bucket,
content, content.Bytes(),
path, path,
fmt.Sprintf("Scoop update for %s version %s", ctx.Config.ProjectName, ctx.Git.CurrentTag), fmt.Sprintf("Scoop update for %s version %s", ctx.Config.ProjectName, ctx.Git.CurrentTag),
) )

View File

@ -1,7 +1,6 @@
package scoop package scoop
import ( import (
"bytes"
"flag" "flag"
"io/ioutil" "io/ioutil"
"os" "os"
@ -535,10 +534,9 @@ func (client *DummyClient) CreateRelease(ctx *context.Context, body string) (rel
return return
} }
func (client *DummyClient) CreateFile(ctx *context.Context, commitAuthor config.CommitAuthor, repo config.Repo, content bytes.Buffer, path, msg string) (err error) { func (client *DummyClient) CreateFile(ctx *context.Context, commitAuthor config.CommitAuthor, repo config.Repo, content []byte, path, msg string) (err error) {
client.CreatedFile = true client.CreatedFile = true
bts, _ := ioutil.ReadAll(&content) client.Content = string(content)
client.Content = string(bts)
return return
} }