Skip to content

Commit

Permalink
bugy#215 added creation of version file for builds
Browse files Browse the repository at this point in the history
  • Loading branch information
bugy committed Jun 16, 2019
1 parent 409f766 commit e5bf2aa
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 15 deletions.
12 changes: 2 additions & 10 deletions tools/add_git_tag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,8 @@ if [ "$TRAVIS_BRANCH" == "master" ]; then
export NEW_GIT_TAG='dev'

elif [ "$TRAVIS_BRANCH" == "stable" ]; then
last_tag=`git describe --abbrev=0 --tags`
npm_tag=`grep -Po '"version": "\d+.\d+.\d+"' web-src/package.json | grep -Po '\d+.\d+.\d+'`
minor_npm_version=${npm_tag%.*}
if [ ${last_tag%.*} == "$minor_npm_version" ]; then
last_patch_version=${last_tag##*.}
next_patch_version=$((last_patch_version + 1))
export NEW_GIT_TAG="$minor_npm_version.$next_patch_version"
else
export NEW_GIT_TAG="$npm_tag"
fi
version=`unzip -qc build/script-server.zip version.txt`
export NEW_GIT_TAG="$version"
fi

set -e
Expand Down
49 changes: 44 additions & 5 deletions tools/build.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#!/usr/bin/env python3

import glob
import json
import os
import shutil
import zipfile
from os.path import join

import init
from utils import file_utils
from utils import process_utils

VERSION_FILE = 'version.txt'

BUILD_FOLDER = 'build'

Expand Down Expand Up @@ -44,11 +48,50 @@ def get_files(self):
return self.files


def get_npm_version():
package_json = json.loads(file_utils.read_file(join('web-src', 'package.json')))
if 'version' in package_json:
return parse_semver_str(package_json['version'])

raise Exception('Failed to find version parameter in package.json')


def parse_semver_str(version_string):
return [int(v) for v in version_string.split('.')]


def create_version_file():
current_branch = process_utils.invoke('git rev-parse --abbrev-ref HEAD').strip()
npm_version = get_npm_version()
if current_branch == 'stable':
last_tag = process_utils.invoke('git describe --abbrev=0 --tags').strip()
last_tag_version = parse_semver_str(last_tag)
if (last_tag_version[0] == npm_version[0]) and (last_tag_version[1] == npm_version[1]):
new_version = [last_tag_version[0], last_tag_version[1], last_tag_version[2] + 1]
else:
new_version = npm_version
new_version = '.'.join([str(v) for v in new_version])
else:
git_hash = process_utils.invoke('git rev-parse --short HEAD').strip()

new_version = str(npm_version[0])
new_version += '.' + str(npm_version[1] + 1)
new_version += '.0-'
new_version += current_branch + '@' + git_hash
file_utils.write_file(VERSION_FILE, new_version)


if os.path.exists(BUILD_FOLDER):
shutil.rmtree(BUILD_FOLDER)
os.mkdir(BUILD_FOLDER)

init.prepare_project('', prod=True)
create_version_file()

build_info = BuildInfo()
build_info.include('launcher.py')
build_info.include('requirements.txt')
build_info.include(VERSION_FILE)
build_info.include(os.path.join('src', '**', '*.py'))
build_info.include(os.path.join('conf', 'logging.json'))
build_info.include(os.path.join('web', '**'))
Expand All @@ -58,10 +101,6 @@ def get_files(self):
build_info.exclude('samples')
build_info.exclude(BUILD_FOLDER)

if os.path.exists(BUILD_FOLDER):
shutil.rmtree(BUILD_FOLDER)
os.mkdir(BUILD_FOLDER)

zip = zipfile.ZipFile(os.path.join(BUILD_FOLDER, 'script-server.zip'), 'w', zipfile.ZIP_DEFLATED)
for file in build_info.get_files():
zip.write(file)

0 comments on commit e5bf2aa

Please sign in to comment.