Skip to content
Permalink
Browse files

tools: Build all branches in Auto Build script

Sanatizes the branch name by replacing anything other than letters,
numbers, or period with a minus sign.  Didn't use underscore, so
that the filename itself can be easily split on underscore for
parsing its various components later.
  • Loading branch information
paulscode committed Jan 10, 2015
1 parent c7fb2b3 commit c3456b080ed76e3823115a3117873b8cd4411e42
Showing with 58 additions and 32 deletions.
  1. +58 −32 tools/auto-build.sh
@@ -1,6 +1,7 @@
#!/bin/bash

if [ "$#" -eq 4 ] && [ "$4" == "-f" ]; then
# forceBuild will build all branches, whether or not there are changes
forceBuild=true
elif [ "$#" -ne 3 ]; then
echo "Usage:"
@@ -10,41 +11,66 @@ else
forceBuild=false
fi

#TODO: Loop through all branches
currentBranch="master"
# Look up all local and remote branches for comparison
localBranches=($(git branch | awk -F ' +' '! /\(no branch\)/ {print $2}'))
remoteBranches=($(git branch -r | awk -F ' origin/+' '! /\->/ {print $2}'))

echo "Checking out branch '""$currentBranch""'"
cmd="git checkout ""$currentBranch"; $cmd
oldRevision=`git rev-parse --short HEAD`
echo "Executing git fetch"
git fetch --all

echo "Executing git pull"
git pull
newRevision=`git rev-parse --short HEAD`

if [ "$oldRevision" == "$newRevision" ] && [ "$forceBuild" == false ]; then
echo "Nothing new to build"
exit 0
else
if [ "$forceBuild" == true ]; then
"Forcing auto-build"
exitCode=0
# Loop through the remote branches (these are the only ones that may have changed)
for currentBranch in "${remoteBranches[@]}"; do
# Determine if the remote branch is not among the local branches
newBranch=true
for b in "${localBranches[@]}"; do
if [ "$b" == "$currentBranch" ]; then
newBranch=false
fi
done

echo "Checking out branch '""$currentBranch""'"
cmd="git checkout ""$currentBranch"; $cmd
if [ "$newBranch" == true ]; then
echo "New branch"
# Always build new branches ("(none)" won't match any revision number)
oldRevision="(none)"
else
oldRevision=`git rev-parse --short HEAD`
fi
echo "Cleaning previous build"
ant clean
ndk-build clean
echo "Building APK"
ndk-build -j4
ant debug
if [ ! -f "bin/Mupen64Plus-debug.apk" ]; then
echo "Error: Build failed"
exit 1

echo "Executing git pull"
git pull
newRevision=`git rev-parse --short HEAD`

# Compare local and remote revision numbers, and build if there are changes
if [ "$oldRevision" == "$newRevision" ] && [ "$forceBuild" == false ]; then
echo "Nothing new to build"
else
#TODO: Sanitize branch name for use in filename
sanitizedBranchName="$currentBranch"

echo "Uploading APK to host"
cmd="scp -v -i ""$3"" bin/Mupen64Plus-debug.apk ""$1"":""$2""/Mupen64PlusAE_""$sanitizedBranchName""_""$(date +'%Y%m%d%H%M')""_""$newRevision"".apk"; $cmd
echo "Done"
exit 0
if [ "$forceBuild" == true ]; then
"Forcing auto-build"
fi
echo "Cleaning previous build"
ant clean
ndk-build clean
echo "Building APK"
ndk-build -j4
ant debug
if [ ! -f "bin/Mupen64Plus-debug.apk" ]; then
echo "Error: Build failed"
# Exit with error code 1 when finished looping through the branches
exitCode=1
else
# Sanatize the branch name for use as part of the APK filename
sanitizedBranchName=${currentBranch//[^a-zA-Z0-9\.]/-}
echo "Uploading APK to host"
cmd="scp -v -i ""$3"" bin/Mupen64Plus-debug.apk ""$1"":""$2""/Mupen64PlusAE_""$sanitizedBranchName""_""$(date +'%Y%m%d%H%M')""_""$newRevision"".apk"; $cmd
fi
fi
fi
done
# Make sure 'master' branch is checked out next time this script is executed from crontab
echo "Switching back to branch 'master'"
git checkout master
echo "Done"
exit $exitCode

2 comments on commit c3456b0

@paulscode

This comment has been minimized.

Copy link
Member Author

@paulscode paulscode replied Jan 10, 2015

FYI, my scheduled crontab will pull this updated script next hour, and then the following hour when it runs again it should build any other branches on mupen64plus-ae/mupen64plus-ae. It does not consider forks. If we want to set up auto-build for other forks, I can schedule separate crontab entries for them.

@littleguy77

This comment has been minimized.

Copy link
Member

@littleguy77 littleguy77 replied Jan 10, 2015

Awesome. I prefer not building forks. Gives me a place to stash "dirty" stuff that is not ready for sharing, but possibly of interest to other devs.

Please sign in to comment.
You can’t perform that action at this time.