diff --git a/src/build.sh b/src/build.sh index f531150..fb483ea 100644 --- a/src/build.sh +++ b/src/build.sh @@ -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 @@ -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) - # -.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: - + deb_version="$(dpkg-parsechangelog --show-field Version)" + # version from last (numeric) git release tag: - + # - stripping any leading non digits as they are not part of the version number + # - stripping trailing -g + 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): -.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 @@ -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