From 09943540896404387a615f0bc867aa10e4eb7501 Mon Sep 17 00:00:00 2001 From: Nightapes Date: Tue, 3 Sep 2019 21:34:00 +0200 Subject: [PATCH 1/4] fix(internal/calculator): fix relase version calculation --- .github/workflows/main.yml | 1 + internal/calculator/calculator.go | 5 +++++ internal/gitutil/gitutil.go | 4 ++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 71444b6..a20cf83 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -30,6 +30,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | go build -o build/go-semantic-release-temp ./cmd/go-semantic-release/ + ./build/go-semantic-release-temp next --no-cache --loglevel trace 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/ diff --git a/internal/calculator/calculator.go b/internal/calculator/calculator.go index 21558ae..dfcaa22 100644 --- a/internal/calculator/calculator.go +++ b/internal/calculator/calculator.go @@ -49,6 +49,11 @@ func (c *Calculator) CalculateNewVersion(commits map[shared.Release][]shared.Ana } case "release": if !firstRelease { + if lastVersion.Prerelease() != "" { + newVersion, _ := lastVersion.SetPrerelease("") + return newVersion + } + if len(commits["major"]) > 0 { return lastVersion.IncMajor() } else if len(commits["minor"]) > 0 { diff --git a/internal/gitutil/gitutil.go b/internal/gitutil/gitutil.go index b161864..1ebb33d 100644 --- a/internal/gitutil/gitutil.go +++ b/internal/gitutil/gitutil.go @@ -6,11 +6,11 @@ import ( "sort" "github.com/Masterminds/semver" + "github.com/Nightapes/go-semantic-release/internal/shared" log "github.com/sirupsen/logrus" "gopkg.in/src-d/go-git.v4" "gopkg.in/src-d/go-git.v4/plumbing" "gopkg.in/src-d/go-git.v4/plumbing/object" - "github.com/Nightapes/go-semantic-release/internal/shared" ) // GitUtil struct @@ -87,7 +87,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("%+v with hash: %s", p.Target(), p.Hash()) + log.Tracef("Tag %+v with hash: %s", p.Target(), p.Hash()) if err == nil { tags = append(tags, v) From 76ffeda95b636fa49ed5fa529a3d84254af08d01 Mon Sep 17 00:00:00 2001 From: Nightapes Date: Tue, 3 Sep 2019 21:44:38 +0200 Subject: [PATCH 2/4] fix(analyzer/angular): allow multi line commits --- internal/analyzer/angular.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/analyzer/angular.go b/internal/analyzer/angular.go index d4e6516..fbfc36b 100644 --- a/internal/analyzer/angular.go +++ b/internal/analyzer/angular.go @@ -22,7 +22,7 @@ const ANGULAR = "angular" func newAngular() *angular { return &angular{ - regex: `^(TAG)(?:\((.*)\))?: (.*)$`, + regex: `^(TAG)(?:\((.*)\))?: (.*)`, log: log.WithField("analyzer", ANGULAR), rules: []Rule{ { From e5ed8edb7529b0c8e191d13f975fb09ff31ab637 Mon Sep 17 00:00:00 2001 From: Nightapes Date: Tue, 3 Sep 2019 22:18:13 +0200 Subject: [PATCH 3/4] refactor(ci): add trace log --- internal/ci/ci.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/ci/ci.go b/internal/ci/ci.go index 066271c..b1b486d 100644 --- a/internal/ci/ci.go +++ b/internal/ci/ci.go @@ -50,6 +50,7 @@ func GetCIProvider(gitUtil *gitutil.GitUtil, envs map[string]string) (*ProviderC config, err := service.detect(envs) if err == nil { log.Infof("Found CI: %s", config.Name) + log.Tracef("Found CI config: %+v", config) return config, nil } log.Debugf("%s", err.Error()) From d03913e6d733591757ef0d6b211d45f72d049d3c Mon Sep 17 00:00:00 2001 From: Nightapes Date: Tue, 3 Sep 2019 22:35:17 +0200 Subject: [PATCH 4/4] fix(pkg/semanticrelease): remove check for branch prefix for releases --- pkg/semanticrelease/semantic-release.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/semanticrelease/semantic-release.go b/pkg/semanticrelease/semantic-release.go index a18e946..bea56bb 100644 --- a/pkg/semanticrelease/semantic-release.go +++ b/pkg/semanticrelease/semantic-release.go @@ -2,7 +2,6 @@ package semanticrelease import ( "io/ioutil" - "strings" "time" "github.com/Masterminds/semver" @@ -98,14 +97,21 @@ func (s *SemanticRelease) GetNextVersion(provider *ci.ProviderConfig, force bool analyzedCommits := s.analyzer.Analyze(commits) var newVersion semver.Version + foundBranchConfig := false for branch, releaseType := range s.config.Branch { - if provider.Branch == branch || strings.HasPrefix(provider.Branch, branch) { + if provider.Branch == branch { log.Debugf("Found branch config for branch %s with release type %s", provider.Branch, releaseType) newVersion = s.calculator.CalculateNewVersion(analyzedCommits, lastVersion, releaseType, firstRelease) + foundBranchConfig = true break } } + if !foundBranchConfig { + log.Warnf("No branch config found for branch %s, will return last known version", provider.Branch) + newVersion = *lastVersion + } + releaseVersion := shared.ReleaseVersion{ Next: shared.ReleaseVersionEntry{ Commit: provider.Commit,