Skip to content

Commit 9afb599

Browse files
committed
test run on kokoro
1 parent 927bc75 commit 9afb599

File tree

1 file changed

+64
-57
lines changed

1 file changed

+64
-57
lines changed

buildscripts/kokoro/cronet.sh

Lines changed: 64 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,23 @@
33
set -exu -o pipefail
44
cat /VERSION
55

6-
BASE_DIR=$(pwd)
6+
BASE_DIR="$(pwd)"
77

8-
# Set up APK size and dex count statuses
9-
10-
gsutil cp gs://grpc-testing-secrets/github_credentials/oauth_token.txt ~/
11-
12-
function set_status_to_fail_on_error {
13-
cd $BASE_DIR/github/grpc-java
14-
15-
# TODO(ericgribkoff) Remove once merged
16-
git checkout $KOKORO_GITHUB_PULL_REQUEST_COMMIT
8+
# Build Cronet
179

18-
./buildscripts/set_github_status.py \
19-
--sha1 $KOKORO_GITHUB_PULL_REQUEST_COMMIT \
20-
--state error \
21-
--description "Failed to calculate DEX count" \
22-
--context android/dex_diff --oauth_file ~/oauth_token.txt
23-
./buildscripts/set_github_status.py \
24-
--sha1 $KOKORO_GITHUB_PULL_REQUEST_COMMIT \
25-
--state error \
26-
--description "Failed to calculate APK size" \
27-
--context android/apk_diff --oauth_file ~/oauth_token.txt
28-
}
29-
trap set_status_to_fail_on_error ERR
10+
cd "$BASE_DIR/github/grpc-java/cronet"
11+
./cronet_deps.sh
12+
../gradlew --include-build .. build
3013

31-
$BASE_DIR/github/grpc-java/buildscripts/set_github_status.py \
32-
--sha1 $KOKORO_GITHUB_PULL_REQUEST_COMMIT \
33-
--state pending \
34-
--description "Waiting for DEX count to be reported" \
35-
--context android/dex_diff --oauth_file ~/oauth_token.txt
36-
$BASE_DIR/github/grpc-java/buildscripts/set_github_status.py \
37-
--sha1 $KOKORO_GITHUB_PULL_REQUEST_COMMIT \
38-
--state pending \
39-
--description "Waiting for APK size to be reported" \
40-
--context android/apk_diff --oauth_file ~/oauth_token.txt
4114

4215

43-
# Build Cronet
4416

45-
cd $BASE_DIR/github/grpc-java/cronet
46-
./cronet_deps.sh
47-
../gradlew --include-build .. build
4817

4918

5019
# Install gRPC and codegen for the Android examples
5120
# (a composite gradle build can't find protoc-gen-grpc-java)
5221

53-
cd $BASE_DIR/github/grpc-java
22+
cd "$BASE_DIR/github/grpc-java"
5423

5524
export GRADLE_OPTS=-Xmx512m
5625
export PROTOBUF_VERSION=3.5.1
@@ -69,53 +38,91 @@ cd ./examples/android/clientcache
6938
./gradlew build
7039
cd ../routeguide
7140
./gradlew build
41+
cd ../helloworld
42+
./gradlew build
7243

7344

74-
# Build and collect APK size and dex count stats for the helloworld example
45+
# Skip APK size and dex count comparisons for non-PR builds
7546

76-
cd ../helloworld
77-
./gradlew build
47+
if [[ -z "$KOKORO_GITHUB_PULL_REQUEST_COMMIT" ]]; then
48+
echo "Skipping APK size and dex count"
49+
exit 0
50+
fi
51+
52+
53+
# Set up APK size and dex count statuses
54+
55+
SET_GITHUB_STATUS="$TMPDIR/set_github_status.py"
56+
cp "$BASE_DIR/github/grpc-java/buildscripts/set_github_status.py" "$SET_GITHUB_STATUS"
57+
58+
gsutil cp gs://grpc-testing-secrets/github_credentials/oauth_token.txt ~/
59+
60+
function set_status_to_fail_on_error {
61+
"$SET_GITHUB_STATUS" \
62+
--sha1 "$KOKORO_GITHUB_PULL_REQUEST_COMMIT" \
63+
--state error \
64+
--description "Failed to calculate DEX count" \
65+
--context android/dex_diff --oauth_file ~/oauth_token.txt
66+
"$SET_GITHUB_STATUS" \
67+
--sha1 "$KOKORO_GITHUB_PULL_REQUEST_COMMIT" \
68+
--state error \
69+
--description "Failed to calculate APK size" \
70+
--context android/apk_diff --oauth_file ~/oauth_token.txt
71+
}
72+
trap set_status_to_fail_on_error ERR
73+
74+
exit 1
75+
76+
"$SET_GITHUB_STATUS" \
77+
--sha1 "$KOKORO_GITHUB_PULL_REQUEST_COMMIT" \
78+
--state pending \
79+
--description "Waiting for DEX count to be reported" \
80+
--context android/dex_diff --oauth_file ~/oauth_token.txt
81+
"$SET_GITHUB_STATUS" \
82+
--sha1 "$KOKORO_GITHUB_PULL_REQUEST_COMMIT" \
83+
--state pending \
84+
--description "Waiting for APK size to be reported" \
85+
--context android/apk_diff --oauth_file ~/oauth_token.txt
86+
87+
# Collect APK size and dex count stats for the helloworld example
7888

