From ea1bf40a1ee1c1c934e47a0020417503ab3d7e7e Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sat, 30 Oct 2021 18:45:44 +0200 Subject: [PATCH] Using Jenkins for PyPI deployment. Travis stopped their generous open source support --- Jenkinsfile-pypi | 43 +++++++++++++++++++++++ ci-scripts/docker/docker_build_jenkins.sh | 31 ++++++++++++++++ setup.py | 8 ++++- 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 Jenkinsfile-pypi create mode 100755 ci-scripts/docker/docker_build_jenkins.sh diff --git a/Jenkinsfile-pypi b/Jenkinsfile-pypi new file mode 100644 index 000000000..72d16f7da --- /dev/null +++ b/Jenkinsfile-pypi @@ -0,0 +1,43 @@ + +@Library("platform") _ + +properties([disableConcurrentBuilds()]) + +// from shared library - uses tags to set the platform name +// (this is a pretty stupid way to set a parameter, but I don't +// know of a better way to parameterize a multibranch pipeline) +platform = pypi_platform() +py_version = pypi_py_version() + +currentBuild.description = "PyPI deployment " + platform + +docker_image = "jenkins-manylinux2014_x86_64-pypi" +target = platform + ".whl" + +node("master") { + + stage("Checkout sources") { + checkout scm + } + + stage("Building target ${target}") { + + sh("rm -rf wheelhouse ; mkdir -p wheelhouse") + + withDockerContainer(image: docker_image, args: "-v " + pwd() + ":/io") { + sh("PY_VERSION=" + py_version + " /io/ci-scripts/docker/docker_build_jenkins.sh") + } + + } + + stage("Publish and test") { + + // publish for release tags + if (BRANCH_NAME.startsWith('v')) { + sh("twine upload --skip-existing wheelhouse/klayout-*manylinux2014*.whl wheelhouse/*.zip") + } + + } + +} + diff --git a/ci-scripts/docker/docker_build_jenkins.sh b/ci-scripts/docker/docker_build_jenkins.sh new file mode 100755 index 000000000..838a02dc0 --- /dev/null +++ b/ci-scripts/docker/docker_build_jenkins.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + + +if [[ -z $PY_VERSION ]]; then + echo '$PY_VERSION is not set' + exit 1 +fi + +echo PY_VERSION=$PY_VERSION + +# Use single cores only so we do not overload the Jenkins host +export KLAYOUT_SETUP_MULTICORE=1 + +# Compile wheel and build source distribution +cd /io +"/opt/python/$PY_VERSION/bin/python" setup.py bdist_wheel -d /io/wheelhouse/ || exit 1 +"/opt/python/$PY_VERSION/bin/python" setup.py sdist --formats=zip -d /io/wheelhouse || exit 1 + +# Bundle external shared libraries into the wheels via auditwheel +for whl in /io/wheelhouse/*linux_*.whl; do + auditwheel repair "$whl" -w /io/wheelhouse/ || exit 1 +done + +# Install packages and test +TEST_HOME=/io/testdata +"/opt/python/$PY_VERSION/bin/pip" install klayout --no-index -f /io/wheelhouse || exit 1 +"/opt/python/$PY_VERSION/bin/python" $TEST_HOME/pymod/import_db.py || exit 1 +"/opt/python/$PY_VERSION/bin/python" $TEST_HOME/pymod/import_rdb.py || exit 1 +"/opt/python/$PY_VERSION/bin/python" $TEST_HOME/pymod/import_tl.py || exit 1 +"/opt/python/$PY_VERSION/bin/python" $TEST_HOME/pymod/pya_tests.py || exit 1 + diff --git a/setup.py b/setup.py index d6e47cd81..3b3b5a3d7 100644 --- a/setup.py +++ b/setup.py @@ -65,7 +65,13 @@ from distutils.errors import CompileError import distutils.command.build_ext import setuptools.command.build_ext import multiprocessing -N_cores = multiprocessing.cpu_count() + +# for Jenkins we do not want to be greedy +multicore = os.getenv("KLAYOUT_SETUP_MULTICORE") +if multicore: + N_cores = int(multicore) +else: + N_cores = multiprocessing.cpu_count() # monkey-patch for parallel compilation