release.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 --no-site-packages -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}
  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. # Check that the supplied version number matches what's inside the source code.
  41. SOURCE_VERSION=`get_source_version`
  42. [ "${VERSION}" == "${SOURCE_VERSION}" -o "${VERSION}.${DEV}" == "${SOURCE_VERSION}" ] || {
  43. echo "Version number specified on the command line ${VERSION} doesn't match"
  44. echo "the actual version number in the source code: ${SOURCE_VERSION}"
  45. exit 1
  46. }
  47. TESTING_ONLY=1
  48. TESTING_VERSION=${VERSION}.${DEV}
  49. if [ -z "${DEV}" ]; then
  50. read -p "You are releasing ${VERSION} to PyPI. Are you sure? [y/n]" -r
  51. echo
  52. if [[ ! $REPLY =~ ^[Yy]$ ]]; then
  53. exit 1
  54. fi
  55. TESTING_ONLY=0
  56. TESTING_VERSION=${VERSION}
  57. else
  58. # Use dev version number for testing.
  59. sed -i -r "s/__version__ = '.*'/__version__ = '${VERSION}.${DEV}'/" python/google/protobuf/__init__.py
  60. fi
  61. cd python
  62. # Run tests locally.
  63. python setup.py build
  64. python setup.py test
  65. # Deploy source package to testing PyPI
  66. python setup.py sdist upload -r https://test.pypi.org/legacy/
  67. # Test locally with different python versions.
  68. run_install_test ${TESTING_VERSION} python2.7 https://test.pypi.org/simple
  69. run_install_test ${TESTING_VERSION} python3.4 https://test.pypi.org/simple
  70. # Deploy egg/wheel packages to testing PyPI and test again.
  71. python setup.py bdist_egg bdist_wheel upload -r https://test.pypi.org/legacy/
  72. run_install_test ${TESTING_VERSION} python2.7 https://test.pypi.org/simple
  73. run_install_test ${TESTING_VERSION} python3.4 https://test.pypi.org/simple
  74. echo "All install tests have passed using testing PyPI."
  75. if [ $TESTING_ONLY -eq 0 ]; then
  76. read -p "Publish to PyPI? [y/n]" -r
  77. echo
  78. if [[ ! $REPLY =~ ^[Yy]$ ]]; then
  79. exit 1
  80. fi
  81. echo "Publishing to PyPI..."
  82. # Be sure to run build before sdist, because otherwise sdist will not include
  83. # well-known types.
  84. python setup.py clean build sdist upload
  85. # Be sure to run clean before bdist_xxx, because otherwise bdist_xxx will
  86. # include files you may not want in the package. E.g., if you have built
  87. # and tested with --cpp_implemenation, bdist_xxx will include the _message.so
  88. # file even when you no longer pass the --cpp_implemenation flag. See:
  89. # https://github.com/google/protobuf/issues/3042
  90. python setup.py clean build bdist_egg bdist_wheel upload
  91. else
  92. # Set the version number back (i.e., remove dev suffix).
  93. sed -i -r "s/__version__ = '.*'/__version__ = '${VERSION}'/" google/protobuf/__init__.py
  94. fi