|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# Copyright The OpenTelemetry Authors |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +# This script builds wheels for a single package when trigged from a push to |
| 18 | +# a tag as part of a GitHub workflow (See .github/publish-a-package.yml). The |
| 19 | +# wheel is then published to PyPI. |
| 20 | + |
| 21 | +set -ev |
| 22 | + |
| 23 | +if [ -z $GITHUB_REF ]; then |
| 24 | + echo 'Failed to run script, missing workflow env variable GITHUB_REF.' |
| 25 | + exit -1 |
| 26 | +fi |
| 27 | + |
| 28 | +pkg_name_and_version=${GITHUB_REF#refs/tags/*} |
| 29 | +pkg_name=${pkg_name_and_version%==*} |
| 30 | +pkg_version=${pkg_name_and_version#opentelemetry-*==} |
| 31 | + |
| 32 | +# Get the latest versions of packaging tools |
| 33 | +python3 -m pip install --upgrade pip setuptools wheel packaging |
| 34 | + |
| 35 | +# Validate vesrion against PEP 440 conventions: https://packaging.pypa.io/en/latest/version.html |
| 36 | +python3 -c "from packaging.version import Version; Version('${pkg_version}')" |
| 37 | + |
| 38 | +basedir=$(git rev-parse --show-toplevel) |
| 39 | +cd $basedir |
| 40 | + |
| 41 | +distdir=${basedir}/dist |
| 42 | +mkdir -p $distdir |
| 43 | +rm -rf $distdir/* |
| 44 | + |
| 45 | +setup_py_file_path=$(ls **/$pkg_name/setup.py) |
| 46 | + |
| 47 | +if [ -z $setup_py_file_path ]; then |
| 48 | + echo "Error! setup.py not found for $pkg_name, can't build." |
| 49 | + exit -1 |
| 50 | +fi |
| 51 | + |
| 52 | +directory_with_package=$(dirname $setup_py_file_path) |
| 53 | + |
| 54 | +cd $directory_with_package |
| 55 | + |
| 56 | +python3 setup.py sdist --dist-dir ${distdir} clean --all |
| 57 | + |
| 58 | +cd $distdir |
| 59 | + |
| 60 | +pkg_tar_gz_file=${pkg_name}-${pkg_version}.tar.gz |
| 61 | + |
| 62 | +if ! [ -f $pkg_tar_gz_file ]; then |
| 63 | + echo 'Error! Tag version does not match version built using latest package files.' |
| 64 | + exit -1 |
| 65 | +fi |
| 66 | + |
| 67 | +# Build a wheel for the source distribution |
| 68 | +pip wheel --no-deps $pkg_tar_gz_file |
0 commit comments