Skip to content

Commit

Permalink
Merge pull request #43 from pjbgf/push-artefacts
Browse files Browse the repository at this point in the history
build: Fix version validation to support `-rc`
  • Loading branch information
pjbgf authored Feb 5, 2024
2 parents 16cfd3d + cf15483 commit 892bb19
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 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
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

0 comments on commit 892bb19

Please sign in to comment.