Skip to content

Commit

Permalink
feat: add force_token to config (#3936)
Browse files Browse the repository at this point in the history
As a follow-up to #3910, this adds `force_token` to the config.

Signed-off-by: jolheiser <john.olheiser@gmail.com>
  • Loading branch information
jolheiser committed Apr 23, 2023
1 parent 44c6f73 commit 6b86499
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
6 changes: 5 additions & 1 deletion internal/pipe/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down
11 changes: 9 additions & 2 deletions www/docs/errors/multiple-tokens.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
```

10 changes: 10 additions & 0 deletions www/docs/static/schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6b86499

Please sign in to comment.