2017-04-14 15:39:32 -03:00
|
|
|
// Package env implements the Pipe interface providing validation of
|
|
|
|
// missing environment variables needed by the release process.
|
2017-01-14 14:06:57 -02:00
|
|
|
package env
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"os"
|
|
|
|
|
2017-01-14 20:01:32 -02:00
|
|
|
"github.com/goreleaser/goreleaser/context"
|
2017-08-20 16:35:46 -03:00
|
|
|
"github.com/goreleaser/goreleaser/pipeline"
|
2017-01-14 14:06:57 -02:00
|
|
|
)
|
|
|
|
|
2017-01-14 19:41:32 +01:00
|
|
|
// ErrMissingToken indicates an error when GITHUB_TOKEN is missing in the environment
|
2017-04-21 11:48:00 -03:00
|
|
|
var ErrMissingToken = errors.New("missing GITHUB_TOKEN")
|
2017-01-14 14:06:57 -02:00
|
|
|
|
|
|
|
// Pipe for env
|
|
|
|
type Pipe struct{}
|
|
|
|
|
2017-12-02 19:53:19 -02:00
|
|
|
func (Pipe) String() string {
|
|
|
|
return "loading environment variables"
|
2017-01-14 14:06:57 -02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run the pipe
|
|
|
|
func (Pipe) Run(ctx *context.Context) (err error) {
|
2017-04-21 11:48:00 -03:00
|
|
|
ctx.Token = os.Getenv("GITHUB_TOKEN")
|
2017-04-29 12:49:22 +02:00
|
|
|
if !ctx.Publish {
|
2017-08-20 16:35:46 -03:00
|
|
|
return pipeline.Skip("publishing is disabled")
|
2017-04-29 12:49:22 +02:00
|
|
|
}
|
2017-04-18 13:10:13 -03:00
|
|
|
if !ctx.Validate {
|
2017-08-20 16:35:46 -03:00
|
|
|
return pipeline.Skip("--skip-validate is set")
|
2017-04-18 13:10:13 -03:00
|
|
|
}
|
2017-01-18 15:08:48 -02:00
|
|
|
if ctx.Token == "" {
|
2017-01-14 14:06:57 -02:00
|
|
|
return ErrMissingToken
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|