2018-10-22 22:31:05 +02:00
|
|
|
import sys
|
2019-05-24 22:14:47 +02:00
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import logging
|
2020-01-23 18:38:41 +01:00
|
|
|
import lbry.build_info as build_info_mod
|
2019-05-24 22:14:47 +02:00
|
|
|
|
|
|
|
log = logging.getLogger()
|
|
|
|
log.addHandler(logging.StreamHandler())
|
|
|
|
log.setLevel(logging.DEBUG)
|
|
|
|
|
|
|
|
|
2020-01-23 18:38:41 +01:00
|
|
|
def _check_and_set(d: dict, key: str, value: str):
|
|
|
|
try:
|
|
|
|
d[key]
|
|
|
|
except KeyError:
|
|
|
|
raise Exception(f"{key} var does not exist in {build_info_mod.__file__}")
|
|
|
|
d[key] = value
|
2018-10-22 22:31:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2020-01-23 18:38:41 +01:00
|
|
|
build_info = {item: build_info_mod.__dict__[item] for item in dir(build_info_mod) if not item.startswith("__")}
|
|
|
|
|
2021-07-21 15:19:51 +02:00
|
|
|
commit_hash = os.getenv('DOCKER_COMMIT', os.getenv('GITHUB_SHA'))
|
2019-11-21 20:16:10 +01:00
|
|
|
if commit_hash is None:
|
|
|
|
raise ValueError("Commit hash not found in env vars")
|
2020-01-23 18:38:41 +01:00
|
|
|
_check_and_set(build_info, "COMMIT_HASH", commit_hash[:6])
|
|
|
|
|
|
|
|
docker_tag = os.getenv('DOCKER_TAG')
|
|
|
|
if docker_tag:
|
|
|
|
_check_and_set(build_info, "DOCKER_TAG", docker_tag)
|
|
|
|
_check_and_set(build_info, "BUILD", "docker")
|
|
|
|
else:
|
2021-07-21 17:32:37 +02:00
|
|
|
if re.match(r'refs/tags/v\d+\.\d+\.\d+$', str(os.getenv('GITHUB_REF'))):
|
|
|
|
_check_and_set(build_info, "BUILD", "release")
|
|
|
|
else:
|
|
|
|
_check_and_set(build_info, "BUILD", "qa")
|
2020-01-23 18:38:41 +01:00
|
|
|
|
|
|
|
log.debug("build info: %s", ", ".join([f"{k}={v}" for k, v in build_info.items()]))
|
|
|
|
with open(build_info_mod.__file__, 'w') as f:
|
|
|
|
f.write("\n".join([f"{k} = \"{v}\"" for k, v in build_info.items()]) + "\n")
|
2018-10-22 22:31:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main())
|