From 0bf72370d5dd17256956b7420869db66874e8dd3 Mon Sep 17 00:00:00 2001 From: plaurent Date: Tue, 27 Aug 2024 16:24:35 -0400 Subject: [PATCH 1/2] [ENGINE-978] Change revision scheme per ENGINE-970 requirements Signed-off-by: plaurent --- hack/build | 4 ++++ tests/version.go | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/hack/build b/hack/build index 7c23dc109f4..f8cac988984 100755 --- a/hack/build +++ b/hack/build @@ -6,6 +6,9 @@ set -e : "${PACKAGE=github.com/docker/buildx}" : "${VERSION=$(./hack/git-meta version)}" : "${REVISION=$(./hack/git-meta revision)}" +: "${PRERELEASE=$(./hack/git-meta version | rev | cut -c3- | rev | cut -d'-' -f 2 | grep -E '(^tp|^rc).*')}" +: "${REVISION_NUMBER=1}" +VERSION=$(printf "v%sm%s%s" "$(./hack/git-meta version | rev | cut -c3- | rev | cut -d'-' -f 1 | cut -c2-)" "${REVISION_NUMBER}" "-${PRERELEASE}") : "${CGO_ENABLED=0}" : "${GO_PKG=github.com/docker/buildx}" @@ -13,5 +16,6 @@ set -e : "${GO_LDFLAGS=-X ${GO_PKG}/version.Version=${VERSION} -X ${GO_PKG}/version.Revision=${REVISION} -X ${GO_PKG}/version.Package=${PACKAGE}}" : "${GO_EXTRA_LDFLAGS=}" + set -x CGO_ENABLED=$CGO_ENABLED go build -mod vendor -trimpath ${GO_EXTRA_FLAGS} -ldflags "${GO_LDFLAGS} ${GO_EXTRA_LDFLAGS}" -o "${DESTDIR}/docker-buildx" ./cmd/buildx diff --git a/tests/version.go b/tests/version.go index 170a676d2aa..da3cfdbf6e7 100644 --- a/tests/version.go +++ b/tests/version.go @@ -1,13 +1,13 @@ package tests import ( + "regexp" "strings" "testing" "github.com/moby/buildkit/util/testutil/integration" "github.com/stretchr/testify/require" "golang.org/x/mod/module" - "golang.org/x/mod/semver" ) var versionTests = []func(t *testing.T, sb integration.Sandbox){ @@ -45,7 +45,8 @@ func testVersion(t *testing.T, sb integration.Sandbox) { // This defaults to something that's still compatible // with semver. version := fields[1] - require.True(t, semver.IsValid(version), "Second field was not valid semver: %+v", version) + regex, err := regexp.CompilePOSIX("^v[0-9]+.[0-9]+.[0-9]+(m[0-9]+|m[0-9]+-rc[0-9]+|m[0-9]+-tp[0-9]+)$") + require.True(t, err == nil && regex.MatchString(version), "Second field was not valid: %+v", version) // Revision should be empty or should look like a git hash. if len(fields) > 2 && len(fields[2]) > 0 { From f572f87eaacf606a752514d89cbefde0199eb6b1 Mon Sep 17 00:00:00 2001 From: plaurent Date: Wed, 28 Aug 2024 13:42:00 -0400 Subject: [PATCH 2/2] [ENGINE-978] Change revision scheme per ENGINE-970 requirements Signed-off-by: plaurent --- hack/build | 7 ++++++- tests/version.go | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/hack/build b/hack/build index f8cac988984..5487230d6d1 100755 --- a/hack/build +++ b/hack/build @@ -8,7 +8,12 @@ set -e : "${REVISION=$(./hack/git-meta revision)}" : "${PRERELEASE=$(./hack/git-meta version | rev | cut -c3- | rev | cut -d'-' -f 2 | grep -E '(^tp|^rc).*')}" : "${REVISION_NUMBER=1}" -VERSION=$(printf "v%sm%s%s" "$(./hack/git-meta version | rev | cut -c3- | rev | cut -d'-' -f 1 | cut -c2-)" "${REVISION_NUMBER}" "-${PRERELEASE}") + +if [ -n "$PRERELEASE" ]; then + PRERELEASE="-$PRERELEASE" +fi + +VERSION=$(printf "v%sm%s%s" "$(./hack/git-meta version | rev | cut -c3- | rev | cut -d'-' -f 1 | cut -c2-)" "${REVISION_NUMBER}" "${PRERELEASE}") : "${CGO_ENABLED=0}" : "${GO_PKG=github.com/docker/buildx}" diff --git a/tests/version.go b/tests/version.go index da3cfdbf6e7..a18a1796a24 100644 --- a/tests/version.go +++ b/tests/version.go @@ -45,8 +45,8 @@ func testVersion(t *testing.T, sb integration.Sandbox) { // This defaults to something that's still compatible // with semver. version := fields[1] - regex, err := regexp.CompilePOSIX("^v[0-9]+.[0-9]+.[0-9]+(m[0-9]+|m[0-9]+-rc[0-9]+|m[0-9]+-tp[0-9]+)$") - require.True(t, err == nil && regex.MatchString(version), "Second field was not valid: %+v", version) + regex := regexp.MustCompilePOSIX("^v[0-9]+.[0-9]+.[0-9]+(m[0-9]+|m[0-9]+-rc[0-9]+|m[0-9]+-tp[0-9]+)$") + require.True(t, regex.MatchString(version), "Second field was not valid: %+v", version) // Revision should be empty or should look like a git hash. if len(fields) > 2 && len(fields[2]) > 0 {