From b82832b2bd1dc343a80eb1f086c1468f1f31baf6 Mon Sep 17 00:00:00 2001 From: walter Date: Sat, 18 Nov 2023 08:04:51 -0600 Subject: [PATCH 1/4] bump by patch --- calculate.go | 12 ++++++------ calculate_test.go | 8 ++++---- execution_test.go | 6 ++++-- simver.go | 2 +- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/calculate.go b/calculate.go index 524bbdf..e6544ed 100644 --- a/calculate.go +++ b/calculate.go @@ -62,13 +62,13 @@ 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 } + matching := mmrt == mrlt + validMmrt := false // first we validate that mmrt is still valid, which means it is greater than or equal to mrlt @@ -77,7 +77,7 @@ func (me *Calculation) CalculateNewTagsRaw(ctx context.Context) *CalculationOutp } // force patch is ignored if this is a merge - if me.ForcePatch && !me.IsMerge { + if (me.ForcePatch && !me.IsMerge) || matching { nvt = BumpPatch(mmrt) validMmrt = false } @@ -93,9 +93,9 @@ func (me *Calculation) CalculateNewTagsRaw(ctx context.Context) *CalculationOutp } 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..befd157 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,7 +226,7 @@ func TestNewCalculationAndCalculateNewTags(t *testing.T) { BaseTags: []string{}, HeadTags: []string{}, RootTags: []string{}, - MergeTags: []string{}, + MergeTags: []string{"v0.2.1"}, }, }, } 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 { From 0c2e2e0cbb59abfb1209a73f9e90a73a5ac1d166 Mon Sep 17 00:00:00 2001 From: walter Date: Sat, 18 Nov 2023 08:27:32 -0600 Subject: [PATCH 2/4] more fixes --- .github/workflows/simver.yaml | 2 +- calculate.go | 21 +++++++++++++------ calculate_test.go | 38 +++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 7 deletions(-) diff --git a/.github/workflows/simver.yaml b/.github/workflows/simver.yaml index bb001a4..3301ec6 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.5.0", }, { name: run simver, diff --git a/calculate.go b/calculate.go index e6544ed..18f040e 100644 --- a/calculate.go +++ b/calculate.go @@ -67,17 +67,26 @@ func (me *Calculation) CalculateNewTagsRaw(ctx context.Context) *CalculationOutp mrlt = baseTag } - matching := mmrt == mrlt + // 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) || matching { + 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,8 +96,8 @@ 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)) } } diff --git a/calculate_test.go b/calculate_test.go index befd157..7f64b32 100644 --- a/calculate_test.go +++ b/calculate_test.go @@ -229,6 +229,44 @@ func TestNewCalculationAndCalculateNewTags(t *testing.T) { 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{}, + }, + }, } ctx := context.Background() From dc80a9d508fdc4991ecd33889bc7034194450a09 Mon Sep 17 00:00:00 2001 From: walter Date: Sat, 18 Nov 2023 08:28:43 -0600 Subject: [PATCH 3/4] tmp --- .github/workflows/simver.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/simver.yaml b/.github/workflows/simver.yaml index 3301ec6..a684c0c 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.5.0", + run: "go install github.com/walteh/simver/cmd/simver_github_actions@v0.4.1-tmp", }, { name: run simver, From 8ed23873d3ec392ad56ddd9fcc4414cee186fc2e Mon Sep 17 00:00:00 2001 From: walter Date: Sat, 18 Nov 2023 08:53:11 -0600 Subject: [PATCH 4/4] bump workflow to working version --- .github/workflows/simver.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/simver.yaml b/.github/workflows/simver.yaml index a684c0c..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-tmp", + run: "go install github.com/walteh/simver/cmd/simver_github_actions@v0.4.2-pr3+2", }, { name: run simver,