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

build: Fix version validation to support -rc #43

Merged
merged 1 commit into from
Feb 5, 2024
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
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
28 changes: 12 additions & 16 deletions hack/make/version.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading