From 52bf9a7121f8330c79736f5bf0c6f9f50f8c2078 Mon Sep 17 00:00:00 2001 From: Matthieu Vachon Date: Fri, 19 May 2023 11:39:54 -0400 Subject: [PATCH] Fixed an issue when the github token has some leading or trailing spaces, like a new line. --- CHANGELOG.md | 12 ++++++++++++ cmd/sfreleaser/github.go | 6 +++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5896714..26ffd18 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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). diff --git a/cmd/sfreleaser/github.go b/cmd/sfreleaser/github.go index 6db2cfe..7b807d4 100644 --- a/cmd/sfreleaser/github.go +++ b/cmd/sfreleaser/github.go @@ -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 := `""` - 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))