You've already forked go-semantic-release
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a6dcad2b69 | ||
|
|
af5c8f5ae3 | ||
|
|
c361744a35 | ||
|
|
6a375f3bab | ||
|
|
d4627a9d46 |
@@ -5,6 +5,7 @@ github:
|
|||||||
commitFormat: angular
|
commitFormat: angular
|
||||||
branch:
|
branch:
|
||||||
master: release
|
master: release
|
||||||
|
beta: beta
|
||||||
assets:
|
assets:
|
||||||
- name: ./build/go-semantic-release
|
- name: ./build/go-semantic-release
|
||||||
compress: false
|
compress: false
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ func New() *Calculator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//IncPrerelease increase prerelease by one
|
//IncPrerelease increase prerelease by one
|
||||||
func (c *Calculator) IncPrerelease(preReleaseType string, version *semver.Version) (semver.Version, error) {
|
func (c *Calculator) IncPrerelease(preReleaseType string, version semver.Version) (semver.Version, error) {
|
||||||
defaultPrerelease := preReleaseType + ".0"
|
defaultPrerelease := preReleaseType + ".0"
|
||||||
if version.Prerelease() == "" || !strings.HasPrefix(version.Prerelease(), preReleaseType) {
|
if !c.hasPrerelease(version, preReleaseType) {
|
||||||
return version.SetPrerelease(defaultPrerelease)
|
return version.SetPrerelease(defaultPrerelease)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,19 +32,31 @@ func (c *Calculator) IncPrerelease(preReleaseType string, version *semver.Versio
|
|||||||
log.Warnf("Could not parse release tag %s, use version %s", version.Prerelease(), version.String())
|
log.Warnf("Could not parse release tag %s, use version %s", version.Prerelease(), version.String())
|
||||||
return version.SetPrerelease(defaultPrerelease)
|
return version.SetPrerelease(defaultPrerelease)
|
||||||
}
|
}
|
||||||
return version.SetPrerelease(preReleaseType + "." + strconv.Itoa((i + 1)))
|
return version.SetPrerelease(preReleaseType + "." + strconv.Itoa(i+1))
|
||||||
|
|
||||||
}
|
}
|
||||||
log.Warnf("Could not parse release tag %s, use version %s", version.Prerelease(), version.String())
|
log.Warnf("Could not parse release tag %s, use version %s", version.Prerelease(), version.String())
|
||||||
return version.SetPrerelease(defaultPrerelease)
|
return version.SetPrerelease(defaultPrerelease)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Calculator) hasPrerelease(version semver.Version, preReleaseType string) bool {
|
||||||
|
if version.Prerelease() == "" || !strings.HasPrefix(version.Prerelease(), preReleaseType) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
//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 {
|
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", "rc":
|
case "beta", "alpha", "rc":
|
||||||
|
var version = *lastVersion
|
||||||
|
if !c.hasPrerelease(*lastVersion, releaseType) {
|
||||||
|
version, _ = c.inc(commits, lastVersion)
|
||||||
|
}
|
||||||
|
|
||||||
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, version)
|
||||||
return version
|
return version
|
||||||
}
|
}
|
||||||
case "release":
|
case "release":
|
||||||
@@ -53,16 +65,23 @@ func (c *Calculator) CalculateNewVersion(commits map[shared.Release][]shared.Ana
|
|||||||
newVersion, _ := lastVersion.SetPrerelease("")
|
newVersion, _ := lastVersion.SetPrerelease("")
|
||||||
return newVersion
|
return newVersion
|
||||||
}
|
}
|
||||||
|
version, done := c.inc(commits, lastVersion)
|
||||||
if len(commits["major"]) > 0 {
|
if done {
|
||||||
return lastVersion.IncMajor()
|
return version
|
||||||
} else if len(commits["minor"]) > 0 {
|
|
||||||
return lastVersion.IncMinor()
|
|
||||||
} else if len(commits["patch"]) > 0 {
|
|
||||||
return lastVersion.IncPatch()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return *lastVersion
|
return *lastVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Calculator) inc(commits map[shared.Release][]shared.AnalyzedCommit, lastVersion *semver.Version) (semver.Version, bool) {
|
||||||
|
if len(commits["major"]) > 0 {
|
||||||
|
return lastVersion.IncMajor(), true
|
||||||
|
} else if len(commits["minor"]) > 0 {
|
||||||
|
return lastVersion.IncMinor(), true
|
||||||
|
} else if len(commits["patch"]) > 0 {
|
||||||
|
return lastVersion.IncPatch(), true
|
||||||
|
}
|
||||||
|
return semver.Version{}, false
|
||||||
|
}
|
||||||
|
|||||||
@@ -58,9 +58,11 @@ func TestCalculator_IncPrerelease(t *testing.T) {
|
|||||||
c := calculator.New()
|
c := calculator.New()
|
||||||
|
|
||||||
for _, test := range testConfigs {
|
for _, test := range testConfigs {
|
||||||
next, err := c.IncPrerelease(test.preReleaseType, test.lastVersion)
|
t.Run(test.testCase, func(t *testing.T) {
|
||||||
|
next, err := c.IncPrerelease(test.preReleaseType, *test.lastVersion)
|
||||||
assert.Equalf(t, test.hasError, err != nil, "Testcase %s should have error: %t -> %s", test.testCase, test.hasError, err)
|
assert.Equalf(t, test.hasError, err != nil, "Testcase %s should have error: %t -> %s", test.testCase, test.hasError, err)
|
||||||
assert.Equal(t, test.nextVersion, next.String())
|
assert.Equal(t, test.nextVersion, next.String())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -79,7 +81,7 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
|
|||||||
testCase: "version with preRelease alpha",
|
testCase: "version with preRelease alpha",
|
||||||
releaseType: "alpha",
|
releaseType: "alpha",
|
||||||
lastVersion: createVersion("1.0.0"),
|
lastVersion: createVersion("1.0.0"),
|
||||||
nextVersion: "1.0.0-alpha.0",
|
nextVersion: "1.1.0-alpha.0",
|
||||||
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
|
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
|
||||||
"major": []shared.AnalyzedCommit{},
|
"major": []shared.AnalyzedCommit{},
|
||||||
"minor": []shared.AnalyzedCommit{
|
"minor": []shared.AnalyzedCommit{
|
||||||
@@ -94,7 +96,7 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
|
|||||||
testCase: "version with preRelease beta",
|
testCase: "version with preRelease beta",
|
||||||
releaseType: "beta",
|
releaseType: "beta",
|
||||||
lastVersion: createVersion("1.0.0"),
|
lastVersion: createVersion("1.0.0"),
|
||||||
nextVersion: "1.0.0-beta.0",
|
nextVersion: "1.1.0-beta.0",
|
||||||
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
|
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
|
||||||
"major": []shared.AnalyzedCommit{},
|
"major": []shared.AnalyzedCommit{},
|
||||||
"minor": []shared.AnalyzedCommit{
|
"minor": []shared.AnalyzedCommit{
|
||||||
@@ -135,7 +137,7 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
|
|||||||
testCase: "version with commits and rc release",
|
testCase: "version with commits and rc release",
|
||||||
releaseType: "rc",
|
releaseType: "rc",
|
||||||
lastVersion: createVersion("1.0.0"),
|
lastVersion: createVersion("1.0.0"),
|
||||||
nextVersion: "1.0.0-rc.0",
|
nextVersion: "2.0.0-rc.0",
|
||||||
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
|
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
|
||||||
"major": []shared.AnalyzedCommit{shared.AnalyzedCommit{}},
|
"major": []shared.AnalyzedCommit{shared.AnalyzedCommit{}},
|
||||||
"minor": []shared.AnalyzedCommit{shared.AnalyzedCommit{}},
|
"minor": []shared.AnalyzedCommit{shared.AnalyzedCommit{}},
|
||||||
@@ -201,8 +203,10 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
|
|||||||
c := calculator.New()
|
c := calculator.New()
|
||||||
|
|
||||||
for _, test := range testConfigs {
|
for _, test := range testConfigs {
|
||||||
|
t.Run(test.testCase, func(t *testing.T) {
|
||||||
next := 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.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)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,18 +15,19 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const defaultCommitList string = `{{ range $index,$commit := .BreakingChanges -}}
|
const defaultCommitList string = `{{ range $index,$commit := .BreakingChanges -}}
|
||||||
{{ if eq $index 0 }}
|
{{ if eq $index 0 -}}
|
||||||
## BREAKING CHANGES
|
## BREAKING CHANGES
|
||||||
{{ end}}
|
{{ end -}}
|
||||||
* **{{$.Backtick}}{{$commit.Scope}}{{$.Backtick}}** {{$commit.ParsedBreakingChangeMessage}}
|
* {{ if $commit.Scope }}**{{$.Backtick}}{{$commit.Scope}}{{$.Backtick}}**{{ end }} {{$commit.ParsedBreakingChangeMessage}}
|
||||||
introduced by commit:
|
introduced by commit:
|
||||||
{{$commit.ParsedMessage}} {{if $.HasURL}} ([{{ printf "%.7s" $commit.Commit.Hash}}]({{ replace $.URL "{{hash}}" $commit.Commit.Hash}})){{end}}
|
{{$commit.ParsedMessage}} {{if $.HasURL}} ([{{ printf "%.7s" $commit.Commit.Hash}}]({{ replace $.URL "{{hash}}" $commit.Commit.Hash}})){{end}}
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
{{ range $key := .Order }}
|
{{ range $key := .Order -}}
|
||||||
{{ $commits := index $.Commits $key}} {{if $commits -}}
|
{{ $commits := index $.Commits $key -}}
|
||||||
|
{{ if $commits -}}
|
||||||
### {{ $key }}
|
### {{ $key }}
|
||||||
{{ range $index,$commit := $commits -}}
|
{{ range $index,$commit := $commits -}}
|
||||||
* **{{$.Backtick}}{{$commit.Scope}}{{$.Backtick}}** {{$commit.ParsedMessage}} {{if $.HasURL}} ([{{ printf "%.7s" $commit.Commit.Hash}}]({{ replace $.URL "{{hash}}" $commit.Commit.Hash}})) {{end}}
|
* {{ if $commit.Scope }}**{{$.Backtick}}{{$commit.Scope}}{{$.Backtick}}** {{end}}{{$commit.ParsedMessage}}{{if $.HasURL}} ([{{ printf "%.7s" $commit.Commit.Hash}}]({{ replace $.URL "{{hash}}" $commit.Commit.Hash}})){{end}}
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
{{ end -}}`
|
{{ end -}}`
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ func TestChangelog(t *testing.T) {
|
|||||||
"minor": []shared.AnalyzedCommit{
|
"minor": []shared.AnalyzedCommit{
|
||||||
shared.AnalyzedCommit{
|
shared.AnalyzedCommit{
|
||||||
Commit: shared.Commit{
|
Commit: shared.Commit{
|
||||||
Message: "feat(test): my first commit",
|
Message: "feat(internal/changelog): my first commit",
|
||||||
Author: "me",
|
Author: "me",
|
||||||
Hash: "12345667",
|
Hash: "12345667",
|
||||||
},
|
},
|
||||||
@@ -46,7 +46,30 @@ func TestChangelog(t *testing.T) {
|
|||||||
},
|
},
|
||||||
result: &shared.GeneratedChangelog{
|
result: &shared.GeneratedChangelog{
|
||||||
Title: "v1.0.0 (2019-07-19)",
|
Title: "v1.0.0 (2019-07-19)",
|
||||||
Content: "# v1.0.0 (2019-07-19)\n\n ### Features\n* **`internal/changelog`** my first commit ([1234566](https://commit.url)) \n\n ",
|
Content: "# v1.0.0 (2019-07-19)\n### Features\n* **`internal/changelog`** my first commit ([1234566](https://commit.url))\n",
|
||||||
|
},
|
||||||
|
hasError: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testCase: "feat no scope",
|
||||||
|
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
|
||||||
|
"minor": []shared.AnalyzedCommit{
|
||||||
|
shared.AnalyzedCommit{
|
||||||
|
Commit: shared.Commit{
|
||||||
|
Message: "feat: my first commit",
|
||||||
|
Author: "me",
|
||||||
|
Hash: "12345667",
|
||||||
|
},
|
||||||
|
ParsedMessage: "my first commit",
|
||||||
|
Tag: "feat",
|
||||||
|
TagString: "Features",
|
||||||
|
Print: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
result: &shared.GeneratedChangelog{
|
||||||
|
Title: "v1.0.0 (2019-07-19)",
|
||||||
|
Content: "# v1.0.0 (2019-07-19)\n### Features\n* my first commit ([1234566](https://commit.url))\n",
|
||||||
},
|
},
|
||||||
hasError: false,
|
hasError: false,
|
||||||
},
|
},
|
||||||
@@ -56,7 +79,7 @@ func TestChangelog(t *testing.T) {
|
|||||||
"minor": []shared.AnalyzedCommit{
|
"minor": []shared.AnalyzedCommit{
|
||||||
shared.AnalyzedCommit{
|
shared.AnalyzedCommit{
|
||||||
Commit: shared.Commit{
|
Commit: shared.Commit{
|
||||||
Message: "feat(test): my first commit",
|
Message: "feat(internal/changelog): my first commit",
|
||||||
Author: "me",
|
Author: "me",
|
||||||
Hash: "12345667",
|
Hash: "12345667",
|
||||||
},
|
},
|
||||||
@@ -68,7 +91,7 @@ func TestChangelog(t *testing.T) {
|
|||||||
},
|
},
|
||||||
shared.AnalyzedCommit{
|
shared.AnalyzedCommit{
|
||||||
Commit: shared.Commit{
|
Commit: shared.Commit{
|
||||||
Message: "feat(test): my first break: BREAKING CHANGE: change api to v2",
|
Message: "feat(internal/changelog): my first break: BREAKING CHANGE: change api to v2",
|
||||||
Author: "me",
|
Author: "me",
|
||||||
Hash: "12345668",
|
Hash: "12345668",
|
||||||
},
|
},
|
||||||
@@ -83,7 +106,7 @@ func TestChangelog(t *testing.T) {
|
|||||||
},
|
},
|
||||||
result: &shared.GeneratedChangelog{
|
result: &shared.GeneratedChangelog{
|
||||||
Title: "v1.0.0 (2019-07-19)",
|
Title: "v1.0.0 (2019-07-19)",
|
||||||
Content: "# v1.0.0 (2019-07-19)\n\n## BREAKING CHANGES\n\n* **`internal/changelog`** change api to v2 \nintroduced by commit: \nmy first break ([1234566](https://commit.url)) \n\n ### Features\n* **`internal/changelog`** my first commit ([1234566](https://commit.url)) \n\n ",
|
Content: "# v1.0.0 (2019-07-19)\n## BREAKING CHANGES\n* **`internal/changelog`** change api to v2 \nintroduced by commit: \nmy first break ([1234566](https://commit.url))\n### Features\n* **`internal/changelog`** my first commit ([1234566](https://commit.url))\n",
|
||||||
},
|
},
|
||||||
hasError: false,
|
hasError: false,
|
||||||
},
|
},
|
||||||
@@ -111,9 +134,11 @@ func TestChangelog(t *testing.T) {
|
|||||||
}, time.Date(2019, 7, 19, 0, 0, 0, 0, time.UTC))
|
}, time.Date(2019, 7, 19, 0, 0, 0, 0, time.UTC))
|
||||||
|
|
||||||
for _, config := range testConfigs {
|
for _, config := range testConfigs {
|
||||||
|
t.Run(config.testCase, func(t *testing.T) {
|
||||||
generatedChangelog, err := cl.GenerateChanglog(templateConfig, config.analyzedCommits)
|
generatedChangelog, err := cl.GenerateChanglog(templateConfig, config.analyzedCommits)
|
||||||
assert.Equalf(t, config.hasError, err != nil, "Testcase %s should have error: %t -> %s", config.testCase, config.hasError, err)
|
assert.Equalf(t, config.hasError, err != nil, "Testcase %s should have error: %t -> %s", config.testCase, config.hasError, err)
|
||||||
assert.Equalf(t, config.result, generatedChangelog, "Testcase %s should have generated changelog", config.testCase)
|
assert.Equalf(t, config.result, generatedChangelog, "Testcase %s should have generated changelog", config.testCase)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user