github.com/triarius/goreleaser@v1.12.5/internal/middleware/skip/skip.go (about)

     1  // Package skip can skip an entire Action.
     2  package skip
     3  
     4  import (
     5  	"fmt"
     6  
     7  	"github.com/caarlos0/log"
     8  	"github.com/triarius/goreleaser/internal/middleware"
     9  	"github.com/triarius/goreleaser/pkg/context"
    10  )
    11  
    12  // Skipper defines a method to skip an entire Piper.
    13  type Skipper interface {
    14  	// Skip returns true if the Piper should be skipped.
    15  	Skip(ctx *context.Context) bool
    16  	fmt.Stringer
    17  }
    18  
    19  // Maybe returns an action that skips immediately if the given p is a Skipper
    20  // and its Skip method returns true.
    21  func Maybe(skipper interface{}, next middleware.Action) middleware.Action {
    22  	if skipper, ok := skipper.(Skipper); ok {
    23  		return func(ctx *context.Context) error {
    24  			if skipper.Skip(ctx) {
    25  				log.Debugf("skipped %s", skipper.String())
    26  				return nil
    27  			}
    28  			return next(ctx)
    29  		}
    30  	}
    31  	return next
    32  }