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"
|
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
|
|
|
|
2017-06-22 05:09:14 +02:00
|
|
|
"github.com/apex/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"
|
2018-09-12 19:18:01 +02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/pipe"
|
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"
|
2016-12-29 13:58:22 +02:00
|
|
|
)
|
|
|
|
|
2021-09-18 15:21:29 +02:00
|
|
|
const brewConfigExtra = "BrewConfig"
|
|
|
|
|
2021-11-07 04:10:44 +02:00
|
|
|
var (
|
|
|
|
// ErrNoArchivesFound happens when 0 archives are found.
|
|
|
|
ErrNoArchivesFound = errors.New("no linux/macos archives found")
|
2017-12-17 20:31:06 +02:00
|
|
|
|
2021-11-07 04:10:44 +02:00
|
|
|
// ErrMultipleArchivesSameOS happens when the config yields multiple archives
|
|
|
|
// for linux or windows.
|
|
|
|
ErrMultipleArchivesSameOS = errors.New("one tap can handle only archive of an OS/Arch combination. Consider using ids in the brew section")
|
|
|
|
)
|
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{}
|
|
|
|
|
2021-09-18 15:21:29 +02:00
|
|
|
func (Pipe) String() string { return "homebrew tap formula" }
|
|
|
|
func (Pipe) Skip(ctx *context.Context) bool { return len(ctx.Config.Brews) == 0 }
|
|
|
|
|
|
|
|
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 == "" {
|
|
|
|
brew.Goamd64 = "v2"
|
|
|
|
}
|
2021-09-18 15:21:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (Pipe) Run(ctx *context.Context) error {
|
|
|
|
cli, err := client.New(ctx)
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2021-09-18 15:21:29 +02:00
|
|
|
func runAll(ctx *context.Context, cli client.Client) error {
|
|
|
|
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 {
|
|
|
|
brew := formula.Extra[brewConfigExtra].(config.Homebrew)
|
|
|
|
var err error
|
|
|
|
cl, err = client.NewIfToken(ctx, cl, brew.Tap.Token)
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
|
|
|
|
repo := client.RepoFromRef(brew.Tap)
|
|
|
|
|
|
|
|
gpath := buildFormulaPath(brew.Folder, formula.Name)
|
|
|
|
log.WithField("formula", gpath).
|
|
|
|
WithField("repo", repo.String()).
|
|
|
|
Info("pushing")
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-01-11 14:15:28 +02:00
|
|
|
return cl.CreateFile(ctx, author, repo, content, gpath, msg)
|
2017-12-02 23:53:19 +02:00
|
|
|
}
|
|
|
|
|
2020-07-06 22:12:41 +02:00
|
|
|
func doRun(ctx *context.Context, brew config.Homebrew, cl client.Client) error {
|
2020-07-06 15:48:17 +02:00
|
|
|
if brew.Tap.Name == "" {
|
2021-09-18 15:21:29 +02:00
|
|
|
return pipe.Skip("brew tap 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(
|
|
|
|
artifact.ByFormats("zip", "tar.gz"),
|
|
|
|
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 {
|
|
|
|
return ErrNoArchivesFound
|
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
|
|
|
|
|
2021-10-02 17:46:27 +02:00
|
|
|
tapOwner, err := tmpl.New(ctx).Apply(brew.Tap.Owner)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
brew.Tap.Owner = tapOwner
|
|
|
|
|
2021-10-02 17:53:06 +02:00
|
|
|
tapName, err := tmpl.New(ctx).Apply(brew.Tap.Name)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
brew.Tap.Name = tapName
|
|
|
|
|
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"
|
|
|
|
path := filepath.Join(ctx.Config.Dist, filename)
|
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
|
|
|
|
2020-07-06 15:48:17 +02:00
|
|
|
func buildFormula(ctx *context.Context, brew config.Homebrew, client client.Client, artifacts []*artifact.Artifact) (string, error) {
|
|
|
|
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).
|
|
|
|
Funcs(template.FuncMap{
|
|
|
|
"join": strings.Join,
|
|
|
|
}).
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-10-18 14:31:20 +02:00
|
|
|
func installs(cfg config.Homebrew, art *artifact.Artifact) []string {
|
2021-10-09 02:25:53 +02:00
|
|
|
if cfg.Install != "" {
|
|
|
|
return split(cfg.Install)
|
|
|
|
}
|
2021-10-18 14:31:20 +02:00
|
|
|
|
2021-10-17 04:52:01 +02:00
|
|
|
install := map[string]bool{}
|
2021-10-18 14:31:20 +02:00
|
|
|
switch art.Type {
|
|
|
|
case artifact.UploadableBinary:
|
|
|
|
name := art.Name
|
|
|
|
bin := art.ExtraOr(artifact.ExtraBinary, art.Name).(string)
|
|
|
|
install[fmt.Sprintf("bin.install %q => %q", name, bin)] = true
|
|
|
|
case artifact.UploadableArchive:
|
|
|
|
for _, bin := range art.ExtraOr(artifact.ExtraBinaries, []string{}).([]string) {
|
|
|
|
install[fmt.Sprintf("bin.install %q", bin)] = true
|
2021-10-09 02:25:53 +02:00
|
|
|
}
|
|
|
|
}
|
2021-10-17 04:52:01 +02:00
|
|
|
|
|
|
|
result := keys(install)
|
2021-10-18 14:31:20 +02:00
|
|
|
sort.Strings(result)
|
2021-10-17 04:52:01 +02:00
|
|
|
log.Warnf("guessing install to be %q", strings.Join(result, ", "))
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-07-06 15:48:17 +02:00
|
|
|
func dataFor(ctx *context.Context, cfg config.Homebrew, cl client.Client, artifacts []*artifact.Artifact) (templateData, error) {
|
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
|
|
|
|
2021-10-18 14:31:20 +02:00
|
|
|
url, err := tmpl.New(ctx).WithArtifact(art, map[string]string{}).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
|
|
|
|
|
|
|
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,
|
2021-10-18 14:31:20 +02:00
|
|
|
Install: installs(cfg, art),
|
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, "_", " ")
|
2021-05-11 06:50:17 +02:00
|
|
|
name = strings.ReplaceAll(name, ".", "_")
|
2020-09-21 15:13:03 +02:00
|
|
|
name = strings.ReplaceAll(name, "@", "AT")
|
|
|
|
return strings.ReplaceAll(strings.Title(name), " ", "")
|
2016-12-29 17:14:52 +02:00
|
|
|
}
|