You've already forked go-semantic-release
fix(github): use env GITHUB_TOKEN for releaser
This commit is contained in:
2
.github/workflows/main.yml
vendored
2
.github/workflows/main.yml
vendored
@@ -63,4 +63,6 @@ jobs:
|
|||||||
GOOS=windows GOARCH=386 go build -o build/go-semantic-release.exe -ldflags "-w -s -X main.version=`./build/go-semantic-release-temp next`" ./cmd/go-semantic-release/
|
GOOS=windows GOARCH=386 go build -o build/go-semantic-release.exe -ldflags "-w -s -X main.version=`./build/go-semantic-release-temp next`" ./cmd/go-semantic-release/
|
||||||
|
|
||||||
- name: Release
|
- name: Release
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
run: ./build/go-semantic-release-temp release --loglevel trace
|
run: ./build/go-semantic-release-temp release --loglevel trace
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ type Client struct {
|
|||||||
func New(c *config.GitHubProvider) (*Client, error) {
|
func New(c *config.GitHubProvider) (*Client, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if c.AccessToken, err = util.GetAccessToken(GITHUB); err != nil {
|
if c.AccessToken, err = util.GetAccessToken("GITHUB_TOKEN"); err != nil {
|
||||||
return &Client{}, err
|
return &Client{}, err
|
||||||
}
|
}
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|||||||
@@ -145,19 +145,19 @@ func initHTTPServer(respCode int, body string) *httptest.Server {
|
|||||||
func TestNew(t *testing.T) {
|
func TestNew(t *testing.T) {
|
||||||
for _, testOject := range testNewClient {
|
for _, testOject := range testNewClient {
|
||||||
if testOject.valid {
|
if testOject.valid {
|
||||||
os.Setenv("GITHUB_ACCESS_TOKEN", "XXX")
|
os.Setenv("GITHUB_TOKEN", "XXX")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := github.New(&testOject.config)
|
_, err := github.New(&testOject.config)
|
||||||
assert.Equal(t, testOject.valid, err == nil)
|
assert.Equal(t, testOject.valid, err == nil)
|
||||||
|
|
||||||
os.Unsetenv("GITHUB_ACCESS_TOKEN")
|
os.Unsetenv("GITHUB_TOKEN")
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetCommitURL(t *testing.T) {
|
func TestGetCommitURL(t *testing.T) {
|
||||||
os.Setenv("GITHUB_ACCESS_TOKEN", "XX")
|
os.Setenv("GITHUB_TOKEN", "XX")
|
||||||
for _, testOject := range testNewClient {
|
for _, testOject := range testNewClient {
|
||||||
client, _ := github.New(&testOject.config)
|
client, _ := github.New(&testOject.config)
|
||||||
actualURL := client.GetCommitURL()
|
actualURL := client.GetCommitURL()
|
||||||
@@ -170,12 +170,12 @@ func TestGetCommitURL(t *testing.T) {
|
|||||||
assert.EqualValues(t, expectedURL, actualURL)
|
assert.EqualValues(t, expectedURL, actualURL)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
os.Unsetenv("GITHUB_ACCESS_TOKEN")
|
os.Unsetenv("GITHUB_TOKEN")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetCompareURL(t *testing.T) {
|
func TestGetCompareURL(t *testing.T) {
|
||||||
os.Setenv("GITHUB_ACCESS_TOKEN", "XX")
|
os.Setenv("GITHUB_TOKEN", "XX")
|
||||||
for _, testOject := range testNewClient {
|
for _, testOject := range testNewClient {
|
||||||
client, _ := github.New(&testOject.config)
|
client, _ := github.New(&testOject.config)
|
||||||
actualURL := client.GetCompareURL("1", "2")
|
actualURL := client.GetCompareURL("1", "2")
|
||||||
@@ -188,12 +188,12 @@ func TestGetCompareURL(t *testing.T) {
|
|||||||
assert.EqualValues(t, expectedURL, actualURL)
|
assert.EqualValues(t, expectedURL, actualURL)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
os.Unsetenv("GITHUB_ACCESS_TOKEN")
|
os.Unsetenv("GITHUB_TOKEN")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValidateConfig(t *testing.T) {
|
func TestValidateConfig(t *testing.T) {
|
||||||
os.Setenv("GITHUB_ACCESS_TOKEN", "XX")
|
os.Setenv("GITHUB_TOKEN", "XX")
|
||||||
for _, testOject := range testHelperMethod {
|
for _, testOject := range testHelperMethod {
|
||||||
client, _ := github.New(&testOject.config)
|
client, _ := github.New(&testOject.config)
|
||||||
err := client.ValidateConfig()
|
err := client.ValidateConfig()
|
||||||
@@ -201,11 +201,11 @@ func TestValidateConfig(t *testing.T) {
|
|||||||
assert.Equal(t, testOject.valid, err == nil)
|
assert.Equal(t, testOject.valid, err == nil)
|
||||||
|
|
||||||
}
|
}
|
||||||
os.Unsetenv("GITHUB_ACCESS_TOKEN")
|
os.Unsetenv("GITHUB_TOKEN")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateRelease(t *testing.T) {
|
func TestCreateRelease(t *testing.T) {
|
||||||
os.Setenv("GITHUB_ACCESS_TOKEN", "XX")
|
os.Setenv("GITHUB_TOKEN", "XX")
|
||||||
|
|
||||||
for _, testObejct := range testReleases {
|
for _, testObejct := range testReleases {
|
||||||
if testObejct.valid {
|
if testObejct.valid {
|
||||||
@@ -232,6 +232,6 @@ func TestCreateRelease(t *testing.T) {
|
|||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
os.Unsetenv("GITHUB_ACCESS_TOKEN")
|
os.Unsetenv("GITHUB_TOKEN")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package releaser
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/Nightapes/go-semantic-release/internal/releaser/github"
|
"github.com/Nightapes/go-semantic-release/internal/releaser/github"
|
||||||
"github.com/Nightapes/go-semantic-release/internal/releaser/gitlab"
|
"github.com/Nightapes/go-semantic-release/internal/releaser/gitlab"
|
||||||
@@ -41,7 +42,7 @@ func (r *Releasers) GetReleaser() (Releaser, error) {
|
|||||||
return github.New(&r.config.GitHubProvider)
|
return github.New(&r.config.GitHubProvider)
|
||||||
case gitlab.GITLAB:
|
case gitlab.GITLAB:
|
||||||
log.Debugf("initialize new %s-provider", gitlab.GITLAB)
|
log.Debugf("initialize new %s-provider", gitlab.GITLAB)
|
||||||
accessToken, err := util.GetAccessToken(gitlab.GITLAB)
|
accessToken, err := util.GetAccessToken(fmt.Sprintf("%s_ACCESS_TOKEN", strings.ToUpper(gitlab.GITLAB)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,11 +49,9 @@ func NewAddHeaderTransport(T http.RoundTripper, key, value string) *AddHeaderTra
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetAccessToken lookup for the providers accesstoken
|
// GetAccessToken lookup for the providers accesstoken
|
||||||
func GetAccessToken(providerName string) (string, error) {
|
func GetAccessToken(envName string) (string, error) {
|
||||||
var token string
|
var token string
|
||||||
var exists bool
|
var exists bool
|
||||||
envName := fmt.Sprintf("%s_ACCESS_TOKEN", strings.ToUpper(providerName))
|
|
||||||
|
|
||||||
log.Debugf("check if %s environment variable is set", envName)
|
log.Debugf("check if %s environment variable is set", envName)
|
||||||
|
|
||||||
if token, exists = os.LookupEnv(envName); !exists {
|
if token, exists = os.LookupEnv(envName); !exists {
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ func TestGetAccessToken(t *testing.T) {
|
|||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := util.GetAccessToken(testObject.providerName)
|
_, err := util.GetAccessToken(envName)
|
||||||
|
|
||||||
assert.Equal(t, testObject.valid, err == nil)
|
assert.Equal(t, testObject.valid, err == nil)
|
||||||
os.Unsetenv(envName)
|
os.Unsetenv(envName)
|
||||||
|
|||||||
Reference in New Issue
Block a user