-
Notifications
You must be signed in to change notification settings - Fork 3.9k
buildscripts: Add Kokoro-based CI for Android APK stats #3984
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
6e7edff
927bc75
bbda65b
27e9efc
e7f8b1a
e8d8c96
4b28497
9beab53
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,118 @@ | |
set -exu -o pipefail | ||
cat /VERSION | ||
|
||
cd ./github/grpc-java/cronet | ||
BASE_DIR="$(pwd)" | ||
|
||
# Build Cronet | ||
|
||
cd "$BASE_DIR/github/grpc-java/cronet" | ||
./cronet_deps.sh | ||
../gradlew --include-build .. build | ||
|
||
|
||
# Install gRPC and codegen for the Android examples | ||
# (a composite gradle build can't find protoc-gen-grpc-java) | ||
|
||
cd "$BASE_DIR/github/grpc-java" | ||
|
||
export GRADLE_OPTS=-Xmx512m | ||
export PROTOBUF_VERSION=3.5.1 | ||
export LDFLAGS=-L/tmp/protobuf/lib | ||
export CXXFLAGS=-I/tmp/protobuf/include | ||
export LD_LIBRARY_PATH=/tmp/protobuf/lib | ||
export OS_NAME=$(uname) | ||
|
||
# Proto deps | ||
buildscripts/make_dependencies.sh | ||
ln -s "/tmp/protobuf-${PROTOBUF_VERSION}/$(uname -s)-$(uname -p)" /tmp/protobuf | ||
|
||
./gradlew install | ||
|
||
cd ./examples/android/clientcache | ||
./gradlew build | ||
cd ../routeguide | ||
./gradlew build | ||
cd ../helloworld | ||
./gradlew build | ||
|
||
|
||
# Skip APK size and dex count comparisons for non-PR builds | ||
|
||
if [[ -z "$KOKORO_GITHUB_PULL_REQUEST_COMMIT" ]]; then | ||
echo "Skipping APK size and dex count" | ||
exit 0 | ||
fi | ||
|
||
|
||
# Set up APK size and dex count statuses | ||
|
||
SET_GITHUB_STATUS="$TMPDIR/set_github_status.py" | ||
cp "$BASE_DIR/github/grpc-java/buildscripts/set_github_status.py" "$SET_GITHUB_STATUS" | ||
|
||
gsutil cp gs://grpc-testing-secrets/github_credentials/oauth_token.txt ~/ | ||
|
||
function set_status_to_fail_on_error { | ||
"$SET_GITHUB_STATUS" \ | ||
--sha1 "$KOKORO_GITHUB_PULL_REQUEST_COMMIT" \ | ||
--state error \ | ||
--description "Failed to calculate DEX count" \ | ||
--context android/dex_diff --oauth_file ~/oauth_token.txt | ||
"$SET_GITHUB_STATUS" \ | ||
--sha1 "$KOKORO_GITHUB_PULL_REQUEST_COMMIT" \ | ||
--state error \ | ||
--description "Failed to calculate APK size" \ | ||
--context android/apk_diff --oauth_file ~/oauth_token.txt | ||
} | ||
trap set_status_to_fail_on_error ERR | ||
|
||
|
||
"$SET_GITHUB_STATUS" \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Setting these statuses is pretty late. You've already done a full build, you just have a small incremental build left. These should either be earlier or removed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed. If this fails the main build status will be reported as failure anyway, so the extra statuses for apk size and dex count are unnecessary. |
||
--sha1 "$KOKORO_GITHUB_PULL_REQUEST_COMMIT" \ | ||
--state pending \ | ||
--description "Waiting for DEX count to be reported" \ | ||
--context android/dex_diff --oauth_file ~/oauth_token.txt | ||
"$SET_GITHUB_STATUS" \ | ||
--sha1 "$KOKORO_GITHUB_PULL_REQUEST_COMMIT" \ | ||
--state pending \ | ||
--description "Waiting for APK size to be reported" \ | ||
--context android/apk_diff --oauth_file ~/oauth_token.txt | ||
|
||
# Collect APK size and dex count stats for the helloworld example | ||
|
||
read -r ignored new_dex_count < \ | ||
<("${ANDROID_HOME}/tools/bin/apkanalyzer" dex references app/build/outputs/apk/release/app-release-unsigned.apk) | ||
|
||
new_apk_size="$(stat --printf=%s app/build/outputs/apk/release/app-release-unsigned.apk)" | ||
|
||
|
||
# Get the APK size and dex count stats using the pull request base commit | ||
|
||
cd $BASE_DIR/github/grpc-java | ||
git checkout HEAD^ | ||
./gradlew install | ||
cd examples/android/helloworld/ | ||
./gradlew build | ||
|
||
read -r ignored old_dex_count < \ | ||
<("${ANDROID_HOME}/tools/bin/apkanalyzer" dex references app/build/outputs/apk/release/app-release-unsigned.apk) | ||
|
||
old_apk_size="$(stat --printf=%s app/build/outputs/apk/release/app-release-unsigned.apk)" | ||
|
||
dex_count_delta="$((new_dex_count-old_dex_count))" | ||
|
||
apk_size_delta="$((new_apk_size-old_apk_size))" | ||
|
||
|
||
# Update the statuses with the deltas | ||
|
||
"$SET_GITHUB_STATUS" \ | ||
--sha1 "$KOKORO_GITHUB_PULL_REQUEST_COMMIT" \ | ||
--state success \ | ||
--description "New DEX reference count: $(printf "%'d" "$new_dex_count") (delta: $(printf "%'d" "$dex_count_delta"))" \ | ||
--context android/dex_diff --oauth_file ~/oauth_token.txt | ||
|
||
"$SET_GITHUB_STATUS" \ | ||
--sha1 "$KOKORO_GITHUB_PULL_REQUEST_COMMIT" \ | ||
--state success \ | ||
--description "New APK size in bytes: $(printf "%'d" "$new_apk_size") (delta: $(printf "%'d" "$apk_size_delta"))" \ | ||
--context android/apk_diff --oauth_file ~/oauth_token.txt |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/usr/bin/env python2.7 | ||
# | ||
# Copyright 2018 gRPC authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import argparse | ||
import json | ||
import urllib2 | ||
|
||
|
||
def run(): | ||
argp = argparse.ArgumentParser(description='Set status on pull request') | ||
|
||
argp.add_argument( | ||
'--sha1', type=str, help='SHA1 of the commit', required=True) | ||
argp.add_argument( | ||
'--state', | ||
type=str, | ||
choices=('error', 'failure', 'pending', 'success'), | ||
help='State to set', | ||
required=True) | ||
argp.add_argument( | ||
'--description', type=str, help='Status description', required=True) | ||
argp.add_argument('--context', type=str, help='Status context', required=True) | ||
argp.add_argument( | ||
'--oauth_file', type=str, help='File with OAuth token', required=True) | ||
|
||
args = argp.parse_args() | ||
sha1 = args.sha1 | ||
state = args.state | ||
description = args.description | ||
context = args.context | ||
oauth_file = args.oauth_file | ||
|
||
with open(oauth_file, 'r') as oauth_file_reader: | ||
oauth_token = oauth_file_reader.read().replace('\n', '') | ||
|
||
req = urllib2.Request( | ||
url='https://api.github.com/repos/grpc/grpc-java/statuses/%s' % sha1, | ||
data=json.dumps({ | ||
'state': state, | ||
'description': description, | ||
'context': context, | ||
}), | ||
headers={ | ||
'Authorization': 'token %s' % oauth_token, | ||
'Content-Type': 'application/json', | ||
}) | ||
print urllib2.urlopen(req).read() | ||
|
||
|
||
if __name__ == '__main__': | ||
run() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this have been caused by d4b11e5 (i.e., it is no longer a problem)? I know I saw the problem earlier, but I don't see it any more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's still a problem. The Gradle composite build documentation's section on current limitations says "Native builds are not supported. (Binary dependencies are not yet supported for native builds)." Although I'm not entirely sure this is the reason for the failure to find protoc-gen-grpc-java, as I'm not sure it applies to the direction of the dependency on a native build here.