This commit is contained in:
Tobias Kaminsky 2017-05-11 12:58:57 +00:00 committed by GitHub
commit 97b9fa39c7
5 changed files with 226 additions and 27 deletions

View file

@ -1,32 +1,43 @@
pipeline:
test:
image: nextcloudci/android:android-17
commands:
# uncomment gplay for Gplay, Modified only
- sh -c "if [ '$FLAVOUR' != 'Generic' ]; then sed -i '/com.google.*.gms/s/^.*\/\///g' build.gradle; fi"
# test:
# image: nextcloudci/android:android-18
# commands:
# # uncomment gplay for Gplay, Modified only
# - sh -c "if [ '$FLAVOUR' != 'Generic' ]; then sed -i '/com.google.*.gms/s/^.*\/\///g' build.gradle; fi"
#
# - echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI -c 20M
# - emulator -avd test -no-window &
# - ./wait_for_emulator.sh
#
# # build app and assemble APK, in debug mode
# - ./gradlew assemble${FLAVOUR}
#
# # run all the instrumented tests of app module - DISABLED until we get an stable setup for Espresso in Travis
# # - ./gradlew connectedDebugAndroidTest --info
#
# # install app, then assemble and install instrumented tests of app module
# - ./gradlew :install${FLAVOUR}Debug
# - ./gradlew :install${FLAVOUR}DebugAndroidTest
#
# # run sample instrumented unit test
# # TODO fails because test runner is not available
# #- adb shell am instrument -w -e debug false -e class com.owncloud.android.datamodel.OCFileUnitTest com.owncloud.android.test/android.support.test.runner.AndroidJUnitRunner
#
# environment:
# - ANDROID_TARGET=android-24
# - ANDROID_ABI=armeabi-v7a
# - LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/:/opt/android-sdk-linux/tools/lib64/gles_mesa/
- echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI -c 20M
- emulator -avd test -no-window &
- ./wait_for_emulator.sh
# build app and assemble APK, in debug mode
- ./gradlew assemble${FLAVOUR}
# run all the instrumented tests of app module - DISABLED until we get an stable setup for Espresso in Travis
# - ./gradlew connectedDebugAndroidTest --info
# install app, then assemble and install instrumented tests of app module
- ./gradlew :install${FLAVOUR}Debug
- ./gradlew :install${FLAVOUR}DebugAndroidTest
# run sample instrumented unit test
# TODO fails because test runner is not available
#- adb shell am instrument -w -e debug false -e class com.owncloud.android.datamodel.OCFileUnitTest com.owncloud.android.test/android.support.test.runner.AndroidJUnitRunner
environment:
- ANDROID_TARGET=android-24
- ANDROID_ABI=armeabi-v7a
- LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/:/opt/android-sdk-linux/tools/lib64/gles_mesa/
lint:
image: nextcloudci/android:android-18
commands:
# needs gplay
- sed -i '/com.google.*.gms/s/^.*\/\///g' build.gradle
- export BRANCH=$(scripts/lint/getBranchName.sh ${GIT_USERNAME} ${GIT_TOKEN} ${DRONE_PULL_REQUEST})
- ruby scripts/lint/lint-up.rb ${GIT_USERNAME} ${GIT_TOKEN} $BRANCH
when:
matrix:
FLAVOUR: Modified
matrix:
FLAVOUR:

1
.drone.yml.sig Normal file
View file

