From 6b86499655267e85213cebbbdbfad837413744a6 Mon Sep 17 00:00:00 2001 From: John Olheiser Date: Sun, 23 Apr 2023 11:53:45 -0500 Subject: [PATCH] feat: add force_token to config (#3936) As a follow-up to #3910, this adds `force_token` to the config. Signed-off-by: jolheiser --- internal/pipe/env/env.go | 6 +++++- pkg/config/config.go | 3 +++ www/docs/errors/multiple-tokens.md | 11 +++++++++-- www/docs/static/schema.json | 10 ++++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/internal/pipe/env/env.go b/internal/pipe/env/env.go index 2664bd0fd..19dc58208 100644 --- a/internal/pipe/env/env.go +++ b/internal/pipe/env/env.go @@ -69,7 +69,11 @@ func (Pipe) Run(ctx *context.Context) error { gitlabToken, gitlabTokenErr := loadEnv("GITLAB_TOKEN", ctx.Config.EnvFiles.GitLabToken) giteaToken, giteaTokenErr := loadEnv("GITEA_TOKEN", ctx.Config.EnvFiles.GiteaToken) - switch os.Getenv("GORELEASER_FORCE_TOKEN") { + forceToken := ctx.Config.ForceToken + if forceToken == "" { + forceToken = os.Getenv("GORELEASER_FORCE_TOKEN") + } + switch strings.ToLower(forceToken) { case "github": gitlabToken = "" giteaToken = "" diff --git a/pkg/config/config.go b/pkg/config/config.go index 226842dc2..ae177870f 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -981,6 +981,9 @@ type Project struct { // this is a hack ¯\_(ツ)_/¯ SingleBuild Build `yaml:"build,omitempty" json:"build,omitempty" jsonschema_description:"deprecated: use builds instead"` // deprecated + // force the SCM token to use when multiple are set + ForceToken string `yaml:"force_token,omitempty" json:"force_token,omitempty" jsonschema:"enum=github,enum=gitlab,enum=gitea,enum=,default="` + // should be set if using github enterprise GitHubURLs GitHubURLs `yaml:"github_urls,omitempty" json:"github_urls,omitempty"` diff --git a/www/docs/errors/multiple-tokens.md b/www/docs/errors/multiple-tokens.md index b403ee8cc..8df1f92d9 100644 --- a/www/docs/errors/multiple-tokens.md +++ b/www/docs/errors/multiple-tokens.md @@ -32,12 +32,12 @@ env_files: gitea_token: ~/nope ``` +This will prevent using both GitLab and Gitea tokens. + ## Forcing a specific token > Since: v1.17 -This will prevent using both GitLab and Gitea tokens. - If GoReleaser is being run with more than one of the `*_TOKEN` environment variables and you can't unset any of them, you can force GoReleaser to use a specific one by exporting a `GORELEASER_FORCE_TOKEN` environment variable. @@ -46,3 +46,10 @@ So, for instance, if you have both `GITHUB_TOKEN` and `GITEA_TOKEN` set and want GoReleaser to pick `GITEA_TOKEN`, you can set `GORELEASER_FORCE_TOKEN=gitea`. GoReleaser will then unset `GITHUB_TOKEN` and proceed. +You can also force a token by using `force_token` in your config: + +```yaml +# .goreleaser.yaml +force_token: gitea +``` + diff --git a/www/docs/static/schema.json b/www/docs/static/schema.json index 27b1e0145..10dec642c 100644 --- a/www/docs/static/schema.json +++ b/www/docs/static/schema.json @@ -2141,6 +2141,16 @@ "$ref": "#/$defs/Build", "description": "deprecated: use builds instead" }, + "force_token": { + "type": "string", + "enum": [ + "github", + "gitlab", + "gitea", + "" + ], + "default": "" + }, "github_urls": { "$ref": "#/$defs/GitHubURLs" },