Skip to content

Commit ee0dbcc

Browse files
authored
Merge branch 'main' into django-asgi
2 parents a5db459 + d9c0116 commit ee0dbcc

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Publish a Package from Tag
2+
3+
on:
4+
push:
5+
tags:
6+
- 'opentelemetry-*==1.*'
7+
8+
jobs:
9+
publish-a-package:
10+
name: Publish package from tag
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v1
14+
- uses: actions/setup-python@v1
15+
with:
16+
python-version: '3.9'
17+
- name: Log tag that triggered publish workflow
18+
run: echo "Attempting to publish package from tag $GITHUB_REF"
19+
- name: Build wheel for tag
20+
run: ./scripts/build_a_package.sh
21+
- name: Install twine
22+
run: |
23+
pip install twine
24+
# We don't need to publish to TestPyPI because we only publish 1 package.
25+
# If it fails no other work needs to be reversed.
26+
- name: Publish to PyPI
27+
env:
28+
TWINE_USERNAME: '__token__'
29+
TWINE_PASSWORD: ${{ secrets.pypi_password }}
30+
run: |
31+
twine upload --skip-existing --verbose dist/*

scripts/build.sh

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ DISTDIR=dist
3131
(
3232
cd $DISTDIR
3333
for x in *.tar.gz ; do
34+
if [[ $x =~ ^opentelemetry-.*-1\.[0-9]+.*\.tar\.gz$ ]]; then
35+
echo "Skipping $x because it is >=1.0 and should be released using a tag."
36+
continue
37+
fi
3438
pip wheel --no-deps $x
3539
done
3640
)

scripts/build_a_package.sh

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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

Comments
 (0)