@ -0,0 +1 @@
eyJhbGciOiJIUzI1NiJ9.cGlwZWxpbmU6CiMgIHRlc3Q6CiMgICAgaW1hZ2U6IG5leHRjbG91ZGNpL2FuZHJvaWQ6YW5kcm9pZC0xOAojICAgIGNvbW1hbmRzOgojICAgICAgIyB1bmNvbW1lbnQgZ3BsYXkgZm9yIEdwbGF5LCBNb2RpZmllZCBvbmx5CiMgICAgICAtIHNoIC1jICJpZiBbICckRkxBVk9VUicgIT0gJ0dlbmVyaWMnIF07IHRoZW4gc2VkIC1pICcvY29tLmdvb2dsZS4qLmdtcy9zL14uKlwvXC8vL2cnIGJ1aWxkLmdyYWRsZTsgZmkiCiMKIyAgICAgIC0gZWNobyBubyB8IGFuZHJvaWQgY3JlYXRlIGF2ZCAtLWZvcmNlIC1uIHRlc3QgLXQgJEFORFJPSURfVEFSR0VUIC0tYWJpICRBTkRST0lEX0FCSSAtYyAyME0KIyAgICAgIC0gZW11bGF0b3IgLWF2ZCB0ZXN0IC1uby13aW5kb3cgJgojICAgICAgLSAuL3dhaXRfZm9yX2VtdWxhdG9yLnNoCiMKIyAgICAgICMgYnVpb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XY3YQojICAgICAgLSBMRF9MSUJSQVJZX1BBVEg9L3Vzci9saWIveDg2XzY0LWxpbnV4LWdudS86L29wdC9hbmRyb2lkLXNkay1saW51eC90b29scy9saWI2NC9nbGVzX21lc2EvCgogIGxpbnQ6CiAgICAgIGltYWdlOiBuZXh0Y2xvdWRjaS9hbmRyb2lkOmFuZHJvaWQtMTgKICAgICAgY29tbWFuZHM6CiAgICAgICAgIyBuZWVkcyBncGxheQogICAgICAgIC0gc2VkIC1pICcvY29tLmdvb2dsZS4qLmdtcy9zL14uKlwvXC8vL2cnIGJ1aWxkLmdyYWRsZQogICAgICAgIC0gZXhwb3J0IEJSQU5DSD0kKHNjcmlwdHMvbGludC9nZXRCcmFuY2hOYW1lLnNoICR7R0lUX1VTRVJOQU1FfSAke0dJVF9UT0tFTn0gJHtEUk9ORV9QVUxMX1JFUVVFU1R9KQogICAgICAgIC0gcnVieSBzY3JpcHRzL2xpbnQvbGludC11cC5yYiAke0dJVF9VU0VSTkFNRX0gJHtHSVRfVE9LRU59ICRCUkFOQ0gKICAgICAgd2hlbjoKICAgICAgICBtYXRyaXg6CiAgICAgICAgICBGTEFWT1VSOiBNb2RpZmllZAoKbWF0cml4OgogIEZMQVZPVVI6CiAgICAtIEdlbmVyaWMKICAgIC0gR3BsYXkKICAgIC0gTW9kaWZpZWQKCmJyYW5jaGVzOiBtYXN0ZXI.BLLV2td-6sZcdGZysr0uI7ErsvhxGE49bIwvlSaB2Ro

5
scripts/lint/getBranchName.sh Executable file
View file

@ -0,0 +1,5 @@
#!/bin/bash
# $1: username, $2: password/token, $3: pull request number
curl 2>/dev/null -u $1:$2 https://api.github.com/repos/nextcloud/android/pulls/$3 | grep \"ref\": | grep -v master | cut -d"\"" -f4

View file

@ -0,0 +1,2 @@
DO NOT TOUCH; GENERATED BY TRAVIS
<span class="mdl-layout-title">Lint Report: 1000 errors and 863 warnings</span>

180
scripts/lint/lint-up.rb Normal file
View file

