Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
walteh committed Nov 18, 2023
1 parent b82832b commit 0c2e2e0
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/simver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 15 additions & 6 deletions calculate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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))
}
}

Expand Down
38 changes: 38 additions & 0 deletions calculate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 0c2e2e0

Please sign in to comment.