-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtrack_Rainbow_version.py
53 lines (42 loc) · 2.08 KB
/
track_Rainbow_version.py
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
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3
import os
import json
import subprocess
CURRENT_PATH = os.path.dirname(os.path.realpath(__file__))
RG_DIR = os.environ.get('RAINBOW_GRADES_DIRECTORY')
REPORT_DIR = os.environ.get('REPORTS_DIRECTORY')
WORKING_DIRECTORY = "."
if __name__ == "__main__":
json_dir = os.path.join(WORKING_DIRECTORY, "RG_version.json")
output_dict = {}
current_commit_hash_rg = 'unknown'
current_short_commit_hash_rg = 'unknown'
current_git_tag_rg = 'unknown'
try:
#run the command 'git rev-parse HEAD' from the RainbowGrades repository directory
current_commit_hash_rg = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=RG_DIR)
current_commit_hash_rg = current_commit_hash_rg.decode('ascii').strip()
current_short_commit_hash_rg = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD'], cwd=RG_DIR)
current_short_commit_hash_rg = current_short_commit_hash_rg.decode('ascii').strip()
print("Commit {0} is currently installed on this system.".format(current_commit_hash_rg))
except:
print("ERROR: could not determine commit hash.")
current_commit_hash_rg = 'unknown'
try:
#run the command 'git describe --tag --abbrev=0' from the RainbowGrades repository directory
current_git_tag_rg = subprocess.check_output(['git', 'describe', '--tag', '--abbrev=0'], cwd=RG_DIR)
current_git_tag_rg = current_git_tag_rg.decode('ascii').strip()
print("Tag {0} is the most recent git tag.".format(current_git_tag_rg))
except:
print("ERROR: could not determine current git tag.")
current_git_tag_rg = 'unknown'
#remove newline at the end of the hash and tag and convert them from bytes to ascii.
output_dict["installed_commit_rg"] = current_commit_hash_rg
output_dict["short_installed_commit_rg"] = current_short_commit_hash_rg
output_dict["most_recent_git_tag_rg"] = current_git_tag_rg
try:
#Update rainbow_grades/RG_version.json to reflect the current commit hash.
with open(json_dir, 'w') as outfile:
json.dump(output_dict, outfile, indent=2)
except:
print("ERROR: could not write to {0}".format(json_dir))