├── .gitignore ├── LICENCE ├── README.md ├── androidTest └── android-test.sh ├── art └── screenshot.png ├── buildreport ├── README.md ├── apk_info.py ├── build-report.sh └── build_report.py └── git └── init-git.sh /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SCRIPTS 2 | 3 | All scripts that I use in my daily development 4 | 5 | # buildreport 6 | Aggregates all data from each tool report and summarize them in html format in order to use it via email. Following information is provided: 7 | - **Pull request info**: Which commits are in the pull request 8 | - **Apk info**: All information about the apk. Comparison is also shown between prior the pull request and after 9 | - **Method count**: Current, Diff, New and Remaining count 10 | - **Apk Size in mb**: Current, Diff, New 11 | - **Min sdk version** 12 | - **Target sdk version** 13 | - **Permissions**: New added permission are shown in green and annotated. Removed permissions are shown in red and annotated 14 | - **Lint summary** 15 | - **Checkstyle summary** 16 | - **Unit tests summary**: Grouped by test classes. Some test classes are highligted regarding to status 17 | - **Red**: Failure tests 18 | - **Orange**: Ignored tests 19 | - **Blue**: These tests take longer than 1 second, usually unit tests should be super fast 20 | 21 | Run the following command in your execute shell. That's it. If you want to compare debug builds, replace RELEASE with DEBUG. If you leave it empty, RELEASE build type will be used as default 22 | ```shell 23 | $ curl https://raw.githubusercontent.com/orhanobut/scripts/master/buildreport/build-report.sh -o build-report.sh 24 | $ sh build-report.sh RELEASE 25 | ``` 26 | 27 | buildreport compares the new changes with the current codebase, therefore it tries to find the base branch current HEAD by using grep. You can add your own grep search text if you need a different solution. 28 | ```shell 29 | sh build-report.sh RELEASE "your grep text" 30 | ``` 31 | 32 | [For more details about buildreport](https://github.com/orhanobut/scripts/blob/master/buildreport/README.md) 33 | 34 | # git 35 | Set up a git with username, email and the aliases. Invoke the following command in your terminal by adding your username and email. It will setup your git with the given parameters and will add the following aliases automatically. 36 | 37 | - Set global user.name 38 | - Set global user.email 39 | - Add the following aliases 40 | 41 | ``` 42 | git l One line commit messages 43 | git lo One line commit message along with tags/branch info 44 | git ld Commits that are not pushed to master yet 45 | git lol Commits with graph 46 | git s status 47 | git ac Add and commit 48 | git c commit 49 | git cm commit -m 50 | git pom pull origin master 51 | git b branch 52 | git co checkout 53 | ``` 54 | 55 | Add your name and email to setup your git 56 | 57 | ```shell 58 | curl https://raw.githubusercontent.com/orhanobut/scripts/master/git/init-git.sh | bash -s 59 | --name 60 | --email 61 | ``` 62 | 63 | # android 64 | Initialize all required artifacts for android development 65 | -------------------------------------------------------------------------------- /androidTest/android-test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | PACKAGE_NAME="" 4 | RUNNER="" 5 | APP_ID="" 6 | 7 | while (( "$#" )); do 8 | case "$1" in 9 | "--package") 10 | shift 11 | PACKAGE_NAME=$1 12 | ;; 13 | "--app-id") 14 | shift 15 | APP_ID=$1 16 | ;; 17 | "--runner") 18 | shift 19 | RUNNER=$1 20 | ;; 21 | esac 22 | shift 23 | done 24 | 25 | if [[ ( $PACKAGE_NAME == "" ) || ( $APP_ID == "" ) || ( $RUNNER == "") ]] 26 | then 27 | echo "Required parameters are missing, --package, --app-id and --runner must be set" 28 | exit 1 29 | fi 30 | 31 | echo "Package name under test = $PACKAGE_NAME" 32 | echo "App id under test = $APP_ID" 33 | echo "Runner for tests = $RUNNER" 34 | 35 | # Installing debug apk 36 | if [ ! -e app/build/outputs/apk/app-debug.apk ] 37 | then 38 | ./gradlew assembleDebug > /dev/null 39 | fi 40 | adb push app/build/outputs/apk/app-debug.apk "/data/local/tmp/$APP_ID" 41 | adb shell pm install -r "/data/local/tmp/$APP_ID" 42 | 43 | # Installing test apk 44 | ./gradlew assembleAndroidTest >> /dev/null 45 | adb push app/build/outputs/apk/app-debug-androidTest.apk "/data/local/tmp/$APP_ID.test" 46 | adb shell pm install -r "/data/local/tmp/$APP_ID.test" 47 | 48 | # Running tests 49 | adb shell am instrument -w -r -e package "$PACKAGE_NAME" -e debug false "$APP_ID.test/$RUNNER" | tee android-test-log.txt 50 | 51 | # Generate report 52 | REPORT_FILE=$(echo $PACKAGE_NAME | tr '.' '_').txt 53 | 54 | grep "Time" android-test-log.txt >> $REPORT_FILE 55 | grep -e "OK (" android-test-log.txt >> $REPORT_FILE 56 | grep -e "Tests run" android-test-log.txt >> $REPORT_FILE 57 | sed -n "s/INSTRUMENTATION_STATUS: class=//gp" android-test-log.txt | uniq >> $REPORT_FILE 58 | 59 | if grep "OK (" android-test-log.txt 60 | then 61 | echo "FUNCTIONAL TESTS SUCCESS" 62 | echo "FUNCTIONAL TESTS SUCCESS" >> android-test-log.txt 63 | else 64 | echo "FUNCTIONAL TESTS FAILED" 65 | echo "FUNCTIONAL TESTS FAILED" >> android-test-log.txt 66 | fi 67 | -------------------------------------------------------------------------------- /art/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orhanobut/scripts/009356959330c81e903829ee122f3f073694368e/art/screenshot.png -------------------------------------------------------------------------------- /buildreport/README.md: -------------------------------------------------------------------------------- 1 | # buildreport 2 | Aggregates all data from each tool report and summarize them in html format in order to use it via email. Following information is provided: 3 | 4 | - **Pull request info**: Which commits are in the pull request 5 | - **Apk info**: All information about the apk. Comparison is also shown between prior the pull request and after 6 | - **Method count**: Current, Diff, New and Remaining count 7 | - **Apk Size in mb**: Current, Diff, New 8 | - **Min sdk version** 9 | - **Target sdk version** 10 | - **Permissions**: New added permission are shown in green and annotated. Removed permissions are shown in red and annotated 11 | - **Lint summary** 12 | - **Checkstyle summary** 13 | - **Unit tests summary**: Grouped by test classes. Some test classes are highligted regarding to status 14 | - **Red**: Failure tests 15 | - **Orange**: Ignored tests 16 | - **Blue**: These tests take longer than 1 second, usually unit tests should be super fast 17 | 18 | # Build Report sample 19 | 20 | 21 | # Usage 22 | Run the following command in your execute shell. That's it. If you want to compare debug builds, replace RELEASE with DEBUG. If you leave it empty, RELEASE build type will be used as default 23 | 24 | ```shell 25 | $ curl https://raw.githubusercontent.com/orhanobut/scripts/master/buildreport/build-report.sh -o build-report.sh 26 | $ sh build-report.sh RELEASE 27 | ``` 28 | 29 | ### Prerequisities 30 | in order to fetch information from html files, [Python 2.7+](https://www.python.org/downloads/) and [BeautifulSoup](https://www.crummy.com/software/BeautifulSoup/bs4/doc/#) must be installed in the machine. 31 | 32 | 33 | # Generated html file 34 | app/build/report/build-report.html 35 | 36 | ### Licence 37 | ``` 38 | Copyright 2016 Orhan Obut 39 | 40 | Licensed under the Apache License, Version 2.0 (the "License"); 41 | you may not use this file except in compliance with the License. 42 | You may obtain a copy of the License at 43 | 44 | http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | Unless required by applicable law or agreed to in writing, software 47 | distributed under the License is distributed on an "AS IS" BASIS, 48 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | See the License for the specific language governing permissions and 50 | limitations under the License. 51 | ``` 52 | -------------------------------------------------------------------------------- /buildreport/apk_info.py: -------------------------------------------------------------------------------- 1 | import os 2 | import subprocess 3 | 4 | 5 | class ApkInfo: 6 | method_count = None 7 | apk_size = None 8 | permissions = None 9 | max_count = None 10 | min_sdk_version = None 11 | target_sdk_version = None 12 | 13 | def __init__(self, method_count=0, apk_size=0, permissions=None, min_sdk=0, target_sdk=0): 14 | self.method_count = method_count 15 | self.apk_size = apk_size 16 | self.permissions = permissions 17 | self.max_count = 65536 18 | self.min_sdk_version = min_sdk 19 | self.target_sdk_version = target_sdk 20 | 21 | @classmethod 22 | def new_info(cls, apk_folder_path): 23 | 24 | classes_dex_path = apk_folder_path + '/classes.dex' 25 | method_count = subprocess.Popen( 26 | 'cat ' + classes_dex_path + ' | head -c 92 | tail -c 4 | hexdump -e \'1/4 "%d\n"\'', 27 | shell=True, 28 | stdout=subprocess.PIPE 29 | ).stdout.read() 30 | 31 | method_count = long(float(method_count)) 32 | 33 | apk_path = apk_folder_path + "/app.apk" 34 | # Apk size 35 | apk_size = os.path.getsize(apk_path) 36 | 37 | # Permissions 38 | permissions = subprocess.check_output(["aapt", "d", "permissions", apk_path]).split("\n") 39 | 40 | # First item is package name, no need 41 | del permissions[0] 42 | 43 | # Last item is None, remove it 44 | del permissions[len(permissions) - 1] 45 | 46 | # Sdk versions 47 | min_sdk = ApkInfo.sdk_version(apk_path, 'minSdkVersion') 48 | target_sdk = ApkInfo.sdk_version(apk_path, 'targetSdkVersion') 49 | 50 | return cls(method_count, apk_size, permissions, min_sdk, target_sdk) 51 | 52 | @staticmethod 53 | def sdk_version(apk_path, name): 54 | sdk_version = subprocess.Popen( 55 | 'aapt list -a ' + apk_path + ' | grep ' + name, 56 | shell=True, 57 | stdout=subprocess.PIPE 58 | ).stdout.read() 59 | 60 | return int(sdk_version.split('=')[1].split(')')[1], 16) 61 | 62 | def __str__(self): 63 | return "method_count : " + str(self.method_count) + \ 64 | ", apk_size : " + str(self.apk_size) + \ 65 | ", permissions : " + str(self.permissions) 66 | 67 | def remaining_method_count(self): 68 | return self.max_count - self.method_count 69 | 70 | def apk_size_in_mb(self): 71 | return self.apk_size / float(1000 * 1000) 72 | 73 | def apk_size_in_mb_formatted(self): 74 | return "{:20.4}".format(str(self.apk_size_in_mb())) 75 | 76 | def apk_size_diff(self, info): 77 | diff = self.apk_size - info.apk_size 78 | return "{:20.4}".format(str(diff / float(1000 * 1000))) 79 | 80 | def permissions_diff(self, info): 81 | list = [] 82 | 83 | compared_permissions = info.permissions 84 | 85 | for item in self.permissions: 86 | permission = str(item) 87 | if permission in compared_permissions: 88 | list.append(PermissionInfo.no_change(permission)) 89 | else: 90 | list.append(PermissionInfo.new_added(permission)) 91 | 92 | for item in compared_permissions: 93 | permission = str(item) 94 | if permission not in self.permissions: 95 | list.append(PermissionInfo.deleted(permission)) 96 | 97 | return list 98 | 99 | 100 | class PermissionInfo: 101 | name = None 102 | deleted = None 103 | new_added = None 104 | 105 | def __init__(self, name, deleted, new_added): 106 | self.name = name 107 | self.deleted = deleted 108 | self.new_added = new_added 109 | 110 | @classmethod 111 | def deleted(cls, name): 112 | return cls(name, False, True) 113 | 114 | @classmethod 115 | def new_added(cls, name): 116 | return cls(name, True, False) 117 | 118 | @classmethod 119 | def no_change(cls, name): 120 | return cls(name, False, False) 121 | -------------------------------------------------------------------------------- /buildreport/build-report.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | BUILD_TYPE=$1 4 | COMPARE_COMMIT_GREP=$2 5 | 6 | if [ -z $BUILD_TYPE ] 7 | then 8 | BUILD_TYPE="RELEASE" 9 | fi 10 | 11 | if [ -z $COMPARE_COMMIT_GREP ] 12 | then 13 | COMPARE_COMMIT_GREP="Merge pull request" 14 | fi 15 | 16 | GRADLE_BUILD_TYPE="assembleRelease" 17 | APP_NAME="app-release.apk" 18 | 19 | if [ $BUILD_TYPE == "DEBUG" ] 20 | then 21 | GRADLE_BUILD_TYPE="assembleDebug" 22 | APP_NAME="app-debug.apk" 23 | fi 24 | 25 | echo "Build type : $BUILD_TYPE" 26 | echo "Gradle build command : ./gradlew $GRADLE_BUILD_TYPE" 27 | echo "App-name : $APP_NAME" 28 | echo "Compare commit grep : $COMPARE_COMMIT_GREP" 29 | 30 | REPORT_PATH="report" 31 | 32 | rm -R "$REPORT_PATH/current/" 33 | rm -R "$REPORT_PATH/new/" 34 | 35 | mkdir "$REPORT_PATH" 36 | mkdir "$REPORT_PATH/current" 37 | mkdir "$REPORT_PATH/new" 38 | 39 | echo "Copy checkstyle report" 40 | cp app/build/reports/checkstyle/checkstyle.html "$REPORT_PATH/checkstyle.html" 41 | 42 | echo "Copy lint report" 43 | cp app/build/outputs/lint-results-debug.html "$REPORT_PATH/lint.html" 44 | 45 | echo "Copy unit tests report" 46 | cp app/build/reports/tests/debug/index.html "$REPORT_PATH/unittests.html" 47 | 48 | echo "Copy android instrumented tests results if exists" 49 | if [ -e "android-test-log.txt" ] 50 | then 51 | cp android-test-log.txt "$REPORT_PATH/android-test-log.txt" 52 | fi 53 | 54 | 55 | 56 | echo "Fetching build_report.py" 57 | curl https://raw.githubusercontent.com/orhanobut/scripts/master/buildreport/build_report.py -o "$REPORT_PATH/build_report.py" 58 | 59 | echo "Fetching apk_info.py" 60 | curl https://raw.githubusercontent.com/orhanobut/scripts/master/buildreport/apk_info.py -o "$REPORT_PATH/apk_info.py" 61 | 62 | PR_BRANCH=$(git rev-parse --short HEAD) 63 | echo "PR BRANCH=$PR_BRANCH" 64 | 65 | MERGE_BRANCH=$(git log --merges --grep "$COMPARE_COMMIT_GREP" -1 --format=format:%h) 66 | echo "MERGE BRANCH=$MERGE_BRANCH" 67 | 68 | # build apk from master and fetch apk info 69 | git checkout $MERGE_BRANCH 70 | echo "Current branch = $MERGE_BRANCH" 71 | echo "Building current apk" 72 | ./gradlew $GRADLE_BUILD_TYPE > "$REPORT_PATH/current/log.txt" 73 | echo "Copying current apk" 74 | cp "app/build/outputs/apk/$APP_NAME" "$REPORT_PATH/current/app.apk" 75 | echo "Unzipping current apk" 76 | unzip "$REPORT_PATH/current/app.apk" -d "$REPORT_PATH/current" >> "$REPORT_PATH/current/log.txt" 77 | 78 | # switch back to PR branch 79 | git checkout $PR_BRANCH 80 | echo "Current branch = $PR_BRANCH" 81 | echo "Building new apk" 82 | ./gradlew clean $GRADLE_BUILD_TYPE > "$REPORT_PATH/new/log.txt" 83 | echo "Copying new apk" 84 | cp "app/build/outputs/apk/$APP_NAME" "$REPORT_PATH/new/app.apk" 85 | echo "Unzipping new apk" 86 | unzip "$REPORT_PATH/new/app.apk" -d "$REPORT_PATH/new" >> "$REPORT_PATH/new/log.txt" 87 | 88 | echo "Building report" 89 | python "$REPORT_PATH/build_report.py" $REPORT_PATH 90 | -------------------------------------------------------------------------------- /buildreport/build_report.py: -------------------------------------------------------------------------------- 1 | from bs4 import BeautifulSoup 2 | import os 3 | import subprocess 4 | from apk_info import ApkInfo 5 | import sys 6 | import os.path 7 | 8 | REPORT_PATH = sys.argv[1:][0] 9 | 10 | 11 | def get_soup(url): 12 | return BeautifulSoup(open(url), 'html.parser') 13 | 14 | 15 | def add_header(text): 16 | file.write("\n\n