7989
read -r ignored new_dex_count < \
80-
<(${ANDROID_HOME}/tools/bin/apkanalyzer dex references app/build/outputs/apk/release/app-release-unsigned.apk)
90+
<("${ANDROID_HOME}/tools/bin/apkanalyzer" dex references app/build/outputs/apk/release/app-release-unsigned.apk)
8191

82-
new_apk_size=$(stat --printf=%s app/build/outputs/apk/release/app-release-unsigned.apk)
92+
new_apk_size="$(stat --printf=%s app/build/outputs/apk/release/app-release-unsigned.apk)"
8393

8494

8595
# Get the APK size and dex count stats using the target branch
8696

8797
sudo apt-get install -y jq
88-
target_branch=$(curl -s https://api.github.com/repos/grpc/grpc-java/pulls/$KOKORO_GITHUB_PULL_REQUEST_NUMBER | jq -r .base.ref)
98+
target_branch="$(curl -s https://api.github.com/repos/grpc/grpc-java/pulls/$KOKORO_GITHUB_PULL_REQUEST_NUMBER | jq -r .base.ref)"
8999

90100
cd $BASE_DIR/github/grpc-java
91-
git checkout $target_branch
101+
git checkout "$target_branch"
92102
./gradlew install
93103
cd examples/android/helloworld/
94104
./gradlew build
95105

96106
read -r ignored old_dex_count < \
97-
<(${ANDROID_HOME}/tools/bin/apkanalyzer dex references app/build/outputs/apk/release/app-release-unsigned.apk)
107+
<("${ANDROID_HOME}/tools/bin/apkanalyzer" dex references app/build/outputs/apk/release/app-release-unsigned.apk)
98108

99-
old_apk_size=$(stat --printf=%s app/build/outputs/apk/release/app-release-unsigned.apk)
109+
old_apk_size="$(stat --printf=%s app/build/outputs/apk/release/app-release-unsigned.apk)"
100110

101-
dex_count_delta=$((new_dex_count-old_dex_count))
111+
dex_count_delta="$((new_dex_count-old_dex_count))"
102112

103-
apk_size_delta=$((new_apk_size-old_apk_size))
113+
apk_size_delta="$((new_apk_size-old_apk_size))"
104114

105115

106116
# Update the statuses with the deltas
107117

108-
# TODO(ericgribkoff) Remove checkout once merged
109-
git checkout $KOKORO_GITHUB_PULL_REQUEST_COMMIT
110-
111-
../../../buildscripts/set_github_status.py \
112-
--sha1 $KOKORO_GITHUB_PULL_REQUEST_COMMIT \
118+
"$SET_GITHUB_STATUS" \
119+
--sha1 "$KOKORO_GITHUB_PULL_REQUEST_COMMIT" \
113120
--state success \
114-
--description "New DEX reference count: $new_dex_count (delta: $dex_count_delta)" \
121+
--description "New DEX reference count: $(printf "%'d" "$new_dex_count") (delta: $(printf "%'d" "$dex_count_delta"))" \
115122
--context android/dex_diff --oauth_file ~/oauth_token.txt
116123

117-
../../../buildscripts/set_github_status.py \
118-
--sha1 $KOKORO_GITHUB_PULL_REQUEST_COMMIT \
124+
"$SET_GITHUB_STATUS" \
125+
--sha1 "$KOKORO_GITHUB_PULL_REQUEST_COMMIT" \
119126
--state success \
120-
--description "New APK size in bytes: $new_apk_size (delta: $apk_size_delta)" \
127+
--description "New APK size in bytes: $(printf "%'d" "$new_apk_size") (delta: $(printf "%'d" "$apk_size_delta"))" \
121128
--context android/apk_diff --oauth_file ~/oauth_token.txt

0 commit comments

Comments
 (0)