mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-19 20:57:53 +02:00
<!-- Hi, thanks for contributing! Please make sure you read our CONTRIBUTING guide. Also, add tests and the respective documentation changes as well. --> <!-- If applied, this commit will... --> ... <!-- Why is this change being made? --> ... <!-- # Provide links to any relevant tickets, URLs or other resources --> ... --------- Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
63 lines
1.5 KiB
Go
63 lines
1.5 KiB
Go
// Package skip can skip an entire Action.
|
|
package skip
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/caarlos0/log"
|
|
"github.com/goreleaser/goreleaser/v2/internal/middleware"
|
|
"github.com/goreleaser/goreleaser/v2/pkg/context"
|
|
)
|
|
|
|
// Skipper defines a method to skip an entire Piper.
|
|
type Skipper interface {
|
|
// Skip returns true if the Piper should be skipped.
|
|
Skip(ctx *context.Context) bool
|
|
fmt.Stringer
|
|
}
|
|
|
|
// Skipper defines a method to skip an entire Piper.
|
|
type ErrSkipper interface {
|
|
// Skip returns true if the Piper should be skipped.
|
|
Skip(ctx *context.Context) (bool, error)
|
|
fmt.Stringer
|
|
}
|
|
|
|
// Maybe returns an action that skips immediately if the given p is a Skipper
|
|
// and its Skip method returns true.
|
|
func Maybe(skipper interface{}, next middleware.Action) middleware.Action {
|
|
if skipper, ok := skipper.(Skipper); ok {
|
|
return Maybe(wrapper{skipper}, next)
|
|
}
|
|
if skipper, ok := skipper.(ErrSkipper); ok {
|
|
return func(ctx *context.Context) error {
|
|
skip, err := skipper.Skip(ctx)
|
|
if err != nil {
|
|
return fmt.Errorf("skip %s: %w", skipper.String(), err)
|
|
}
|
|
if skip {
|
|
log.Debugf("skipped %s", skipper.String())
|
|
return nil
|
|
}
|
|
return next(ctx)
|
|
}
|
|
}
|
|
return next
|
|
}
|
|
|
|
var _ ErrSkipper = wrapper{}
|
|
|
|
type wrapper struct {
|
|
skipper Skipper
|
|
}
|
|
|
|
// String implements SkipperErr
|
|
func (w wrapper) String() string {
|
|
return w.skipper.String()
|
|
}
|
|
|
|
// Skip implements SkipperErr
|
|
func (w wrapper) Skip(ctx *context.Context) (bool, error) {
|
|
return w.skipper.Skip(ctx), nil
|
|
}
|