From 6ba2994dcf0a57ab5b02cad4ddc56e3ccf946e38 Mon Sep 17 00:00:00 2001 From: Robur Date: Mon, 20 Nov 2023 11:52:59 +0000 Subject: [PATCH] Fix debian packaging (version to always include -#commit-g) If the build is a release, use -0-g0000000. Also add this sanitization to the check_versions.sh --- packaging/check_versions.sh | 26 +++++++++++++++++++++++++- packaging/dpkg-repo.sh | 10 ++++++++++ packaging/versions.txt | 1 + 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/packaging/check_versions.sh b/packaging/check_versions.sh index 1b93100..03c0aff 100755 --- a/packaging/check_versions.sh +++ b/packaging/check_versions.sh @@ -15,11 +15,14 @@ freebsd_sanitize_version () { exit 1; fi if [ $version_with_commit -eq 0 ]; then - v="${v}.0.g0000000" + v="${v}.0.g0000000.${post}" + else + v="${v}.${post}" fi echo $v } +echo "using FreeBSD pkg to compare versions now:" while read version_a version_b; do version_a=$(freebsd_sanitize_version $version_a) version_b=$(freebsd_sanitize_version $version_b) @@ -27,7 +30,28 @@ while read version_a version_b; do printf "%s %s %s\n" "$version_a" "$result" "$version_b" done < versions.txt +debian_sanitize_version () { + post=$(echo $1 | rev | cut -d '-' -f 1-2 | rev) + v=$(echo $1 | rev | cut -d '-' -f 3- | rev) + version_good=$(echo $v | grep -c '^[0-9]\+\.[0-9]\+\.[0-9]\+$') + version_with_commit=$(echo $v | grep -c '^[0-9]\+\.[0-9]\+\.[0-9]\+\-[0-9]\+\-g[0-9a-fA-f]\+$') + if [ $version_good -eq 0 -a $version_with_commit -eq 0 ]; then + echo "invalid version $v"; + exit 1; + fi + if [ $version_with_commit -eq 0 ]; then + v="${v}-0-g0000000-${post}" + else + v="${v}-${post}" + fi + echo $v +} + +echo "" +echo "using Debian dpkg to compare versions now:" while read version_a version_b; do + version_a=$(debian_sanitize_version $version_a) + version_b=$(debian_sanitize_version $version_b) if dpkg --compare-versions "$version_a" lt "$version_b"; then echo "$version_a < $version_b" else diff --git a/packaging/dpkg-repo.sh b/packaging/dpkg-repo.sh index b8e784a..8e8921b 100755 --- a/packaging/dpkg-repo.sh +++ b/packaging/dpkg-repo.sh @@ -104,6 +104,16 @@ mkdir "${PKG_ROOT}" dpkg-deb -R "${FILENAME}" "${PKG_ROOT}" VERSION=$(dpkg-deb -f "${FILENAME}" Version) +# if we've a tagged version (1.5.0), append the number of commits and a dummy hash +VERSION_GOOD=$(echo $VERSION | grep -c '^[0-9]\+\.[0-9]\+\.[0-9]\+$') || true +VERSION_WITH_COMMIT=$(echo $VERSION | grep -c '^[0-9]\+\.[0-9]\+\.[0-9]\+\-[0-9]\+\-g[0-9a-fA-f]\+$') || true +if [ $VERSION_GOOD -eq 0 -a $VERSION_WITH_COMMIT -eq 0 ]; then + die "version does not conform to (MAJOR.MINOR.PATCH[-#NUM_COMMITS-g])" +fi +if [ $VERSION_WITH_COMMIT -eq 0 ]; then + VERSION="${VERSION}-0-g0000000" +fi + NEW_VERSION="${VERSION}"-"${BUILD_TIME}"-"${SHA}" sed -i "" -e "s/Version:.*/Version: ${NEW_VERSION}/g" "${PKG_ROOT}/DEBIAN/control" diff --git a/packaging/versions.txt b/packaging/versions.txt index f62c530..2326bd4 100644 --- a/packaging/versions.txt +++ b/packaging/versions.txt @@ -6,3 +6,4 @@ 3.0.0-20230101-abcd 3.0.1-20230204-bdbd 1.5.0-20220516-a0d5a2 1.5.0-3-g26b5a59-20220527-0bc180 1.5.0-3-g26b5a59-20220527-0bc180 1.5.1-20220527-0bc180 +0.1.0-20221120104301-f9e456637274844d45d9758ec661a136d0cda7966b075e4426b69fe6da00427b 0.1.0-237-g62965d4-20230527202149-6118c39221f318154e234098b5cffd4dc1d80f19cf2200cc6b1eb768dbf6decb