Skip to content

Commit

Permalink
Fixed an issue when the github token has some leading or trailing spa…
Browse files Browse the repository at this point in the history
…ces, like a new line.
  • Loading branch information
maoueh committed May 19, 2023
1 parent fe1db91 commit 52bf9a7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,28 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## v0.5.3

### Fixed

* Fixed an issue when the github token has some leading or trailing spaces, like a new line.

## v0.5.2

### Changed

* Improved `sfreleaser release` to print some troubleshooting idea using `sfreleaser doctor`.

## v0.5.1

### Added

* Added support for `brew-tap-repo` to set the Brew tap repository where to push the binary (config at `release.brew-tap-repo`).

## v0.5.0

### Added

* Removed the need to have `.goreleaser.yaml` file in the repository (file is now generated on the fly).

* Added support for disabling Brew tap release (enabled by default).
Expand Down
6 changes: 3 additions & 3 deletions cmd/sfreleaser/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ var (
ghActionTokenRegex = `v[0-9]\.[0-9a-f]{40}`
)

var githubTokenRegex = regexp.MustCompile(fmt.Sprintf(`^(%s|%s|%s)$`, ghpPersonalLegacyTokenRegex, ghPersonalTokenRegex, ghActionTokenRegex))
var githubTokenRegex = regexp.MustCompile(fmt.Sprintf(`^\s*(%s|%s|%s)\s*$`, ghpPersonalLegacyTokenRegex, ghPersonalTokenRegex, ghActionTokenRegex))

func configureGitHubTokenEnvFile(releaseEnvFile string) {
zlog.Debug("verifying github token")
globalGitHubTokenFile := filepath.Join(cli.UserHomeDirectory(), ".config", "goreleaser", "github_token")

from := `"<Not Found>"`
token := os.Getenv("GITHUB_TOKEN")
token := strings.TrimSpace(os.Getenv("GITHUB_TOKEN"))

if token != "" {
from = "environment variable GITHUB_TOKEN"
} else if token == "" && cli.FileExists(globalGitHubTokenFile) {
from = fmt.Sprintf("global config file %q", globalGitHubTokenFile)
token = cli.ReadFile(globalGitHubTokenFile)
token = strings.TrimSpace(cli.ReadFile(globalGitHubTokenFile))
}

zlog.Debug("completed scan for GitHub token", zap.Bool("found", token != ""), zap.String("from", globalGitHubTokenFile))
Expand Down

0 comments on commit 52bf9a7

Please sign in to comment.