1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-02-11 13:38:41 +02:00

feat: skip formula upload

This commit is contained in:
Carlos Alexandro Becker 2018-01-10 19:22:37 -02:00 committed by Carlos Alexandro Becker
parent 43c65c19c1
commit 4d71720b67
9 changed files with 65 additions and 34 deletions

View File

@ -50,6 +50,7 @@ type Homebrew struct {
Conflicts []string `yaml:",omitempty"` Conflicts []string `yaml:",omitempty"`
Description string `yaml:",omitempty"` Description string `yaml:",omitempty"`
Homepage string `yaml:",omitempty"` Homepage string `yaml:",omitempty"`
SkipUpload bool `yaml:"skip_upload,omitempty"`
// Capture all undefined fields and should be empty after loading // Capture all undefined fields and should be empty after loading
XXX map[string]interface{} `yaml:",inline"` XXX map[string]interface{} `yaml:",inline"`

View File

@ -42,6 +42,11 @@ brew:
# Default is empty. # Default is empty.
description: "Software to create fast and easy drum rolls." description: "Software to create fast and easy drum rolls."
# Setting this will prevent goreleaser to actually try to commit the updated
# formula - instead, the formula file will be stored on the dist folder only,
# leaving the responsibility of publishing it to the user.
skip_upload: true
# Packages your package depends on. # Packages your package depends on.
dependencies: dependencies:
- git - git

View File

@ -10,5 +10,5 @@ import (
// AssertSkipped asserts that a pipe was skipped // AssertSkipped asserts that a pipe was skipped
func AssertSkipped(t *testing.T, err error) { func AssertSkipped(t *testing.T, err error) {
_, ok := err.(pipeline.ErrSkip) _, ok := err.(pipeline.ErrSkip)
assert.True(t, ok) assert.True(t, ok, "expected a pipeline.ErrSkip but got %v", err)
} }

View File

@ -109,7 +109,7 @@ func (Pipe) Run(ctx *context.Context) error {
func doRun(ctx *context.Context) error { func doRun(ctx *context.Context) error {
if !ctx.Publish { if !ctx.Publish {
return pipeline.Skip("--skip-publish is set") return pipeline.ErrSkipPublish
} }
// Handle every configured artifactory instance // Handle every configured artifactory instance

View File

@ -616,7 +616,7 @@ func TestRunPipe_SkipWhenPublishFalse(t *testing.T) {
err := Pipe{}.Run(ctx) err := Pipe{}.Run(ctx)
assert.True(t, pipeline.IsSkip(err)) assert.True(t, pipeline.IsSkip(err))
assert.Equal(t, err.Error(), "--skip-publish is set") assert.EqualError(t, err, pipeline.ErrSkipPublish.Error())
} }
func TestRunPipe_DirUpload(t *testing.T) { func TestRunPipe_DirUpload(t *testing.T) {

View File

@ -85,15 +85,9 @@ func contains(ss []string, s string) bool {
} }
func doRun(ctx *context.Context, client client.Client) error { func doRun(ctx *context.Context, client client.Client) error {
if !ctx.Publish {
return pipeline.Skip("--skip-publish is set")
}
if ctx.Config.Brew.GitHub.Name == "" { if ctx.Config.Brew.GitHub.Name == "" {
return pipeline.Skip("brew section is not configured") return pipeline.Skip("brew section is not configured")
} }
if ctx.Config.Release.Draft {
return pipeline.Skip("release is marked as draft")
}
if ctx.Config.Archive.Format == "binary" { if ctx.Config.Archive.Format == "binary" {
return pipeline.Skip("archive format is binary") return pipeline.Skip("archive format is binary")
} }
@ -125,6 +119,16 @@ func doRun(ctx *context.Context, client client.Client) error {
return err return err
} }
if ctx.Config.Brew.SkipUpload {
return pipeline.Skip("brew.skip_upload is set")
}
if !ctx.Publish {
return pipeline.ErrSkipPublish
}
if ctx.Config.Release.Draft {
return pipeline.Skip("release is marked as draft")
}
path = filepath.Join(ctx.Config.Brew.Folder, filename) path = filepath.Join(ctx.Config.Brew.Folder, filename)
log.WithField("formula", path). log.WithField("formula", path).
WithField("repo", ctx.Config.Brew.GitHub.String()). WithField("repo", ctx.Config.Brew.GitHub.String()).

View File

@ -272,33 +272,50 @@ func TestRunPipeBinaryRelease(t *testing.T) {
assert.False(t, client.CreatedFile) assert.False(t, client.CreatedFile)
} }
func TestRunPipeNoPublish(t *testing.T) { func TestRunPipeNoUpload(t *testing.T) {
var ctx = &context.Context{ folder, err := ioutil.TempDir("", "goreleasertest")
Publish: false, assert.NoError(t, err)
} var ctx = context.New(config.Project{
client := &DummyClient{} Dist: folder,
testlib.AssertSkipped(t, doRun(ctx, client)) ProjectName: "foo",
assert.False(t, client.CreatedFile) Release: config.Release{},
} Brew: config.Homebrew{
GitHub: config.Repo{
func TestRunPipeDraftRelease(t *testing.T) { Owner: "test",
var ctx = &context.Context{ Name: "test",
Publish: true,
Config: config.Project{
Release: config.Release{
Draft: true,
},
Brew: config.Homebrew{
GitHub: config.Repo{
Owner: "test",
Name: "test",
},
}, },
}, },
} })
var path = filepath.Join(folder, "whatever.tar.gz")
_, err = os.Create(path)
assert.NoError(t, err)
ctx.Artifacts.Add(artifact.Artifact{
Name: "bin",
Path: path,
Goos: "darwin",
Goarch: "amd64",
Type: artifact.UploadableArchive,
})
client := &DummyClient{} client := &DummyClient{}
testlib.AssertSkipped(t, doRun(ctx, client))
assert.False(t, client.CreatedFile) var assertNoPublish = func(t *testing.T) {
testlib.AssertSkipped(t, doRun(ctx, client))
assert.False(t, client.CreatedFile)
}
t.Run("skip upload", func(tt *testing.T) {
ctx.Publish = true
ctx.Config.Brew.SkipUpload = true
assertNoPublish(tt)
})
t.Run("skip publish", func(tt *testing.T) {
ctx.Publish = false
assertNoPublish(tt)
})
t.Run("draft release", func(tt *testing.T) {
ctx.Publish = true
ctx.Config.Release.Draft = true
assertNoPublish(tt)
})
} }
func TestRunPipeFormatBinary(t *testing.T) { func TestRunPipeFormatBinary(t *testing.T) {

View File

@ -14,6 +14,10 @@ type Piper interface {
Run(ctx *context.Context) error Run(ctx *context.Context) error
} }
// ErrSkipPublish happens when skip publish is set and a pipe is refusing
// to proceed because of that.
var ErrSkipPublish = Skip("--skip-publish is set")
// IsSkip returns true if the error is an ErrSkip // IsSkip returns true if the error is an ErrSkip
func IsSkip(err error) bool { func IsSkip(err error) bool {
_, ok := err.(ErrSkip) _, ok := err.(ErrSkip)

View File

@ -46,7 +46,7 @@ func (Pipe) Run(ctx *context.Context) error {
func doRun(ctx *context.Context, c client.Client) error { func doRun(ctx *context.Context, c client.Client) error {
if !ctx.Publish { if !ctx.Publish {
return pipeline.Skip("--skip-publish is set") return pipeline.ErrSkipPublish
} }
log.WithField("tag", ctx.Git.CurrentTag). log.WithField("tag", ctx.Git.CurrentTag).
WithField("repo", ctx.Config.Release.GitHub.String()). WithField("repo", ctx.Config.Release.GitHub.String()).