Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Merge pull request #3223 from xmudrii/fix-release-comparison" #3254

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions pkg/release/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,17 +282,7 @@ func (p *Publisher) VerifyLatestUpdate(
return false, fmt.Errorf("invalid GCS version format %s", gcsVersion)
}

// The version format that we use is:
// - Stable: "v<major>.<minor>.<patch>-<number-of-commits>+<build-number>"
// - Prerelease: "v<major>.<minor>.<patch>-<prerelease>.<number-of-commits>+<build-number>"
// blang/semver library considers "-<number-of-commits>" part as the prerelease part even though
// the version is stable. This is causing issues when we're supposed to bump the version marker
// from rc to stable.
// blang/semver models prerelease as a slice of prereleases, so stable releases
// are going to have one element (the number of commits), and prereleases are going to have three elements
// (alpha/beta/rc, number of prerelease, number of commits).
// We can use this to determine when we're switching from rc to stable and act accordingly.
if sv.LTE(gcsSemverVersion) && len(sv.Pre) >= len(gcsSemverVersion.Pre) {
if sv.LTE(gcsSemverVersion) {
logrus.Infof(
"Not updating version, because %s <= %s", version, gcsVersion,
)
Expand Down
177 changes: 0 additions & 177 deletions pkg/release/publish_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,180 +325,3 @@ func TestPublishReleaseNotesIndex(t *testing.T) {
}
}
}

