Skip to content

Commit 4369e8c

Browse files
authored
buildscripts: add Kokoro-based CI for Android APK stats (#3984)
1 parent 921b668 commit 4369e8c

File tree

4 files changed

+160
-9
lines changed

4 files changed

+160
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Config file for internal CI
22

33
# Location of the continuous shell script in repository.
4-
build_file: "grpc-java/buildscripts/kokoro/cronet.sh"
4+
build_file: "grpc-java/buildscripts/kokoro/android.sh"
55
timeout_mins: 45

buildscripts/kokoro/android.sh

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/bin/bash
2+
3+
set -exu -o pipefail
4+
cat /VERSION
5+
6+
BASE_DIR="$(pwd)"
7+
8+
# Build Cronet
9+
10+
cd "$BASE_DIR/github/grpc-java/cronet"
11+
./cronet_deps.sh
12+
../gradlew --include-build .. build
13+
14+
15+
# Install gRPC and codegen for the Android examples
16+
# (a composite gradle build can't find protoc-gen-grpc-java)
17+
18+
cd "$BASE_DIR/github/grpc-java"
19+
20+
export GRADLE_OPTS=-Xmx512m
21+
export PROTOBUF_VERSION=3.5.1
22+
export LDFLAGS=-L/tmp/protobuf/lib
23+
export CXXFLAGS=-I/tmp/protobuf/include
24+
export LD_LIBRARY_PATH=/tmp/protobuf/lib
25+
export OS_NAME=$(uname)
26+
27+
# Proto deps
28+
buildscripts/make_dependencies.sh
29+
ln -s "/tmp/protobuf-${PROTOBUF_VERSION}/$(uname -s)-$(uname -p)" /tmp/protobuf
30+
31+
./gradlew install
32+
33+
cd ./examples/android/clientcache
34+
./gradlew build
35+
cd ../routeguide
36+
./gradlew build
37+
cd ../helloworld
38+
./gradlew build
39+
40+
41+
# Skip APK size and dex count comparisons for non-PR builds
42+
43+
if [[ -z "$KOKORO_GITHUB_PULL_REQUEST_COMMIT" ]]; then
44+
echo "Skipping APK size and dex count"
45+
exit 0
46+
fi
47+
48+
49+
# Save a copy of set_github_status.py (it may differ from the base commit)
50+
51+
SET_GITHUB_STATUS="$TMPDIR/set_github_status.py"
52+
cp "$BASE_DIR/github/grpc-java/buildscripts/set_github_status.py" "$SET_GITHUB_STATUS"
53+
54+
55+
# Collect APK size and dex count stats for the helloworld example
56+
57+
read -r ignored new_dex_count < \
58+
<("${ANDROID_HOME}/tools/bin/apkanalyzer" dex references app/build/outputs/apk/release/app-release-unsigned.apk)
59+
60+
new_apk_size="$(stat --printf=%s app/build/outputs/apk/release/app-release-unsigned.apk)"
61+
62+
63+
# Get the APK size and dex count stats using the pull request base commit
64+
65+
cd $BASE_DIR/github/grpc-java
66+
git checkout HEAD^
67+
./gradlew install
68+
cd examples/android/helloworld/
69+
./gradlew build
70+
71+
read -r ignored old_dex_count < \
72+
<("${ANDROID_HOME}/tools/bin/apkanalyzer" dex references app/build/outputs/apk/release/app-release-unsigned.apk)
73+
74+
old_apk_size="$(stat --printf=%s app/build/outputs/apk/release/app-release-unsigned.apk)"
75+
76+
dex_count_delta="$((new_dex_count-old_dex_count))"
77+
78+
apk_size_delta="$((new_apk_size-old_apk_size))"
79+
80+
81+
# Update the statuses with the deltas
82+
83+
gsutil cp gs://grpc-testing-secrets/github_credentials/oauth_token.txt ~/
84+
85+
"$SET_GITHUB_STATUS" \
86+
--sha1 "$KOKORO_GITHUB_PULL_REQUEST_COMMIT" \
87+
--state success \
88+
--description "New DEX reference count: $(printf "%'d" "$new_dex_count") (delta: $(printf "%'d" "$dex_count_delta"))" \
89+
--context android/dex_diff --oauth_file ~/oauth_token.txt
90+
91+
"$SET_GITHUB_STATUS" \
92+
--sha1 "$KOKORO_GITHUB_PULL_REQUEST_COMMIT" \
93+
--state success \
94+
--description "New APK size in bytes: $(printf "%'d" "$new_apk_size") (delta: $(printf "%'d" "$apk_size_delta"))" \
95+
--context android/apk_diff --oauth_file ~/oauth_token.txt

buildscripts/kokoro/cronet.sh

-8
This file was deleted.

buildscripts/set_github_status.py

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env python2.7
2+
#
3+
# Copyright 2018 gRPC authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
import argparse
18+
import json
19+
import urllib2
20+
21+
22+
def run():
23+
argp = argparse.ArgumentParser(description='Set status on pull request')
24+
25+
argp.add_argument(
26+
'--sha1', type=str, help='SHA1 of the commit', required=True)
27+
argp.add_argument(
28+
'--state',
29+
type=str,
30+
choices=('error', 'failure', 'pending', 'success'),
31+
help='State to set',
32+
required=True)
33+
argp.add_argument(
34+
'--description', type=str, help='Status description', required=True)
35+
argp.add_argument('--context', type=str, help='Status context', required=True)
36+
argp.add_argument(
37+
'--oauth_file', type=str, help='File with OAuth token', required=True)
38+
39+
args = argp.parse_args()
40+
sha1 = args.sha1
41+
state = args.state
42+
description = args.description
43+
context = args.context
44+
oauth_file = args.oauth_file
45+
46+
with open(oauth_file, 'r') as oauth_file_reader:
47+
oauth_token = oauth_file_reader.read().replace('\n', '')
48+
49+
req = urllib2.Request(
50+
url='https://api.github.com/repos/grpc/grpc-java/statuses/%s' % sha1,
51+
data=json.dumps({
52+
'state': state,
53+
'description': description,
54+
'context': context,
55+
}),
56+
headers={
57+
'Authorization': 'token %s' % oauth_token,
58+
'Content-Type': 'application/json',
59+
})
60+
print urllib2.urlopen(req).read()
61+
62+
63+
if __name__ == '__main__':
64+
run()

0 commit comments

Comments
 (0)