github.com/tomsquest/goreleaser@v0.34.3-0.20171008022654-7d6ef4d338b3/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  // Description of the pipe
    20  func (Pipe) Description() string {
    21  	return "Loading environment variables"
    22  }
    23  
    24  // Run the pipe
    25  func (Pipe) Run(ctx *context.Context) (err error) {
    26  	ctx.Token = os.Getenv("GITHUB_TOKEN")
    27  	if !ctx.Publish {
    28  		return pipeline.Skip("publishing is disabled")
    29  	}
    30  	if !ctx.Validate {
    31  		return pipeline.Skip("--skip-validate is set")
    32  	}
    33  	if ctx.Token == "" {
    34  		return ErrMissingToken
    35  	}
    36  	return
    37  }