mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-17 20:47:50 +02:00
feat: add url_template in brew section (#735)
This commit is contained in:
parent
9154294c00
commit
36bb63f86b
@ -50,6 +50,7 @@ type Homebrew struct {
|
||||
SkipUpload bool `yaml:"skip_upload,omitempty"`
|
||||
DownloadStrategy string `yaml:"download_strategy,omitempty"`
|
||||
SourceTarball string `yaml:"-"`
|
||||
URLTemplate string `yaml:"url_template,omitempty"`
|
||||
}
|
||||
|
||||
// Scoop contains the scoop.sh section
|
||||
|
@ -33,10 +33,11 @@ const (
|
||||
timestamp = "Timestamp"
|
||||
|
||||
// artifact-only keys
|
||||
os = "Os"
|
||||
arch = "Arch"
|
||||
arm = "Arm"
|
||||
binary = "Binary"
|
||||
os = "Os"
|
||||
arch = "Arch"
|
||||
arm = "Arm"
|
||||
binary = "Binary"
|
||||
artifactName = "ArtifactName"
|
||||
)
|
||||
|
||||
// New Template
|
||||
@ -64,6 +65,7 @@ func (t *Template) WithArtifact(a artifact.Artifact, replacements map[string]str
|
||||
t.fields[arch] = replace(replacements, a.Goarch)
|
||||
t.fields[arm] = replace(replacements, a.Goarm)
|
||||
t.fields[binary] = bin
|
||||
t.fields[artifactName] = a.Name
|
||||
return t
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ import (
|
||||
"github.com/goreleaser/goreleaser/context"
|
||||
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||
"github.com/goreleaser/goreleaser/internal/client"
|
||||
"github.com/goreleaser/goreleaser/internal/tmpl"
|
||||
"github.com/goreleaser/goreleaser/pipeline"
|
||||
)
|
||||
|
||||
@ -159,11 +160,11 @@ func buildFormula(ctx *context.Context, artifact artifact.Artifact) (bytes.Buffe
|
||||
}
|
||||
|
||||
func doBuildFormula(data templateData) (out bytes.Buffer, err error) {
|
||||
tmpl, err := template.New(data.Name).Parse(formulaTemplate)
|
||||
t, err := template.New(data.Name).Parse(formulaTemplate)
|
||||
if err != nil {
|
||||
return out, err
|
||||
}
|
||||
err = tmpl.Execute(&out, data)
|
||||
err = t.Execute(&out, data)
|
||||
return
|
||||
}
|
||||
|
||||
@ -173,16 +174,25 @@ func dataFor(ctx *context.Context, artifact artifact.Artifact) (result templateD
|
||||
return
|
||||
}
|
||||
var cfg = ctx.Config.Brew
|
||||
|
||||
if ctx.Config.Brew.URLTemplate == "" {
|
||||
ctx.Config.Brew.URLTemplate = fmt.Sprintf("%s/%s/%s/releases/download/{{ .Tag }}/{{ .ArtifactName }}",
|
||||
ctx.Config.GitHubURLs.Download,
|
||||
ctx.Config.Release.GitHub.Owner,
|
||||
ctx.Config.Release.GitHub.Name)
|
||||
}
|
||||
url, err := tmpl.New(ctx).WithArtifact(artifact, map[string]string{}).Apply(ctx.Config.Brew.URLTemplate)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return templateData{
|
||||
Name: formulaNameFor(ctx.Config.Brew.Name),
|
||||
DownloadURL: ctx.Config.GitHubURLs.Download,
|
||||
DownloadURL: url,
|
||||
Desc: cfg.Description,
|
||||
Homepage: cfg.Homepage,
|
||||
Repo: ctx.Config.Release.GitHub,
|
||||
Tag: ctx.Git.CurrentTag,
|
||||
Version: ctx.Version,
|
||||
Caveats: split(cfg.Caveats),
|
||||
File: artifact.Name,
|
||||
SHA256: sum,
|
||||
Dependencies: cfg.Dependencies,
|
||||
Conflicts: cfg.Conflicts,
|
||||
|
@ -37,17 +37,11 @@ func TestSimpleName(t *testing.T) {
|
||||
var defaultTemplateData = templateData{
|
||||
Desc: "Some desc",
|
||||
Homepage: "https://google.com",
|
||||
DownloadURL: "https://github.com",
|
||||
DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_x86_64.tar.gz",
|
||||
Name: "Test",
|
||||
Repo: config.Repo{
|
||||
Owner: "caarlos0",
|
||||
Name: "test",
|
||||
},
|
||||
Tag: "v0.1.3",
|
||||
Version: "0.1.3",
|
||||
Caveats: []string{},
|
||||
File: "test_Darwin_x86_64.tar.gz",
|
||||
SHA256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68",
|
||||
Version: "0.1.3",
|
||||
Caveats: []string{},
|
||||
SHA256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68",
|
||||
}
|
||||
|
||||
func assertDefaultTemplateData(t *testing.T, formulae string) {
|
||||
@ -292,6 +286,7 @@ func TestRunPipeNoUpload(t *testing.T) {
|
||||
},
|
||||
},
|
||||
})
|
||||
ctx.Git = context.GitInfo{CurrentTag: "v1.0.1"}
|
||||
var path = filepath.Join(folder, "whatever.tar.gz")
|
||||
_, err = os.Create(path)
|
||||
assert.NoError(t, err)
|
||||
|
@ -1,17 +1,12 @@
|
||||
package brew
|
||||
|
||||
import "github.com/goreleaser/goreleaser/config"
|
||||
|
||||
type templateData struct {
|
||||
Name string
|
||||
Desc string
|
||||
Homepage string
|
||||
DownloadURL string
|
||||
Repo config.Repo // FIXME: will not work for anything but github right now.
|
||||
Tag string
|
||||
Version string
|
||||
Caveats []string
|
||||
File string
|
||||
SHA256 string
|
||||
Plist string
|
||||
DownloadStrategy string
|
||||
@ -24,7 +19,7 @@ type templateData struct {
|
||||
const formulaTemplate = `class {{ .Name }} < Formula
|
||||
desc "{{ .Desc }}"
|
||||
homepage "{{ .Homepage }}"
|
||||
url "{{ .DownloadURL }}/{{ .Repo.Owner }}/{{ .Repo.Name }}/releases/download/{{ .Tag }}/{{ .File }}"
|
||||
url "{{ .DownloadURL }}"
|
||||
{{- if .DownloadStrategy }}, :using => {{ .DownloadStrategy }}{{- end }}
|
||||
version "{{ .Version }}"
|
||||
sha256 "{{ .SHA256 }}"
|
||||
|
@ -27,6 +27,10 @@ brew:
|
||||
owner: user
|
||||
name: homebrew-tap
|
||||
|
||||
# Template for the url.
|
||||
# Default is "https://github.com/<repo_owner>/<repo_name>/releases/download/{{ .Tag }}/{{ .ArtifactName }}"
|
||||
url_template: "http://github.mycompany.com/foo/bar/releases/{{ .Tag }}/{{ .ArtifactName }}"
|
||||
|
||||
# Allows you to set a custom download strategy.
|
||||
# Default is empty.
|
||||
download_strategy: GitHubPrivateRepositoryReleaseDownloadStrategy
|
||||
|
@ -29,12 +29,13 @@ On fields that support templating, this fields are always available:
|
||||
On fields that are related to a single artifact (e.g., the binary name), you
|
||||
may have some extra fields:
|
||||
|
||||
| Key | Description |
|
||||
| :-------: | :-----------------------------------: |
|
||||
| `.Os` | `GOOS` (usually allow replacements) |
|
||||
| `.Arch` | `GOARCH` (usually allow replacements) |
|
||||
| `.Arm` | `GOARM` (usually allow replacements) |
|
||||
| `.Binary` | Binary name |
|
||||
| Key | Description |
|
||||
| :-------------: | :-----------------------------------: |
|
||||
| `.Os` | `GOOS` (usually allow replacements) |
|
||||
| `.Arch` | `GOARCH` (usually allow replacements) |
|
||||
| `.Arm` | `GOARM` (usually allow replacements) |
|
||||
| `.Binary` | Binary name |
|
||||
| `.ArtifactName` | Archive name |
|
||||
|
||||
On all fields, you have these available functions:
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user