Use Travis to extract testing APKs for PSLab
Travis CI is a popular continuous integration tool built to test software and deployments done at GitHub repositories. They provide free plans to open source projects. PSLab Android is using Travis to ensure that all the pull requests made and the merges are build-bug frees. Travis can do this pretty well, but that is not all it can do. It’s a powerful tool and we can think of it as a virtual machine (with high specs) installed in a server for us to utilize efficiently.
There was a need in PSLab development that, if we want to test the functionalities of code at a branch. To fulfil this need, one has to download the branch to his local machine and use gradle to build a new apk. This is a tedious task, not to mention reviewers, even developers wouldn’t like to do this.
If the apk files were generated and in a branch, we can simply download them using a console command.
$ wget https://raw.github.com/fossasia/<repository>/<branch>/<file with extension>
With the help of Travis integration, we can create a simple script to generate these apks for us. This is done as follows;
Once the Travis build is complete for a triggering event such as a pull request, it will run it’s “after_success” block. We are going to execute a script at this point. Simply add the following code snippet.
after_success: - 'if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then bash <script-name>.sh; fi'
This will run the script you have mentioned using bash. Here we will have the following code snippets in the specified bash script.
First of all we have to define the branch we want to build. This can be done using a variable assignment.
Once the build is complete, there will be new folders in the virtual machine. One of them is the app folder. Inside this folder contains the build folder where all the apk files are generated. So the next step is to copy these apk files to a place of our preference. I am using a folder named apk to make it much sense.
cd apk \cp -r ../app/build/outputs/apk/*/**.apk . \cp -r ../app/build/outputs/apk/debug/output.json debug-output.json \cp -r ../app/build/outputs/apk/release/output.json release-output.json \cp -r ../README.md .
Usually, the build folder has following apk files
Release apks are usually signed with a key and it would cause issues while installation. So we have to filter out the debug apk that we usually use for debugging and get it as the output apk. This involves simple file handling operations in Linux and a bit of git.
First of all, rename the apk file so that it will be different from other files.
# Rename apks with dev prefixes mv app-debug.apk app-dev-debug.apk
Then add and commit them to a specific branch where we want the output from.
git add -A git commit -am "Travis build pushed [development]" git push origin apk --force --quiet> /dev/null
Once it is all done, you will have a branch created and updated with the apk files you have defined.
Figure 1: UI of pslab-android apk branch