From cd5a91d4c81d6ccf7d09163491156638daf20744 Mon Sep 17 00:00:00 2001 From: Nicholas Staples Date: Mon, 1 Feb 2016 11:37:22 +0000 Subject: [PATCH 1/3] version file has been updated to include a travis commit and time of build. --- .travis.yml | 1 + app/__init__.py | 16 +++++++++------- app/status/healthcheck.py | 4 +++- app/version.py | 3 ++- scripts/update_version_file.sh | 6 ++++++ 5 files changed, 21 insertions(+), 9 deletions(-) create mode 100755 scripts/update_version_file.sh diff --git a/.travis.yml b/.travis.yml index 687ad4a23..446eb43c4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,6 +40,7 @@ deploy: region: eu-west-1 on: *2 before_deploy: +- ./scripts/update_version_file.sh - zip -r notifications-api * - mkdir -p dpl_cd_upload - mv notifications-api.zip dpl_cd_upload/notifications-api-$TRAVIS_BRANCH-$TRAVIS_BUILD_NUMBER-$TRAVIS_COMMIT.zip diff --git a/app/__init__.py b/app/__init__.py index 7b38a376e..5fefc46d4 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -121,13 +121,15 @@ def convert_to_number(value): def get_api_version(): - _version_re = re.compile(r'__version__\s+=\s+(.*)') - version = 'n/a' - dir_path = os.path.dirname(os.path.abspath(__file__)) - with open(os.path.join(dir_path, 'version.py'), 'rb') as f: - version = str(ast.literal_eval(_version_re.search( - f.read().decode('utf-8')).group(1))) - return version + build = 'n/a' + build_time = "n/a" + try: + from app import version + build = version.__build__ + build_time = version.__time__ + except: + pass + return build, build_time def get_db_version(): diff --git a/app/status/healthcheck.py b/app/status/healthcheck.py index b513bc600..b16619828 100644 --- a/app/status/healthcheck.py +++ b/app/status/healthcheck.py @@ -7,6 +7,8 @@ status = Blueprint('status', __name__) @status.route('/_status', methods=['GET', 'POST']) def show_status(): from app import (get_api_version, get_db_version) + build, build_time = get_api_version() return jsonify(status="ok", - api_version=get_api_version(), + api_build=build, + api_built_time=build_time, db_version=get_db_version()), 200 diff --git a/app/version.py b/app/version.py index df9144c54..49af4a53e 100644 --- a/app/version.py +++ b/app/version.py @@ -1 +1,2 @@ -__version__ = '0.1.1' +__build__ = "12345" +__time__ = "2016-01-01:10:10:10" diff --git a/scripts/update_version_file.sh b/scripts/update_version_file.sh new file mode 100755 index 000000000..27117f6dd --- /dev/null +++ b/scripts/update_version_file.sh @@ -0,0 +1,6 @@ +#!/bin/bash +# +# Update the version file of the project from the Travis build details +# +sed -i -e "s/__build__ =.*/__build__ = \"$TRAVIS_COMMIT\"/g" ./app/version.py +sed -i -e "s/__time__ =.*/__time__ = \"$('date +%Y-%m-%d:%H:%M:%S')\"/g" ./app/version.py \ No newline at end of file From d4b95efb6fe4d771714220c25095f9956953987c Mon Sep 17 00:00:00 2001 From: Nicholas Staples Date: Mon, 1 Feb 2016 12:00:02 +0000 Subject: [PATCH 2/3] Remove unused file. --- scripts/push-tag.sh | 55 --------------------------------------------- 1 file changed, 55 deletions(-) delete mode 100644 scripts/push-tag.sh diff --git a/scripts/push-tag.sh b/scripts/push-tag.sh deleted file mode 100644 index 5a74e9a05..000000000 --- a/scripts/push-tag.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/bash - -function pretty() { - local blue="\033[34m" - local reset="\033[0m" - while read line; do - echo -e "${blue}[publishing]${reset} ${line}" - done -} - -function warn() { - local orange="\033[33m" - local reset="\033[0m" - while read line; do - echo -e "${orange}[warning]${reset} ${line}" - done -} - -function get_sha(){ - REF=$(git log -n 1 -- VERSION --name-only) - SHA=$(echo $REF | awk '{ print $2 }') - - echo "checking out ${SHA}" | pretty - - git checkout $SHA -} - -function get_version(){ - VERSION=$(python setup.py --version) - echo "latest version is ${VERSION}" | pretty -} - -function push_tag_or_die(){ - TAG_EXISTS=$(git tag | grep -G "^${VERSION}$") - if [ "$TAG_EXISTS" ]; then - echo "Tag already exists, exiting" | warn - exit 0 - else - push_tag $VERSION - fi -} - -function push_tag(){ - git tag -a $VERSION -m "Version tag for ${VERSION}" - echo "Pushing tags to github ${VERSION} to Github" | pretty - git push origin --tags -} - -function main(){ - get_sha - get_version - push_tag_or_die -} - -main \ No newline at end of file From 238e8942af439070252a1f036583c695cdd68f9b Mon Sep 17 00:00:00 2001 From: Nicholas Staples Date: Tue, 2 Feb 2016 11:06:22 +0000 Subject: [PATCH 3/3] Fix for pull request comment. --- app/version.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/version.py b/app/version.py index 49af4a53e..62a3e5dfd 100644 --- a/app/version.py +++ b/app/version.py @@ -1,2 +1,2 @@ -__build__ = "12345" -__time__ = "2016-01-01:10:10:10" +__build__ = "" +__time__ = ""