From b42d7a2e97b78469bee037c887813eaa32e1adc8 Mon Sep 17 00:00:00 2001 From: Michael McCallum Date: Mon, 29 Jun 2020 14:17:47 +1200 Subject: [PATCH] Allow 2 point versions in images: We only use 2 points X.Y always unless there is really a patch which is extremely uncommon. Developers choose the X and tooling chooses the Y. That is the developers only ever have to make a simple decision did I break it or not. * these are still semver but just treat the patch as optional * add tests for various combinations of updates --- internal/policy/semver.go | 2 +- internal/policy/semver_test.go | 50 ++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/internal/policy/semver.go b/internal/policy/semver.go index 50f65cd5..d7bf2952 100644 --- a/internal/policy/semver.go +++ b/internal/policy/semver.go @@ -69,7 +69,7 @@ func shouldUpdate(spt SemverPolicyType, matchPreRelease bool, current, new strin } parts := strings.SplitN(new, ".", 3) - if len(parts) != 3 { + if len(parts) != 2 && len(parts) != 3 { return false, ErrNoMajorMinorPatchElementsFound } diff --git a/internal/policy/semver_test.go b/internal/policy/semver_test.go index 5222050f..7bfbd8cd 100644 --- a/internal/policy/semver_test.go +++ b/internal/policy/semver_test.go @@ -47,6 +47,16 @@ func Test_shouldUpdate(t *testing.T) { want: false, wantErr: false, }, + { + name: "minor increase - 2 points, policy all", + args: args{ + current: "1.4", + new: "1.5", + spt: SemverPolicyTypeAll, + }, + want: true, + wantErr: false, + }, { name: "minor increase, policy major", args: args{ @@ -77,6 +87,26 @@ func Test_shouldUpdate(t *testing.T) { want: true, wantErr: false, }, + { + name: "patch release, policy patch", + args: args{ + current: "1.4", + new: "1.4.6", + spt: SemverPolicyTypePatch, + }, + want: true, + wantErr: false, + }, + { + name: "minor and patch release, policy patch", + args: args{ + current: "1.4", + new: "1.5.6", + spt: SemverPolicyTypePatch, + }, + want: false, + wantErr: false, + }, { name: "patch decrease, policy patch", args: args{ @@ -87,6 +117,16 @@ func Test_shouldUpdate(t *testing.T) { want: false, wantErr: false, }, + { + name: "2 points minor change, policy patch", + args: args{ + current: "1.4", + new: "1.5", + spt: SemverPolicyTypePatch, + }, + want: false, + wantErr: false, + }, { name: "patch AND major increase, policy patch", args: args{ @@ -117,6 +157,16 @@ func Test_shouldUpdate(t *testing.T) { want: true, wantErr: false, }, + { + name: "minor increase 2 points, policy minor", + args: args{ + current: "1.4", + new: "1.5", + spt: SemverPolicyTypeMinor, + }, + want: true, + wantErr: false, + }, { name: "patch increase, policy minor", args: args{