test_packages.sh 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/usr/bin/env bash
  2. # Copyright 2018 gRPC authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. set -ex
  16. cd "$(dirname "$0")"
  17. shopt -s nullglob
  18. if [[ "$1" == "binary" ]]
  19. then
  20. echo "Testing Python binary distribution"
  21. ARCHIVES=("$EXTERNAL_GIT_ROOT"/input_artifacts/grpcio-[0-9]*.whl)
  22. TOOLS_ARCHIVES=("$EXTERNAL_GIT_ROOT"/input_artifacts/grpcio_tools-[0-9]*.whl)
  23. else
  24. echo "Testing Python source distribution"
  25. ARCHIVES=("$EXTERNAL_GIT_ROOT"/input_artifacts/grpcio-[0-9]*.tar.gz)
  26. TOOLS_ARCHIVES=("$EXTERNAL_GIT_ROOT"/input_artifacts/grpcio-tools-[0-9]*.tar.gz)
  27. fi
  28. HEALTH_ARCHIVES=("$EXTERNAL_GIT_ROOT"/input_artifacts/grpcio-health-checking-[0-9]*.tar.gz)
  29. REFLECTION_ARCHIVES=("$EXTERNAL_GIT_ROOT"/input_artifacts/grpcio-reflection-[0-9]*.tar.gz)
  30. TESTING_ARCHIVES=("$EXTERNAL_GIT_ROOT"/input_artifacts/grpcio-testing-[0-9]*.tar.gz)
  31. VIRTUAL_ENV=$(mktemp -d)
  32. python3 -m virtualenv "$VIRTUAL_ENV"
  33. PYTHON=$VIRTUAL_ENV/bin/python
  34. "$PYTHON" -m pip install --upgrade six pip wheel
  35. function validate_wheel_hashes() {
  36. for file in "$@"; do
  37. "$PYTHON" -m wheel unpack "$file" -d /tmp || return 1
  38. done
  39. return 0
  40. }
  41. function at_least_one_installs() {
  42. for file in "$@"; do
  43. if "$PYTHON" -m pip install "$file"; then
  44. return 0
  45. fi
  46. done
  47. return 1
  48. }
  49. #
  50. # Validate the files in wheel matches their hashes and size in RECORD
  51. #
  52. if [[ "$1" == "binary" ]]; then
  53. validate_wheel_hashes "${ARCHIVES[@]}"
  54. validate_wheel_hashes "${TOOLS_ARCHIVES[@]}"
  55. fi
  56. #
  57. # Install our distributions in order of dependencies
  58. #
  59. at_least_one_installs "${ARCHIVES[@]}"
  60. at_least_one_installs "${TOOLS_ARCHIVES[@]}"
  61. at_least_one_installs "${HEALTH_ARCHIVES[@]}"
  62. at_least_one_installs "${REFLECTION_ARCHIVES[@]}"
  63. at_least_one_installs "${TESTING_ARCHIVES[@]}"
  64. #
  65. # Test our distributions
  66. #
  67. # TODO(jtattermusch): add a .proto file to the distribtest, generate python
  68. # code from it and then use the generated code from distribtest.py
  69. "$PYTHON" -m grpc_tools.protoc --help
  70. "$PYTHON" distribtest.py