" + text + "

\n\n") 17 | 18 | 19 | def write(text): 20 | file.write(text) 21 | 22 | def generate_pr_info(): 23 | commits = subprocess.Popen( 24 | 'git log @~.. --oneline --no-merges --pretty=%B', 25 | shell=True, 26 | stdout=subprocess.PIPE 27 | ).stdout.read() 28 | commits = commits.split('\n') 29 | 30 | write('') 36 | 37 | def generate_lint_report(): 38 | soup = get_soup(REPORT_PATH + "/lint.html") 39 | table = soup.find('table', attrs={'class': 'overview'}) 40 | 41 | categories = table.find_all('td', attrs={'class': 'categoryColumn'}) 42 | for category in categories: 43 | category.a.wrap(soup.new_tag('b')) 44 | category.a.insert_before(soup.new_tag('hr')) 45 | 46 | # This report is sent via email and it doesn't contain any css/img files, no image will be shown. 47 | # Therefore remove all images 48 | img_tags = table.find_all('img') 49 | for img in img_tags: 50 | text = img["alt"] 51 | img.insert_after('[{0}]'.format(str(text))) 52 | img.extract() 53 | 54 | # Remove links since they point to local address 55 | a_tags = table.find_all('a') 56 | for a in a_tags: 57 | a_content = a.string 58 | a.insert_after(str(a_content)) 59 | a.extract() 60 | 61 | write(str(table)) 62 | 63 | 64 | def generate_checkstyle_report(): 65 | soup = get_soup(REPORT_PATH + "/checkstyle.html") 66 | 67 | table = soup.find('table', attrs={'class': 'log'}) 68 | table.attrs = None 69 | 70 | write(str(table)) 71 | 72 | 73 | def generate_unit_tests(): 74 | soup = get_soup(REPORT_PATH + "/unittests.html") 75 | 76 | # Add summary 77 | div_summary = soup.find('div', attrs={'id': 'summary'}) 78 | write(str(div_summary)) 79 | 80 | # Tabs are generated dynamically based on the status. For example: If there is no failure test 81 | # Failure tab won't be shown, therefore we need to dynamically fetch the classes tab which is 82 | # always the last tab 83 | tab_links = soup.find('ul', attrs={'class': 'tabLinks'}).find_all('li') 84 | last_tab = "tab" + str(len(tab_links) - 1) 85 | 86 | # Add test classes 87 | div_classes = soup.find('div', attrs={'id': last_tab}) 88 | div_classes.h2.extract() 89 | 90 | tr_tags = div_classes.tbody.find_all('tr') 91 | for tr in tr_tags: 92 | td_tags = tr.find_all('td') 93 | 94 | # 0 : Empty column, we will replace it with name 95 | # 1 : Test count 96 | # 2 : Failure test count 97 | # 3 : Ignored test count 98 | # 4 : Duration in second 99 | # 5 : Status 100 | 101 | for index, item in enumerate(td_tags): 102 | # There is a bug in the generated report. An empty redundant column is generated. 103 | # We fix it by removing basically and add the class name as new column 104 | if index == 0: 105 | item.extract() 106 | 107 | # If the test class has failures, paint to red 108 | if index == 2: 109 | fail_count = float(item.string) 110 | if fail_count > 0: 111 | tr['bgcolor'] = "#ff9999" 112 | 113 | # If the test class has ignoring tests, paint to orange 114 | if index == 3: 115 | ignore_count = float(item.string) 116 | if ignore_count > 0: 117 | tr['bgcolor'] = "#ffeb99" 118 | 119 | # If the duration is longer than 1 second, paint to blue 120 | if index == 4: 121 | duration = float(item.string[:-1]) 122 | if duration > 1: 123 | tr['bgcolor'] = "#ccccff" 124 | 125 | # There is a bug in generated test report html which is class names are not inside tag 126 | # Remove the links and move them inside a td tag 127 | links = div_classes.find_all('a') 128 | for a in links: 129 | a.wrap(soup.new_tag('td')) 130 | a.insert_after(str(a.string)) 131 | a.extract() 132 | 133 | write(str(div_classes)) 134 | 135 | 136 | def apk_info_row(current, change, new, remaining): 137 | return "Current: " + str(current) + "" + \ 138 | "Diff: " + str(change) + "" + \ 139 | "New: " + str(new) + "" + \ 140 | "Remaining: " + str(remaining) + "" 141 | 142 | 143 | def generate_apk_info(): 144 | current_apk_info = ApkInfo.new_info('report/current') 145 | new_apk_info = ApkInfo.new_info('report/new') 146 | 147 | write("") 148 | 149 | # Method count 150 | method_count_text = apk_info_row( 151 | current_apk_info.method_count, 152 | (new_apk_info.method_count - current_apk_info.method_count), 153 | new_apk_info.method_count, 154 | new_apk_info.remaining_method_count() 155 | ) 156 | write("") 157 | 158 | # APK Size 159 | apk_size_text = apk_info_row( 160 | current_apk_info.apk_size_in_mb_formatted(), 161 | new_apk_info.apk_size_diff(current_apk_info), 162 | new_apk_info.apk_size_in_mb_formatted(), 163 | "-" 164 | ) 165 | write("") 166 | 167 | # Min Sdk Version 168 | min_sdk_version = apk_info_row(current_apk_info.min_sdk_version, "-", new_apk_info.min_sdk_version, "-") 169 | write("") 170 | 171 | # Target Sdk Version 172 | target_sdk_version = apk_info_row(current_apk_info.target_sdk_version, "-", new_apk_info.target_sdk_version, "-") 173 | write("") 174 | 175 | # Permissions 176 | # Check what permission is added 177 | write("") 178 | permissions = current_apk_info.permissions_diff(new_apk_info) 179 | for permission in permissions: 180 | if permission.deleted: 181 | write("") 182 | elif permission.new_added: 183 | write("") 184 | else: 185 | write("") 186 | write("
Method Count" + method_count_text + "
Apk Size (mb)" + apk_size_text + "
Min Sdk Version" + min_sdk_version + "
Target Sdk Version" + target_sdk_version + "
Permissions
[REMOVED] " + permission.name + "
[NEW] " + permission.name + "
" + permission.name + "
") 187 | 188 | def generate_functional_test_results(report_path): 189 | total_elapsed_time = subprocess.Popen( 190 | 'grep "Time" '+ report_path +' ', 191 | shell=True, 192 | stdout=subprocess.PIPE 193 | ).stdout.read() 194 | write('

