Skip to content

Commit

Permalink
build: Fix version validation to support -rc
Browse files Browse the repository at this point in the history
Signed-off-by: Paulo Gomes <[email protected]>
  • Loading branch information
pjbgf committed Feb 5, 2024
1 parent 16cfd3d commit 9df6ba5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
31 changes: 13 additions & 18 deletions hack/make/version.mk
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,18 @@ endif
# to default format: v0.0~aaaaaadirty.testing.0
ifeq ($(VERSION),)
VERSION = "v0.0~$(COMMIT)$(DIRTY).testing.0"
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]+')

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"
VERSION_REGEX = ^v([0-9]+\.[0-9]+)(-rc[0-9]+){0,1}\.(production|testing)\.([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]})

ifeq ($(RPM_VERSION),)
VERSION_MSG = "Tag ($(TAG)) does not match expected format"
else ifeq ($(RPM_RELEASE),)
VERSION_MSG = "Tag ($(TAG)) does not match expected format"
else ifeq ($(RPM_CHANNEL),)
VERSION_MSG = "Tag ($(TAG)) does not match expected format"
endif
endif

0 comments on commit 9df6ba5

Please sign in to comment.