blob: 15a70db31f8f9a0865144b8b3bbd25399c04abda [file] [log] [blame]
Jisi Liu09354db2017-07-18 15:38:30 -07001#!/bin/bash
2
3set -ex
4
5function get_source_version() {
6 grep "__version__ = '.*'" python/google/protobuf/__init__.py | sed -r "s/__version__ = '(.*)'/\1/"
7}
8
9function run_install_test() {
10 local VERSION=$1
11 local PYTHON=$2
12 local PYPI=$3
13
Paul Yang3b0f10b2021-08-20 08:49:08 -070014 virtualenv -p `which $PYTHON` test-venv
Jisi Liu09354db2017-07-18 15:38:30 -070015
16 # Intentionally put a broken protoc in the path to make sure installation
17 # doesn't require protoc installed.
18 touch test-venv/bin/protoc
19 chmod +x test-venv/bin/protoc
20
21 source test-venv/bin/activate
Jisi Liu7ad8e7a2017-12-22 11:47:13 -080022 pip install -i ${PYPI} protobuf==${VERSION} --no-cache-dir
Jisi Liu09354db2017-07-18 15:38:30 -070023 deactivate
24 rm -fr test-venv
25}
26
27
28[ $# -lt 1 ] && {
29 echo "Usage: $0 VERSION ["
30 echo ""
31 echo "Examples:"
32 echo " Test 3.3.0 release using version number 3.3.0.dev1:"
33 echo " $0 3.0.0 dev1"
34 echo " Actually release 3.3.0 to PyPI:"
35 echo " $0 3.3.0"
36 exit 1
37}
38VERSION=$1
39DEV=$2
40
41# Make sure we are in a protobuf source tree.
42[ -f "python/google/protobuf/__init__.py" ] || {
43 echo "This script must be ran under root of protobuf source tree."
44 exit 1
45}
46
47# Make sure all files are world-readable.
48find python -type d -exec chmod a+r,a+x {} +
49find python -type f -exec chmod a+r {} +
Feng Xiao3a06fe12017-12-14 17:54:18 -080050umask 0022
Jisi Liu09354db2017-07-18 15:38:30 -070051
52# Check that the supplied version number matches what's inside the source code.
53SOURCE_VERSION=`get_source_version`
54
55[ "${VERSION}" == "${SOURCE_VERSION}" -o "${VERSION}.${DEV}" == "${SOURCE_VERSION}" ] || {
56 echo "Version number specified on the command line ${VERSION} doesn't match"
57 echo "the actual version number in the source code: ${SOURCE_VERSION}"
58 exit 1
59}
60
61TESTING_ONLY=1
62TESTING_VERSION=${VERSION}.${DEV}
63if [ -z "${DEV}" ]; then
64 read -p "You are releasing ${VERSION} to PyPI. Are you sure? [y/n]" -r
65 echo
66 if [[ ! $REPLY =~ ^[Yy]$ ]]; then
67 exit 1
68 fi
69 TESTING_ONLY=0
70 TESTING_VERSION=${VERSION}
71else
72 # Use dev version number for testing.
73 sed -i -r "s/__version__ = '.*'/__version__ = '${VERSION}.${DEV}'/" python/google/protobuf/__init__.py
74fi
75
Paul Yang81771b92021-08-27 15:41:58 -070076# Copy LICENSE
77cp LICENSE python/LICENSE
78
Jisi Liu09354db2017-07-18 15:38:30 -070079cd python
80
81# Run tests locally.
Adam Cozzetteb45ce5e2020-11-10 14:33:16 -080082python3 setup.py build
83python3 setup.py test
Jisi Liu09354db2017-07-18 15:38:30 -070084
85# Deploy source package to testing PyPI
Adam Cozzetteb45ce5e2020-11-10 14:33:16 -080086python3 setup.py sdist
Joshua Haberman0ff63992020-05-28 10:56:10 -070087twine upload --skip-existing -r testpypi -u protobuf-wheel-test dist/*
Jisi Liu09354db2017-07-18 15:38:30 -070088
89# Test locally with different python versions.
Paul Yang5b4ac532019-02-01 18:43:55 -080090run_install_test ${TESTING_VERSION} python3 https://test.pypi.org/simple
Jisi Liu09354db2017-07-18 15:38:30 -070091
92# Deploy egg/wheel packages to testing PyPI and test again.
Adam Cozzetteb45ce5e2020-11-10 14:33:16 -080093python3 setup.py clean build bdist_wheel
Joshua Haberman0ff63992020-05-28 10:56:10 -070094twine upload --skip-existing -r testpypi -u protobuf-wheel-test dist/*
Jisi Liu7ad8e7a2017-12-22 11:47:13 -080095
Paul Yang5b4ac532019-02-01 18:43:55 -080096run_install_test ${TESTING_VERSION} python3 https://test.pypi.org/simple
Jisi Liu09354db2017-07-18 15:38:30 -070097
98echo "All install tests have passed using testing PyPI."
99
100if [ $TESTING_ONLY -eq 0 ]; then
101 read -p "Publish to PyPI? [y/n]" -r
102 echo
103 if [[ ! $REPLY =~ ^[Yy]$ ]]; then
104 exit 1
105 fi
106 echo "Publishing to PyPI..."
107 # Be sure to run build before sdist, because otherwise sdist will not include
108 # well-known types.
Adam Cozzetteb45ce5e2020-11-10 14:33:16 -0800109 python3 setup.py clean build sdist
Joshua Haberman0ff63992020-05-28 10:56:10 -0700110 twine upload --skip-existing -u protobuf-packages dist/*
Jisi Liu09354db2017-07-18 15:38:30 -0700111 # Be sure to run clean before bdist_xxx, because otherwise bdist_xxx will
112 # include files you may not want in the package. E.g., if you have built
113 # and tested with --cpp_implemenation, bdist_xxx will include the _message.so
114 # file even when you no longer pass the --cpp_implemenation flag. See:
Feng Xiaoafe98de2018-08-22 11:55:30 -0700115 # https://github.com/protocolbuffers/protobuf/issues/3042
Adam Cozzetteb45ce5e2020-11-10 14:33:16 -0800116 python3 setup.py clean build bdist_wheel
Joshua Haberman0ff63992020-05-28 10:56:10 -0700117 twine upload --skip-existing -u protobuf-packages dist/*
Jisi Liu09354db2017-07-18 15:38:30 -0700118else
119 # Set the version number back (i.e., remove dev suffix).
120 sed -i -r "s/__version__ = '.*'/__version__ = '${VERSION}'/" google/protobuf/__init__.py
121fi