From d08871688722c5303b56e5a76456aec7d10e770b Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Tue, 3 Dec 2019 11:39:29 -0500 Subject: [PATCH] 15900: Report stable gem version for a given commit. Arvados-DCO-1.1-Signed-off-by: Tom Clegg --- build/version-at-commit.sh | 17 +++++++++++++++++ sdk/cli/arvados-cli.gemspec | 5 ++--- sdk/ruby/arvados.gemspec | 5 ++--- services/login-sync/arvados-login-sync.gemspec | 5 ++--- 4 files changed, 23 insertions(+), 9 deletions(-) create mode 100755 build/version-at-commit.sh diff --git a/build/version-at-commit.sh b/build/version-at-commit.sh new file mode 100755 index 0000000000..2f514c82da --- /dev/null +++ b/build/version-at-commit.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +set -e -o pipefail +commit="$1" +versionglob="[0-9].[0-9]*.[0-9]*" + +if ! git describe --exact-match --match "$versionglob" "$commit" 2>/dev/null; then + if git merge-base --is-ancestor "$commit" origin/master; then + # x.(y+1).0.preTIMESTAMP, where x.y.z is the newest version that does not contain $commit + v=$(git tag | grep -vFf <(git tag --contains "$commit") | sort -Vr | head -n1 | perl -pe 's/\.(\d+)\.\d+/".".($1+1).".0"/e') + else + # x.y.(z+1).preTIMESTAMP, where x.y.z is the latest released ancestor of $commit + v=$(git describe --abbrev=0 --match "$versionglob" "$commit" | perl -pe 's/(\d+)$/$1+1/e') + fi + ts=$(TZ=UTC git log -n1 --format=%cd --date="format-local:%Y%m%d%H%M%S" "$commit") + echo "$v.pre$ts" +fi diff --git a/sdk/cli/arvados-cli.gemspec b/sdk/cli/arvados-cli.gemspec index 8c8b0a82a4..749797cf84 100644 --- a/sdk/cli/arvados-cli.gemspec +++ b/sdk/cli/arvados-cli.gemspec @@ -7,14 +7,13 @@ if not File.exist?('/usr/bin/git') then exit end -git_latest_tag = `git tag -l |sort -V -r |head -n1` -git_latest_tag = git_latest_tag.encode('utf-8').strip +version = `#{__dir__}/../../build/version-at-commit.sh HEAD`.encode('utf-8').strip git_timestamp, git_hash = `git log -n1 --first-parent --format=%ct:%H .`.chomp.split(":") git_timestamp = Time.at(git_timestamp.to_i).utc Gem::Specification.new do |s| s.name = 'arvados-cli' - s.version = "#{git_latest_tag}.#{git_timestamp.strftime('%Y%m%d%H%M%S')}" + s.version = version s.date = git_timestamp.strftime("%Y-%m-%d") s.summary = "Arvados CLI tools" s.description = "Arvados command line tools, git commit #{git_hash}" diff --git a/sdk/ruby/arvados.gemspec b/sdk/ruby/arvados.gemspec index ef189bb7ac..9f314e6c9c 100644 --- a/sdk/ruby/arvados.gemspec +++ b/sdk/ruby/arvados.gemspec @@ -7,14 +7,13 @@ if not File.exist?('/usr/bin/git') then exit end -git_latest_tag = `git tag -l |sort -V -r |head -n1` -git_latest_tag = git_latest_tag.encode('utf-8').strip +version = `#{__dir__}/../../build/version-at-commit.sh HEAD`.encode('utf-8').strip git_timestamp, git_hash = `git log -n1 --first-parent --format=%ct:%H .`.chomp.split(":") git_timestamp = Time.at(git_timestamp.to_i).utc Gem::Specification.new do |s| s.name = 'arvados' - s.version = "#{git_latest_tag}.#{git_timestamp.strftime('%Y%m%d%H%M%S')}" + s.version = version s.date = git_timestamp.strftime("%Y-%m-%d") s.summary = "Arvados client library" s.description = "Arvados client library, git commit #{git_hash}" diff --git a/services/login-sync/arvados-login-sync.gemspec b/services/login-sync/arvados-login-sync.gemspec index 36e5ed9252..f580d529d8 100644 --- a/services/login-sync/arvados-login-sync.gemspec +++ b/services/login-sync/arvados-login-sync.gemspec @@ -7,14 +7,13 @@ if not File.exist?('/usr/bin/git') then exit end -git_latest_tag = `git tag -l |sort -V -r |head -n1` -git_latest_tag = git_latest_tag.encode('utf-8').strip +version = `#{__dir__}/../../build/version-at-commit.sh HEAD`.encode('utf-8').strip git_timestamp, git_hash = `git log -n1 --first-parent --format=%ct:%H .`.chomp.split(":") git_timestamp = Time.at(git_timestamp.to_i).utc Gem::Specification.new do |s| s.name = 'arvados-login-sync' - s.version = "#{git_latest_tag}.#{git_timestamp.strftime('%Y%m%d%H%M%S')}" + s.version = version s.date = git_timestamp.strftime("%Y-%m-%d") s.summary = "Set up local login accounts for Arvados users" s.description = "Creates and updates local login accounts for Arvados users. Built from git commit #{git_hash}" -- 2.30.2