2017-04-14 20:39:32 +02:00
|
|
|
// Package env implements the Pipe interface providing validation of
|
|
|
|
// missing environment variables needed by the release process.
|
2017-01-14 18:06:57 +02:00
|
|
|
package env
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"os"
|
|
|
|
|
2017-06-22 05:09:14 +02:00
|
|
|
"github.com/apex/log"
|
2017-01-15 00:01:32 +02:00
|
|
|
"github.com/goreleaser/goreleaser/context"
|
2017-01-14 18:06:57 +02:00
|
|
|
)
|
|
|
|
|
2017-01-14 20:41:32 +02:00
|
|
|
// ErrMissingToken indicates an error when GITHUB_TOKEN is missing in the environment
|
2017-04-21 16:48:00 +02:00
|
|
|
var ErrMissingToken = errors.New("missing GITHUB_TOKEN")
|
2017-01-14 18:06:57 +02:00
|
|
|
|
|
|
|
// Pipe for env
|
|
|
|
type Pipe struct{}
|
|
|
|
|
2017-01-14 20:41:32 +02:00
|
|
|
// Description of the pipe
|
2017-01-14 19:14:35 +02:00
|
|
|
func (Pipe) Description() string {
|
2017-01-19 11:04:41 +02:00
|
|
|
return "Loading environment variables"
|
2017-01-14 18:06:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run the pipe
|
|
|
|
func (Pipe) Run(ctx *context.Context) (err error) {
|
2017-04-21 16:48:00 +02:00
|
|
|
ctx.Token = os.Getenv("GITHUB_TOKEN")
|
2017-04-29 12:49:22 +02:00
|
|
|
if !ctx.Publish {
|
2017-06-22 15:47:34 +02:00
|
|
|
log.Warn("github token not validated because publishing has been disabled")
|
2017-04-29 12:49:22 +02:00
|
|
|
return nil
|
|
|
|
}
|
2017-04-18 18:10:13 +02:00
|
|
|
if !ctx.Validate {
|
2017-06-22 15:47:34 +02:00
|
|
|
log.Warn("skipped validations because --skip-validate is set")
|
2017-04-18 18:10:13 +02:00
|
|
|
return nil
|
|
|
|
}
|
2017-01-18 19:08:48 +02:00
|
|
|
if ctx.Token == "" {
|
2017-01-14 18:06:57 +02:00
|
|
|
return ErrMissingToken
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|