2020-08-31 13:57:42 +00:00
|
|
|
import subprocess
|
|
|
|
import sys
|
2021-02-01 20:25:20 +00:00
|
|
|
|
2020-08-31 13:57:42 +00:00
|
|
|
try:
|
|
|
|
version = sys.argv[1].replace('v', '')
|
|
|
|
except IndexError:
|
|
|
|
version = "git"
|
|
|
|
|
2020-09-15 11:12:51 +00:00
|
|
|
if version == "auto":
|
|
|
|
try:
|
|
|
|
version = subprocess.check_output("git describe --exact-match HEAD".split()).decode("utf-8").rstrip().replace('v', '')
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
if e.returncode == 128:
|
|
|
|
version = "git"
|
|
|
|
|
2020-08-31 13:57:42 +00:00
|
|
|
commit = subprocess.check_output("git rev-parse --short HEAD".split()).decode("utf-8").rstrip()
|
|
|
|
|
|
|
|
file = f'package main; const VERSION = "{version}"; const COMMIT = "{commit}";'
|
|
|
|
|
|
|
|
try:
|
|
|
|
writeto = sys.argv[2]
|
|
|
|
except IndexError:
|
|
|
|
writeto = "version.go"
|
|
|
|
|
|
|
|
with open(writeto, 'w') as f:
|
|
|
|
f.write(file)
|
|
|
|
|