Skip to content

Commit

Permalink
fix: default evn tokenfiles (#1389)
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
  • Loading branch information
caarlos0 committed Mar 16, 2020
1 parent f18a5d1 commit bc64da1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
5 changes: 2 additions & 3 deletions internal/pipe/env/env.go
Expand Up @@ -26,8 +26,7 @@ func (Pipe) String() string {
return "loading environment variables"
}

// Default sets the pipe defaults
func (Pipe) Default(ctx *context.Context) error {
func setDefaultTokenFiles(ctx *context.Context) {
var env = &ctx.Config.EnvFiles
if env.GitHubToken == "" {
env.GitHubToken = "~/.config/goreleaser/github_token"
Expand All @@ -38,11 +37,11 @@ func (Pipe) Default(ctx *context.Context) error {
if env.GiteaToken == "" {
env.GiteaToken = "~/.config/goreleaser/gitea_token"
}
return nil
}

// Run the pipe
func (Pipe) Run(ctx *context.Context) error {
setDefaultTokenFiles(ctx)
githubToken, githubTokenErr := loadEnv("GITHUB_TOKEN", ctx.Config.EnvFiles.GitHubToken)
gitlabToken, gitlabTokenErr := loadEnv("GITLAB_TOKEN", ctx.Config.EnvFiles.GitLabToken)
giteaToken, giteaTokenErr := loadEnv("GITEA_TOKEN", ctx.Config.EnvFiles.GiteaToken)
Expand Down
6 changes: 3 additions & 3 deletions internal/pipe/env/env_test.go
Expand Up @@ -16,10 +16,10 @@ func TestDescription(t *testing.T) {
assert.NotEmpty(t, Pipe{}.String())
}

func TestDefault(t *testing.T) {
func TestSetDefaultTokenFiles(t *testing.T) {
t.Run("empty config", func(tt *testing.T) {
ctx := context.New(config.Project{})
assert.NoError(t, Pipe{}.Default(ctx))
setDefaultTokenFiles(ctx)
assert.Equal(t, "~/.config/goreleaser/github_token", ctx.Config.EnvFiles.GitHubToken)
assert.Equal(t, "~/.config/goreleaser/gitlab_token", ctx.Config.EnvFiles.GitLabToken)
assert.Equal(t, "~/.config/goreleaser/gitea_token", ctx.Config.EnvFiles.GiteaToken)
Expand All @@ -31,7 +31,7 @@ func TestDefault(t *testing.T) {
GitHubToken: cfg,
},
})
assert.NoError(t, Pipe{}.Default(ctx))
setDefaultTokenFiles(ctx)
assert.Equal(t, cfg, ctx.Config.EnvFiles.GitHubToken)
})
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/defaults/defaults.go
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/goreleaser/goreleaser/internal/pipe/build"
"github.com/goreleaser/goreleaser/internal/pipe/checksums"
"github.com/goreleaser/goreleaser/internal/pipe/docker"
"github.com/goreleaser/goreleaser/internal/pipe/env"
"github.com/goreleaser/goreleaser/internal/pipe/nfpm"
"github.com/goreleaser/goreleaser/internal/pipe/project"
"github.com/goreleaser/goreleaser/internal/pipe/release"
Expand All @@ -35,7 +34,6 @@ type Defaulter interface {
// Defaulters is the list of defaulters
// nolint: gochecknoglobals
var Defaulters = []Defaulter{
env.Pipe{},
snapshot.Pipe{},
release.Pipe{},
project.Pipe{},
Expand Down

0 comments on commit bc64da1

Please sign in to comment.