15900: Report stable gem version for a given commit.
authorTom Clegg <tclegg@veritasgenetics.com>
Tue, 3 Dec 2019 16:39:29 +0000 (11:39 -0500)
committerTom Clegg <tclegg@veritasgenetics.com>
Tue, 3 Dec 2019 16:39:29 +0000 (11:39 -0500)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg@veritasgenetics.com>

build/version-at-commit.sh [new file with mode: 0755]
sdk/cli/arvados-cli.gemspec
sdk/ruby/arvados.gemspec
services/login-sync/arvados-login-sync.gemspec

diff --git a/build/version-at-commit.sh b/build/version-at-commit.sh
new file mode 100755 (executable)
index 0000000..2f514c8
--- /dev/null
@@ -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
index 8c8b0a82a4a6e02eb1d140c2195af5dcaae6028c..749797cf848afbd698da32cc7feb7afd00f02d03 100644 (file)
@@ -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}"
index ef189bb7ac49fd7af7bad9fd313cf3ce942d5ff0..9f314e6c9c0e28d82c3a2e767a04dcb058d8aea5 100644 (file)
@@ -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}"
index 36e5ed925283676d28f53a51e021bbfe118925de..f580d529d8a658b2e1a2a57f706aa3bff5fa89e2 100644 (file)
@@ -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}"