' + total_elapsed_time + '

') 195 | 196 | total_test_count = subprocess.Popen( 197 | 'grep "OK (" '+ report_path +' ', 198 | shell=True, 199 | stdout=subprocess.PIPE 200 | ).stdout.read() 201 | write('

' + total_test_count + '

') 202 | 203 | tested_classes = subprocess.Popen( 204 | 'sed -n "s/INSTRUMENTATION_STATUS: class=//gp" '+ report_path +' | uniq', 205 | shell=True, 206 | stdout=subprocess.PIPE 207 | ).stdout.read() 208 | tested_classes = tested_classes.split('\n') 209 | 210 | write('') 216 | 217 | 218 | with open(REPORT_PATH + '/build-report.html', 'w+') as file: 219 | print "Generating pull request info" 220 | add_header("Pull Request Info") 221 | generate_pr_info() 222 | 223 | print "Generating APK info (release)" 224 | add_header("APK Info (release)") 225 | generate_apk_info() 226 | 227 | print "Generating lint report" 228 | add_header("Lint") 229 | generate_lint_report() 230 | 231 | print "Generating checkstyle report" 232 | add_header("Checkstyle") 233 | generate_checkstyle_report() 234 | 235 | print "Generating unit tests" 236 | add_header("Unit Tests") 237 | generate_unit_tests() 238 | 239 | functional_tests_path=REPORT_PATH+"/android-test-log.txt" 240 | if os.path.isfile(functional_tests_path): 241 | print "Generating functionals tests" 242 | add_header("Functional Tests") 243 | generate_functional_test_results(functional_tests_path) 244 | 245 | print "Build report is generated at " + REPORT_PATH + "/build-report.html" 246 | -------------------------------------------------------------------------------- /git/init-git.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | NAME="" 4 | EMAIL="" 5 | 6 | while (( "$#" )); do 7 | case "$1" in 8 | "--name") 9 | shift 10 | NAME=$1 11 | ;; 12 | "--email") 13 | shift 14 | EMAIL=$1 15 | ;; 16 | esac 17 | shift 18 | done 19 | 20 | if [[ $NAME == "" ]] 21 | then 22 | echo "Name is missing. Add your name by using --name " 23 | exit 1 24 | fi 25 | 26 | if [[ $EMAIL == "" ]] 27 | then 28 | echo "Email is missing. Add your email by using --email " 29 | exit 1 30 | fi 31 | 32 | echo "Setting username as $1" 33 | git config --global user.name $NAME 34 | 35 | echo "Setting user email as $2" 36 | git config --global user.email $EMAIL 37 | 38 | echo "Setting aliases" 39 | echo "l -> log --oneline" 40 | git config --global alias.l "log --oneline" 41 | 42 | echo "lo -> log --oneline --decorate" 43 | git config --global alias.lo "log --oneline --decorate" 44 | 45 | echo "ld -> log --oneline origin/master.." 46 | git config --global alias.ld "log --oneline origin/master.." 47 | 48 | echo "lds -> log --oneline origin/master.. --shortstat" 49 | git config --global alias.lds "log --oneline origin/master.. --shortstat" 50 | 51 | echo "lol -> log --oneline --decorate --graph" 52 | git config --global alias.lol "log --oneline --decorate --graph" 53 | 54 | echo "s -> status" 55 | git config --global alias.s "status" 56 | 57 | echo "ac -> git add . && git commit -am" 58 | git config --global alias.ac "!git add . && git commit -am" 59 | 60 | echo "c -> git commit" 61 | git config --global alias.c "commit" 62 | 63 | echo "cm -> git commit -m " 64 | git config --global alias.cm "commit -m" 65 | 66 | echo "pom -> git pull origin master" 67 | git config --global alias.pom "pull origin master" 68 | 69 | echo "b -> git branch" 70 | git config --global alias.b "branch" 71 | 72 | echo "co -> git checkout" 73 | git config --global alias.co "checkout" 74 | 75 | 76 | 77 | 78 | --------------------------------------------------------------------------------