mirror of
https://github.com/goreleaser/goreleaser.git
synced 2024-12-31 01:53:50 +02:00
feat: scoop formula path
closes #2310 Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
This commit is contained in:
parent
a0dd45592e
commit
c5bcff2b00
@ -7,6 +7,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
@ -97,7 +98,7 @@ func doRun(ctx *context.Context, cl client.Client) error {
|
||||
return ErrNoWindows
|
||||
}
|
||||
|
||||
path := scoop.Name + ".json"
|
||||
filename := scoop.Name + ".json"
|
||||
|
||||
data, err := dataFor(ctx, cl, archives)
|
||||
if err != nil {
|
||||
@ -108,9 +109,9 @@ func doRun(ctx *context.Context, cl client.Client) error {
|
||||
return err
|
||||
}
|
||||
|
||||
filename := filepath.Join(ctx.Config.Dist, path)
|
||||
log.WithField("manifest", filename).Info("writing")
|
||||
if err := os.WriteFile(filename, content.Bytes(), 0o644); err != nil {
|
||||
distPath := filepath.Join(ctx.Config.Dist, filename)
|
||||
log.WithField("manifest", distPath).Info("writing")
|
||||
if err := os.WriteFile(distPath, content.Bytes(), 0o644); err != nil {
|
||||
return fmt.Errorf("failed to write scoop manifest: %w", err)
|
||||
}
|
||||
|
||||
@ -142,7 +143,7 @@ func doRun(ctx *context.Context, cl client.Client) error {
|
||||
scoop.CommitAuthor,
|
||||
repo,
|
||||
content.Bytes(),
|
||||
path,
|
||||
path.Join(scoop.Folder, filename),
|
||||
commitMessage,
|
||||
)
|
||||
}
|
||||
|
@ -61,6 +61,12 @@ func Test_doRun(t *testing.T) {
|
||||
file := filepath.Join(folder, "archive")
|
||||
require.NoError(t, os.WriteFile(file, []byte("lorem ipsum"), 0o644))
|
||||
|
||||
type args struct {
|
||||
ctx *context.Context
|
||||
client *DummyClient
|
||||
}
|
||||
|
||||
type asserter func(*testing.T, args)
|
||||
type errChecker func(*testing.T, error)
|
||||
shouldErr := func(msg string) errChecker {
|
||||
return func(t *testing.T, err error) {
|
||||
@ -69,19 +75,20 @@ func Test_doRun(t *testing.T) {
|
||||
require.EqualError(t, err, msg)
|
||||
}
|
||||
}
|
||||
noAssertions := func(t *testing.T, _ args) {
|
||||
t.Helper()
|
||||
}
|
||||
shouldNotErr := func(t *testing.T, err error) {
|
||||
t.Helper()
|
||||
require.NoError(t, err)
|
||||
}
|
||||
type args struct {
|
||||
ctx *context.Context
|
||||
client client.Client
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
artifacts []*artifact.Artifact
|
||||
assertError errChecker
|
||||
assert asserter
|
||||
}{
|
||||
{
|
||||
"valid public github",
|
||||
@ -113,6 +120,7 @@ func Test_doRun(t *testing.T) {
|
||||
Owner: "test",
|
||||
Name: "test",
|
||||
},
|
||||
Folder: "scoops",
|
||||
Description: "A run pipe test formula",
|
||||
Homepage: "https://github.com/goreleaser",
|
||||
},
|
||||
@ -125,6 +133,10 @@ func Test_doRun(t *testing.T) {
|
||||
{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
|
||||
},
|
||||
shouldNotErr,
|
||||
func(t *testing.T, a args) {
|
||||
t.Helper()
|
||||
require.Equal(t, "scoops/run-pipe.json", a.client.Path)
|
||||
},
|
||||
},
|
||||
{
|
||||
"wrap in directory",
|
||||
@ -184,6 +196,7 @@ func Test_doRun(t *testing.T) {
|
||||
},
|
||||
},
|
||||
shouldNotErr,
|
||||
noAssertions,
|
||||
},
|
||||
{
|
||||
"valid enterprise github",
|
||||
@ -228,6 +241,10 @@ func Test_doRun(t *testing.T) {
|
||||
{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
|
||||
},
|
||||
shouldNotErr,
|
||||
func(t *testing.T, a args) {
|
||||
t.Helper()
|
||||
require.Equal(t, "run-pipe.json", a.client.Path)
|
||||
},
|
||||
},
|
||||
{
|
||||
"valid public gitlab",
|
||||
@ -281,6 +298,7 @@ func Test_doRun(t *testing.T) {
|
||||
},
|
||||
},
|
||||
shouldNotErr,
|
||||
noAssertions,
|
||||
},
|
||||
{
|
||||
"valid enterprise gitlab",
|
||||
@ -335,6 +353,7 @@ func Test_doRun(t *testing.T) {
|
||||
},
|
||||
},
|
||||
shouldNotErr,
|
||||
noAssertions,
|
||||
},
|
||||
{
|
||||
"token type not implemented for pipe",
|
||||
@ -377,6 +396,7 @@ func Test_doRun(t *testing.T) {
|
||||
{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
|
||||
},
|
||||
shouldErr(ErrTokenTypeNotImplementedForScoop.Error()),
|
||||
noAssertions,
|
||||
},
|
||||
{
|
||||
"no windows build",
|
||||
@ -420,6 +440,7 @@ func Test_doRun(t *testing.T) {
|
||||
{Name: "foo_1.0.1_linux_386.tar.gz", Goos: "linux", Goarch: "386"},
|
||||
},
|
||||
shouldErr("scoop requires a windows build"),
|
||||
noAssertions,
|
||||
},
|
||||
{
|
||||
"no scoop",
|
||||
@ -455,6 +476,7 @@ func Test_doRun(t *testing.T) {
|
||||
{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386"},
|
||||
},
|
||||
shouldErr(pipe.ErrSkipDisabledPipe.Error()),
|
||||
noAssertions,
|
||||
},
|
||||
{
|
||||
"no publish",
|
||||
@ -499,6 +521,7 @@ func Test_doRun(t *testing.T) {
|
||||
{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
|
||||
},
|
||||
shouldErr(pipe.ErrSkipPublishEnabled.Error()),
|
||||
noAssertions,
|
||||
},
|
||||
{
|
||||
"is draft",
|
||||
@ -539,6 +562,7 @@ func Test_doRun(t *testing.T) {
|
||||
{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
|
||||
},
|
||||
shouldErr("release is marked as draft"),
|
||||
noAssertions,
|
||||
},
|
||||
{
|
||||
"is prerelease and skip upload set to auto",
|
||||
@ -589,6 +613,7 @@ func Test_doRun(t *testing.T) {
|
||||
{Name: "foo_1.0.1-pre.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
|
||||
},
|
||||
shouldErr("release is prerelease"),
|
||||
noAssertions,
|
||||
},
|
||||
{
|
||||
"skip upload set to true",
|
||||
@ -633,6 +658,7 @@ func Test_doRun(t *testing.T) {
|
||||
{Name: "foo_1.0.1-pre.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
|
||||
},
|
||||
shouldErr("scoop.skip_upload is true"),
|
||||
noAssertions,
|
||||
},
|
||||
{
|
||||
"release is disabled",
|
||||
@ -673,6 +699,7 @@ func Test_doRun(t *testing.T) {
|
||||
{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
|
||||
},
|
||||
shouldErr("release is disabled"),
|
||||
noAssertions,
|
||||
},
|
||||
{
|
||||
"no archive",
|
||||
@ -713,6 +740,7 @@ func Test_doRun(t *testing.T) {
|
||||
{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
|
||||
},
|
||||
shouldErr("archive format is binary"),
|
||||
noAssertions,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
@ -724,6 +752,7 @@ func Test_doRun(t *testing.T) {
|
||||
require.NoError(t, Pipe{}.Default(ctx))
|
||||
|
||||
tt.assertError(t, doRun(ctx, tt.args.client))
|
||||
tt.assert(t, tt.args)
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -1096,6 +1125,7 @@ func TestWrapInDirectory(t *testing.T) {
|
||||
type DummyClient struct {
|
||||
CreatedFile bool
|
||||
Content string
|
||||
Path string
|
||||
NotImplemented bool
|
||||
}
|
||||
|
||||
@ -1117,6 +1147,7 @@ func (dc *DummyClient) ReleaseURLTemplate(ctx *context.Context) (string, error)
|
||||
func (dc *DummyClient) CreateFile(ctx *context.Context, commitAuthor config.CommitAuthor, repo client.Repo, content []byte, path, msg string) (err error) {
|
||||
dc.CreatedFile = true
|
||||
dc.Content = string(content)
|
||||
dc.Path = path
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -116,6 +116,7 @@ type Homebrew struct {
|
||||
type Scoop struct {
|
||||
Name string `yaml:",omitempty"`
|
||||
Bucket RepoRef `yaml:",omitempty"`
|
||||
Folder string `yaml:",omitempty"`
|
||||
CommitAuthor CommitAuthor `yaml:"commit_author,omitempty"`
|
||||
CommitMessageTemplate string `yaml:"commit_msg_template,omitempty"`
|
||||
Homepage string `yaml:",omitempty"`
|
||||
|
@ -24,6 +24,10 @@ scoop:
|
||||
# Optionally a token can be provided, if it differs from the token provided to GoReleaser
|
||||
token: "{{ .Env.SCOOP_BUCKET_GITHUB_TOKEN }}"
|
||||
|
||||
# Folder inside the repository to put the scoop.
|
||||
# Default is the root folder.
|
||||
folder: Scoops
|
||||
|
||||
# Git author used to commit to the repository.
|
||||
# Defaults are shown.
|
||||
commit_author:
|
||||
|
Loading…
Reference in New Issue
Block a user