Skip to content

Commit

Permalink
bump by patch (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
walteh authored Nov 18, 2023
2 parents 246b1eb + 8ed2387 commit 48ac354
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 17 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.4.2-pr3+2",
},
{
name: run simver,
Expand Down
29 changes: 19 additions & 10 deletions calculate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
Expand Down
44 changes: 41 additions & 3 deletions calculate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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{},
},
},
Expand Down
6 changes: 4 additions & 2 deletions execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -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},
},
},
}

Expand Down
2 changes: 1 addition & 1 deletion simver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 48ac354

Please sign in to comment.