From 925e39c5a80952f7e7a3018b17327824af0f4395 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Fri, 24 May 2019 16:14:47 -0400 Subject: [PATCH] improve set_build.py, pin torba version - adds BUILD_COMMIT to lbrynet.build_type --- .travis.yml | 17 +++++++++------ lbrynet/build_type.py | 1 + scripts/set_build.py | 50 ++++++++++++++++++++++--------------------- scripts/wine_build.sh | 7 +++--- setup.py | 2 +- tox.ini | 1 + 6 files changed, 42 insertions(+), 36 deletions(-) diff --git a/.travis.yml b/.travis.yml index afe118576..0cd3060e3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,9 @@ dist: xenial language: python python: "3.7" +env: + - TORBA=master + jobs: include: @@ -10,7 +13,7 @@ jobs: name: "pylint lbrynet" install: - pip install astroid pylint - - pip install git+https://github.com/lbryio/torba.git@master#egg=torba + - pip install git+https://github.com/lbryio/torba.git@${TORBA}#egg=torba - pip install -e . script: pylint lbrynet @@ -18,7 +21,7 @@ jobs: name: "Unit Tests" install: - pip install coverage - - pip install git+https://github.com/lbryio/torba.git@master#egg=torba + - pip install git+https://github.com/lbryio/torba.git@${TORBA}#egg=torba - pip install -e . script: - HOME=/tmp coverage run -p --source=lbrynet -m unittest discover -vv tests.unit @@ -27,10 +30,10 @@ jobs: - bash <(curl -s https://codecov.io/bash) - name: "Integration Tests" - cache: false install: - pip install tox-travis coverage - - pushd .. && git clone --single-branch --branch master https://github.com/lbryio/torba.git && popd + - pushd .. && git clone --single-branch --branch ${TORBA} https://github.com/lbryio/torba.git && popd + script: tox after_success: - coverage combine tests/ @@ -39,7 +42,7 @@ jobs: - name: "Run Examples" install: - pip install coverage - - pip install git+https://github.com/lbryio/torba.git@master#egg=torba + - pip install git+https://github.com/lbryio/torba.git@${TORBA}#egg=torba - pip install -e . script: - HOME=/tmp coverage run -p --source=lbrynet scripts/generate_json_api.py @@ -56,7 +59,7 @@ jobs: - docker pull lbry/pyinstaller34_32bits:py371 script: - python scripts/set_build.py - - docker run -v "$(pwd):/src/lbry" lbry/pyinstaller34_32bits:py371 lbry/scripts/wine_build.sh + - docker run -v "$(pwd):/src/lbry" lbry/pyinstaller34_32bits:py371 lbry/scripts/wine_build.sh ${TORBA} - sudo zip -j dist/lbrynet-windows.zip dist/lbrynet.exe deploy: provider: releases @@ -80,7 +83,7 @@ jobs: env: OS=linux install: - pip3 install pyinstaller - - pip3 install git+https://github.com/lbryio/torba.git + - pip3 install git+https://github.com/lbryio/torba.git@${TORBA}#egg=torba - python3 scripts/set_build.py - pip3 install -e . script: diff --git a/lbrynet/build_type.py b/lbrynet/build_type.py index 862548fbc..07a818289 100644 --- a/lbrynet/build_type.py +++ b/lbrynet/build_type.py @@ -1,2 +1,3 @@ # don't touch this. CI server changes this during build/deployment BUILD = "dev" +BUILD_COMMIT = "source installation" diff --git a/scripts/set_build.py b/scripts/set_build.py index f4b4d4253..5e639d2ab 100644 --- a/scripts/set_build.py +++ b/scripts/set_build.py @@ -1,33 +1,35 @@ +"""Set the build version to be 'qa', 'rc', 'release'""" -"""Set the build version to be 'dev', 'qa', 'rc', 'release'""" - -import os.path -import re -import subprocess import sys +import os +import re +import logging + +log = logging.getLogger() +log.addHandler(logging.StreamHandler()) +log.setLevel(logging.DEBUG) + + +def get_build_type(travis_tag=None): + if not travis_tag: + return "qa" + log.debug("getting build type for tag: \"%s\"", travis_tag) + if re.match('v\d+\.\d+\.\d+rc\d+$', travis_tag): + return 'rc' + elif re.match('v\d+\.\d+\.\d+$', travis_tag): + return 'release' + return 'qa' def main(): - build = get_build() root_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) - with open(os.path.join(root_dir, 'lbrynet', 'build_type.py'), 'w') as f: - f.write("BUILD = '{}'\n".format(build)) - - -def get_build(): - try: - tag = subprocess.check_output(['git', 'describe', '--exact-match', '--all']).strip() - if re.match('tags\/v\d+\.\d+\.\d+rc\d+$', tag.decode()): - print('Build: rc') - return 'rc' - elif re.match('tags\/v\d+\.\d+\.\d+$', tag.decode()): - print('Build: release') - return 'release' - print('Build: qa') - return 'qa' - except subprocess.CalledProcessError: - print("Couldn't determine build type, defaulting to qa.") - return 'qa' + build_type_path = os.path.join(root_dir, 'lbrynet', 'build_type.py') + log.debug("configuring build type file: %s", build_type_path) + travis_commit = os.environ['TRAVIS_COMMIT'][:6] + build_type = get_build_type(os.environ.get('TRAVIS_TAG', None)) + log.debug("setting build type=%s, build commit=%s", build_type, travis_commit) + with open(build_type_path, 'w') as f: + f.write("BUILD = \"{}\"\nBUILD_COMMIT = \"{}\"\n".format(build_type, travis_commit)) if __name__ == '__main__': diff --git a/scripts/wine_build.sh b/scripts/wine_build.sh index 175adbc11..a98acf050 100755 --- a/scripts/wine_build.sh +++ b/scripts/wine_build.sh @@ -1,13 +1,10 @@ set -x - +TORBA=$1 rm -rf /tmp/.wine-* apt-get -qq update apt-get -qq install -y git - pip install setuptools_scm -git clone https://github.com/lbryio/torba.git --depth 1 -cd torba && pip install -e . && cd .. cd lbry @@ -15,6 +12,8 @@ cd lbry wget -Onetifaces-0.10.7-cp37-cp37m-win32.whl https://ci.appveyor.com/api/buildjobs/6hworunifsymrhp2/artifacts/dist%2Fnetifaces-0.10.7-cp37-cp37m-win32.whl pip install netifaces-0.10.7-cp37-cp37m-win32.whl +pip install git+https://github.com/lbryio/torba.git@${TORBA}#egg=torba + pip install -e . pip install pywin32 diff --git a/setup.py b/setup.py index 5735a25f7..50ba48881 100644 --- a/setup.py +++ b/setup.py @@ -23,7 +23,7 @@ setup( 'console_scripts': 'lbrynet=lbrynet.extras.cli:main' }, install_requires=[ - 'torba', + 'torba==0.5.4', 'aiohttp==3.5.4', 'aioupnp', 'appdirs==1.4.3', diff --git a/tox.ini b/tox.ini index d66c1b87b..0d2faf5e8 100644 --- a/tox.ini +++ b/tox.ini @@ -5,6 +5,7 @@ envlist = py37-integration deps = coverage ../torba + extras = test changedir = {toxinidir}/tests setenv =