Autonomous PR Testing

Yubaraj poudel
2 min readJun 8, 2019

--

For Android only

Sometimes it can be a good idea to leave someone to do the frequently occurring same job and focus on something else. While working I found the same situation. Every time a new Pull Request created in the GitHub, pull that PR, checkout to that and run in the mobile.

Though it sounds funny to deal with this problem but for me was like its a quite boring job to wait for PR being pulled and again run through the device. So, I came up the idea with how can we easily let the computer to do this job with bash scripting.

Script file I made to this job testpr.sh

#!/usr/bin/env bash
# Author : Yubaraj Poudel
# Since : 10/03/2019
BRANCH_NAME="master"

builApp
() {
# run adb
[! -f "gradlew"] && echo "gradlew file not exists" && exit
# build and run the debug apk
./gradlew assembleDebug
}

installApp() {
adb install -r -g "$(find . -name "*.apk" -type f)"
adb shell am start -n org.bcss.collect.android/org.odk.collect.android.activities.SplashScreenActivity
}

askToTestRelease() {
read -p "Do you want to test realease (y/n)?" choice
case "$choice" in
y|Y ) echo "pulling master" ;;
n|N ) exit;;
* ) echo "invalid" && exit;;
esac
}

#check the branch name is provided in the command or not
if [ "$#" -ne 1 ]; then
RED='\033[1;33m'
NC='\033[0m' #no color
echo "${RED}Need to provide pullrequest(branch) name${NC}";
echo "https://github.com/fieldsight/fieldsight-mobile/pulls";
# confirm whether want to test default master
askToTestRelease
else BRANCH_NAME=$1
fi

echo "$BRANCH_NAME";

# get the current branch name
BRANCH=$(git branch)

# check the current branch is master or not
[[ $BRANCH != "master" ]] && git checkout master

#pull the branch from origin
git pull origin "$BRANCH_NAME"

if [
$? -eq 0 ]; then
echo "$1 is fetched successfully";
#checkout to the branch
git checkout "$BRANCH_NAME"
builApp && installApp
else
echo "Failed to pull, please check branch name"
fi

To use this, u can copy this script in your any project inside the project folder.

To pull the pr and run it simply run the command

./testpr.sh branch_name

if you do not provide the branch name it will pull the master and run from master.

Sometimes you might have a problem running this file because of permissions issues. To give the permission if you are Linux or Mac user then

sudo chmod u=rwx ./testpr.sh -R

If you get easier to do your task please give a clap for this article. Thank you.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Yubaraj poudel
Yubaraj poudel

Written by Yubaraj poudel

Senior Software engineer | Blogger

No responses yet

Write a response