Jisi Liu | 09354db | 2017-07-18 15:38:30 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | set -ex |
| 4 | |
| 5 | function get_source_version() { |
| 6 | grep "__version__ = '.*'" python/google/protobuf/__init__.py | sed -r "s/__version__ = '(.*)'/\1/" |
| 7 | } |
| 8 | |
| 9 | function run_install_test() { |
| 10 | local VERSION=$1 |
| 11 | local PYTHON=$2 |
| 12 | local PYPI=$3 |
| 13 | |
Adam Cozzette | 2ad43bf | 2020-08-14 08:57:23 -0700 | [diff] [blame] | 14 | # Setuptools 45.0 removed support for Python 2, so to test with Python 2 we |
| 15 | # pass --no-setuptools here and then install an older setuptools version |
| 16 | # below. |
| 17 | virtualenv -p `which $PYTHON` --no-setuptools test-venv |
Jisi Liu | 09354db | 2017-07-18 15:38:30 -0700 | [diff] [blame] | 18 | |
| 19 | # Intentionally put a broken protoc in the path to make sure installation |
| 20 | # doesn't require protoc installed. |
| 21 | touch test-venv/bin/protoc |
| 22 | chmod +x test-venv/bin/protoc |
| 23 | |
| 24 | source test-venv/bin/activate |
Adam Cozzette | 2ad43bf | 2020-08-14 08:57:23 -0700 | [diff] [blame] | 25 | pip install "setuptools<45" |
Jisi Liu | 7ad8e7a | 2017-12-22 11:47:13 -0800 | [diff] [blame] | 26 | pip install -i ${PYPI} protobuf==${VERSION} --no-cache-dir |
Jisi Liu | 09354db | 2017-07-18 15:38:30 -0700 | [diff] [blame] | 27 | deactivate |
| 28 | rm -fr test-venv |
| 29 | } |
| 30 | |
| 31 | |
| 32 | [ $# -lt 1 ] && { |
| 33 | echo "Usage: $0 VERSION [" |
| 34 | echo "" |
| 35 | echo "Examples:" |
| 36 | echo " Test 3.3.0 release using version number 3.3.0.dev1:" |
| 37 | echo " $0 3.0.0 dev1" |
| 38 | echo " Actually release 3.3.0 to PyPI:" |
| 39 | echo " $0 3.3.0" |
| 40 | exit 1 |
| 41 | } |
| 42 | VERSION=$1 |
| 43 | DEV=$2 |
| 44 | |
| 45 | # Make sure we are in a protobuf source tree. |
| 46 | [ -f "python/google/protobuf/__init__.py" ] || { |
| 47 | echo "This script must be ran under root of protobuf source tree." |
| 48 | exit 1 |
| 49 | } |
| 50 | |
| 51 | # Make sure all files are world-readable. |
| 52 | find python -type d -exec chmod a+r,a+x {} + |
| 53 | find python -type f -exec chmod a+r {} + |
Feng Xiao | 3a06fe1 | 2017-12-14 17:54:18 -0800 | [diff] [blame] | 54 | umask 0022 |
Jisi Liu | 09354db | 2017-07-18 15:38:30 -0700 | [diff] [blame] | 55 | |
| 56 | # Check that the supplied version number matches what's inside the source code. |
| 57 | SOURCE_VERSION=`get_source_version` |
| 58 | |
| 59 | [ "${VERSION}" == "${SOURCE_VERSION}" -o "${VERSION}.${DEV}" == "${SOURCE_VERSION}" ] || { |
| 60 | echo "Version number specified on the command line ${VERSION} doesn't match" |
| 61 | echo "the actual version number in the source code: ${SOURCE_VERSION}" |
| 62 | exit 1 |
| 63 | } |
| 64 | |
| 65 | TESTING_ONLY=1 |
| 66 | TESTING_VERSION=${VERSION}.${DEV} |
| 67 | if [ -z "${DEV}" ]; then |
| 68 | read -p "You are releasing ${VERSION} to PyPI. Are you sure? [y/n]" -r |
| 69 | echo |
| 70 | if [[ ! $REPLY =~ ^[Yy]$ ]]; then |
| 71 | exit 1 |
| 72 | fi |
| 73 | TESTING_ONLY=0 |
| 74 | TESTING_VERSION=${VERSION} |
| 75 | else |
| 76 | # Use dev version number for testing. |
| 77 | sed -i -r "s/__version__ = '.*'/__version__ = '${VERSION}.${DEV}'/" python/google/protobuf/__init__.py |
| 78 | fi |
| 79 | |
| 80 | cd python |
| 81 | |
| 82 | # Run tests locally. |
Adam Cozzette | b45ce5e | 2020-11-10 14:33:16 -0800 | [diff] [blame^] | 83 | python3 setup.py build |
| 84 | python3 setup.py test |
Jisi Liu | 09354db | 2017-07-18 15:38:30 -0700 | [diff] [blame] | 85 | |
| 86 | # Deploy source package to testing PyPI |
Adam Cozzette | b45ce5e | 2020-11-10 14:33:16 -0800 | [diff] [blame^] | 87 | python3 setup.py sdist |
Joshua Haberman | 0ff6399 | 2020-05-28 10:56:10 -0700 | [diff] [blame] | 88 | twine upload --skip-existing -r testpypi -u protobuf-wheel-test dist/* |
Jisi Liu | 09354db | 2017-07-18 15:38:30 -0700 | [diff] [blame] | 89 | |
| 90 | # Test locally with different python versions. |
Jisi Liu | 19a7e20 | 2017-08-16 10:30:38 -0700 | [diff] [blame] | 91 | run_install_test ${TESTING_VERSION} python2.7 https://test.pypi.org/simple |
Paul Yang | 5b4ac53 | 2019-02-01 18:43:55 -0800 | [diff] [blame] | 92 | run_install_test ${TESTING_VERSION} python3 https://test.pypi.org/simple |
Jisi Liu | 09354db | 2017-07-18 15:38:30 -0700 | [diff] [blame] | 93 | |
| 94 | # Deploy egg/wheel packages to testing PyPI and test again. |
Adam Cozzette | b45ce5e | 2020-11-10 14:33:16 -0800 | [diff] [blame^] | 95 | python3 setup.py clean build bdist_wheel |
Joshua Haberman | 0ff6399 | 2020-05-28 10:56:10 -0700 | [diff] [blame] | 96 | twine upload --skip-existing -r testpypi -u protobuf-wheel-test dist/* |
Jisi Liu | 7ad8e7a | 2017-12-22 11:47:13 -0800 | [diff] [blame] | 97 | |
Jisi Liu | 19a7e20 | 2017-08-16 10:30:38 -0700 | [diff] [blame] | 98 | run_install_test ${TESTING_VERSION} python2.7 https://test.pypi.org/simple |
Paul Yang | 5b4ac53 | 2019-02-01 18:43:55 -0800 | [diff] [blame] | 99 | run_install_test ${TESTING_VERSION} python3 https://test.pypi.org/simple |
Jisi Liu | 09354db | 2017-07-18 15:38:30 -0700 | [diff] [blame] | 100 | |
| 101 | echo "All install tests have passed using testing PyPI." |
| 102 | |
| 103 | if [ $TESTING_ONLY -eq 0 ]; then |
| 104 | read -p "Publish to PyPI? [y/n]" -r |
| 105 | echo |
| 106 | if [[ ! $REPLY =~ ^[Yy]$ ]]; then |
| 107 | exit 1 |
| 108 | fi |
| 109 | echo "Publishing to PyPI..." |
| 110 | # Be sure to run build before sdist, because otherwise sdist will not include |
| 111 | # well-known types. |
Adam Cozzette | b45ce5e | 2020-11-10 14:33:16 -0800 | [diff] [blame^] | 112 | python3 setup.py clean build sdist |
Joshua Haberman | 0ff6399 | 2020-05-28 10:56:10 -0700 | [diff] [blame] | 113 | twine upload --skip-existing -u protobuf-packages dist/* |
Jisi Liu | 09354db | 2017-07-18 15:38:30 -0700 | [diff] [blame] | 114 | # Be sure to run clean before bdist_xxx, because otherwise bdist_xxx will |
| 115 | # include files you may not want in the package. E.g., if you have built |
| 116 | # and tested with --cpp_implemenation, bdist_xxx will include the _message.so |
| 117 | # file even when you no longer pass the --cpp_implemenation flag. See: |
Feng Xiao | afe98de | 2018-08-22 11:55:30 -0700 | [diff] [blame] | 118 | # https://github.com/protocolbuffers/protobuf/issues/3042 |
Adam Cozzette | b45ce5e | 2020-11-10 14:33:16 -0800 | [diff] [blame^] | 119 | python3 setup.py clean build bdist_wheel |
Joshua Haberman | 0ff6399 | 2020-05-28 10:56:10 -0700 | [diff] [blame] | 120 | twine upload --skip-existing -u protobuf-packages dist/* |
Jisi Liu | 09354db | 2017-07-18 15:38:30 -0700 | [diff] [blame] | 121 | else |
| 122 | # Set the version number back (i.e., remove dev suffix). |
| 123 | sed -i -r "s/__version__ = '.*'/__version__ = '${VERSION}'/" google/protobuf/__init__.py |
| 124 | fi |