2019-05-24 22:14:47 +02:00
|
|
|
"""Set the build version to be 'qa', 'rc', 'release'"""
|
2018-10-22 22:31:05 +02:00
|
|
|
|
|
|
|
import sys
|
2019-05-24 22:14:47 +02:00
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import logging
|
|
|
|
|
|
|
|
log = logging.getLogger()
|
|
|
|
log.addHandler(logging.StreamHandler())
|
|
|
|
log.setLevel(logging.DEBUG)
|
|
|
|
|
|
|
|
|
2019-08-20 21:11:52 +02:00
|
|
|
def get_build_type(ci_tag=None):
|
|
|
|
if not ci_tag:
|
2019-05-24 22:14:47 +02:00
|
|
|
return "qa"
|
2019-08-20 21:11:52 +02:00
|
|
|
log.debug("getting build type for tag: \"%s\"", ci_tag)
|
|
|
|
if re.match(r'v\d+\.\d+\.\d+rc\d+$', ci_tag):
|
2019-05-24 22:14:47 +02:00
|
|
|
return 'rc'
|
2019-08-20 21:11:52 +02:00
|
|
|
elif re.match(r'v\d+\.\d+\.\d+$', ci_tag):
|
2019-05-24 22:14:47 +02:00
|
|
|
return 'release'
|
|
|
|
return 'qa'
|
2018-10-22 22:31:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
root_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
2019-11-21 20:16:10 +01:00
|
|
|
build_type_path = os.path.join(root_dir, 'lbry', 'lbry', 'build_type.py')
|
2019-05-24 22:14:47 +02:00
|
|
|
log.debug("configuring build type file: %s", build_type_path)
|
2019-11-21 20:16:10 +01:00
|
|
|
commit_hash = os.getenv('CI_COMMIT_SHA', os.getenv('TRAVIS_COMMIT'))
|
|
|
|
if commit_hash is None:
|
|
|
|
raise ValueError("Commit hash not found in env vars")
|
|
|
|
commit_hash = commit_hash[:6]
|
|
|
|
build_type = get_build_type(os.getenv('CI_COMMIT_TAG', os.getenv('TRAVIS_TAG')))
|
2019-08-20 21:11:52 +02:00
|
|
|
log.debug("setting build type=%s, build commit=%s", build_type, commit_hash)
|
2019-05-24 22:14:47 +02:00
|
|
|
with open(build_type_path, 'w') as f:
|
2019-08-20 21:11:52 +02:00
|
|
|
f.write(f"BUILD = \"{build_type}\"\nBUILD_COMMIT = \"{commit_hash}\"\n")
|
2018-10-22 22:31:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main())
|