-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathpublish-python-version
executable file
·73 lines (59 loc) · 1.85 KB
/
publish-python-version
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env bash
# SPDX-FileCopyrightText: 2020 Open Networking Foundation <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0
# pypi-publish.sh - Publishes Python modules to PyPI
#
# Makes the following assumptions:
# - PyPI credentials are populated in ~/.pypirc
# - git repo is tagged with a SEMVER released version. If not, exit.
# - If required, Environmental variables can be set for:
# PYPI_INDEX - name of PyPI index to use (see contents of ~/.pypirc for reference)
# PYPI_MODULE_DIRS - pipe-separated list of modules to be uploaded
# PYPI_PREP_COMMANDS - commands to run (in root directory) to prepare for sdist
set -eu -o pipefail
echo "Using twine version:"
twine --version
pypi_success=0
# environmental vars
BASEDIR=${BASEDIR:-.}
PYPI_PREP_COMMANDS=${PYPI_PREP_COMMANDS:-}
PYPI_INDEX=${PYPI_INDEX:-testpypi}
PYPI_MODULE_DIRS=${PYPI_MODULE_DIRS:-.}
# Read in the desired version
export VERSION=$(< ./VERSION)
# match bare versions or v-prefixed golang style version
if [[ "$VERSION" =~ ^v?([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]
then
echo "git has a SemVer released version tag: '$VERSION', publishing to PyPI"
else
echo "No SemVer released version tag found, exiting..."
exit 0
fi
# Run commands if PYPI_PREP_COMMANDS if not null
if [[ -n "$PYPI_PREP_COMMANDS" ]]
then
$PYPI_PREP_COMMANDS
fi
# iterate over $PYPI_MODULE_DIRS
# field separator is pipe character
IFS=$'|'
for pymod in $PYPI_MODULE_DIRS
do
pymoddir="$BASEDIR/$pymod"
if [ ! -f "$pymoddir/setup.py" ]
then
echo "Directory with python module not found at '$pymoddir'"
pypi_success=1
else
pushd "$pymoddir"
echo "Building python module in '$pymoddir'"
# Create source distribution
python3 setup.py sdist
# Upload to PyPI
echo "Uploading to PyPI"
python3 -m twine upload -r "$PYPI_INDEX" dist/*
popd
fi
done
exit $pypi_success