From cf1548309f0c517570449a760c38f7c5f9927ca8 Mon Sep 17 00:00:00 2001 From: Paulo Gomes Date: Mon, 5 Feb 2024 17:39:17 +0000 Subject: [PATCH] build: Fix version validation to support -rc Signed-off-by: Paulo Gomes --- Makefile | 2 +- hack/make/version.mk | 28 ++++++++++++---------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 11bdaf5..c9d5bcb 100644 --- a/Makefile +++ b/Makefile @@ -54,7 +54,7 @@ build: ## build all policies. %-build-sign: ## sign the generate rpms of a given policy. @$(RUNNER) run --rm \ -e USER=$(shell id -u) -e GROUP=$(shell id -g) \ - -e SIGN_KEY_EMAIL -e RPM_CHANNEL="$(RPM_CHANNEL)" \ + -e SIGN_KEY_EMAIL="$(SIGN_KEY_EMAIL)" -e RPM_CHANNEL="$(RPM_CHANNEL)" \ -e TESTING_PRIVATE_KEY_PASS_PHRASE \ -e TESTING_PRIVATE_KEY \ -e PRIVATE_KEY -e PRIVATE_KEY_PASS_PHRASE \ diff --git a/hack/make/version.mk b/hack/make/version.mk index 01e4cdc..edc9319 100644 --- a/hack/make/version.mk +++ b/hack/make/version.mk @@ -24,27 +24,23 @@ ifneq ($(TAG),) endif endif +VERSION_REGEX = ^v([0-9]+\.[0-9]+)(-rc[0-9]+){0,1}\.(production|testing)\.([0-9]+)$$ + # If a tag was not set, or worktree is dirty, fallback # to default format: v0.0~aaaaaadirty.testing.0 ifeq ($(VERSION),) VERSION = "v0.0~$(COMMIT)$(DIRTY).testing.0" + VERSION_REGEX = ^v([0-9]+\.[0-9]+)(~[a-fA-F0-9]{7,10}$(DIRTY))\.(testing)\.([0-9]+)$$ endif -rpm_version_regex := s/\-/~/g; s/^v([0-9]+\.[0-9]+[-~a-zA-Z0-9]*)\.[a-z]+\.[0-9]+$$/\1/; -rpm_channel_regex := s/^v[0-9]+\.[0-9]+[-~a-zA-Z0-9]*\.([a-z]+)\.[0-9]+$$/\1/; -rpm_release_regex := s/^v[0-9]+\.[0-9]+[-~a-zA-Z0-9]*\.[a-z]+\.([0-9]+)$$/\1/; - -CHECKED_VERSION = $(shell echo $(VERSION) | grep -E 'v[0-9]+\.[0-9]+[~a-zA-Z0-9]*\.[a-z]+\.[0-9]+') +RPM_VERSION = $(shell [[ $(VERSION) =~ $(VERSION_REGEX) ]] && echo $${BASH_REMATCH[1]}) +RPM_RELEASE = $(shell [[ $(VERSION) =~ $(VERSION_REGEX) ]] && echo $${BASH_REMATCH[4]}) +RPM_CHANNEL = $(shell [[ $(VERSION) =~ $(VERSION_REGEX) ]] && echo $${BASH_REMATCH[3]}) -ifneq ($(CHECKED_VERSION),) - RPM_VERSION = $(shell sed -E -e "$(rpm_version_regex)" <<<"$(VERSION)") - RPM_RELEASE = $(shell sed -E -e "$(rpm_release_regex)" <<<"$(VERSION)") - RPM_CHANNEL = $(shell sed -E -e "$(rpm_channel_regex)" <<<"$(VERSION)") - - ALLOWED_CHANNELS := production testing - ifneq ($(filter-out $(ALLOWED_CHANNELS),$(RPM_CHANNEL)),) - VERSION_MSG = "RPM_CHANNEL $(RPM_CHANNEL) does not match one of: [testing, production]" - endif -else - VERSION_MSG = "Tag ($(TAG)) or version ($(VERSION)) does not match expected format" +ifeq ($(RPM_VERSION),) + VERSION_MSG = "Tag ($(TAG)) or Version ($(VERSION)) does not match expected format" +else ifeq ($(RPM_RELEASE),) + VERSION_MSG = "Tag ($(TAG)) or Version ($(VERSION)) does not match expected format" +else ifeq ($(RPM_CHANNEL),) + VERSION_MSG = "Tag ($(TAG)) or Version ($(VERSION)) does not match expected format" endif