You've already forked go-semantic-release
Compare commits
11 Commits
v1.2.0
...
v1.2.3-bet
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af5c8f5ae3 | ||
|
|
c361744a35 | ||
|
|
6a375f3bab | ||
|
|
d4627a9d46 | ||
|
|
af2addbffd | ||
|
|
7157d64b7b | ||
|
|
575ba5d5bd | ||
|
|
a8b68f9182 | ||
|
|
f6a2d837b1 | ||
|
|
279509c922 | ||
|
|
d0035d6bca |
6
.github/workflows/main.yml
vendored
6
.github/workflows/main.yml
vendored
@@ -35,9 +35,12 @@ jobs:
|
||||
- name: Build Docker image
|
||||
if: github.ref != 'refs/heads/master'
|
||||
run: |
|
||||
docker build -t nightapes/go-semantic-release:development .
|
||||
docker login -u nightapes -p ${{ secrets.DOCKER_PASSWORD }}
|
||||
docker login -u nightapes -p ${{ secrets.GITHUB_TOKEN }} docker.pkg.github.com
|
||||
docker build -t nightapes/go-semantic-release:development .
|
||||
docker push nightapes/go-semantic-release:development
|
||||
docker tag nightapes/go-semantic-release:development docker.pkg.github.com/nightapes/go-semantic-release/go-semantic-release:development
|
||||
docker push docker.pkg.github.com/nightapes/go-semantic-release/go-semantic-release:development
|
||||
|
||||
- name: Push Docker image
|
||||
if: github.ref != 'refs/heads/master'
|
||||
@@ -48,4 +51,5 @@ jobs:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
docker login -u nightapes -p ${{ secrets.DOCKER_PASSWORD }}
|
||||
docker login -u nightapes -p $GITHUB_TOKEN docker.pkg.github.com
|
||||
./build/go-semantic-release-temp release --loglevel trace
|
||||
|
||||
@@ -5,6 +5,7 @@ github:
|
||||
commitFormat: angular
|
||||
branch:
|
||||
master: release
|
||||
beta: beta
|
||||
assets:
|
||||
- name: ./build/go-semantic-release
|
||||
compress: false
|
||||
@@ -17,7 +18,9 @@ changelog:
|
||||
hooks:
|
||||
preRelease:
|
||||
- docker build -t nightapes/go-semantic-release:latest .
|
||||
- docker build -t nightapes/go-semantic-release:$RELEASE_VERSION .
|
||||
- docker tag nightapes/go-semantic-release:latest docker.pkg.github.com/nightapes/go-semantic-release/go-semantic-release:$RELEASE_VERSION
|
||||
- docker tag nightapes/go-semantic-release:latest nightapes/go-semantic-release:$RELEASE_VERSION
|
||||
postRelease:
|
||||
- docker push nightapes/go-semantic-release:latest
|
||||
- docker push nightapes/go-semantic-release:$RELEASE_VERSION
|
||||
- docker push docker.pkg.github.com/nightapes/go-semantic-release/go-semantic-release:$RELEASE_VERSION
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
## Release Types
|
||||
|
||||
| Type | Implemendet | Git tag | Changelog | Release | Write access git | Api token |
|
||||
| ---------- | :----------------: | :----------------: | :----------------: | :----------------: | :----------------: | :----------------: |
|
||||
| ----------- | :----------------: | :----------------: | :----------------: | :----------------: | :----------------: | :----------------: |
|
||||
| `github` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | :white_check_mark: |
|
||||
| `gitlab` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | :white_check_mark: |
|
||||
| `git` | :white_check_mark: | :white_check_mark: | | | :white_check_mark: | |
|
||||
| `bitbuckt` | Comming soon | :white_check_mark: | | | :white_check_mark: | |
|
||||
| `bitbucket` | Comming soon | :white_check_mark: | | | :white_check_mark: | |
|
||||
|
||||
|
||||
## Supported CI Pipelines
|
||||
|
||||
64
cmd/go-semantic-release/commands/hooks.go
Normal file
64
cmd/go-semantic-release/commands/hooks.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"github.com/Nightapes/go-semantic-release/internal/hooks"
|
||||
"github.com/Nightapes/go-semantic-release/pkg/semanticrelease"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(hooksCmd)
|
||||
}
|
||||
|
||||
var hooksCmd = &cobra.Command{
|
||||
Use: "hooks",
|
||||
Short: "Run all hooks",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
config, err := cmd.Flags().GetString("config")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
repository, err := cmd.Flags().GetString("repository")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
force, err := cmd.Flags().GetBool("no-cache")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ignoreConfigChecks, err := cmd.Flags().GetBool("no-checks")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
releaseConfig := readConfig(config)
|
||||
|
||||
s, err := semanticrelease.New(releaseConfig, repository, !ignoreConfigChecks)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
provider, err := s.GetCIProvider()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
releaseVersion, err := s.GetNextVersion(provider, force)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
hook := hooks.New(releaseConfig, releaseVersion)
|
||||
|
||||
err = hook.PreRelease()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return hook.PostRelease()
|
||||
},
|
||||
}
|
||||
@@ -19,9 +19,9 @@ func New() *Calculator {
|
||||
}
|
||||
|
||||
//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"
|
||||
if version.Prerelease() == "" || !strings.HasPrefix(version.Prerelease(), preReleaseType) {
|
||||
if !c.hasPrerelease(version, preReleaseType) {
|
||||
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())
|
||||
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())
|
||||
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
|
||||
func (c *Calculator) CalculateNewVersion(commits map[shared.Release][]shared.AnalyzedCommit, lastVersion *semver.Version, releaseType string, firstRelease bool) semver.Version {
|
||||
switch releaseType {
|
||||
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 {
|
||||
version, _ := c.IncPrerelease(releaseType, lastVersion)
|
||||
version, _ := c.IncPrerelease(releaseType, version)
|
||||
return version
|
||||
}
|
||||
case "release":
|
||||
@@ -53,16 +65,23 @@ func (c *Calculator) CalculateNewVersion(commits map[shared.Release][]shared.Ana
|
||||
newVersion, _ := lastVersion.SetPrerelease("")
|
||||
return newVersion
|
||||
}
|
||||
|
||||
if len(commits["major"]) > 0 {
|
||||
return lastVersion.IncMajor()
|
||||
} else if len(commits["minor"]) > 0 {
|
||||
return lastVersion.IncMinor()
|
||||
} else if len(commits["patch"]) > 0 {
|
||||
return lastVersion.IncPatch()
|
||||
version, done := c.inc(commits, lastVersion)
|
||||
if done {
|
||||
return version
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
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.Equal(t, test.nextVersion, next.String())
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
@@ -79,7 +81,7 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
|
||||
testCase: "version with preRelease alpha",
|
||||
releaseType: "alpha",
|
||||
lastVersion: createVersion("1.0.0"),
|
||||
nextVersion: "1.0.0-alpha.0",
|
||||
nextVersion: "1.1.0-alpha.0",
|
||||
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
|
||||
"major": []shared.AnalyzedCommit{},
|
||||
"minor": []shared.AnalyzedCommit{
|
||||
@@ -94,7 +96,7 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
|
||||
testCase: "version with preRelease beta",
|
||||
releaseType: "beta",
|
||||
lastVersion: createVersion("1.0.0"),
|
||||
nextVersion: "1.0.0-beta.0",
|
||||
nextVersion: "1.1.0-beta.0",
|
||||
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
|
||||
"major": []shared.AnalyzedCommit{},
|
||||
"minor": []shared.AnalyzedCommit{
|
||||
@@ -135,7 +137,7 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
|
||||
testCase: "version with commits and rc release",
|
||||
releaseType: "rc",
|
||||
lastVersion: createVersion("1.0.0"),
|
||||
nextVersion: "1.0.0-rc.0",
|
||||
nextVersion: "2.0.0-rc.0",
|
||||
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
|
||||
"major": []shared.AnalyzedCommit{shared.AnalyzedCommit{}},
|
||||
"minor": []shared.AnalyzedCommit{shared.AnalyzedCommit{}},
|
||||
@@ -201,8 +203,10 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
|
||||
c := calculator.New()
|
||||
|
||||
for _, test := range testConfigs {
|
||||
t.Run(test.testCase, func(t *testing.T) {
|
||||
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)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,18 +15,19 @@ import (
|
||||
)
|
||||
|
||||
const defaultCommitList string = `{{ range $index,$commit := .BreakingChanges -}}
|
||||
{{ if eq $index 0 }}
|
||||
{{ if eq $index 0 -}}
|
||||
## BREAKING CHANGES
|
||||
{{ end}}
|
||||
* **{{$.Backtick}}{{$commit.Scope}}{{$.Backtick}}** {{$commit.ParsedBreakingChangeMessage}}
|
||||
{{ end -}}
|
||||
* {{ if $commit.Scope }}**{{$.Backtick}}{{$commit.Scope}}{{$.Backtick}}**{{ end }} {{$commit.ParsedBreakingChangeMessage}}
|
||||
introduced by commit:
|
||||
{{$commit.ParsedMessage}} {{if $.HasURL}} ([{{ printf "%.7s" $commit.Commit.Hash}}]({{ replace $.URL "{{hash}}" $commit.Commit.Hash}})){{end}}
|
||||
{{ end -}}
|
||||
{{ range $key := .Order }}
|
||||
{{ $commits := index $.Commits $key}} {{if $commits -}}
|
||||
{{ range $key := .Order -}}
|
||||
{{ $commits := index $.Commits $key -}}
|
||||
{{ if $commits -}}
|
||||
### {{ $key }}
|
||||
{{ 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 -}}`
|
||||
|
||||
@@ -32,7 +32,7 @@ func TestChangelog(t *testing.T) {
|
||||
"minor": []shared.AnalyzedCommit{
|
||||
shared.AnalyzedCommit{
|
||||
Commit: shared.Commit{
|
||||
Message: "feat(test): my first commit",
|
||||
Message: "feat(internal/changelog): my first commit",
|
||||
Author: "me",
|
||||
Hash: "12345667",
|
||||
},
|
||||
@@ -46,7 +46,30 @@ func TestChangelog(t *testing.T) {
|
||||
},
|
||||
result: &shared.GeneratedChangelog{
|
||||
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,
|
||||
},
|
||||
@@ -56,7 +79,7 @@ func TestChangelog(t *testing.T) {
|
||||
"minor": []shared.AnalyzedCommit{
|
||||
shared.AnalyzedCommit{
|
||||
Commit: shared.Commit{
|
||||
Message: "feat(test): my first commit",
|
||||
Message: "feat(internal/changelog): my first commit",
|
||||
Author: "me",
|
||||
Hash: "12345667",
|
||||
},
|
||||
@@ -68,7 +91,7 @@ func TestChangelog(t *testing.T) {
|
||||
},
|
||||
shared.AnalyzedCommit{
|
||||
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",
|
||||
Hash: "12345668",
|
||||
},
|
||||
@@ -83,7 +106,7 @@ func TestChangelog(t *testing.T) {
|
||||
},
|
||||
result: &shared.GeneratedChangelog{
|
||||
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,
|
||||
},
|
||||
@@ -111,9 +134,11 @@ func TestChangelog(t *testing.T) {
|
||||
}, time.Date(2019, 7, 19, 0, 0, 0, 0, time.UTC))
|
||||
|
||||
for _, config := range testConfigs {
|
||||
t.Run(config.testCase, func(t *testing.T) {
|
||||
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.result, generatedChangelog, "Testcase %s should have generated changelog", config.testCase)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ func (g *GitUtil) GetLastVersion() (*semver.Version, string, error) {
|
||||
|
||||
err = gitTags.ForEach(func(p *plumbing.Reference) error {
|
||||
v, err := semver.NewVersion(p.Name().Short())
|
||||
log.Tracef("Tag %+v with hash: %s", p.Target(), p.Hash())
|
||||
log.Tracef("Tag %+v with hash: %s", p.Name().Short(), p.Hash())
|
||||
|
||||
if err == nil {
|
||||
tags = append(tags, v)
|
||||
|
||||
@@ -3,6 +3,7 @@ package hooks
|
||||
import (
|
||||
"bufio"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/Nightapes/go-semantic-release/internal/shared"
|
||||
@@ -51,9 +52,14 @@ func (h *Hooks) PostRelease() error {
|
||||
|
||||
func (h *Hooks) runCommand(command string) error {
|
||||
|
||||
splittedCmd := strings.Split(strings.ReplaceAll(command, "$RELEASE_VERSION", h.version.Next.Version.String()), " ")
|
||||
cmdReplaced := strings.ReplaceAll(command, "$RELEASE_VERSION", h.version.Next.Version.String())
|
||||
|
||||
cmd := exec.Command(splittedCmd[0], splittedCmd[1:]...)
|
||||
var cmd *exec.Cmd
|
||||
if runtime.GOOS == "windows" {
|
||||
cmd = exec.Command("cmd.exe", "/C", cmdReplaced)
|
||||
} else {
|
||||
cmd = exec.Command("sh", "-c", cmdReplaced)
|
||||
}
|
||||
|
||||
cmdReader, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
@@ -63,7 +69,7 @@ func (h *Hooks) runCommand(command string) error {
|
||||
scanner := bufio.NewScanner(cmdReader)
|
||||
go func() {
|
||||
for scanner.Scan() {
|
||||
log.WithField("cmd", splittedCmd[0]).Infof("%s\n", scanner.Text())
|
||||
log.WithField("cmd", strings.Fields(cmdReplaced)[0]).Infof("%s\n", scanner.Text())
|
||||
}
|
||||
}()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user