You've already forked go-semantic-release
Compare commits
6 Commits
1.0.0-beta
...
1.0.0-beta
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2c26c8aa6d | ||
|
|
4b72df07c8 | ||
|
|
df544f5be7 | ||
|
|
a2fc03c64d | ||
|
|
2eb64f153a | ||
|
|
a6c651a97f |
9
internal/cache/cache_test.go
vendored
9
internal/cache/cache_test.go
vendored
@@ -3,13 +3,14 @@ package cache_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/Masterminds/semver"
|
||||
"github.com/Nightapes/go-semantic-release/internal/cache"
|
||||
"github.com/Nightapes/go-semantic-release/internal/shared"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
)
|
||||
|
||||
func TestReadCacheNotFound(t *testing.T) {
|
||||
@@ -54,7 +55,6 @@ func TestWriteAndReadCache(t *testing.T) {
|
||||
VersionString: "1.1.0",
|
||||
},
|
||||
Branch: "master",
|
||||
Draft: true,
|
||||
Commits: map[shared.Release][]shared.AnalyzedCommit{
|
||||
"major": []shared.AnalyzedCommit{
|
||||
shared.AnalyzedCommit{
|
||||
@@ -97,7 +97,6 @@ func TestWriteNotFound(t *testing.T) {
|
||||
Version: createVersion("1.1.0"),
|
||||
},
|
||||
Branch: "master",
|
||||
Draft: true,
|
||||
})
|
||||
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
|
||||
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 {
|
||||
case "beta", "alpha":
|
||||
case "beta", "alpha", "rc":
|
||||
if len(commits["major"]) > 0 || len(commits["minor"]) > 0 || len(commits["patch"]) > 0 {
|
||||
version, _ := c.IncPrerelease(releaseType, lastVersion)
|
||||
return version, true
|
||||
}
|
||||
case "rc":
|
||||
if len(commits["major"]) > 0 || len(commits["minor"]) > 0 || len(commits["patch"]) > 0 {
|
||||
version, _ := c.IncPrerelease(releaseType, lastVersion)
|
||||
return version, false
|
||||
return version
|
||||
}
|
||||
case "release":
|
||||
if !firstRelease {
|
||||
if len(commits["major"]) > 0 {
|
||||
return lastVersion.IncMajor(), false
|
||||
return lastVersion.IncMajor()
|
||||
} else if len(commits["minor"]) > 0 {
|
||||
return lastVersion.IncMinor(), false
|
||||
return lastVersion.IncMinor()
|
||||
} 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
|
||||
lastVersion *semver.Version
|
||||
nextVersion string
|
||||
isDraft bool
|
||||
isFirst bool
|
||||
analyzedCommits map[shared.Release][]shared.AnalyzedCommit
|
||||
}{
|
||||
@@ -90,7 +89,6 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
|
||||
"none": []shared.AnalyzedCommit{},
|
||||
},
|
||||
isFirst: false,
|
||||
isDraft: true,
|
||||
},
|
||||
{
|
||||
testCase: "version with preRelease beta",
|
||||
@@ -106,7 +104,6 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
|
||||
"none": []shared.AnalyzedCommit{},
|
||||
},
|
||||
isFirst: false,
|
||||
isDraft: true,
|
||||
},
|
||||
{
|
||||
testCase: "version without commits",
|
||||
@@ -120,7 +117,6 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
|
||||
"none": []shared.AnalyzedCommit{},
|
||||
},
|
||||
isFirst: false,
|
||||
isDraft: false,
|
||||
},
|
||||
{
|
||||
testCase: "version with commits and first release",
|
||||
@@ -134,7 +130,6 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
|
||||
"none": []shared.AnalyzedCommit{},
|
||||
},
|
||||
isFirst: true,
|
||||
isDraft: false,
|
||||
},
|
||||
{
|
||||
testCase: "version with commits and rc release",
|
||||
@@ -148,7 +143,6 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
|
||||
"none": []shared.AnalyzedCommit{},
|
||||
},
|
||||
isFirst: false,
|
||||
isDraft: false,
|
||||
},
|
||||
{
|
||||
testCase: "version with commits and rc release",
|
||||
@@ -162,7 +156,6 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
|
||||
"none": []shared.AnalyzedCommit{},
|
||||
},
|
||||
isFirst: false,
|
||||
isDraft: false,
|
||||
},
|
||||
{
|
||||
testCase: "version with commits and major release",
|
||||
@@ -176,7 +169,6 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
|
||||
"none": []shared.AnalyzedCommit{},
|
||||
},
|
||||
isFirst: false,
|
||||
isDraft: false,
|
||||
},
|
||||
{
|
||||
testCase: "version with commits and minor release",
|
||||
@@ -190,7 +182,6 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
|
||||
"none": []shared.AnalyzedCommit{},
|
||||
},
|
||||
isFirst: false,
|
||||
isDraft: false,
|
||||
},
|
||||
{
|
||||
testCase: "version with commits and minor patch",
|
||||
@@ -204,15 +195,13 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
|
||||
"none": []shared.AnalyzedCommit{},
|
||||
},
|
||||
isFirst: false,
|
||||
isDraft: false,
|
||||
},
|
||||
}
|
||||
|
||||
c := calculator.New()
|
||||
|
||||
for _, test := range testConfigs {
|
||||
next, draft := 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)
|
||||
next := c.CalculateNewVersion(test.analyzedCommits, test.lastVersion, test.releaseType, test.isFirst)
|
||||
assert.Equalf(t, test.nextVersion, next.String(), "Should have version %s for testcase %s", test.nextVersion, test.testCase)
|
||||
}
|
||||
|
||||
|
||||
@@ -96,7 +96,6 @@ func (g *Client) CreateRelease(releaseVersion *shared.ReleaseVersion, generatedC
|
||||
TargetCommitish: &releaseVersion.Branch,
|
||||
Name: &generatedChangelog.Title,
|
||||
Body: &generatedChangelog.Content,
|
||||
Draft: &releaseVersion.Draft,
|
||||
Prerelease: &prerelease,
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -90,7 +90,6 @@ var testReleases = []testReleaseStruct{
|
||||
Commit: "bar",
|
||||
},
|
||||
Branch: "master",
|
||||
Draft: false,
|
||||
},
|
||||
generatedChangelog: &shared.GeneratedChangelog{
|
||||
Title: "title",
|
||||
@@ -115,7 +114,6 @@ var testReleases = []testReleaseStruct{
|
||||
Commit: "bar",
|
||||
},
|
||||
Branch: "master",
|
||||
Draft: false,
|
||||
},
|
||||
generatedChangelog: &shared.GeneratedChangelog{
|
||||
Title: "title",
|
||||
|
||||
@@ -94,7 +94,6 @@ func TestCreateRelease(t *testing.T) {
|
||||
Commit: "bar",
|
||||
},
|
||||
Branch: "master",
|
||||
Draft: false,
|
||||
},
|
||||
generatedChangelog: &shared.GeneratedChangelog{
|
||||
Title: "title",
|
||||
@@ -119,7 +118,6 @@ func TestCreateRelease(t *testing.T) {
|
||||
Commit: "bar",
|
||||
},
|
||||
Branch: "master",
|
||||
Draft: false,
|
||||
},
|
||||
generatedChangelog: &shared.GeneratedChangelog{
|
||||
Title: "title",
|
||||
@@ -145,7 +143,6 @@ func TestCreateRelease(t *testing.T) {
|
||||
Commit: "bar",
|
||||
},
|
||||
Branch: "master",
|
||||
Draft: false,
|
||||
},
|
||||
generatedChangelog: &shared.GeneratedChangelog{
|
||||
Title: "title",
|
||||
|
||||
@@ -214,6 +214,8 @@ func TestDoAndRoundTrip(t *testing.T) {
|
||||
|
||||
}))
|
||||
|
||||
defer testServer.Close()
|
||||
|
||||
req, err := http.NewRequest("POST", testServer.URL+testOject.path, nil)
|
||||
assert.NoError(t, err)
|
||||
|
||||
@@ -225,6 +227,5 @@ func TestDoAndRoundTrip(t *testing.T) {
|
||||
assert.Equal(t, testOject.statusCode, resp.StatusCode)
|
||||
assert.Equal(t, testOject.responseBody, testOject.responseBodyType)
|
||||
}
|
||||
testServer.Close()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,17 +6,16 @@ import (
|
||||
|
||||
//ReleaseVersion struct
|
||||
type ReleaseVersion struct {
|
||||
Last ReleaseVersionEntry `yaml:"last"`
|
||||
Next ReleaseVersionEntry `yaml:"next"`
|
||||
Branch string `yaml:"branch"`
|
||||
Draft bool `yaml:"draft"`
|
||||
Last ReleaseVersionEntry `yaml:"last"`
|
||||
Next ReleaseVersionEntry `yaml:"next"`
|
||||
Branch string `yaml:"branch"`
|
||||
Commits map[Release][]AnalyzedCommit `yaml:"commits"`
|
||||
}
|
||||
|
||||
//ReleaseVersionEntry struct
|
||||
type ReleaseVersionEntry struct {
|
||||
Commit string `yaml:"commit"`
|
||||
VersionString string `yaml:"version"`
|
||||
Commit string `yaml:"commit"`
|
||||
VersionString string `yaml:"version"`
|
||||
Version *semver.Version `yaml:"-"`
|
||||
}
|
||||
|
||||
|
||||
@@ -38,15 +38,15 @@ type GitLabProvider struct {
|
||||
|
||||
// ReleaseConfig struct
|
||||
type ReleaseConfig struct {
|
||||
CommitFormat string `yaml:"commitFormat"`
|
||||
Branch map[string]string `yaml:"branch"`
|
||||
Changelog ChangelogConfig `yaml:"changelog,omitempty"`
|
||||
Release string `yaml:"release,omitempty"`
|
||||
GitHubProvider GitHubProvider `yaml:"github,omitempty"`
|
||||
GitLabProvider GitLabProvider `yaml:"gitlab,omitempty"`
|
||||
Assets []Asset `yaml:"assets"`
|
||||
ReleaseTitle string `yaml:"title"`
|
||||
IsPreRelease, IsDraft bool
|
||||
CommitFormat string `yaml:"commitFormat"`
|
||||
Branch map[string]string `yaml:"branch"`
|
||||
Changelog ChangelogConfig `yaml:"changelog,omitempty"`
|
||||
Release string `yaml:"release,omitempty"`
|
||||
GitHubProvider GitHubProvider `yaml:"github,omitempty"`
|
||||
GitLabProvider GitLabProvider `yaml:"gitlab,omitempty"`
|
||||
Assets []Asset `yaml:"assets"`
|
||||
ReleaseTitle string `yaml:"title"`
|
||||
IsPreRelease bool
|
||||
}
|
||||
|
||||
// Read ReleaseConfig
|
||||
|
||||
@@ -3,11 +3,12 @@ package config_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/Nightapes/go-semantic-release/pkg/config"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/Nightapes/go-semantic-release/pkg/config"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestReadCacheNotFound(t *testing.T) {
|
||||
@@ -88,7 +89,6 @@ github:
|
||||
Compress: false}},
|
||||
ReleaseTitle: "go-semantic-release release",
|
||||
IsPreRelease: false,
|
||||
IsDraft: false,
|
||||
}, result)
|
||||
|
||||
}
|
||||
@@ -105,7 +105,6 @@ github:
|
||||
// Version: createVersion("1.1.0"),
|
||||
// },
|
||||
// Branch: "master",
|
||||
// Draft: true,
|
||||
// })
|
||||
// assert.Errorf(t, err, "Write non exsiting file")
|
||||
|
||||
|
||||
@@ -97,12 +97,11 @@ func (s *SemanticRelease) GetNextVersion(provider *ci.ProviderConfig, force bool
|
||||
|
||||
analyzedCommits := s.analyzer.Analyze(commits)
|
||||
|
||||
isDraft := false
|
||||
var newVersion semver.Version
|
||||
for branch, releaseType := range s.config.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)
|
||||
newVersion, isDraft = s.calculator.CalculateNewVersion(analyzedCommits, lastVersion, releaseType, firstRelease)
|
||||
newVersion = s.calculator.CalculateNewVersion(analyzedCommits, lastVersion, releaseType, firstRelease)
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -117,7 +116,6 @@ func (s *SemanticRelease) GetNextVersion(provider *ci.ProviderConfig, force bool
|
||||
Version: lastVersion,
|
||||
},
|
||||
Branch: provider.Branch,
|
||||
Draft: isDraft,
|
||||
Commits: analyzedCommits,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user