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 | |
Paul Yang | 3b0f10b | 2021-08-20 08:49:08 -0700 | [diff] [blame] | 14 | virtualenv -p `which $PYTHON` test-venv |
Jisi Liu | 09354db | 2017-07-18 15:38:30 -0700 | [diff] [blame] | 15 | |
| 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 Liu | 7ad8e7a | 2017-12-22 11:47:13 -0800 | [diff] [blame] | 22 | pip install -i ${PYPI} protobuf==${VERSION} --no-cache-dir |
Jisi Liu | 09354db | 2017-07-18 15:38:30 -0700 | [diff] [blame] | 23 | 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 | } |
| 38 | VERSION=$1 |
| 39 | DEV=$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. |
| 48 | find python -type d -exec chmod a+r,a+x {} + |
| 49 | find python -type f -exec chmod a+r {} + |
Feng Xiao | 3a06fe1 | 2017-12-14 17:54:18 -0800 | [diff] [blame] | 50 | umask 0022 |
Jisi Liu | 09354db | 2017-07-18 15:38:30 -0700 | [diff] [blame] | 51 | |
| 52 | # Check that the supplied version number matches what's inside the source code. |
| 53 | SOURCE_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 | |
| 61 | TESTING_ONLY=1 |
| 62 | TESTING_VERSION=${VERSION}.${DEV} |
| 63 | if [ -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} |
| 71 | else |
| 72 | # Use dev version number for testing. |
| 73 | sed -i -r "s/__version__ = '.*'/__version__ = '${VERSION}.${DEV}'/" python/google/protobuf/__init__.py |
| 74 | fi |
| 75 | |
Paul Yang | 81771b9 | 2021-08-27 15:41:58 -0700 | [diff] [blame] | 76 | # Copy LICENSE |
| 77 | cp LICENSE python/LICENSE |
| 78 | |
Jisi Liu | 09354db | 2017-07-18 15:38:30 -0700 | [diff] [blame] | 79 | cd python |
| 80 | |
| 81 | # Run tests locally. |
Adam Cozzette | b45ce5e | 2020-11-10 14:33:16 -0800 | [diff] [blame] | 82 | python3 setup.py build |
| 83 | python3 setup.py test |
Jisi Liu | 09354db | 2017-07-18 15:38:30 -0700 | [diff] [blame] | 84 | |
| 85 | # Deploy source package to testing PyPI |
Adam Cozzette | b45ce5e | 2020-11-10 14:33:16 -0800 | [diff] [blame] | 86 | python3 setup.py sdist |
Joshua Haberman | 0ff6399 | 2020-05-28 10:56:10 -0700 | [diff] [blame] | 87 | twine upload --skip-existing -r testpypi -u protobuf-wheel-test dist/* |
Jisi Liu | 09354db | 2017-07-18 15:38:30 -0700 | [diff] [blame] | 88 | |
| 89 | # Test locally with different python versions. |
Paul Yang | 5b4ac53 | 2019-02-01 18:43:55 -0800 | [diff] [blame] | 90 | run_install_test ${TESTING_VERSION} python3 https://test.pypi.org/simple |
Jisi Liu | 09354db | 2017-07-18 15:38:30 -0700 | [diff] [blame] | 91 | |
| 92 | # Deploy egg/wheel packages to testing PyPI and test again. |
Adam Cozzette | b45ce5e | 2020-11-10 14:33:16 -0800 | [diff] [blame] | 93 | python3 setup.py clean build bdist_wheel |
Joshua Haberman | 0ff6399 | 2020-05-28 10:56:10 -0700 | [diff] [blame] | 94 | twine upload --skip-existing -r testpypi -u protobuf-wheel-test dist/* |
Jisi Liu | 7ad8e7a | 2017-12-22 11:47:13 -0800 | [diff] [blame] | 95 | |
Paul Yang | 5b4ac53 | 2019-02-01 18:43:55 -0800 | [diff] [blame] | 96 | run_install_test ${TESTING_VERSION} python3 https://test.pypi.org/simple |
Jisi Liu | 09354db | 2017-07-18 15:38:30 -0700 | [diff] [blame] | 97 | |
| 98 | echo "All install tests have passed using testing PyPI." |
| 99 | |
| 100 | if [ $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 Cozzette | b45ce5e | 2020-11-10 14:33:16 -0800 | [diff] [blame] | 109 | python3 setup.py clean build sdist |
Joshua Haberman | 0ff6399 | 2020-05-28 10:56:10 -0700 | [diff] [blame] | 110 | twine upload --skip-existing -u protobuf-packages dist/* |
Jisi Liu | 09354db | 2017-07-18 15:38:30 -0700 | [diff] [blame] | 111 | # 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 Xiao | afe98de | 2018-08-22 11:55:30 -0700 | [diff] [blame] | 115 | # https://github.com/protocolbuffers/protobuf/issues/3042 |
Adam Cozzette | b45ce5e | 2020-11-10 14:33:16 -0800 | [diff] [blame] | 116 | python3 setup.py clean build bdist_wheel |
Joshua Haberman | 0ff6399 | 2020-05-28 10:56:10 -0700 | [diff] [blame] | 117 | twine upload --skip-existing -u protobuf-packages dist/* |
Jisi Liu | 09354db | 2017-07-18 15:38:30 -0700 | [diff] [blame] | 118 | else |
| 119 | # Set the version number back (i.e., remove dev suffix). |
| 120 | sed -i -r "s/__version__ = '.*'/__version__ = '${VERSION}'/" google/protobuf/__init__.py |
| 121 | fi |