Skip to content

Commit

Permalink
Back to "git describe" to yield version number
Browse files Browse the repository at this point in the history
  • Loading branch information
rhaschke committed Oct 12, 2023
1 parent bcd8e6e commit aa3c66c
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ function update_repo {
cd "$old_path" || return 1
}

function git_version_from_commit_msg {
local version
local sha
read -r sha version <<< "$(git log --pretty=format:'%h %s' | grep -E "[0-9.]+\.[0-9]+$" | head -n 1)"
echo "$version-$(git rev-list --count "$sha"..HEAD)"
}

function pkg_exists {
local version; version=$(apt-cache policy "$(deb_pkg_name "$1")" | sed -n 's#^\s*Candidate:\s\(.*\)#\1#p')
if [ "$SKIP_EXISTING" == "true" ] && [ -n "$version" ] && [ "$version" != "(none)" ]; then
Expand Down Expand Up @@ -72,12 +79,22 @@ function build_pkg {
# https://github.com/ros-infrastructure/bloom/pull/643
echo 11 > debian/compat

# Set version based on last changelog entry and append build timestamp (following official ROS scheme)
# <changelog version>-<increment><debian distro>.date.time
# This way, we cannot yet distinguish different, not-yet-released versions (which git describe would do)
# However, git describe relied on tags being available, which is often not the case!
# TODO: Increase the increment on each build
version="$(dpkg-parsechangelog --show-field Version).$(date +%Y%m%d.%H%M)"
# version from last changelog entry: <changelog version>-<increment><debian distro>
deb_version="$(dpkg-parsechangelog --show-field Version)"
# version from last (numeric) git release tag: <release version>-<git offset>
# - stripping any leading non digits as they are not part of the version number
# - stripping trailing -g<sha>
git_version="$(git describe --tag --long --match "*[0-9]*" 2>/dev/null | sed 's@^[^0-9]*@@;s@-g[0-9a-f]*$@@')"
if [ -z "$git_version" ] || [ "$git_version$DEB_DISTRO" \< "$deb_version" ]; then
gha_warning "git version ($git_version) is older than changelog version ($deb_version)"
git_version=$(git_version_from_commit_msg)
fi
if [ "$git_version$DEB_DISTRO" \< "$deb_version" ]; then
return 5
fi

# Apppend build timestamp (following ROS scheme): <release version>-<git offset><debian distro>.date.time
version="$git_version$DEB_DISTRO.$(date +%Y%m%d.%H%M)"
debchange -v "$version" \
--preserve --force-distribution "$DEB_DISTRO" \
--urgency high -m "Append timestamp when binarydeb was built." || return 3
Expand Down Expand Up @@ -143,6 +160,7 @@ function build_source {
2) msg_prefix="bloom-generate failed" ;;
3) msg_prefix="debchange failed" ;;
4) msg_prefix="sbuild failed" ;;
5) msg_prefix="missing release tag for latest version" ;;
*) msg_prefix="unnamed step failed ($exit_code)" ;;
esac

Expand Down

0 comments on commit aa3c66c

Please sign in to comment.