mirror of https://github.com/hrfee/jfa-go
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
689 B
28 lines
689 B
4 years ago
|
import subprocess
|
||
|
import sys
|
||
4 years ago
|
|
||
4 years ago
|
try:
|
||
|
version = sys.argv[1].replace('v', '')
|
||
|
except IndexError:
|
||
|
version = "git"
|
||
|
|
||
4 years ago
|
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"
|
||
|
|
||
4 years ago
|
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)
|
||
|
|