From ec8071898d2059d05defdb6d0ae67270958a6cce Mon Sep 17 00:00:00 2001 From: Charlie Sharpsteen Date: Wed, 15 Jul 2026 08:54:27 -0500 Subject: [PATCH] Handle pre-release versions This commit updates the logic that generates package versions from Git tags. If the tag matches a semver.org pre-release with "alpha", "beta" or "rc" as the pre-release identifier, then the "-" in the version string is substituted for "~". That is, a tag like `9.0.0-beta1` becomes the following package version: `9.0.0~beta1` This is done because the `dpkg` and `rpm` package managers treat `~` specially and sort any version strings containing it before all other strings. This changes allows a `9.0.0~alpha1` package to upgrade to `9.0.0~beta1`, and then to `9.0.0~rc0`, and finally to `9.0.0`. See: https://semver.org See: https://manpages.debian.org/bookworm/dpkg-dev/deb-version.7.en.html#Sorting_algorithm See: https://rpm.org/docs/6.0.x/man/rpm-version.7#Comparing Signed-off-by: Charlie Sharpsteen --- lib/vanagon/project/dsl.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/vanagon/project/dsl.rb b/lib/vanagon/project/dsl.rb index f96adc83..97fec349 100644 --- a/lib/vanagon/project/dsl.rb +++ b/lib/vanagon/project/dsl.rb @@ -194,7 +194,16 @@ def release_from_git # def version_from_git git_version = Git.open(File.expand_path("..", @configdir)).describe('HEAD', tags: true, abbrev: 9) - version(git_version.split('-').reject(&:empty?).join('.')) + case git_version + # Matches semver.org spec for a pre-release, with a well-known alpha, + # beta, or RC identifier. Substitute "-" for "~" so that dpkg and + # rpm treat this as a pre-release and will upgrade packages to the + # final version. + when /\A\d+\.\d+\.\d+-(?:alpha|beta|rc)\d+/ + version(git_version.sub('-', '~')) + else + version(git_version.split('-').reject(&:empty?).join('.')) + end rescue Git::Error VanagonLogger.error "Directory '#{File.expand_path('..', @configdir)}' cannot be versioned by git. Maybe it hasn't been tagged yet?" end