func TestVerifyLatestUpdate(t *testing.T) {
for _, tc := range []struct {
prepare func(*releasefakes.FakePublisherClient, string)
version string
gcsVersion string
needsUpdate bool
shouldError bool
}{
{ // success same version
prepare: func(mock *releasefakes.FakePublisherClient, gcsVersion string) {
mock.NormalizePathReturns("", nil)
mock.GSUtilOutputReturns(gcsVersion, nil)
},
version: "v1.24.0",
gcsVersion: "v1.24.0",
needsUpdate: false,
shouldError: false,
},

{ // success version > gcsVersion (patch)
prepare: func(mock *releasefakes.FakePublisherClient, gcsVersion string) {
mock.NormalizePathReturns("", nil)
mock.GSUtilOutputReturns(gcsVersion, nil)
},
version: "v1.24.1",
gcsVersion: "v1.24.0",
needsUpdate: true,
shouldError: false,
},
{ // success version < gcsVersion (patch)
prepare: func(mock *releasefakes.FakePublisherClient, gcsVersion string) {
mock.NormalizePathReturns("", nil)
mock.GSUtilOutputReturns(gcsVersion, nil)
},
version: "v1.24.0",
gcsVersion: "v1.24.1",
needsUpdate: false,
shouldError: false,
},

{ // success version > gcsVersion (minor)
prepare: func(mock *releasefakes.FakePublisherClient, gcsVersion string) {
mock.NormalizePathReturns("", nil)
mock.GSUtilOutputReturns(gcsVersion, nil)
},
version: "v1.25.0",
gcsVersion: "v1.24.0",
needsUpdate: true,
shouldError: false,
},
{ // success version < gcsVersion (minor)
prepare: func(mock *releasefakes.FakePublisherClient, gcsVersion string) {
mock.NormalizePathReturns("", nil)
mock.GSUtilOutputReturns(gcsVersion, nil)
},
version: "v1.23.0",
gcsVersion: "v1.24.0",
needsUpdate: false,
shouldError: false,
},

{ // success version = gcsVersion (with build version)
prepare: func(mock *releasefakes.FakePublisherClient, gcsVersion string) {
mock.NormalizePathReturns("", nil)
mock.GSUtilOutputReturns(gcsVersion, nil)
},
version: "v1.28.0-7+c4e17abb04728e",
gcsVersion: "v1.28.0-7+c4e17abb04728e",
needsUpdate: false,
shouldError: false,
},
{ // success version > gcsVersion (with build version)
prepare: func(mock *releasefakes.FakePublisherClient, gcsVersion string) {
mock.NormalizePathReturns("", nil)
mock.GSUtilOutputReturns(gcsVersion, nil)
},
version: "v1.28.0-9+aaaaaabb04728e",
gcsVersion: "v1.28.0-7+c4e17abb04728e",
needsUpdate: true,
shouldError: false,
},
{ // success version < gcsVersion (with build version)
prepare: func(mock *releasefakes.FakePublisherClient, gcsVersion string) {
mock.NormalizePathReturns("", nil)
mock.GSUtilOutputReturns(gcsVersion, nil)
},
version: "v1.28.0-7+c4e17abb04728e",
gcsVersion: "v1.28.0-9+aaaaaabb04728e",
needsUpdate: false,
shouldError: false,
},
{ // success version > gcsVersion (with build version)
prepare: func(mock *releasefakes.FakePublisherClient, gcsVersion string) {
mock.NormalizePathReturns("", nil)
mock.GSUtilOutputReturns(gcsVersion, nil)
},
version: "v1.28.1-1+aaaaaabb04728e",
gcsVersion: "v1.28.0-7+c4e17abb04728e",
needsUpdate: true,
shouldError: false,
},
{ // success version = gcsVersion (with build version, prerelease)
prepare: func(mock *releasefakes.FakePublisherClient, gcsVersion string) {
mock.NormalizePathReturns("", nil)
mock.GSUtilOutputReturns(gcsVersion, nil)
},
version: "v1.28.0-rc.1.9+3fb5377b25ec51",
gcsVersion: "v1.28.0-rc.1.9+3fb5377b25ec51",
needsUpdate: false,
shouldError: false,
},
{ // success version > gcsVersion (with build version, prerelease)
prepare: func(mock *releasefakes.FakePublisherClient, gcsVersion string) {
mock.NormalizePathReturns("", nil)
mock.GSUtilOutputReturns(gcsVersion, nil)
},
version: "v1.28.0-rc.1.10+3fb5377b25ec51",
gcsVersion: "v1.28.0-rc.1.9+3fb5377b25ec51",
needsUpdate: true,
shouldError: false,
},
{ // success version < gcsVersion (with build version, prerelease)
prepare: func(mock *releasefakes.FakePublisherClient, gcsVersion string) {
mock.NormalizePathReturns("", nil)
mock.GSUtilOutputReturns(gcsVersion, nil)
},
version: "v1.28.0-rc.1.9+3fb5377b25ec51",
gcsVersion: "v1.28.0-rc.1.10+3fb5377b25ec51",
needsUpdate: false,
shouldError: false,
},
{ // success version < gcsVersion (with build version, prerelease)
prepare: func(mock *releasefakes.FakePublisherClient, gcsVersion string) {
mock.NormalizePathReturns("", nil)
mock.GSUtilOutputReturns(gcsVersion, nil)
},
version: "v1.28.0-beta.1.9+3fb5377b25ec51",
gcsVersion: "v1.28.0-rc.1.9+3fb5377b25ec51",
needsUpdate: false,
shouldError: false,
},
{ // success version > gcsVersion (with build version, prerelease)
prepare: func(mock *releasefakes.FakePublisherClient, gcsVersion string) {
mock.NormalizePathReturns("", nil)
mock.GSUtilOutputReturns(gcsVersion, nil)
},
version: "v1.28.0-rc.1.9+3fb5377b25ec51",
gcsVersion: "v1.28.0-beta.1.9+3fb5377b25ec51",
needsUpdate: true,
shouldError: false,
},
{ // success version > gcsVersion (with build version, stable and prerelease)
prepare: func(mock *releasefakes.FakePublisherClient, gcsVersion string) {
mock.NormalizePathReturns("", nil)
mock.GSUtilOutputReturns(gcsVersion, nil)
},
version: "v1.28.0-7+c4e17abb04728e",
gcsVersion: "v1.28.0-rc.1.9+3fb5377b25ec51",
needsUpdate: true,
shouldError: false,
},
} {
sut := release.NewPublisher()
clientMock := &releasefakes.FakePublisherClient{}
sut.SetClient(clientMock)
tc.prepare(clientMock, tc.gcsVersion)

needsUpdate, err := sut.VerifyLatestUpdate("", "", tc.version)
if tc.shouldError {
require.NotNil(t, err)
} else {
require.Nil(t, err)
require.Equal(t, tc.needsUpdate, needsUpdate)
}
}
}