@ -0,0 +1,180 @@
## Script from https://github.com/tir38/android-lint-entropy-reducer at 07.05.2017
# adapts to drone, use git username / token as parameter
puts "=================== starting Android Lint Entropy Reducer ===================="
# get args
git_user, git_token, git_branch = ARGV
# ======================== SETUP ============================
# User name for git commits made by this script.
TRAVIS_GIT_USERNAME = String.new("Drone CI server")
# File name and relative path of generated Lint report. Must match build.gradle file:
# lintOptions {
# htmlOutput file("[FILE_NAME].html")
# }
LINT_REPORT_FILE = String.new("build/reports/lint/lint.html")
# File name and relative path of previous results of this script.
PREVIOUS_LINT_RESULTS_FILE=String.new("scripts/lint/lint-results.txt")
# Flag to evaluate warnings. true = check warnings; false = ignore warnings
CHECK_WARNINGS = true
# File name and relative path to custom lint rules; Can be null or "".
CUSTOM_LINT_FILE = String.new("")
# ================ SETUP DONE; DON'T TOUCH ANYTHING BELOW ================
require 'fileutils'
require 'pathname'
require 'open3'
# since we need the xml-simple gem, and we want this script self-contained, let's grab it just when we need it
begin
gem "xml-simple"
rescue LoadError
system("gem install xml-simple")
Gem.clear_paths
end
require 'xmlsimple'
# add custom Lint jar
if CUSTOM_LINT_FILE != nil &&
CUSTOM_LINT_FILE.length > 0
ENV["ANDROID_LINT_JARS"] = Dir.pwd + "/" + CUSTOM_LINT_FILE
puts "adding custom lint rules to default set: "
puts ENV["ANDROID_LINT_JARS"]
end
# run Lint
puts "running Lint..."
system './gradlew clean lint'
# confirm that Lint ran w/out error
result = $?.to_i
if result != 0
puts "FAIL: failed to run ./gradlew clean lint"
exit 1
end
# find Lint report file
lint_reports = Dir.glob(LINT_REPORT_FILE)
if lint_reports.length == 0
puts "Lint HTML report not found."
exit 1
end
lint_report = String.new(lint_reports[0])
# find error/warning count string in HTML report
error_warning_string = ""
File.open lint_report do |file|
error_warning_string = file.find { |line| line =~ /[0-9]* errors and [0-9]* warnings/ }
end
# find number of errors
error_string = error_warning_string.match(/[0-9]* errors/)[0]
current_error_count = error_string.match(/[0-9]*/)[0].to_i
puts "found errors: " + current_error_count.to_s
# find number of warnings
if CHECK_WARNINGS == true
warning_string = error_warning_string.match(/[0-9]* warnings/)[0]
current_warning_count = warning_string.match(/[0-9]*/)[0].to_i
puts "found warnings: " + current_warning_count.to_s
end
# get previous error and warning counts from last successful build
previous_results = false
previous_lint_reports = Dir.glob(PREVIOUS_LINT_RESULTS_FILE)
if previous_lint_reports == nil ||
previous_lint_reports.length == 0
previous_lint_report = File.new(PREVIOUS_LINT_RESULTS_FILE, "w") # create for writing to later
else
previous_lint_report = String.new(previous_lint_reports[0])
previous_error_warning_string = ""
File.open previous_lint_report do |file|
previous_error_warning_string = file.find { |line| line =~ /[0-9]* errors and [0-9]* warnings/ }
end
unless previous_error_warning_string.nil?
previous_results = true
previous_error_string = previous_error_warning_string.match(/[0-9]* errors/)[0]
previous_error_count = previous_error_string.match(/[0-9]*/)[0].to_i
puts "previous errors: " + previous_error_count.to_s
if CHECK_WARNINGS == true
previous_warning_string = previous_error_warning_string.match(/[0-9]* warnings/)[0]
previous_warning_count = previous_warning_string.match(/[0-9]*/)[0].to_i
puts "previous warnings: " + previous_warning_count.to_s
end
end
end
# compare previous error count with current error count
if previous_results == true &&
current_error_count > previous_error_count
puts "FAIL: error count increased"
exit 1
end
# compare previous warning count with current warning count
if CHECK_WARNINGS == true &&
previous_results == true &&
current_warning_count > previous_warning_count
puts "FAIL: warning count increased"
exit 1
end
# check if warning and error count stayed the same
if previous_results == true &&
current_error_count == previous_error_count &&
current_warning_count == previous_warning_count
puts "SUCCESS: count stayed the same"
exit 0
end
# either error count or warning count DECREASED
# write new results to file (will overwrite existing, or create new)
File.write(previous_lint_report, "DO NOT TOUCH; GENERATED BY DRONE\n" + error_warning_string)
# push changes to github (if this script is run locally, we don't want to overwrite git username and email, so save temporarily)
previous_git_username, st = Open3.capture2('git config user.name')
previous_git_username = previous_git_username.strip
previous_git_email, st = Open3.capture3('git config user.email')
previous_git_email = previous_git_email.strip
# update git user name and email for this script
system ("git config --local user.name '" + git_user + "'")
system ("git config --local user.email '.'") # set email blank
system ("git remote rm origin")
system ("git remote add origin https://" + git_user + ":" + git_token + "@github.com/nextcloud/android")
# add previous Lint result file to git
system ('git add ' + PREVIOUS_LINT_RESULTS_FILE)
# commit changes; Add "skip ci" so that we don't accidentally trigger another Drone build
system ('git commit -m "Drone: update Lint results to reflect reduced error/warning count [skip ci]" ')
# push to origin
system ('git push origin HEAD:' + git_branch)
# restore previous git user name and email
system("git config --local user.name '#{previous_git_username}'")
system("git config --local user.email '#{previous_git_email}'")
puts "SUCCESS: count was reduced"
exit 0 # success