You've already forked goreleaser
mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-07-17 01:42:37 +02:00
skipped as an error type
This commit is contained in:
@ -84,7 +84,13 @@ func Release(flags Flags) error {
|
|||||||
ctx.RmDist = flags.Bool("rm-dist")
|
ctx.RmDist = flags.Bool("rm-dist")
|
||||||
for _, pipe := range pipes {
|
for _, pipe := range pipes {
|
||||||
log.Infof("\033[1m%s\033[0m", strings.ToUpper(pipe.Description()))
|
log.Infof("\033[1m%s\033[0m", strings.ToUpper(pipe.Description()))
|
||||||
if err := pipe.Run(ctx); err != nil {
|
var err = pipe.Run(ctx)
|
||||||
|
if err == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if skip, ok := err.(pipeline.SkipErr); ok {
|
||||||
|
log.WithField("reason", skip.Error()).Warn("skipped")
|
||||||
|
} else {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/goreleaser/goreleaser/context"
|
"github.com/goreleaser/goreleaser/context"
|
||||||
"github.com/goreleaser/goreleaser/internal/archiveformat"
|
"github.com/goreleaser/goreleaser/internal/archiveformat"
|
||||||
"github.com/goreleaser/goreleaser/internal/client"
|
"github.com/goreleaser/goreleaser/internal/client"
|
||||||
|
"github.com/goreleaser/goreleaser/pipeline"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ErrNoDarwin64Build when there is no build for darwin_amd64 (goos doesn't
|
// ErrNoDarwin64Build when there is no build for darwin_amd64 (goos doesn't
|
||||||
@ -37,20 +38,16 @@ func (Pipe) Run(ctx *context.Context) error {
|
|||||||
|
|
||||||
func doRun(ctx *context.Context, client client.Client) error {
|
func doRun(ctx *context.Context, client client.Client) error {
|
||||||
if !ctx.Publish {
|
if !ctx.Publish {
|
||||||
log.Warn("skipped because --skip-publish is set")
|
return pipeline.Skip("--skip-publish is set")
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
if ctx.Config.Brew.GitHub.Name == "" {
|
if ctx.Config.Brew.GitHub.Name == "" {
|
||||||
log.Warn("skipped because brew section is not configured")
|
return pipeline.Skip("brew section is not configured")
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
if ctx.Config.Release.Draft {
|
if ctx.Config.Release.Draft {
|
||||||
log.Warn("skipped because release is marked as draft")
|
return pipeline.Skip("release is marked as draft")
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
if ctx.Config.Archive.Format == "binary" {
|
if ctx.Config.Archive.Format == "binary" {
|
||||||
log.Warn("skipped because archive format is binary")
|
return pipeline.Skip("archive format is binary")
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var group = ctx.Binaries["darwinamd64"]
|
var group = ctx.Binaries["darwinamd64"]
|
||||||
|
@ -27,7 +27,7 @@ func (Pipe) Run(ctx *context.Context) (err error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if ctx.RmDist {
|
if ctx.RmDist {
|
||||||
log.Warn("rm-dist is set, removing ./dist")
|
log.Info("rm-dist is set, removing ./dist")
|
||||||
return os.RemoveAll(ctx.Config.Dist)
|
return os.RemoveAll(ctx.Config.Dist)
|
||||||
}
|
}
|
||||||
files, err := ioutil.ReadDir(ctx.Config.Dist)
|
files, err := ioutil.ReadDir(ctx.Config.Dist)
|
||||||
|
8
pipeline/env/env.go
vendored
8
pipeline/env/env.go
vendored
@ -6,8 +6,8 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/apex/log"
|
|
||||||
"github.com/goreleaser/goreleaser/context"
|
"github.com/goreleaser/goreleaser/context"
|
||||||
|
"github.com/goreleaser/goreleaser/pipeline"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ErrMissingToken indicates an error when GITHUB_TOKEN is missing in the environment
|
// ErrMissingToken indicates an error when GITHUB_TOKEN is missing in the environment
|
||||||
@ -25,12 +25,10 @@ func (Pipe) Description() string {
|
|||||||
func (Pipe) Run(ctx *context.Context) (err error) {
|
func (Pipe) Run(ctx *context.Context) (err error) {
|
||||||
ctx.Token = os.Getenv("GITHUB_TOKEN")
|
ctx.Token = os.Getenv("GITHUB_TOKEN")
|
||||||
if !ctx.Publish {
|
if !ctx.Publish {
|
||||||
log.Warn("github token not validated because publishing has been disabled")
|
return pipeline.Skip("publishing is disabled")
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
if !ctx.Validate {
|
if !ctx.Validate {
|
||||||
log.Warn("skipped validations because --skip-validate is set")
|
return pipeline.Skip("--skip-validate is set")
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
if ctx.Token == "" {
|
if ctx.Token == "" {
|
||||||
return ErrMissingToken
|
return ErrMissingToken
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
"github.com/apex/log"
|
"github.com/apex/log"
|
||||||
"github.com/goreleaser/goreleaser/context"
|
"github.com/goreleaser/goreleaser/context"
|
||||||
|
"github.com/goreleaser/goreleaser/pipeline"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -27,8 +28,7 @@ func (Pipe) Description() string {
|
|||||||
// Run the pipe
|
// Run the pipe
|
||||||
func (Pipe) Run(ctx *context.Context) error {
|
func (Pipe) Run(ctx *context.Context) error {
|
||||||
if len(ctx.Config.FPM.Formats) == 0 {
|
if len(ctx.Config.FPM.Formats) == 0 {
|
||||||
log.Warn("skipping because no output formats configured")
|
return pipeline.Skip("no output formats configured")
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
_, err := exec.LookPath("fpm")
|
_, err := exec.LookPath("fpm")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/apex/log"
|
"github.com/apex/log"
|
||||||
"github.com/goreleaser/goreleaser/context"
|
"github.com/goreleaser/goreleaser/context"
|
||||||
"github.com/goreleaser/goreleaser/internal/git"
|
"github.com/goreleaser/goreleaser/internal/git"
|
||||||
|
"github.com/goreleaser/goreleaser/pipeline"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Pipe for brew deployment
|
// Pipe for brew deployment
|
||||||
@ -43,8 +44,7 @@ func (Pipe) Run(ctx *context.Context) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !ctx.Validate {
|
if !ctx.Validate {
|
||||||
log.Warn("skipped validations because --skip-validate is set")
|
return pipeline.Skip("--skip-validate is set")
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
return validate(ctx, commit, tag)
|
return validate(ctx, commit, tag)
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
// Package pipeline provides a generic pipe interface.
|
// Package pipeline provides a generic pipe interface.
|
||||||
package pipeline
|
package pipeline
|
||||||
|
|
||||||
import "github.com/goreleaser/goreleaser/context"
|
import (
|
||||||
|
"github.com/goreleaser/goreleaser/context"
|
||||||
|
)
|
||||||
|
|
||||||
// Pipe interface
|
// Pipe interface
|
||||||
type Pipe interface {
|
type Pipe interface {
|
||||||
@ -11,3 +13,18 @@ type Pipe interface {
|
|||||||
// Run the pipe
|
// Run the pipe
|
||||||
Run(ctx *context.Context) error
|
Run(ctx *context.Context) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ErrSkip occurs when a pipe is skipped for some reason
|
||||||
|
type ErrSkip struct {
|
||||||
|
reason string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface. returns the reason the pipe was skipped
|
||||||
|
func (e ErrSkip) Error() string {
|
||||||
|
return e.reason
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip skips this pipe with the given reason
|
||||||
|
func Skip(reason string) ErrSkip {
|
||||||
|
return ErrSkip{reason}
|
||||||
|
}
|
||||||
|
15
pipeline/pipe_test.go
Normal file
15
pipeline/pipe_test.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package pipeline
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSkipPipe(t *testing.T) {
|
||||||
|
var assert = assert.New(t)
|
||||||
|
var reason = "this is a test"
|
||||||
|
var err = Skip(reason)
|
||||||
|
assert.Error(err)
|
||||||
|
assert.Equal(reason, err.Error())
|
||||||
|
}
|
@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/apex/log"
|
"github.com/apex/log"
|
||||||
"github.com/goreleaser/goreleaser/context"
|
"github.com/goreleaser/goreleaser/context"
|
||||||
"github.com/goreleaser/goreleaser/internal/client"
|
"github.com/goreleaser/goreleaser/internal/client"
|
||||||
|
"github.com/goreleaser/goreleaser/pipeline"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -27,8 +28,7 @@ func (Pipe) Run(ctx *context.Context) error {
|
|||||||
|
|
||||||
func doRun(ctx *context.Context, client client.Client) error {
|
func doRun(ctx *context.Context, client client.Client) error {
|
||||||
if !ctx.Publish {
|
if !ctx.Publish {
|
||||||
log.Warn("skipped because --skip-publish is set")
|
return pipeline.Skip("--skip-publish is set")
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
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()).
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
|
|
||||||
"github.com/apex/log"
|
"github.com/apex/log"
|
||||||
"github.com/goreleaser/goreleaser/context"
|
"github.com/goreleaser/goreleaser/context"
|
||||||
|
"github.com/goreleaser/goreleaser/pipeline"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
yaml "gopkg.in/yaml.v2"
|
yaml "gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
@ -55,8 +56,7 @@ func (Pipe) Description() string {
|
|||||||
// Run the pipe
|
// Run the pipe
|
||||||
func (Pipe) Run(ctx *context.Context) error {
|
func (Pipe) Run(ctx *context.Context) error {
|
||||||
if ctx.Config.Snapcraft.Summary == "" && ctx.Config.Snapcraft.Description == "" {
|
if ctx.Config.Snapcraft.Summary == "" && ctx.Config.Snapcraft.Description == "" {
|
||||||
log.Warn("skipping because no summary nor description were provided")
|
return pipeline.Skip("no summary nor description were provided")
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
if ctx.Config.Snapcraft.Summary == "" {
|
if ctx.Config.Snapcraft.Summary == "" {
|
||||||
return ErrNoSummary
|
return ErrNoSummary
|
||||||
@ -100,6 +100,7 @@ func archFor(key string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func create(ctx *context.Context, folder, arch string, binaries []context.Binary) error {
|
func create(ctx *context.Context, folder, arch string, binaries []context.Binary) error {
|
||||||
|
var log = log.WithField("arch", arch)
|
||||||
// prime is the directory that then will be compressed to make the .snap package.
|
// prime is the directory that then will be compressed to make the .snap package.
|
||||||
folderDir := filepath.Join(ctx.Config.Dist, folder)
|
folderDir := filepath.Join(ctx.Config.Dist, folder)
|
||||||
primeDir := filepath.Join(folderDir, "prime")
|
primeDir := filepath.Join(folderDir, "prime")
|
||||||
@ -109,7 +110,7 @@ func create(ctx *context.Context, folder, arch string, binaries []context.Binary
|
|||||||
}
|
}
|
||||||
|
|
||||||
var file = filepath.Join(primeDir, "meta", "snap.yaml")
|
var file = filepath.Join(primeDir, "meta", "snap.yaml")
|
||||||
log.WithField("file", file).Info("creating snap metadata")
|
log.WithField("file", file).Debug("creating snap metadata")
|
||||||
|
|
||||||
var metadata = &SnapcraftMetadata{
|
var metadata = &SnapcraftMetadata{
|
||||||
Version: ctx.Version,
|
Version: ctx.Version,
|
||||||
@ -129,8 +130,10 @@ func create(ctx *context.Context, folder, arch string, binaries []context.Binary
|
|||||||
for _, binary := range binaries {
|
for _, binary := range binaries {
|
||||||
log.WithField("path", binary.Path).
|
log.WithField("path", binary.Path).
|
||||||
WithField("name", binary.Name).
|
WithField("name", binary.Name).
|
||||||
Info("passed binary to snapcraft")
|
Debug("passed binary to snapcraft")
|
||||||
appMetadata := AppMetadata{Command: binary.Name}
|
appMetadata := AppMetadata{
|
||||||
|
Command: binary.Name,
|
||||||
|
}
|
||||||
if configAppMetadata, ok := ctx.Config.Snapcraft.Apps[binary.Name]; ok {
|
if configAppMetadata, ok := ctx.Config.Snapcraft.Apps[binary.Name]; ok {
|
||||||
appMetadata.Plugs = configAppMetadata.Plugs
|
appMetadata.Plugs = configAppMetadata.Plugs
|
||||||
appMetadata.Daemon = configAppMetadata.Daemon
|
appMetadata.Daemon = configAppMetadata.Daemon
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
"github.com/goreleaser/goreleaser/config"
|
"github.com/goreleaser/goreleaser/config"
|
||||||
"github.com/goreleaser/goreleaser/context"
|
"github.com/goreleaser/goreleaser/context"
|
||||||
|
"github.com/goreleaser/goreleaser/pipeline"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
yaml "gopkg.in/yaml.v2"
|
yaml "gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
@ -25,7 +26,7 @@ func TestRunPipeMissingInfo(t *testing.T) {
|
|||||||
ErrNoDescription: {
|
ErrNoDescription: {
|
||||||
Summary: "dummy summary",
|
Summary: "dummy summary",
|
||||||
},
|
},
|
||||||
nil: {}, // should skip instead of error
|
pipeline.Skip("no summary nor description were provided"): {},
|
||||||
} {
|
} {
|
||||||
t.Run(fmt.Sprintf("testing if %v happens", eerr), func(t *testing.T) {
|
t.Run(fmt.Sprintf("testing if %v happens", eerr), func(t *testing.T) {
|
||||||
var assert = assert.New(t)
|
var assert = assert.New(t)
|
||||||
@ -145,7 +146,14 @@ func TestNoSnapcraftInPath(t *testing.T) {
|
|||||||
|
|
||||||
func addBinaries(t *testing.T, ctx *context.Context, name, dist string) {
|
func addBinaries(t *testing.T, ctx *context.Context, name, dist string) {
|
||||||
var assert = assert.New(t)
|
var assert = assert.New(t)
|
||||||
for _, plat := range []string{"linuxamd64", "linux386", "darwinamd64", "linuxarm64", "linuxarmhf"} {
|
for _, plat := range []string{
|
||||||
|
"linuxamd64",
|
||||||
|
"linux386",
|
||||||
|
"darwinamd64",
|
||||||
|
"linuxarm64",
|
||||||
|
"linuxarm6",
|
||||||
|
"linuxwtf",
|
||||||
|
} {
|
||||||
var folder = name + "_" + plat
|
var folder = name + "_" + plat
|
||||||
assert.NoError(os.Mkdir(filepath.Join(dist, folder), 0755))
|
assert.NoError(os.Mkdir(filepath.Join(dist, folder), 0755))
|
||||||
var binPath = filepath.Join(dist, folder, name)
|
var binPath = filepath.Join(dist, folder, name)
|
||||||
|
Reference in New Issue
Block a user