From eafb1d527d8fc1f367215429fde9421aac876ef2 Mon Sep 17 00:00:00 2001 From: Lidi Zheng Date: Mon, 17 Dec 2018 18:14:58 -0800 Subject: Reorgnize dependencies and variables --- .../helper_scripts/prepare_build_linux_perf_rc | 5 ++++ .../helper_scripts/prepare_build_macos_rc | 4 ++- tools/run_tests/python_utils/check_on_pr.py | 35 +++++++++++----------- 3 files changed, 26 insertions(+), 18 deletions(-) (limited to 'tools') diff --git a/tools/internal_ci/helper_scripts/prepare_build_linux_perf_rc b/tools/internal_ci/helper_scripts/prepare_build_linux_perf_rc index dc3c75a6a1..8223e03abd 100644 --- a/tools/internal_ci/helper_scripts/prepare_build_linux_perf_rc +++ b/tools/internal_ci/helper_scripts/prepare_build_linux_perf_rc @@ -34,4 +34,9 @@ fi sudo pip install tabulate +# Python dependencies for tools/run_tests/python_utils/check_on_pr.py +sudo -H pip install pyjwt cryptography requests + +ls -al "${KOKORO_KEYSTORE_DIR}/73836_grpc_checks_private_key" + git submodule update --init diff --git a/tools/internal_ci/helper_scripts/prepare_build_macos_rc b/tools/internal_ci/helper_scripts/prepare_build_macos_rc index bafe0d98c1..b770808db9 100644 --- a/tools/internal_ci/helper_scripts/prepare_build_macos_rc +++ b/tools/internal_ci/helper_scripts/prepare_build_macos_rc @@ -31,6 +31,8 @@ date pip install google-api-python-client oauth2client --user python export GOOGLE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/GrpcTesting-d0eeee2db331.json +ls -al "${KOKORO_KEYSTORE_DIR}/73836_grpc_checks_private_key" + # If this is a PR using RUN_TESTS_FLAGS var, then add flags to filter tests if [ -n "$KOKORO_GITHUB_PULL_REQUEST_NUMBER" ]; then set +x @@ -63,7 +65,7 @@ time pod repo update # needed by python # python time pip install virtualenv --user python -time pip install -U Mako six tox setuptools twisted pyyaml --user python +time pip install -U Mako six tox setuptools twisted pyyaml pyjwt cryptography requests --user python export PYTHONPATH=/Library/Python/3.4/site-packages # Install Python 3.7 diff --git a/tools/run_tests/python_utils/check_on_pr.py b/tools/run_tests/python_utils/check_on_pr.py index 78f1dca817..d59f99b252 100644 --- a/tools/run_tests/python_utils/check_on_pr.py +++ b/tools/run_tests/python_utils/check_on_pr.py @@ -25,21 +25,21 @@ _GITHUB_API_PREFIX = 'https://api.github.com' _GITHUB_REPO = 'grpc/grpc' _GITHUB_APP_ID = 22338 _INSTALLATION_ID = 519109 -_GITHUB_APP_KEY = open( - os.path.join(os.environ['KOKORO_KEYSTORE_DIR'], '73836_grpc_checks_private_key'), - 'rb').read() _ACCESS_TOKEN_CACHE = None def _jwt_token(): + github_app_key = open( + os.path.join(os.environ['KOKORO_KEYSTORE_DIR'], + '73836_grpc_checks_private_key'), 'rb').read() return jwt.encode( { 'iat': int(time.time()), 'exp': int(time.time() + 60 * 10), # expire in 10 minutes 'iss': _GITHUB_APP_ID, }, - _GITHUB_APP_KEY, + github_app_key, algorithm='RS256') @@ -90,25 +90,26 @@ def check_on_pr(name, summary, success=True): summary: A str in Markdown to be used as the detail information of the check. success: A bool indicates whether the check is succeed or not. """ + if 'KOKORO_GIT_COMMIT' not in os.environ: + print('Missing KOKORO_GIT_COMMIT env var: not checking') + return + if 'KOKORO_KEYSTORE_DIR' not in os.environ: + print('Missing KOKORO_KEYSTORE_DIR env var: not checking') + return if 'ghprbPullId' not in os.environ: - print('Missing ghprbPullId env var: not commenting') + print('Missing ghprbPullId env var: not checking') return - commit = _latest_commit() + completion_time = str( + datetime.datetime.utcnow().replace(microsecond=0).isoformat()) + 'Z' resp = _call( '/repos/%s/check-runs' % _GITHUB_REPO, method='POST', json={ - 'name': - name, - 'head_sha': - commit['sha'], - 'status': - 'completed', - 'completed_at': - '%sZ' % - datetime.datetime.utcnow().replace(microsecond=0).isoformat(), - 'conclusion': - 'success' if success else 'failure', + 'name': name, + 'head_sha': os.environ['KOKORO_GIT_COMMIT'], + 'status': 'completed', + 'completed_at': completion_time, + 'conclusion': 'success' if success else 'failure', 'output': { 'title': name, 'summary': summary, -- cgit v1.2.3