1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/pipeline/env/env.go
Carlos Alexandro Becker 1ed299a6d7 refactor: defaulter interface
Right now the code looks weird because the defaults
of a pipe are far away of the implementation of the pipe.

the intend of this PR is to bring them closer by having a
Defaulter interface.

I also renamed the Pipe interface to Piper, and removed
the Description method in favor for fmt.Stringer.
2017-12-03 13:00:01 -02:00

38 lines
854 B
Go

// Package env implements the Pipe interface providing validation of
// missing environment variables needed by the release process.
package env
import (
"errors"
"os"
"github.com/goreleaser/goreleaser/context"
"github.com/goreleaser/goreleaser/pipeline"
)
// ErrMissingToken indicates an error when GITHUB_TOKEN is missing in the environment
var ErrMissingToken = errors.New("missing GITHUB_TOKEN")
// Pipe for env
type Pipe struct{}
// Description of the pipe
func (Pipe) String() string {
return "loading environment variables"
}
// Run the pipe
func (Pipe) Run(ctx *context.Context) (err error) {
ctx.Token = os.Getenv("GITHUB_TOKEN")
if !ctx.Publish {
return pipeline.Skip("publishing is disabled")
}
if !ctx.Validate {
return pipeline.Skip("--skip-validate is set")
}
if ctx.Token == "" {
return ErrMissingToken
}
return
}