Created
June 2, 2020 17:47
-
-
Save jonchui/fa40ee380b11ec3b4929a8005f283bc8 to your computer and use it in GitHub Desktop.
Uploads Waldo to buddybuild post build
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Buddybuild_postbuild.sh - Runs after builds completes (includes all unit tests) | |
# https://docs.buddybuild.com/builds/custom_build_steps.html#postbuild | |
# | |
# Currently, our postbuild does one thing: | |
# | |
# 1) Uploads .app simulator build to waldo, IF and only IF, | |
# a) on the develop branch (aka. so that we do not run on every PR's push, ONLY when PR is merged to develop) | |
# OR | |
# b) if the commit message explictly has `[waldo run]` in it. that overrides everything | |
# | |
# NOTE: we made this so it can be run locally. | |
# | |
#Initial buddybuild-logging" | |
echo "=== Starting buddybuild_postbuild.sh script. Can also be run locally, to upload to waldo.io" | |
echo "=== BUDDYBUILD_SCHEME: $BUDDYBUILD_SCHEME ===" | |
echo "=== BUDDYBUILD_APP_ID: $BUDDYBUILD_APP_ID ===" | |
echo "=== BUDDYBUILD_BUILD_NUMBER: $BUDDYBUILD_BUILD_NUMBER ===" | |
echo "=== BUDDYBUILD_PRODUCT_DIR: $BUDDYBUILD_PRODUCT_DIR ===" | |
echo "=== BUDDYBUILD_TRIGGERED_BY: $BUDDYBUILD_TRIGGERED_BY ===" | |
echo "=== BUDDYBUILD_TEST_DIR: $BUDDYBUILD_TEST_DIR ===" | |
# Check if we are on develop branch | |
CURRENT_BRANCH=$BUDDYBUILD_BRANCH | |
if test -z "$CURRENT_BRANCH" | |
then | |
echo "CURRENT_BRANCH is unset. So we are NOT RUNNING IN BUDDYBUILD. Setting to local branch name" | |
CURRENT_BRANCH="$(git symbolic-ref HEAD 2>/dev/null)" | |
echo "BECAUSE we are not running in buddybuild, will run waldo by default:" | |
SHOULD_RUN_WALDO_UPLOAD=true | |
fi | |
echo "=== Current git branch: $CURRENT_BRANCH" | |
# See if buddybuild is merging a commit (b/c we are behind develop). This is only `buddybuild`, if | |
# buddybuild needs to merge in develop changes | |
export GIT_REVISION_AUTHOR=$(git log -1 --pretty=format:"%an <%ae>") | |
if [[ ${GIT_REVISION_AUTHOR} == *"buddybuild"* ]];then | |
echo "=== last commit is buddybuild , so we are assuming a merge commit. Need to look one level deeper for our commit message ... " | |
# See if commit message has "[waldo run]" in it. If so, we should run WALDO | |
export GIT_COMMIT_MSG=`git log -n 1 --pretty=format:'%s%n%n%b' HEAD~1` | |
export GIT_REVISION_AUTHOR=$(git log -1 --pretty=format:"%an <%ae>" HEAD~1) | |
else | |
# See if commit message has "[waldo run]" in it. If so, we should run WALDO | |
export GIT_COMMIT_MSG=`git log -n 1 --pretty=format:'%s%n%n%b'` | |
fi | |
echo "=== Current non-buddybuild git commit message, by '$GIT_REVISION_AUTHOR' : '$GIT_COMMIT_MSG'" | |
if [[ ${GIT_COMMIT_MSG} == *"[waldo run]"* ]];then | |
echo "=== Found \"[waldo run]\" in commit message. Will run waldo upload." | |
SHOULD_RUN_WALDO_UPLOAD=true | |
else | |
echo "=== Did NOT find \"[waldo run]\" in commit message. Will NOT set SHOULD_RUN_WALDO_UPLOAD=true." | |
fi | |
if [[ ${CURRENT_BRANCH} == *"develop"* ]];then | |
echo "=== Found develop branch. Will run waldo" | |
SHOULD_RUN_WALDO_UPLOAD=true | |
else | |
echo "=== NOT on develop branch. Will NOT set SHOULD_RUN_WALDO_UPLOAD=true" | |
fi | |
if [ -z ${SHOULD_RUN_WALDO_UPLOAD+x} ] ; then | |
#unset, so we should NOT upload | |
echo "=== NOT RUNNING WALDO. Neither condition met (a) on develop branch, or b) [waldo run] in git commit message" | |
else | |
# First find the debug_simulator_path | |
DEBUG_SIMULATOR_PATH="/tmp/sandbox/$BUDDYBUILD_APP_ID/bbtest/Build/Products/QA-iphonesimulator" | |
if [ ! -e "$DEBUG_SIMULATOR_PATH" ]; then | |
echo "Could not find path BUDDYBUILD simulator @ $DEBUG_SIMULATOR_PATH, gonna try with bbbuild" | |
DEBUG_SIMULATOR_PATH="/tmp/sandbox/$BUDDYBUILD_APP_ID/bbbuild/Build/Products/QA-iphonesimulator" | |
if [ ! -e "$DEBUG_SIMULATOR_PATH" ]; then | |
echo "NEIHER buddybuild paths exist... looking to see if we are running a local xcode build" | |
# does not exist, possible we're running script locally? If so, let's get local app_path`. Ex. on local machine: `/Users/jonchui/Library/Developer/Xcode/DerivedData/Phoenix-iOS-fnsruhzdsjicaigvxyhcsbdnmnse/Build/Products/QA-iphoneos` | |
DEBUG_SIMULATOR_PATH=`xcodebuild -scheme "Phoenix-QA" -workspace "Phoenix-iOS/Phoenix-iOS.xcworkspace" -showBuildSettings | grep -m 1 "CONFIGURATION_BUILD_DIR" | grep -oEi "\/.*"` | |
if [ ! -e "$DEBUG_SIMULATOR_PATH" ]; then | |
# One last try, possible we're in the `Phoenix-iOS` directory, so we can just run from there | |
DEBUG_SIMULATOR_PATH=`xcodebuild -scheme "Phoenix-QA" -workspace "Phoenix-iOS.xcworkspace" -showBuildSettings | grep -m 1 "CONFIGURATION_BUILD_DIR" | grep -oEi "\/.*"` | |
if [ ! -e "$DEBUG_SIMULATOR_PATH" ]; then | |
# Still does not exist, let's return ;( | |
echo "=== ERROR: DEBUG_SIMULATOR_PATH $DEBUG_SIMULATOR_PATH does not exist . Have you ran your unit tests? ;(" | |
echo "=== Going to run ... " | |
xcodebuild test -scheme "Phoenix-QA" -enableCodeCoverage "YES" -configuration "Debug" ENABLE_TESTABILITY=YES -destination "platform=iOS Simulator,OS=13.3,name=iPhone 8" -workspace "Phoenix-iOS/Phoenix-iOS.xcworkspace" ONLY_ACTIVE_ARCH=YES | |
exit 1 | |
fi | |
fi | |
fi | |
echo "=== Found BUDDYBUILD simulator debug path: $DEBUG_SIMULATOR_PATH" | |
fi | |
# next let's get the path to the .app file | |
APP_PATH="$DEBUG_SIMULATOR_PATH/Catalyze.app" | |
if [ ! -e "$APP_PATH" ]; then | |
echo "=== ERROR: could not find Catalyze.app at path :$APP_PATH" | |
echo "=== Possible you have not built the app yet?" | |
exit 1 | |
fi | |
# set up the custom reporting folders | |
# mkdir /tmp/sandbox/workspace/buddybuild_artifacts | |
echo "=== Checking if waldo.io's cli_bin is installed... " | |
# waldo expects the app to be zipped, but the CLI des it | |
# zip -r $ZIPPED_APP $APP_PATH | |
# get waldo BIN | |
WALDO_CLI_BIN=/usr/local/bin | |
if [ ! -e "$WALDO_CLI_BIN"/waldo ]; then | |
echo "=== Downloading waldo CLI ===" | |
curl -fLs https://github.com/waldoapp/waldo-cli/releases/download/1.5.0/waldo > "$WALDO_CLI_BIN"/waldo | |
chmod +x "$WALDO_CLI_BIN"/waldo | |
fi | |
# export to waldo | |
export WALDO_UPLOAD_TOKEN=98a445a7bf1998f3efde3cbb677758d1 | |
echo "=== SUCCESS - running: " "$WALDO_CLI_BIN"/waldo "$APP_PATH" | |
"$WALDO_CLI_BIN"/waldo "$APP_PATH" | |
echo "=== Completed upload of app to waldo ===" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment