You've already forked go-semantic-release
Compare commits
22 Commits
1.0.0-beta
...
1.0.0-rc.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7729ba5914 | ||
|
|
72200582fd | ||
|
|
2c26c8aa6d | ||
|
|
4b72df07c8 | ||
|
|
df544f5be7 | ||
|
|
812723e1f4 | ||
|
|
e91d9b0dac | ||
|
|
a2fc03c64d | ||
|
|
e419086dbe | ||
|
|
4c7cfd5e90 | ||
|
|
89f4842a2b | ||
|
|
7857b5f6f3 | ||
|
|
115964c9c1 | ||
|
|
2f2f7e51fb | ||
|
|
f1bb5470c0 | ||
|
|
be1e483baa | ||
|
|
17f1890ca1 | ||
|
|
6a53c3e587 | ||
|
|
a068e65369 | ||
|
|
9e847c6af9 | ||
|
|
2eb64f153a | ||
|
|
a6c651a97f |
39
.github/workflows/main.yml
vendored
Normal file
39
.github/workflows/main.yml
vendored
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
name: Go
|
||||||
|
on: [push, pull_request]
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
build:
|
||||||
|
name: Build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- name: Set up Go 1.12
|
||||||
|
uses: actions/setup-go@v1
|
||||||
|
with:
|
||||||
|
go-version: 1.12
|
||||||
|
id: go
|
||||||
|
|
||||||
|
- name: Check out code into the Go module directory
|
||||||
|
uses: actions/checkout@v1
|
||||||
|
|
||||||
|
- name: Lint
|
||||||
|
run: |
|
||||||
|
export PATH=$PATH:$(go env GOPATH)/bin
|
||||||
|
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.16.0
|
||||||
|
golangci-lint run ./...
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: go test ./...
|
||||||
|
|
||||||
|
- name: Build binary
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run: |
|
||||||
|
go build -o build/go-semantic-release-temp ./cmd/go-semantic-release/
|
||||||
|
go build -o build/go-semantic-release -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
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run: ./build/go-semantic-release-temp release --loglevel trace
|
||||||
@@ -1,10 +1,7 @@
|
|||||||
commitFormat: angular
|
commitFormat: angular
|
||||||
title: "go-semantic-release release"
|
title: "go-semantic-release release"
|
||||||
branch:
|
branch:
|
||||||
master: beta
|
master: rc
|
||||||
rc: rc
|
|
||||||
beta: beta
|
|
||||||
alpha: alpha
|
|
||||||
changelog:
|
changelog:
|
||||||
printAll: false
|
printAll: false
|
||||||
template: ''
|
template: ''
|
||||||
|
|||||||
9
internal/cache/cache_test.go
vendored
9
internal/cache/cache_test.go
vendored
@@ -3,13 +3,14 @@ package cache_test
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
|
||||||
"github.com/Masterminds/semver"
|
"github.com/Masterminds/semver"
|
||||||
"github.com/Nightapes/go-semantic-release/internal/cache"
|
"github.com/Nightapes/go-semantic-release/internal/cache"
|
||||||
"github.com/Nightapes/go-semantic-release/internal/shared"
|
"github.com/Nightapes/go-semantic-release/internal/shared"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestReadCacheNotFound(t *testing.T) {
|
func TestReadCacheNotFound(t *testing.T) {
|
||||||
@@ -54,7 +55,6 @@ func TestWriteAndReadCache(t *testing.T) {
|
|||||||
VersionString: "1.1.0",
|
VersionString: "1.1.0",
|
||||||
},
|
},
|
||||||
Branch: "master",
|
Branch: "master",
|
||||||
Draft: true,
|
|
||||||
Commits: map[shared.Release][]shared.AnalyzedCommit{
|
Commits: map[shared.Release][]shared.AnalyzedCommit{
|
||||||
"major": []shared.AnalyzedCommit{
|
"major": []shared.AnalyzedCommit{
|
||||||
shared.AnalyzedCommit{
|
shared.AnalyzedCommit{
|
||||||
@@ -97,7 +97,6 @@ func TestWriteNotFound(t *testing.T) {
|
|||||||
Version: createVersion("1.1.0"),
|
Version: createVersion("1.1.0"),
|
||||||
},
|
},
|
||||||
Branch: "master",
|
Branch: "master",
|
||||||
Draft: true,
|
|
||||||
})
|
})
|
||||||
assert.Errorf(t, err, "Write non exsiting file")
|
assert.Errorf(t, err, "Write non exsiting file")
|
||||||
|
|
||||||
|
|||||||
@@ -40,29 +40,24 @@ func (c *Calculator) IncPrerelease(preReleaseType string, version *semver.Versio
|
|||||||
}
|
}
|
||||||
|
|
||||||
//CalculateNewVersion from given commits and lastversion
|
//CalculateNewVersion from given commits and lastversion
|
||||||
func (c *Calculator) CalculateNewVersion(commits map[shared.Release][]shared.AnalyzedCommit, lastVersion *semver.Version, releaseType string, firstRelease bool) (semver.Version, bool) {
|
func (c *Calculator) CalculateNewVersion(commits map[shared.Release][]shared.AnalyzedCommit, lastVersion *semver.Version, releaseType string, firstRelease bool) semver.Version {
|
||||||
switch releaseType {
|
switch releaseType {
|
||||||
case "beta", "alpha":
|
case "beta", "alpha", "rc":
|
||||||
if len(commits["major"]) > 0 || len(commits["minor"]) > 0 || len(commits["patch"]) > 0 {
|
if len(commits["major"]) > 0 || len(commits["minor"]) > 0 || len(commits["patch"]) > 0 {
|
||||||
version, _ := c.IncPrerelease(releaseType, lastVersion)
|
version, _ := c.IncPrerelease(releaseType, lastVersion)
|
||||||
return version, true
|
return version
|
||||||
}
|
|
||||||
case "rc":
|
|
||||||
if len(commits["major"]) > 0 || len(commits["minor"]) > 0 || len(commits["patch"]) > 0 {
|
|
||||||
version, _ := c.IncPrerelease(releaseType, lastVersion)
|
|
||||||
return version, false
|
|
||||||
}
|
}
|
||||||
case "release":
|
case "release":
|
||||||
if !firstRelease {
|
if !firstRelease {
|
||||||
if len(commits["major"]) > 0 {
|
if len(commits["major"]) > 0 {
|
||||||
return lastVersion.IncMajor(), false
|
return lastVersion.IncMajor()
|
||||||
} else if len(commits["minor"]) > 0 {
|
} else if len(commits["minor"]) > 0 {
|
||||||
return lastVersion.IncMinor(), false
|
return lastVersion.IncMinor()
|
||||||
} else if len(commits["patch"]) > 0 {
|
} else if len(commits["patch"]) > 0 {
|
||||||
return lastVersion.IncPatch(), false
|
return lastVersion.IncPatch()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return *lastVersion, false
|
return *lastVersion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,7 +72,6 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
|
|||||||
releaseType string
|
releaseType string
|
||||||
lastVersion *semver.Version
|
lastVersion *semver.Version
|
||||||
nextVersion string
|
nextVersion string
|
||||||
isDraft bool
|
|
||||||
isFirst bool
|
isFirst bool
|
||||||
analyzedCommits map[shared.Release][]shared.AnalyzedCommit
|
analyzedCommits map[shared.Release][]shared.AnalyzedCommit
|
||||||
}{
|
}{
|
||||||
@@ -90,7 +89,6 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
|
|||||||
"none": []shared.AnalyzedCommit{},
|
"none": []shared.AnalyzedCommit{},
|
||||||
},
|
},
|
||||||
isFirst: false,
|
isFirst: false,
|
||||||
isDraft: true,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
testCase: "version with preRelease beta",
|
testCase: "version with preRelease beta",
|
||||||
@@ -106,7 +104,6 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
|
|||||||
"none": []shared.AnalyzedCommit{},
|
"none": []shared.AnalyzedCommit{},
|
||||||
},
|
},
|
||||||
isFirst: false,
|
isFirst: false,
|
||||||
isDraft: true,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
testCase: "version without commits",
|
testCase: "version without commits",
|
||||||
@@ -120,7 +117,6 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
|
|||||||
"none": []shared.AnalyzedCommit{},
|
"none": []shared.AnalyzedCommit{},
|
||||||
},
|
},
|
||||||
isFirst: false,
|
isFirst: false,
|
||||||
isDraft: false,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
testCase: "version with commits and first release",
|
testCase: "version with commits and first release",
|
||||||
@@ -134,7 +130,6 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
|
|||||||
"none": []shared.AnalyzedCommit{},
|
"none": []shared.AnalyzedCommit{},
|
||||||
},
|
},
|
||||||
isFirst: true,
|
isFirst: true,
|
||||||
isDraft: false,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
testCase: "version with commits and rc release",
|
testCase: "version with commits and rc release",
|
||||||
@@ -148,7 +143,6 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
|
|||||||
"none": []shared.AnalyzedCommit{},
|
"none": []shared.AnalyzedCommit{},
|
||||||
},
|
},
|
||||||
isFirst: false,
|
isFirst: false,
|
||||||
isDraft: false,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
testCase: "version with commits and rc release",
|
testCase: "version with commits and rc release",
|
||||||
@@ -162,7 +156,6 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
|
|||||||
"none": []shared.AnalyzedCommit{},
|
"none": []shared.AnalyzedCommit{},
|
||||||
},
|
},
|
||||||
isFirst: false,
|
isFirst: false,
|
||||||
isDraft: false,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
testCase: "version with commits and major release",
|
testCase: "version with commits and major release",
|
||||||
@@ -176,7 +169,6 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
|
|||||||
"none": []shared.AnalyzedCommit{},
|
"none": []shared.AnalyzedCommit{},
|
||||||
},
|
},
|
||||||
isFirst: false,
|
isFirst: false,
|
||||||
isDraft: false,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
testCase: "version with commits and minor release",
|
testCase: "version with commits and minor release",
|
||||||
@@ -190,7 +182,6 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
|
|||||||
"none": []shared.AnalyzedCommit{},
|
"none": []shared.AnalyzedCommit{},
|
||||||
},
|
},
|
||||||
isFirst: false,
|
isFirst: false,
|
||||||
isDraft: false,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
testCase: "version with commits and minor patch",
|
testCase: "version with commits and minor patch",
|
||||||
@@ -204,15 +195,13 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
|
|||||||
"none": []shared.AnalyzedCommit{},
|
"none": []shared.AnalyzedCommit{},
|
||||||
},
|
},
|
||||||
isFirst: false,
|
isFirst: false,
|
||||||
isDraft: false,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
c := calculator.New()
|
c := calculator.New()
|
||||||
|
|
||||||
for _, test := range testConfigs {
|
for _, test := range testConfigs {
|
||||||
next, draft := c.CalculateNewVersion(test.analyzedCommits, test.lastVersion, test.releaseType, test.isFirst)
|
next := c.CalculateNewVersion(test.analyzedCommits, test.lastVersion, test.releaseType, test.isFirst)
|
||||||
assert.Equalf(t, test.isDraft, draft, "Should have draft %t for testcase %s", test.isDraft, test.testCase)
|
|
||||||
assert.Equalf(t, test.nextVersion, next.String(), "Should have version %s for testcase %s", test.nextVersion, test.testCase)
|
assert.Equalf(t, test.nextVersion, next.String(), "Should have version %s for testcase %s", test.nextVersion, test.testCase)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ func GetCIProvider(gitUtil *gitutil.GitUtil, envs map[string]string) (*ProviderC
|
|||||||
|
|
||||||
services := []Service{
|
services := []Service{
|
||||||
Travis{},
|
Travis{},
|
||||||
|
GithubActions{},
|
||||||
Git{gitUtil: gitUtil}, // GIt must be the last option to check
|
Git{gitUtil: gitUtil}, // GIt must be the last option to check
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -89,6 +89,28 @@ func TestCi(t *testing.T) {
|
|||||||
result: &ci.ProviderConfig{IsPR: false, PR: "", PRBranch: "", Branch: "master", Tag: "TAG", Commit: "190bfd6aa60022afd0ef830342cfb07e33c45f37", BuildURL: "https://travis-ci.com/owner/repo/builds/1234", Service: "travis", Name: "Travis CI"},
|
result: &ci.ProviderConfig{IsPR: false, PR: "", PRBranch: "", Branch: "master", Tag: "TAG", Commit: "190bfd6aa60022afd0ef830342cfb07e33c45f37", BuildURL: "https://travis-ci.com/owner/repo/builds/1234", Service: "travis", Name: "Travis CI"},
|
||||||
hasError: false,
|
hasError: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
service: "Github Actions PR",
|
||||||
|
envs: map[string]string{
|
||||||
|
"GITHUB_EVENT_NAME": "pull_request",
|
||||||
|
"GITHUB_SHA": "190bfd6aa60022afd0ef830342cfb07e33c45f37",
|
||||||
|
"GITHUB_REF": "master",
|
||||||
|
"GITHUB_ACTION": "action",
|
||||||
|
},
|
||||||
|
result: &ci.ProviderConfig{IsPR: true, PR: "", PRBranch: "", Branch: "master", Tag: "", Commit: "190bfd6aa60022afd0ef830342cfb07e33c45f37", BuildURL: "", Service: "GithubActions", Name: "GithubActions CI"},
|
||||||
|
hasError: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
service: "Github Actions Push",
|
||||||
|
envs: map[string]string{
|
||||||
|
"GITHUB_EVENT_NAME": "push",
|
||||||
|
"GITHUB_SHA": "190bfd6aa60022afd0ef830342cfb07e33c45f37",
|
||||||
|
"GITHUB_REF": "refs/heads/feature-branch-1",
|
||||||
|
"GITHUB_ACTION": "action",
|
||||||
|
},
|
||||||
|
result: &ci.ProviderConfig{IsPR: false, PR: "", PRBranch: "", Branch: "feature-branch-1", Tag: "", Commit: "190bfd6aa60022afd0ef830342cfb07e33c45f37", BuildURL: "", Service: "GithubActions", Name: "GithubActions CI"},
|
||||||
|
hasError: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, config := range testConfigs {
|
for _, config := range testConfigs {
|
||||||
|
|||||||
43
internal/ci/github_actions.go
Normal file
43
internal/ci/github_actions.go
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package ci
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
//GithubActions struct
|
||||||
|
type GithubActions struct{}
|
||||||
|
|
||||||
|
//Detect if on GithubActions
|
||||||
|
func (t GithubActions) detect(envs map[string]string) (*ProviderConfig, error) {
|
||||||
|
|
||||||
|
if _, exists := envs["GITHUB_ACTION"]; !exists {
|
||||||
|
return nil, fmt.Errorf("not running on Github Actions")
|
||||||
|
}
|
||||||
|
|
||||||
|
isPR := false
|
||||||
|
|
||||||
|
value := envs["GITHUB_EVENT_NAME"]
|
||||||
|
|
||||||
|
if value == "pull_request" {
|
||||||
|
isPR = true
|
||||||
|
} else {
|
||||||
|
log.Debugf("GITHUB_EVENT_NAME=%s, not running on pr", value)
|
||||||
|
}
|
||||||
|
|
||||||
|
branch := envs["GITHUB_REF"]
|
||||||
|
|
||||||
|
if strings.HasPrefix(envs["GITHUB_REF"], "refs/heads/") {
|
||||||
|
branch = strings.Replace(branch, "refs/heads/", "", 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &ProviderConfig{
|
||||||
|
Service: "GithubActions",
|
||||||
|
Name: "GithubActions CI",
|
||||||
|
Commit: envs["GITHUB_SHA"],
|
||||||
|
Branch: branch,
|
||||||
|
IsPR: isPR,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
@@ -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()
|
||||||
@@ -96,7 +96,6 @@ func (g *Client) CreateRelease(releaseVersion *shared.ReleaseVersion, generatedC
|
|||||||
TargetCommitish: &releaseVersion.Branch,
|
TargetCommitish: &releaseVersion.Branch,
|
||||||
Name: &generatedChangelog.Title,
|
Name: &generatedChangelog.Title,
|
||||||
Body: &generatedChangelog.Content,
|
Body: &generatedChangelog.Content,
|
||||||
Draft: &releaseVersion.Draft,
|
|
||||||
Prerelease: &prerelease,
|
Prerelease: &prerelease,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -90,7 +90,6 @@ var testReleases = []testReleaseStruct{
|
|||||||
Commit: "bar",
|
Commit: "bar",
|
||||||
},
|
},
|
||||||
Branch: "master",
|
Branch: "master",
|
||||||
Draft: false,
|
|
||||||
},
|
},
|
||||||
generatedChangelog: &shared.GeneratedChangelog{
|
generatedChangelog: &shared.GeneratedChangelog{
|
||||||
Title: "title",
|
Title: "title",
|
||||||
@@ -115,7 +114,6 @@ var testReleases = []testReleaseStruct{
|
|||||||
Commit: "bar",
|
Commit: "bar",
|
||||||
},
|
},
|
||||||
Branch: "master",
|
Branch: "master",
|
||||||
Draft: false,
|
|
||||||
},
|
},
|
||||||
generatedChangelog: &shared.GeneratedChangelog{
|
generatedChangelog: &shared.GeneratedChangelog{
|
||||||
Title: "title",
|
Title: "title",
|
||||||
@@ -145,19 +143,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 +168,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 +186,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 +199,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 +230,6 @@ func TestCreateRelease(t *testing.T) {
|
|||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
os.Unsetenv("GITHUB_ACCESS_TOKEN")
|
os.Unsetenv("GITHUB_TOKEN")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,7 +94,6 @@ func TestCreateRelease(t *testing.T) {
|
|||||||
Commit: "bar",
|
Commit: "bar",
|
||||||
},
|
},
|
||||||
Branch: "master",
|
Branch: "master",
|
||||||
Draft: false,
|
|
||||||
},
|
},
|
||||||
generatedChangelog: &shared.GeneratedChangelog{
|
generatedChangelog: &shared.GeneratedChangelog{
|
||||||
Title: "title",
|
Title: "title",
|
||||||
@@ -119,7 +118,6 @@ func TestCreateRelease(t *testing.T) {
|
|||||||
Commit: "bar",
|
Commit: "bar",
|
||||||
},
|
},
|
||||||
Branch: "master",
|
Branch: "master",
|
||||||
Draft: false,
|
|
||||||
},
|
},
|
||||||
generatedChangelog: &shared.GeneratedChangelog{
|
generatedChangelog: &shared.GeneratedChangelog{
|
||||||
Title: "title",
|
Title: "title",
|
||||||
@@ -145,7 +143,6 @@ func TestCreateRelease(t *testing.T) {
|
|||||||
Commit: "bar",
|
Commit: "bar",
|
||||||
},
|
},
|
||||||
Branch: "master",
|
Branch: "master",
|
||||||
Draft: false,
|
|
||||||
},
|
},
|
||||||
generatedChangelog: &shared.GeneratedChangelog{
|
generatedChangelog: &shared.GeneratedChangelog{
|
||||||
Title: "title",
|
Title: "title",
|
||||||
|
|||||||
@@ -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)
|
||||||
@@ -193,7 +193,7 @@ func TestDoAndRoundTrip(t *testing.T) {
|
|||||||
hasError: true,
|
hasError: true,
|
||||||
responseBody: &example{},
|
responseBody: &example{},
|
||||||
responseBodyType: &example{},
|
responseBodyType: &example{},
|
||||||
path: "broken",
|
path: "4/broken",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,6 +214,8 @@ func TestDoAndRoundTrip(t *testing.T) {
|
|||||||
|
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
defer testServer.Close()
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", testServer.URL+testOject.path, nil)
|
req, err := http.NewRequest("POST", testServer.URL+testOject.path, nil)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
@@ -225,6 +227,5 @@ func TestDoAndRoundTrip(t *testing.T) {
|
|||||||
assert.Equal(t, testOject.statusCode, resp.StatusCode)
|
assert.Equal(t, testOject.statusCode, resp.StatusCode)
|
||||||
assert.Equal(t, testOject.responseBody, testOject.responseBodyType)
|
assert.Equal(t, testOject.responseBody, testOject.responseBodyType)
|
||||||
}
|
}
|
||||||
testServer.Close()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,17 +6,16 @@ import (
|
|||||||
|
|
||||||
//ReleaseVersion struct
|
//ReleaseVersion struct
|
||||||
type ReleaseVersion struct {
|
type ReleaseVersion struct {
|
||||||
Last ReleaseVersionEntry `yaml:"last"`
|
Last ReleaseVersionEntry `yaml:"last"`
|
||||||
Next ReleaseVersionEntry `yaml:"next"`
|
Next ReleaseVersionEntry `yaml:"next"`
|
||||||
Branch string `yaml:"branch"`
|
Branch string `yaml:"branch"`
|
||||||
Draft bool `yaml:"draft"`
|
|
||||||
Commits map[Release][]AnalyzedCommit `yaml:"commits"`
|
Commits map[Release][]AnalyzedCommit `yaml:"commits"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//ReleaseVersionEntry struct
|
//ReleaseVersionEntry struct
|
||||||
type ReleaseVersionEntry struct {
|
type ReleaseVersionEntry struct {
|
||||||
Commit string `yaml:"commit"`
|
Commit string `yaml:"commit"`
|
||||||
VersionString string `yaml:"version"`
|
VersionString string `yaml:"version"`
|
||||||
Version *semver.Version `yaml:"-"`
|
Version *semver.Version `yaml:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,15 +38,15 @@ type GitLabProvider struct {
|
|||||||
|
|
||||||
// ReleaseConfig struct
|
// ReleaseConfig struct
|
||||||
type ReleaseConfig struct {
|
type ReleaseConfig struct {
|
||||||
CommitFormat string `yaml:"commitFormat"`
|
CommitFormat string `yaml:"commitFormat"`
|
||||||
Branch map[string]string `yaml:"branch"`
|
Branch map[string]string `yaml:"branch"`
|
||||||
Changelog ChangelogConfig `yaml:"changelog,omitempty"`
|
Changelog ChangelogConfig `yaml:"changelog,omitempty"`
|
||||||
Release string `yaml:"release,omitempty"`
|
Release string `yaml:"release,omitempty"`
|
||||||
GitHubProvider GitHubProvider `yaml:"github,omitempty"`
|
GitHubProvider GitHubProvider `yaml:"github,omitempty"`
|
||||||
GitLabProvider GitLabProvider `yaml:"gitlab,omitempty"`
|
GitLabProvider GitLabProvider `yaml:"gitlab,omitempty"`
|
||||||
Assets []Asset `yaml:"assets"`
|
Assets []Asset `yaml:"assets"`
|
||||||
ReleaseTitle string `yaml:"title"`
|
ReleaseTitle string `yaml:"title"`
|
||||||
IsPreRelease, IsDraft bool
|
IsPreRelease bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read ReleaseConfig
|
// Read ReleaseConfig
|
||||||
|
|||||||
@@ -3,11 +3,12 @@ package config_test
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/Nightapes/go-semantic-release/pkg/config"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
|
"github.com/Nightapes/go-semantic-release/pkg/config"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestReadCacheNotFound(t *testing.T) {
|
func TestReadCacheNotFound(t *testing.T) {
|
||||||
@@ -88,7 +89,6 @@ github:
|
|||||||
Compress: false}},
|
Compress: false}},
|
||||||
ReleaseTitle: "go-semantic-release release",
|
ReleaseTitle: "go-semantic-release release",
|
||||||
IsPreRelease: false,
|
IsPreRelease: false,
|
||||||
IsDraft: false,
|
|
||||||
}, result)
|
}, result)
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -105,7 +105,6 @@ github:
|
|||||||
// Version: createVersion("1.1.0"),
|
// Version: createVersion("1.1.0"),
|
||||||
// },
|
// },
|
||||||
// Branch: "master",
|
// Branch: "master",
|
||||||
// Draft: true,
|
|
||||||
// })
|
// })
|
||||||
// assert.Errorf(t, err, "Write non exsiting file")
|
// assert.Errorf(t, err, "Write non exsiting file")
|
||||||
|
|
||||||
|
|||||||
@@ -83,8 +83,8 @@ func (s *SemanticRelease) GetNextVersion(provider *ci.ProviderConfig, force bool
|
|||||||
firstRelease := false
|
firstRelease := false
|
||||||
|
|
||||||
if lastVersion == nil {
|
if lastVersion == nil {
|
||||||
defaultVersion, _ := semver.NewVersion("1.0.0")
|
lastVersion, _ = semver.NewVersion("1.0.0")
|
||||||
lastVersion = defaultVersion
|
log.Infof("This is the first release, will set version to %s", lastVersion.String())
|
||||||
firstRelease = true
|
firstRelease = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,12 +97,11 @@ func (s *SemanticRelease) GetNextVersion(provider *ci.ProviderConfig, force bool
|
|||||||
|
|
||||||
analyzedCommits := s.analyzer.Analyze(commits)
|
analyzedCommits := s.analyzer.Analyze(commits)
|
||||||
|
|
||||||
isDraft := false
|
|
||||||
var newVersion semver.Version
|
var newVersion semver.Version
|
||||||
for branch, releaseType := range s.config.Branch {
|
for branch, releaseType := range s.config.Branch {
|
||||||
if provider.Branch == branch || strings.HasPrefix(provider.Branch, branch) {
|
if provider.Branch == branch || strings.HasPrefix(provider.Branch, branch) {
|
||||||
log.Debugf("Found branch config for branch %s with release type %s", provider.Branch, releaseType)
|
log.Debugf("Found branch config for branch %s with release type %s", provider.Branch, releaseType)
|
||||||
newVersion, isDraft = s.calculator.CalculateNewVersion(analyzedCommits, lastVersion, releaseType, firstRelease)
|
newVersion = s.calculator.CalculateNewVersion(analyzedCommits, lastVersion, releaseType, firstRelease)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -117,10 +116,13 @@ func (s *SemanticRelease) GetNextVersion(provider *ci.ProviderConfig, force bool
|
|||||||
Version: lastVersion,
|
Version: lastVersion,
|
||||||
},
|
},
|
||||||
Branch: provider.Branch,
|
Branch: provider.Branch,
|
||||||
Draft: isDraft,
|
|
||||||
Commits: analyzedCommits,
|
Commits: analyzedCommits,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if firstRelease {
|
||||||
|
releaseVersion.Last.Version, _ = semver.NewVersion("0.0.0")
|
||||||
|
}
|
||||||
|
|
||||||
log.Infof("New version %s -> %s", lastVersion.String(), newVersion.String())
|
log.Infof("New version %s -> %s", lastVersion.String(), newVersion.String())
|
||||||
err = cache.Write(s.repository, releaseVersion)
|
err = cache.Write(s.repository, releaseVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -179,12 +181,12 @@ func (s *SemanticRelease) WriteChangeLog(changelogContent, file string) error {
|
|||||||
func (s *SemanticRelease) Release(provider *ci.ProviderConfig, force bool) error {
|
func (s *SemanticRelease) Release(provider *ci.ProviderConfig, force bool) error {
|
||||||
|
|
||||||
if provider.IsPR {
|
if provider.IsPR {
|
||||||
log.Debugf("Will not perform a new release. This is a pull request")
|
log.Infof("Will not perform a new release. This is a pull request")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := s.config.Branch[provider.Branch]; !ok {
|
if _, ok := s.config.Branch[provider.Branch]; !ok {
|
||||||
log.Debugf("Will not perform a new release. Current %s branch is not configured in release config", provider.Branch)
|
log.Infof("Will not perform a new release. Current %s branch is not configured in release config", provider.Branch)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user