release.sh 3.6 KB

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