2016-12-29 13:58:22 +02:00
|
|
|
package brew
|
|
|
|
|
|
|
|
import (
|
2020-11-26 15:06:47 +02:00
|
|
|
"bufio"
|
2016-12-29 13:58:22 +02:00
|
|
|
"bytes"
|
2020-09-21 19:47:51 +02:00
|
|
|
"errors"
|
2017-12-02 23:53:19 +02:00
|
|
|
"fmt"
|
2021-04-25 18:00:51 +02:00
|
|
|
"os"
|
2018-11-07 18:15:07 +02:00
|
|
|
"path"
|
2017-01-14 15:18:48 +02:00
|
|
|
"path/filepath"
|
2023-06-14 05:13:21 +02:00
|
|
|
"reflect"
|
2021-09-29 02:34:35 +02:00
|
|
|
"sort"
|
2016-12-29 13:58:22 +02:00
|
|
|
"strings"
|
2016-12-29 17:14:52 +02:00
|
|
|
"text/template"
|
2016-12-29 13:58:22 +02:00
|
|
|
|
2022-06-22 02:11:15 +02:00
|
|
|
"github.com/caarlos0/log"
|
2017-12-18 00:14:41 +02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/artifact"
|
2017-05-13 23:06:15 +02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/client"
|
2022-01-11 14:15:28 +02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/commitauthor"
|
2023-06-06 06:02:40 +02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/deprecate"
|
2018-09-12 19:18:01 +02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/pipe"
|
2023-11-04 01:31:37 +02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/skips"
|
2018-07-26 15:03:28 +02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/tmpl"
|
2018-08-15 04:50:20 +02:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
|
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
2023-11-30 04:12:46 +02:00
|
|
|
"golang.org/x/text/cases"
|
|
|
|
"golang.org/x/text/language"
|
2016-12-29 13:58:22 +02:00
|
|
|
)
|
|
|
|
|
2021-09-18 15:21:29 +02:00
|
|
|
const brewConfigExtra = "BrewConfig"
|
|
|
|
|
2023-03-29 15:24:53 +02:00
|
|
|
// ErrMultipleArchivesSameOS happens when the config yields multiple archives
|
|
|
|
// for linux or windows.
|
2023-05-02 14:18:36 +02:00
|
|
|
var ErrMultipleArchivesSameOS = errors.New("one tap can handle only one archive of an OS/Arch combination. Consider using ids in the brew section")
|
2023-03-29 15:24:53 +02:00
|
|
|
|
|
|
|
// ErrNoArchivesFound happens when 0 archives are found.
|
|
|
|
type ErrNoArchivesFound struct {
|
|
|
|
goarm string
|
|
|
|
goamd64 string
|
|
|
|
ids []string
|
|
|
|
}
|
2017-12-17 20:31:06 +02:00
|
|
|
|
2023-03-29 15:24:53 +02:00
|
|
|
func (e ErrNoArchivesFound) Error() string {
|
|
|
|
return fmt.Sprintf("no linux/macos archives found matching goos=[darwin linux] goarch=[amd64 arm64 arm] goamd64=%s goarm=%s ids=%v", e.goamd64, e.goarm, e.ids)
|
|
|
|
}
|
2017-01-16 18:52:27 +02:00
|
|
|
|
2020-05-26 05:48:10 +02:00
|
|
|
// Pipe for brew deployment.
|
2016-12-30 13:27:35 +02:00
|
|
|
type Pipe struct{}
|
|
|
|
|
2023-11-04 01:31:37 +02:00
|
|
|
func (Pipe) String() string { return "homebrew tap formula" }
|
|
|
|
func (Pipe) ContinueOnError() bool { return true }
|
|
|
|
func (Pipe) Skip(ctx *context.Context) bool {
|
|
|
|
return skips.Any(ctx, skips.Homebrew) || len(ctx.Config.Brews) == 0
|
|
|
|
}
|
2021-09-18 15:21:29 +02:00
|
|
|
|
|
|
|
func (Pipe) Default(ctx *context.Context) error {
|
|
|
|
for i := range ctx.Config.Brews {
|
|
|
|
brew := &ctx.Config.Brews[i]
|
|
|
|
|
2022-01-11 14:15:28 +02:00
|
|
|
brew.CommitAuthor = commitauthor.Default(brew.CommitAuthor)
|
|
|
|
|
2021-09-18 15:21:29 +02:00
|
|
|
if brew.CommitMessageTemplate == "" {
|
|
|
|
brew.CommitMessageTemplate = "Brew formula update for {{ .ProjectName }} version {{ .Tag }}"
|
|
|
|
}
|
|
|
|
if brew.Name == "" {
|
|
|
|
brew.Name = ctx.Config.ProjectName
|
|
|
|
}
|
|
|
|
if brew.Goarm == "" {
|
|
|
|
brew.Goarm = "6"
|
|
|
|
}
|
2022-04-12 03:43:22 +02:00
|
|
|
if brew.Goamd64 == "" {
|
2022-04-16 20:26:14 +02:00
|
|
|
brew.Goamd64 = "v1"
|
2022-04-12 03:43:22 +02:00
|
|
|
}
|
2023-06-06 06:02:40 +02:00
|
|
|
if brew.Plist != "" {
|
|
|
|
deprecate.Notice(ctx, "brews.plist")
|
|
|
|
}
|
2023-06-14 05:13:21 +02:00
|
|
|
if !reflect.DeepEqual(brew.Tap, config.RepoRef{}) {
|
|
|
|
brew.Repository = brew.Tap
|
|
|
|
deprecate.Notice(ctx, "brews.tap")
|
|
|
|
}
|
2021-09-18 15:21:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (Pipe) Run(ctx *context.Context) error {
|
feat: allow goreleaser to run in gerrit, soft-serve and others (#4271)
Currently, GoReleaser will assume you're running against github, gitea
or gitlab.
You could set `release.disable: true`, but it would still set and try to
use some defaults that could break things up.
Now, if you disable the release, goreleaser will not set these defaults.
It'll also hard error in some cases in which it would happily produce
invalid resources before, namely, if `release.disable` is set, and, for
example, `brews.url_template` is empty (in which case it would try to
use the one from the release, usually github).
closes #4208
2023-09-04 16:23:38 +02:00
|
|
|
cli, err := client.NewReleaseClient(ctx)
|
2021-09-18 15:21:29 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return runAll(ctx, cli)
|
2016-12-30 13:27:35 +02:00
|
|
|
}
|
|
|
|
|
2020-05-26 05:48:10 +02:00
|
|
|
// Publish brew formula.
|
2018-10-10 17:47:31 +02:00
|
|
|
func (Pipe) Publish(ctx *context.Context) error {
|
2020-08-16 16:29:56 +02:00
|
|
|
cli, err := client.New(ctx)
|
2017-09-22 14:42:36 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-08-16 16:29:56 +02:00
|
|
|
return publishAll(ctx, cli)
|
|
|
|
}
|
|
|
|
|
feat: allow goreleaser to run in gerrit, soft-serve and others (#4271)
Currently, GoReleaser will assume you're running against github, gitea
or gitlab.
You could set `release.disable: true`, but it would still set and try to
use some defaults that could break things up.
Now, if you disable the release, goreleaser will not set these defaults.
It'll also hard error in some cases in which it would happily produce
invalid resources before, namely, if `release.disable` is set, and, for
example, `brews.url_template` is empty (in which case it would try to
use the one from the release, usually github).
closes #4208
2023-09-04 16:23:38 +02:00
|
|
|
func runAll(ctx *context.Context, cli client.ReleaseURLTemplater) error {
|
2021-09-18 15:21:29 +02:00
|
|
|
for _, brew := range ctx.Config.Brews {
|
|
|
|
err := doRun(ctx, brew, cli)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-08-16 16:29:56 +02:00
|
|
|
func publishAll(ctx *context.Context, cli client.Client) error {
|
|
|
|
// even if one of them skips, we run them all, and then show return the skips all at once.
|
|
|
|
// this is needed so we actually create the `dist/foo.rb` file, which is useful for debugging.
|
2021-04-19 14:31:57 +02:00
|
|
|
skips := pipe.SkipMemento{}
|
2021-09-18 15:21:29 +02:00
|
|
|
for _, formula := range ctx.Artifacts.Filter(artifact.ByType(artifact.BrewTap)).List() {
|
|
|
|
err := doPublish(ctx, formula, cli)
|
2020-08-16 16:29:56 +02:00
|
|
|
if err != nil && pipe.IsSkip(err) {
|
|
|
|
skips.Remember(err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if err != nil {
|
2019-08-31 15:27:04 +02:00
|
|
|
return err
|
|
|
|
}
|
2019-06-10 15:35:19 +02:00
|
|
|
}
|
2020-08-16 16:29:56 +02:00
|
|
|
return skips.Evaluate()
|
2017-03-26 20:30:21 +02:00
|
|
|
}
|
|
|
|
|
2021-09-18 15:21:29 +02:00
|
|
|
func doPublish(ctx *context.Context, formula *artifact.Artifact, cl client.Client) error {
|
2022-06-24 04:36:19 +02:00
|
|
|
brew, err := artifact.Extra[config.Homebrew](*formula, brewConfigExtra)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-07-06 15:48:17 +02:00
|
|
|
|
2021-09-18 15:21:29 +02:00
|
|
|
if strings.TrimSpace(brew.SkipUpload) == "true" {
|
|
|
|
return pipe.Skip("brew.skip_upload is set")
|
2017-12-02 23:53:19 +02:00
|
|
|
}
|
|
|
|
|
2021-09-18 15:21:29 +02:00
|
|
|
if strings.TrimSpace(brew.SkipUpload) == "auto" && ctx.Semver.Prerelease != "" {
|
|
|
|
return pipe.Skip("prerelease detected with 'auto' upload, skipping homebrew publish")
|
|
|
|
}
|
|
|
|
|
2023-06-14 05:13:21 +02:00
|
|
|
repo := client.RepoFromRef(brew.Repository)
|
2021-09-18 15:21:29 +02:00
|
|
|
|
|
|
|
gpath := buildFormulaPath(brew.Folder, formula.Name)
|
|
|
|
|
|
|
|
msg, err := tmpl.New(ctx).Apply(brew.CommitMessageTemplate)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-01-11 14:15:28 +02:00
|
|
|
author, err := commitauthor.Get(ctx, brew.CommitAuthor)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-09-18 15:21:29 +02:00
|
|
|
content, err := os.ReadFile(formula.Path)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-06-14 05:13:21 +02:00
|
|
|
if brew.Repository.Git.URL != "" {
|
2023-04-30 15:18:13 +02:00
|
|
|
return client.NewGitUploadClient(repo.Branch).
|
|
|
|
CreateFile(ctx, author, repo, content, gpath, msg)
|
|
|
|
}
|
|
|
|
|
2023-06-14 05:13:21 +02:00
|
|
|
cl, err = client.NewIfToken(ctx, cl, brew.Repository.Token)
|
2023-04-30 15:18:13 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-06-14 05:13:21 +02:00
|
|
|
if !brew.Repository.PullRequest.Enabled {
|
2023-09-24 21:18:07 +02:00
|
|
|
log.Debug("brews.pull_request disabled")
|
2023-04-07 03:58:06 +02:00
|
|
|
return cl.CreateFile(ctx, author, repo, content, gpath, msg)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Info("brews.pull_request enabled, creating a PR")
|
|
|
|
pcl, ok := cl.(client.PullRequestOpener)
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("client does not support pull requests")
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := cl.CreateFile(ctx, author, repo, content, gpath, msg); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-05-29 19:37:10 +02:00
|
|
|
return pcl.OpenPullRequest(ctx, client.Repo{
|
2023-06-14 05:13:21 +02:00
|
|
|
Name: brew.Repository.PullRequest.Base.Name,
|
|
|
|
Owner: brew.Repository.PullRequest.Base.Owner,
|
|
|
|
Branch: brew.Repository.PullRequest.Base.Branch,
|
2023-06-25 07:16:37 +02:00
|
|
|
}, repo, msg, brew.Repository.PullRequest.Draft)
|
2017-12-02 23:53:19 +02:00
|
|
|
}
|
|
|
|
|
feat: allow goreleaser to run in gerrit, soft-serve and others (#4271)
Currently, GoReleaser will assume you're running against github, gitea
or gitlab.
You could set `release.disable: true`, but it would still set and try to
use some defaults that could break things up.
Now, if you disable the release, goreleaser will not set these defaults.
It'll also hard error in some cases in which it would happily produce
invalid resources before, namely, if `release.disable` is set, and, for
example, `brews.url_template` is empty (in which case it would try to
use the one from the release, usually github).
closes #4208
2023-09-04 16:23:38 +02:00
|
|
|
func doRun(ctx *context.Context, brew config.Homebrew, cl client.ReleaseURLTemplater) error {
|
2023-06-14 05:13:21 +02:00
|
|
|
if brew.Repository.Name == "" {
|
|
|
|
return pipe.Skip("brew.repository.name is not set")
|
2020-07-06 22:12:41 +02:00
|
|
|
}
|
|
|
|
|
2021-04-19 14:31:57 +02:00
|
|
|
filters := []artifact.Filter{
|
2019-06-10 15:35:19 +02:00
|
|
|
artifact.Or(
|
2017-12-17 20:59:54 +02:00
|
|
|
artifact.ByGoos("darwin"),
|
2019-06-10 15:35:19 +02:00
|
|
|
artifact.ByGoos("linux"),
|
2017-12-17 20:59:54 +02:00
|
|
|
),
|
2019-09-09 14:34:52 +02:00
|
|
|
artifact.Or(
|
2022-04-12 03:43:22 +02:00
|
|
|
artifact.And(
|
|
|
|
artifact.ByGoarch("amd64"),
|
|
|
|
artifact.ByGoamd64(brew.Goamd64),
|
|
|
|
),
|
2019-09-09 14:34:52 +02:00
|
|
|
artifact.ByGoarch("arm64"),
|
2021-10-12 19:55:43 +02:00
|
|
|
artifact.ByGoarch("all"),
|
2019-09-27 02:46:05 +02:00
|
|
|
artifact.And(
|
|
|
|
artifact.ByGoarch("arm"),
|
|
|
|
artifact.ByGoarm(brew.Goarm),
|
|
|
|
),
|
2019-09-09 14:34:52 +02:00
|
|
|
),
|
2021-10-17 04:52:01 +02:00
|
|
|
artifact.Or(
|
|
|
|
artifact.And(
|
2023-11-24 19:03:05 +02:00
|
|
|
artifact.ByFormats("zip", "tar.gz", "tar.xz"),
|
2021-10-17 04:52:01 +02:00
|
|
|
artifact.ByType(artifact.UploadableArchive),
|
|
|
|
),
|
|
|
|
artifact.ByType(artifact.UploadableBinary),
|
|
|
|
),
|
2021-12-08 02:53:39 +02:00
|
|
|
artifact.OnlyReplacingUnibins,
|
2017-07-14 01:22:10 +02:00
|
|
|
}
|
2019-06-10 15:35:19 +02:00
|
|
|
if len(brew.IDs) > 0 {
|
|
|
|
filters = append(filters, artifact.ByIDs(brew.IDs...))
|
|
|
|
}
|
|
|
|
|
2021-04-19 14:31:57 +02:00
|
|
|
archives := ctx.Artifacts.Filter(artifact.And(filters...)).List()
|
2019-06-10 15:35:19 +02:00
|
|
|
if len(archives) == 0 {
|
2023-03-29 15:24:53 +02:00
|
|
|
return ErrNoArchivesFound{
|
|
|
|
goamd64: brew.Goamd64,
|
|
|
|
goarm: brew.Goarm,
|
|
|
|
ids: brew.IDs,
|
|
|
|
}
|
2017-07-14 01:22:10 +02:00
|
|
|
}
|
2018-01-10 01:31:18 +02:00
|
|
|
|
2020-08-15 22:16:48 +02:00
|
|
|
name, err := tmpl.New(ctx).Apply(brew.Name)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
brew.Name = name
|
|
|
|
|
2023-06-14 05:13:21 +02:00
|
|
|
ref, err := client.TemplateRef(tmpl.New(ctx).Apply, brew.Repository)
|
2021-10-02 17:46:27 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-06-14 05:13:21 +02:00
|
|
|
brew.Repository = ref
|
2021-10-02 17:53:06 +02:00
|
|
|
|
2021-10-10 19:46:52 +02:00
|
|
|
skipUpload, err := tmpl.New(ctx).Apply(brew.SkipUpload)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
brew.SkipUpload = skipUpload
|
|
|
|
|
2020-07-06 22:12:41 +02:00
|
|
|
content, err := buildFormula(ctx, brew, cl, archives)
|
2016-12-29 13:58:22 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-01-10 01:31:18 +02:00
|
|
|
|
2021-04-19 14:31:57 +02:00
|
|
|
filename := brew.Name + ".rb"
|
2023-06-25 04:38:09 +02:00
|
|
|
path := filepath.Join(ctx.Config.Dist, "homebrew", brew.Folder, filename)
|
|
|
|
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-01-10 01:31:18 +02:00
|
|
|
log.WithField("formula", path).Info("writing")
|
2021-04-25 18:00:51 +02:00
|
|
|
if err := os.WriteFile(path, []byte(content), 0o644); err != nil { //nolint: gosec
|
2020-09-21 19:47:51 +02:00
|
|
|
return fmt.Errorf("failed to write brew formula: %w", err)
|
2018-01-10 01:31:18 +02:00
|
|
|
}
|
|
|
|
|
2021-09-18 15:21:29 +02:00
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
|
|
|
Name: filename,
|
|
|
|
Path: path,
|
|
|
|
Type: artifact.BrewTap,
|
|
|
|
Extra: map[string]interface{}{
|
|
|
|
brewConfigExtra: brew,
|
|
|
|
},
|
|
|
|
})
|
2020-04-29 20:09:00 +02:00
|
|
|
|
2021-09-18 15:21:29 +02:00
|
|
|
return nil
|
2018-11-06 14:46:00 +02:00
|
|
|
}
|
|
|
|
|
2019-08-13 20:28:03 +02:00
|
|
|
func buildFormulaPath(folder, filename string) string {
|
2018-11-07 18:15:07 +02:00
|
|
|
return path.Join(folder, filename)
|
2016-12-30 13:48:06 +02:00
|
|
|
}
|
2016-12-29 13:58:22 +02:00
|
|
|
|
feat: allow goreleaser to run in gerrit, soft-serve and others (#4271)
Currently, GoReleaser will assume you're running against github, gitea
or gitlab.
You could set `release.disable: true`, but it would still set and try to
use some defaults that could break things up.
Now, if you disable the release, goreleaser will not set these defaults.
It'll also hard error in some cases in which it would happily produce
invalid resources before, namely, if `release.disable` is set, and, for
example, `brews.url_template` is empty (in which case it would try to
use the one from the release, usually github).
closes #4208
2023-09-04 16:23:38 +02:00
|
|
|
func buildFormula(ctx *context.Context, brew config.Homebrew, client client.ReleaseURLTemplater, artifacts []*artifact.Artifact) (string, error) {
|
2020-07-06 15:48:17 +02:00
|
|
|
data, err := dataFor(ctx, brew, client, artifacts)
|
2016-12-30 13:48:06 +02:00
|
|
|
if err != nil {
|
2019-06-26 19:12:33 +02:00
|
|
|
return "", err
|
2016-12-30 13:48:06 +02:00
|
|
|
}
|
2019-06-26 19:12:33 +02:00
|
|
|
return doBuildFormula(ctx, data)
|
2016-12-30 13:53:05 +02:00
|
|
|
}
|
|
|
|
|
2019-06-26 19:12:33 +02:00
|
|
|
func doBuildFormula(ctx *context.Context, data templateData) (string, error) {
|
2021-05-30 19:25:25 +02:00
|
|
|
t, err := template.
|
|
|
|
New(data.Name).
|
|
|
|
Parse(formulaTemplate)
|
2016-12-29 17:14:52 +02:00
|
|
|
if err != nil {
|
2019-06-26 19:12:33 +02:00
|
|
|
return "", err
|
2016-12-29 17:14:52 +02:00
|
|
|
}
|
2019-06-26 19:12:33 +02:00
|
|
|
var out bytes.Buffer
|
|
|
|
if err := t.Execute(&out, data); err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2020-11-26 15:06:47 +02:00
|
|
|
|
|
|
|
content, err := tmpl.New(ctx).Apply(out.String())
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
out.Reset()
|
|
|
|
|
|
|
|
// Sanitize the template output and get rid of trailing whitespace.
|
|
|
|
var (
|
|
|
|
r = strings.NewReader(content)
|
|
|
|
s = bufio.NewScanner(r)
|
|
|
|
)
|
|
|
|
for s.Scan() {
|
|
|
|
l := strings.TrimRight(s.Text(), " ")
|
|
|
|
_, _ = out.WriteString(l)
|
|
|
|
_ = out.WriteByte('\n')
|
|
|
|
}
|
|
|
|
if err := s.Err(); err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return out.String(), nil
|
2016-12-29 17:14:52 +02:00
|
|
|
}
|
|
|
|
|
2022-11-25 14:32:43 +02:00
|
|
|
func installs(ctx *context.Context, cfg config.Homebrew, art *artifact.Artifact) ([]string, error) {
|
2023-07-30 05:03:54 +02:00
|
|
|
tpl := tmpl.New(ctx).WithArtifact(art)
|
|
|
|
|
|
|
|
extraInstall, err := tpl.Apply(cfg.ExtraInstall)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
install, err := tpl.Apply(cfg.Install)
|
2022-11-25 14:32:43 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-07-30 05:03:54 +02:00
|
|
|
if install != "" {
|
|
|
|
return append(split(install), split(extraInstall)...), nil
|
2021-10-09 02:25:53 +02:00
|
|
|
}
|
2021-10-18 14:31:20 +02:00
|
|
|
|
2023-07-30 05:03:54 +02:00
|
|
|
installMap := map[string]bool{}
|
2021-10-18 14:31:20 +02:00
|
|
|
switch art.Type {
|
|
|
|
case artifact.UploadableBinary:
|
|
|
|
name := art.Name
|
2022-06-24 04:36:19 +02:00
|
|
|
bin := artifact.ExtraOr(*art, artifact.ExtraBinary, art.Name)
|
2023-07-30 05:03:54 +02:00
|
|
|
installMap[fmt.Sprintf("bin.install %q => %q", name, bin)] = true
|
2021-10-18 14:31:20 +02:00
|
|
|
case artifact.UploadableArchive:
|
2022-06-24 04:36:19 +02:00
|
|
|
for _, bin := range artifact.ExtraOr(*art, artifact.ExtraBinaries, []string{}) {
|
2023-07-30 05:03:54 +02:00
|
|
|
installMap[fmt.Sprintf("bin.install %q", bin)] = true
|
2021-10-09 02:25:53 +02:00
|
|
|
}
|
|
|
|
}
|
2021-10-17 04:52:01 +02:00
|
|
|
|
2023-07-30 05:03:54 +02:00
|
|
|
result := keys(installMap)
|
2021-10-18 14:31:20 +02:00
|
|
|
sort.Strings(result)
|
2023-07-30 05:03:54 +02:00
|
|
|
log.WithField("install", result).Info("guessing install")
|
|
|
|
|
|
|
|
return append(result, split(extraInstall)...), nil
|
2021-10-17 04:52:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func keys(m map[string]bool) []string {
|
|
|
|
keys := make([]string, 0, len(m))
|
|
|
|
for k := range m {
|
|
|
|
keys = append(keys, k)
|
|
|
|
}
|
|
|
|
return keys
|
2021-10-09 02:25:53 +02:00
|
|
|
}
|
|
|
|
|
feat: allow goreleaser to run in gerrit, soft-serve and others (#4271)
Currently, GoReleaser will assume you're running against github, gitea
or gitlab.
You could set `release.disable: true`, but it would still set and try to
use some defaults that could break things up.
Now, if you disable the release, goreleaser will not set these defaults.
It'll also hard error in some cases in which it would happily produce
invalid resources before, namely, if `release.disable` is set, and, for
example, `brews.url_template` is empty (in which case it would try to
use the one from the release, usually github).
closes #4208
2023-09-04 16:23:38 +02:00
|
|
|
func dataFor(ctx *context.Context, cfg config.Homebrew, cl client.ReleaseURLTemplater, artifacts []*artifact.Artifact) (templateData, error) {
|
2023-06-06 05:32:34 +02:00
|
|
|
sort.Slice(cfg.Dependencies, func(i, j int) bool {
|
|
|
|
return cfg.Dependencies[i].Name < cfg.Dependencies[j].Name
|
|
|
|
})
|
2021-04-19 14:31:57 +02:00
|
|
|
result := templateData{
|
2021-09-29 02:34:35 +02:00
|
|
|
Name: formulaNameFor(cfg.Name),
|
|
|
|
Desc: cfg.Description,
|
|
|
|
Homepage: cfg.Homepage,
|
|
|
|
Version: ctx.Version,
|
|
|
|
License: cfg.License,
|
|
|
|
Caveats: split(cfg.Caveats),
|
|
|
|
Dependencies: cfg.Dependencies,
|
|
|
|
Conflicts: cfg.Conflicts,
|
|
|
|
Plist: cfg.Plist,
|
2022-03-17 02:12:57 +02:00
|
|
|
Service: split(cfg.Service),
|
2022-03-17 02:40:25 +02:00
|
|
|
PostInstall: split(cfg.PostInstall),
|
2021-09-29 02:34:35 +02:00
|
|
|
Tests: split(cfg.Test),
|
|
|
|
CustomRequire: cfg.CustomRequire,
|
|
|
|
CustomBlock: split(cfg.CustomBlock),
|
2019-06-10 15:35:19 +02:00
|
|
|
}
|
|
|
|
|
2021-09-29 02:34:35 +02:00
|
|
|
counts := map[string]int{}
|
2021-10-18 14:31:20 +02:00
|
|
|
for _, art := range artifacts {
|
|
|
|
sum, err := art.Checksum("sha256")
|
2019-06-10 15:35:19 +02:00
|
|
|
if err != nil {
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if cfg.URLTemplate == "" {
|
2020-07-06 15:48:17 +02:00
|
|
|
url, err := cl.ReleaseURLTemplate(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return result, err
|
2019-08-13 20:28:03 +02:00
|
|
|
}
|
2020-07-06 15:48:17 +02:00
|
|
|
cfg.URLTemplate = url
|
2019-06-10 15:35:19 +02:00
|
|
|
}
|
2021-09-29 02:34:35 +02:00
|
|
|
|
2022-11-25 20:26:14 +02:00
|
|
|
url, err := tmpl.New(ctx).WithArtifact(art).Apply(cfg.URLTemplate)
|
2019-06-10 15:35:19 +02:00
|
|
|
if err != nil {
|
|
|
|
return result, err
|
|
|
|
}
|
2021-09-29 02:34:35 +02:00
|
|
|
|
2022-11-25 14:32:43 +02:00
|
|
|
install, err := installs(ctx, cfg, art)
|
|
|
|
if err != nil {
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
|
2021-09-29 02:34:35 +02:00
|
|
|
pkg := releasePackage{
|
|
|
|
DownloadURL: url,
|
|
|
|
SHA256: sum,
|
2021-10-18 14:31:20 +02:00
|
|
|
OS: art.Goos,
|
|
|
|
Arch: art.Goarch,
|
2021-09-29 02:34:35 +02:00
|
|
|
DownloadStrategy: cfg.DownloadStrategy,
|
2022-11-25 14:32:43 +02:00
|
|
|
Install: install,
|
2019-06-10 15:35:19 +02:00
|
|
|
}
|
2021-09-29 02:34:35 +02:00
|
|
|
|
|
|
|
counts[pkg.OS+pkg.Arch]++
|
|
|
|
|
|
|
|
switch pkg.OS {
|
|
|
|
case "darwin":
|
|
|
|
result.MacOSPackages = append(result.MacOSPackages, pkg)
|
|
|
|
case "linux":
|
|
|
|
result.LinuxPackages = append(result.LinuxPackages, pkg)
|
2019-06-10 15:35:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-29 02:34:35 +02:00
|
|
|
for _, v := range counts {
|
|
|
|
if v > 1 {
|
|
|
|
return result, ErrMultipleArchivesSameOS
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-26 02:57:46 +02:00
|
|
|
if len(result.MacOSPackages) == 1 && result.MacOSPackages[0].Arch == "amd64" {
|
|
|
|
result.HasOnlyAmd64MacOsPkg = true
|
|
|
|
}
|
|
|
|
|
2021-09-29 02:34:35 +02:00
|
|
|
sort.Slice(result.LinuxPackages, lessFnFor(result.LinuxPackages))
|
|
|
|
sort.Slice(result.MacOSPackages, lessFnFor(result.MacOSPackages))
|
2019-06-10 15:35:19 +02:00
|
|
|
return result, nil
|
2016-12-29 13:58:22 +02:00
|
|
|
}
|
2016-12-29 14:55:35 +02:00
|
|
|
|
2021-09-29 02:34:35 +02:00
|
|
|
func lessFnFor(list []releasePackage) func(i, j int) bool {
|
|
|
|
return func(i, j int) bool { return list[i].OS > list[j].OS && list[i].Arch > list[j].Arch }
|
|
|
|
}
|
|
|
|
|
2017-07-16 21:01:20 +02:00
|
|
|
func split(s string) []string {
|
2018-04-05 23:11:31 +02:00
|
|
|
strings := strings.Split(strings.TrimSpace(s), "\n")
|
|
|
|
if len(strings) == 1 && strings[0] == "" {
|
|
|
|
return []string{}
|
|
|
|
}
|
|
|
|
return strings
|
2017-07-16 21:01:20 +02:00
|
|
|
}
|
|
|
|
|
2021-05-11 06:50:17 +02:00
|
|
|
// formulaNameFor transforms the formula name into a form
|
|
|
|
// that more resembles a valid Ruby class name
|
|
|
|
// e.g. foo_bar@v6.0.0-rc is turned into FooBarATv6_0_0RC
|
|
|
|
// The order of these replacements is important
|
2016-12-29 14:55:35 +02:00
|
|
|
func formulaNameFor(name string) string {
|
2020-09-21 15:13:03 +02:00
|
|
|
name = strings.ReplaceAll(name, "-", " ")
|
|
|
|
name = strings.ReplaceAll(name, "_", " ")
|
2022-05-20 15:25:35 +02:00
|
|
|
name = strings.ReplaceAll(name, ".", "")
|
2023-11-30 04:12:46 +02:00
|
|
|
name = cases.Title(language.English).String(name)
|
|
|
|
name = strings.ReplaceAll(name, " ", "")
|
|
|
|
return strings.ReplaceAll(name, "@", "AT")
|
2016-12-29 17:14:52 +02:00
|
|
|
}
|