gitee.com/mirrors_opencollective/goreleaser@v0.45.0/pipeline/env/env.go (about)

     1  // Package env implements the Pipe interface providing validation of
     2  // missing environment variables needed by the release process.
     3  package env
     4  
     5  import (
     6  	"errors"
     7  	"os"
     8  
     9  	"github.com/goreleaser/goreleaser/context"
    10  	"github.com/goreleaser/goreleaser/pipeline"
    11  )
    12  
    13  // ErrMissingToken indicates an error when GITHUB_TOKEN is missing in the environment
    14  var ErrMissingToken = errors.New("missing GITHUB_TOKEN")
    15  
    16  // Pipe for env
    17  type Pipe struct{}
    18  
    19  func (Pipe) String() string {
    20  	return "loading environment variables"
    21  }
    22  
    23  // Run the pipe
    24  func (Pipe) Run(ctx *context.Context) (err error) {
    25  	ctx.Token = os.Getenv("GITHUB_TOKEN")
    26  	if !ctx.Publish {
    27  		return pipeline.Skip("publishing is disabled")
    28  	}
    29  	if !ctx.Validate {
    30  		return pipeline.Skip("--skip-validate is set")
    31  	}
    32  	if ctx.Token == "" {
    33  		return ErrMissingToken
    34  	}
    35  	return
    36  }