summaryrefslogtreecommitdiff
path: root/tools/get-scala-revision
blob: 8747fdc3fb03b4aa0517d8ea258f9f2cd4fc81ce (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env bash
#
# Usage: get-scala-revision [dir]
# Figures out current scala revision of a git clone.
# If no dir is given, current working dir is used.
#
# Example build version string:
#   v2.10.0-M1-0098-g6f1c486d0b-2012-02-01
#

[[ $# -eq 0 ]] || cd "$1"

ensure_tag () {
  sha=$1
  rev=$2
  
  [[ -n $(git tag -l $rev) ]] || {
    git tag -a -m "generated by get-scala-revision" $rev $sha
  }
}

# Ensure some baseline tags are present so if this repository's
# tags are screwed up or stale, we should still have a reference
# point for a build string.
ensure_tag 58cb15c40d v2.10.0-M1
ensure_tag 29f3eace1e v2.9.1
ensure_tag b0d78f6b9c v2.8.2

# the closest tag, obtained separately because we have to
# reconstruct the string around the padded distance.
tag=$(git describe --tags --match 'v2*' --abbrev=0)

# printf %016s is not portable for 0-padding, has to be a digit.
# so we're stuck disassembling it.
described=$(git describe --tags --match 'v2*' --abbrev=10)
suffix="${described##${tag}-}"
counter=$(echo $suffix | cut -d - -f 1)
hash=$(echo $suffix | cut -d - -f 2)

# v2.10.0-M1-0098-g6f1c486d0b-2012-02-01
printf "%s-%04d-%s-%s\n" "$tag" "$counter" "$hash" $(date "+%Y-%m-%d")