From 8c05c18c2a2d203cb42cb488ecee7d11d848e751 Mon Sep 17 00:00:00 2001 From: Juri Engel Date: Mon, 13 May 2019 10:27:45 +0200 Subject: [PATCH] Add gilab ci pipeline, publish library when a tag is pushed --- .gitlab-ci.yml | 34 ++++++++++++++++++++++++++++++++++ deploy.py | 14 +++++--------- 2 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..2df3e03 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,34 @@ +# Include Global Configurations +include: + - project: 'api-server/gitlab-ci-scripts' + ref: v1.1 + file: '.global-configuration.yml' + +image: code.route360.net:4567/docker/general-image/service/psql9.6:0.0.4 + +stages: + - build + - deploy + +build: + stage: build + script: + - configure_sonar_scanner + - configure_python3_virtual_env + - python3 -m compileall -f targomo_python deploy.py setup.py + - sonarscanner -Dsonar.sources=targomo_python + only: + - /^feature.*$/ + - /^release.*$/ + - develop + - master + +deploy: + stage: deploy + script: + - configure_python3_virtual_env + - insert_pypirc + - echo $CI_COMMIT_TAG + - python3 deploy.py --version $CI_COMMIT_TAG + only: + - tags diff --git a/deploy.py b/deploy.py index 03073ef..0551e82 100644 --- a/deploy.py +++ b/deploy.py @@ -1,25 +1,21 @@ ### publish new version of this library to PyPI -import git from shutil import copyfile import fileinput import sys import os +import argparse +parser = argparse.ArgumentParser(description="Publish the Targomo python library to PyPi") +parser.add_argument("--version", required=True, type=str, help="The version number", nargs="?") +args = parser.parse_args() copyfile("./setup.py.default", "./setup.py") -repo = git.Repo(".") -lasttag = sorted(repo.tags, key=lambda t: t.commit.committed_date)[-1] -nexttag = "0." + str(int(str(lasttag).replace("0.", "")) + 1) - for line in fileinput.input("./setup.py", inplace=True): - line = line.replace("$VERSION", str(nexttag)) + line = line.replace("$VERSION", args.version) sys.stdout.write(line), -new_tag = repo.create_tag(str(nexttag), message='Automatic deployment of new version "{0}"'.format(nexttag)) -repo.remotes.origin.push(new_tag) - os.system("python3 setup.py sdist") os.system("twine upload --repository pypitest dist/*") os.system("twine upload --repository pypi dist/*")