1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-02-09 13:36:56 +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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 47 additions and 48 deletions

View File

@ -2,7 +2,6 @@
package client
import (
"bytes"
"os"
"github.com/goreleaser/goreleaser/pkg/config"
@ -19,6 +18,6 @@ type Info struct {
// Client interface
type Client interface {
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)
}

View File

@ -1,7 +1,6 @@
package client
import (
"bytes"
"crypto/tls"
"net/http"
"net/url"
@ -56,7 +55,7 @@ func (c *githubClient) CreateFile(
ctx *context.Context,
commitAuthor config.CommitAuthor,
repo config.Repo,
content bytes.Buffer,
content []byte,
path,
message string,
) error {
@ -65,7 +64,7 @@ func (c *githubClient) CreateFile(
Name: github.String(commitAuthor.Name),
Email: github.String(commitAuthor.Email),
},
Content: content.Bytes(),
Content: content,
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 path = filepath.Join(ctx.Config.Dist, filename)
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
}
@ -164,28 +164,31 @@ func doRun(ctx *context.Context, brew config.Homebrew, client client.Client) err
Info("pushing")
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 {
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)
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)
if err != nil {
return out, err
return "", err
}
err = t.Execute(&out, data)
return
var out bytes.Buffer
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) {

View File

@ -1,7 +1,6 @@
package brew
import (
"bytes"
"flag"
"fmt"
"io/ioutil"
@ -66,10 +65,11 @@ func TestFullFormulae(t *testing.T) {
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.Install = []string{"custom install script", "another install script"}
data.Tests = []string{`system "#{bin}/foo -version"`}
out, err := doBuildFormula(data)
data.Tests = []string{`system "#{bin}/{{.ProjectName}} -version"`}
formulae, err := doBuildFormula(context.New(config.Project{
ProjectName: "foo",
}), data)
assert.NoError(t, err)
formulae := out.String()
var golden = "testdata/test.rb.golden"
if *update {
@ -82,9 +82,8 @@ func TestFullFormulae(t *testing.T) {
}
func TestFormulaeSimple(t *testing.T) {
out, err := doBuildFormula(defaultTemplateData)
formulae, err := doBuildFormula(context.New(config.Project{}), defaultTemplateData)
assert.NoError(t, err)
formulae := out.String()
assertDefaultTemplateData(t, formulae)
assert.NotContains(t, formulae, "def caveats")
assert.NotContains(t, formulae, "depends_on")
@ -126,6 +125,9 @@ func TestRunPipe(t *testing.T) {
},
Version: "1.0.1",
Artifacts: artifact.New(),
Env: map[string]string{
"FOO": "foo_is_bar",
},
Config: config.Project{
Dist: folder,
ProjectName: name,
@ -148,14 +150,14 @@ func TestRunPipe(t *testing.T) {
IDs: []string{
"foo",
},
Description: "A run pipe test formula",
Description: "A run pipe test formula and FOO={{ .Env.FOO }}",
Homepage: "https://github.com/goreleaser",
Caveats: "don't do this",
Caveats: "don't do this {{ .ProjectName }}",
Test: "system \"true\"\nsystem \"#{bin}/foo -h\"",
Plist: `<xml>whatever</xml>`,
Dependencies: []string{"zsh", "bash"},
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
}
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
bts, _ := ioutil.ReadAll(&content)
client.Content = string(bts)
client.Content = string(content)
return
}

View File

@ -1,6 +1,6 @@
# This file was generated by GoReleaser. DO NOT EDIT.
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"
version "1.0.1"
@ -19,11 +19,11 @@ class CustomBlock < Formula
conflicts_with "qt"
def install
bin.install "foo"
bin.install "custom_block"
end
def caveats; <<~EOS
don't do this
don't do this custom_block
EOS
end

View File

@ -1,6 +1,6 @@
# This file was generated by GoReleaser. DO NOT EDIT.
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"
version "1.0.1"
@ -17,11 +17,11 @@ class CustomDownloadStrategy < Formula
conflicts_with "qt"
def install
bin.install "foo"
bin.install "custom_download_strategy"
end
def caveats; <<~EOS
don't do this
don't do this custom_download_strategy
EOS
end

View File

@ -1,7 +1,7 @@
# This file was generated by GoReleaser. DO NOT EDIT.
require_relative "custom_download_strategy"
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"
version "1.0.1"
@ -18,11 +18,11 @@ class CustomRequire < Formula
conflicts_with "qt"
def install
bin.install "foo"
bin.install "custom_require"
end
def caveats; <<~EOS
don't do this
don't do this custom_require
EOS
end

View File

@ -1,6 +1,6 @@
# This file was generated by GoReleaser. DO NOT EDIT.
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"
version "1.0.1"
@ -17,11 +17,11 @@ class Default < Formula
conflicts_with "qt"
def install
bin.install "foo"
bin.install "default"
end
def caveats; <<~EOS
don't do this
don't do this default
EOS
end

View File

@ -1,6 +1,6 @@
# This file was generated by GoReleaser. DO NOT EDIT.
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"
version "1.0.1"
@ -17,11 +17,11 @@ class GithubEnterpriseUrl < Formula
conflicts_with "qt"
def install
bin.install "foo"
bin.install "github_enterprise_url"
end
def caveats; <<~EOS
don't do this
don't do this github_enterprise_url
EOS
end

View File

@ -1,7 +1,6 @@
package release
import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
@ -332,7 +331,7 @@ func (client *DummyClient) CreateRelease(ctx *context.Context, body string) (rel
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
}

View File

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

View File

@ -1,7 +1,6 @@
package scoop
import (
"bytes"
"flag"
"io/ioutil"
"os"
@ -535,10 +534,9 @@ func (client *DummyClient) CreateRelease(ctx *context.Context, body string) (rel
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
bts, _ := ioutil.ReadAll(&content)
client.Content = string(bts)
client.Content = string(content)
return
}