Skip to content

Commit

Permalink
no meaninless pull
Browse files Browse the repository at this point in the history
  • Loading branch information
walteh committed Nov 18, 2023
1 parent 48ac354 commit 1aaa2ec
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 12 deletions.
8 changes: 8 additions & 0 deletions calculate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Calculation struct {
NextValidTag NVT
IsMerge bool
ForcePatch bool
Skip bool
}

var (
Expand Down Expand Up @@ -56,6 +57,13 @@ func (me *Calculation) CalculateNewTagsRaw(ctx context.Context) *CalculationOutp
MergeTags: []string{},
}

if me.Skip {
zerolog.Ctx(ctx).Debug().
Any("calculation", me).
Msg("Skipping calculation")
return out
}

nvt := string(me.NextValidTag)

mmrt := string(me.MyMostRecentTag)
Expand Down
20 changes: 20 additions & 0 deletions calculate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,26 @@ func TestNewCalculationAndCalculateNewTags(t *testing.T) {
MergeTags: []string{},
},
},

{
name: "skip if flagged",
calculation: &simver.Calculation{
ForcePatch: false,
IsMerge: true,
MostRecentLiveTag: "v0.4.2",
MyMostRecentBuild: 3.000000,
MyMostRecentTag: "v0.4.2",
NextValidTag: "v0.5.0",
PR: 3.000000,
Skip: true,
},
output: &simver.CalculationOutput{
BaseTags: []string{},
HeadTags: []string{},
RootTags: []string{},
MergeTags: []string{},
},
},
}

ctx := context.Background()
Expand Down
19 changes: 9 additions & 10 deletions execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func Calculate(ctx context.Context, ex Execution) *Calculation {
IsMerge: ex.IsMerge(),
MostRecentLiveTag: mrlt,
ForcePatch: ForcePatch(ctx, ex, mmrt),
Skip: Skip(ctx, ex, mmrt),
MyMostRecentTag: mmrt,
MyMostRecentBuild: MyMostRecentBuildNumber(ex),
PR: ex.PR(),
Expand Down Expand Up @@ -87,29 +88,27 @@ func BumpPatch[S ~string](arg S) S {

}

func ForcePatch(ctx context.Context, ee Execution, mmrt MMRT) bool {
// if our head branch has a
func Skip(ctx context.Context, ee Execution, mmrt MMRT) bool {
reg := regexp.MustCompile(fmt.Sprintf(`^%s$`, mmrt))

// head commit tags matching mmrt
hct := ee.HeadCommitTags().SemversMatching(func(s string) bool {
return reg.MatchString(s)
})

if len(hct) > 0 {
return false
}
return len(hct) > 0
}

func ForcePatch(ctx context.Context, ee Execution, mmrt MMRT) bool {
// if our head branch has a
reg := regexp.MustCompile(fmt.Sprintf(`^%s$`, mmrt))

// head branch tags matching mmrt
hbt := ee.HeadBranchTags().SemversMatching(func(s string) bool {
return reg.MatchString(s)
})

if len(hbt) > 0 {
return true
}

return false
return len(hbt) > 0
}

func MostRecentLiveTag(e Execution) MRLT {
Expand Down
36 changes: 34 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, bump by patch",
name: "when merging a branch that already is tagged correctly, but not on head, bump by patch",
baseBranchTags: simver.Tags{
simver.Tag{Name: "v0.2.0-pr1+1"},
simver.Tag{Name: "v0.2.0"},
Expand All @@ -487,7 +487,7 @@ func TestNewTags(t *testing.T) {
},
headCommitTags: simver.Tags{
simver.Tag{Name: "v0.3.0-reserved"},
simver.Tag{Name: "v0.3.0"},
// simver.Tag{Name: "v0.3.0"},
},
rootBranchTags: simver.Tags{
simver.Tag{Name: "v0.2.0-pr1+1"},
Expand All @@ -503,6 +503,38 @@ func TestNewTags(t *testing.T) {
simver.Tag{Name: "v0.3.1", Ref: merge_ref},
},
},
{
name: "when merging a branch that already is tagged correctly, on head, do nothing",
baseBranchTags: simver.Tags{
simver.Tag{Name: "v0.2.0-pr1+1"},
simver.Tag{Name: "v0.2.0"},
simver.Tag{Name: "v0.3.0-pr1+base"},
simver.Tag{Name: "v0.3.0-reserved"},
simver.Tag{Name: "v0.3.0"},
},
headBranchTags: simver.Tags{
simver.Tag{Name: "v0.2.0-pr1+1"},
simver.Tag{Name: "v0.2.0"},
simver.Tag{Name: "v0.3.0-pr1+base"},
simver.Tag{Name: "v0.3.0-reserved"},
simver.Tag{Name: "v0.3.0"},
},
headCommitTags: simver.Tags{
simver.Tag{Name: "v0.3.0-reserved"},
simver.Tag{Name: "v0.3.0"},
},
rootBranchTags: simver.Tags{
simver.Tag{Name: "v0.2.0-pr1+1"},
simver.Tag{Name: "v0.2.0"},
simver.Tag{Name: "v0.3.0-pr1+base"},
simver.Tag{Name: "v0.3.0-reserved"},
simver.Tag{Name: "v0.3.0"},
},
pr: 1,
isMerge: true,
isTargetingRoot: true,
expectedTags: simver.Tags{},
},
}

ctx := context.Background()
Expand Down

0 comments on commit 1aaa2ec

Please sign in to comment.