ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
incremental_prev_tag.py
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file incremental_prev_tag.py
1 #!/usr/bin/env python
2 from __future__ import print_function
3 
4 import os
5 import sys
6 from subprocess import check_output
7 
8 
9 def split_version(s):
10  assert s.startswith("v")
11  return tuple(int(c) for c in s[1:].split(".", 3))
12 
13 
14 tags_raw = check_output(["git", "tag", "-l"]).decode("utf8").strip().split("\n")
15 
16 try:
17  desc = check_output(["git", "describe", "--exact-match", "HEAD"]).strip()
18  on_tagged_commit = True
19 except Exception as e:
20  on_tagged_commit = False
21 
22 sys.stderr.write("On tagged commit? %s\n" % on_tagged_commit)
23 
24 tags = []
25 
26 for t in tags_raw:
27  assert t.startswith("v")
28  version = split_version(t)
29  sys.stderr.write("%s -> %s\n" % (t, version))
30  tags.append(version)
31 
32 tags = list(sorted(tags))
33 
34 
35 if not on_tagged_commit:
36  sys.stderr.write("Not on tagged commit, testing against highest tag\n")
37  prev_tag = tags[-1]
38 else:
39  current_tag = split_version(desc)
40  sys.stderr.write("Currently on %s\n" % str(current_tag))
41  idx = tags.index(current_tag)
42  assert idx != 0, "This doesn't work on the first ever tag"
43  prev_tag = tags[idx - 1]
44 
45 sys.stderr.write("Testing previous tag: v%s\n" % ".".join(map(str, prev_tag)))
46 
47 # this is the only thing that goes into stdout so we can catch it
48 sys.stdout.write("v%d.%02d.%02d" % prev_tag)