diff --git a/.github/workflows/simver.yaml b/.github/workflows/simver.yaml index bb001a4..d334ecc 100644 --- a/.github/workflows/simver.yaml +++ b/.github/workflows/simver.yaml @@ -30,7 +30,7 @@ }, { name: install simver, - run: "go install github.com/walteh/simver/cmd/simver_github_actions@v0.4.1", + run: "go install github.com/walteh/simver/cmd/simver_github_actions@v0.4.2-pr3+2", }, { name: run simver, diff --git a/calculate.go b/calculate.go index 524bbdf..18f040e 100644 --- a/calculate.go +++ b/calculate.go @@ -62,22 +62,31 @@ func (me *Calculation) CalculateNewTagsRaw(ctx context.Context) *CalculationOutp mrlt := string(me.MostRecentLiveTag) - matching := mmrt == mrlt - // first we check to see if mrlt exists, if not we set it to the base if mrlt == "" { mrlt = baseTag } + // mmrt and mrlt will always be the same on the first pr build + // matching := mmrt == mrlt && me.MyMostRecentBuild != 0 + validMmrt := false // first we validate that mmrt is still valid, which means it is greater than or equal to mrlt - if mmrt != "" && semver.Compare(mmrt, mrlt) >= 0 { + if mmrt != "" && semver.Compare(mmrt, mrlt) > 0 { validMmrt = true } - // force patch is ignored if this is a merge - if me.ForcePatch && !me.IsMerge { + if mmrt != "" && semver.Compare(mmrt, mrlt) == 0 && me.MyMostRecentBuild != 0 { + validMmrt = false + nvt = BumpPatch(mmrt) + } + + if me.MyMostRecentBuild == 0 { + validMmrt = false + + // force patch is ignored if this is a merge + } else if me.ForcePatch && !me.IsMerge { nvt = BumpPatch(mmrt) validMmrt = false } @@ -87,15 +96,15 @@ func (me *Calculation) CalculateNewTagsRaw(ctx context.Context) *CalculationOutp mmrt = nvt // pr will be 0 if this is not a and is a push to the root branch if me.PR != 0 && !me.IsMerge { - out.RootTags = append(out.RootTags, nvt+"-reserved") - out.BaseTags = append(out.BaseTags, nvt+fmt.Sprintf("-pr%d+base", me.PR)) + out.RootTags = append(out.RootTags, mmrt+"-reserved") + out.BaseTags = append(out.BaseTags, mmrt+fmt.Sprintf("-pr%d+base", me.PR)) } } if me.IsMerge { - if !matching { - out.MergeTags = append(out.MergeTags, mmrt) - } + // if !matching { + out.MergeTags = append(out.MergeTags, mmrt) + // } } else { if me.PR == 0 { out.HeadTags = append(out.HeadTags, mmrt) diff --git a/calculate_test.go b/calculate_test.go index 9a618f0..7f64b32 100644 --- a/calculate_test.go +++ b/calculate_test.go @@ -194,7 +194,7 @@ func TestNewCalculationAndCalculateNewTags(t *testing.T) { }, }, { - name: "when merging a branch that already is tagged correctly, don't do anything", + name: "when merging a branch that already is tagged correctly, bump by patch", calculation: &simver.Calculation{ ForcePatch: false, IsMerge: true, @@ -208,11 +208,11 @@ func TestNewCalculationAndCalculateNewTags(t *testing.T) { BaseTags: []string{}, HeadTags: []string{}, RootTags: []string{}, - MergeTags: []string{}, + MergeTags: []string{"v0.3.1"}, }, }, { - name: "when merging a branch that already is tagged correctly, don't do anything (ignoring force patch)", + name: "when merging a branch that already is tagged correctly, bump by patch (ignoring force patch)", calculation: &simver.Calculation{ ForcePatch: true, IsMerge: true, @@ -226,6 +226,44 @@ func TestNewCalculationAndCalculateNewTags(t *testing.T) { BaseTags: []string{}, HeadTags: []string{}, RootTags: []string{}, + MergeTags: []string{"v0.2.1"}, + }, + }, + { + name: "when merging a branch that already is tagged correctly on first build, bump to next", + calculation: &simver.Calculation{ + ForcePatch: true, + IsMerge: true, + MostRecentLiveTag: "v0.2.0", + MyMostRecentBuild: 0, + MyMostRecentTag: "v0.2.0", + NextValidTag: "v0.3.0", + PR: 1.000000, + }, + output: &simver.CalculationOutput{ + BaseTags: []string{}, + HeadTags: []string{}, + RootTags: []string{}, + MergeTags: []string{"v0.3.0"}, + }, + }, + + { + name: "when starting a branch on the first build, bump to next", + calculation: &simver.Calculation{ + + ForcePatch: true, + IsMerge: false, + MostRecentLiveTag: "v0.4.1", + MyMostRecentBuild: 0.000000, + MyMostRecentTag: "v0.4.1", + NextValidTag: "v0.5.0", + PR: 3.000000, + }, + output: &simver.CalculationOutput{ + BaseTags: []string{"v0.5.0-pr3+base"}, + HeadTags: []string{"v0.5.0-pr3+1"}, + RootTags: []string{"v0.5.0-reserved"}, MergeTags: []string{}, }, }, diff --git a/execution_test.go b/execution_test.go index ffd1ac4..6322e45 100644 --- a/execution_test.go +++ b/execution_test.go @@ -470,7 +470,7 @@ func TestNewTags(t *testing.T) { }, }, { - name: "when merging a branch that already is tagged correctly, don't do anything", + name: "when merging a branch that already is tagged correctly, bump by patch", baseBranchTags: simver.Tags{ simver.Tag{Name: "v0.2.0-pr1+1"}, simver.Tag{Name: "v0.2.0"}, @@ -499,7 +499,9 @@ func TestNewTags(t *testing.T) { pr: 1, isMerge: true, isTargetingRoot: true, - expectedTags: simver.Tags{}, + expectedTags: simver.Tags{ + simver.Tag{Name: "v0.3.1", Ref: merge_ref}, + }, }, } diff --git a/simver.go b/simver.go index 743b0bb..2a89466 100644 --- a/simver.go +++ b/simver.go @@ -61,7 +61,7 @@ func (e *rawExecution) PR() int { } func (e *rawExecution) IsMerge() bool { - return e.pr.Merged + return !e.pr.IsSimulatedPush() && e.pr.Merged } func (e *rawExecution) RootBranch() string {