Skip to content

Instantly share code, notes, and snippets.

@crsantos
Created December 14, 2012 11:10

Revisions

  1. crsantos created this gist Dec 14, 2012.
    106 changes: 106 additions & 0 deletions iosbuildtestflight
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,106 @@
    #!/bin/bash
    # Bash script to generate a "Release" Build - Based on arrix.blogspot.com
    # - The file must lay on the same .xcodeproj folder
    # - Project must be set up with "Debug" (with developer provisioning profiles)
    # and "Release" (with distribution provisioning profiles)
    # - Project build version will be upgraded with the current datetime and marketing version
    # will be the same provided as the second parameter of the script: see USAGE.
    #
    # USAGE: sh build.sh AppName 0.1.1

    config='Ad Hoc' # This is the config you setted for ad-hoc distribution
    project_dir=$(pwd)
    # build_version="$(date -u +%Y%m%d%H%M)"
    API_TOKEN="REPLACE_ME"
    TEAM_TOKEN="REPLACE_ME"
    DISTRIBUTIONLISTS="REPLACE_ME eg. Testers"
    NOTIFY="False"
    NOTES=" "

    usage(){
    echo "\n\t*****************************************************************"
    echo "\t\tUSAGE: sh $0 AppName 0.1 0.1.15"
    echo "\t\t You must provide the app name: (i.e.) MyApp"
    echo "\t\tYou must provide a marketing-version: (i.e.) 1.0"
    echo "\t\tYou must provide a build-version: (i.e.) 1.0.0"
    echo "\n\t\t\tString format must match!"
    echo "\t*****************************************************************\n\n"
    exit 1
    }

    die() {
    echo "$*" >&2
    exit 1
    }

    doIt(){

    appname=$1
    version=$2
    buildv=$3
    echo "\n1/6 - Updating marketing version number and build to: $version ($buildv)..." # agvtool bump -all
    agvtool new-version -all "$buildv" > /dev/null
    agvtool new-marketing-version "$version" > /dev/null

    fullversion="$(agvtool mvers -terse1)($(agvtool vers -terse))" # gets current version
    echo "\n\n2/6 - Building $appname using configuration $config..."
    echo "\t\tBuilding version $fullversion\n\n"

    xcodebuild -target "$appname" -configuration "$config" > ~/Desktop/$appname.$fullversion.log || die "\nBuild failed!\n" # Builds on xcode

    clear # clear screen

    echo "\n\n3/6 - Making ipa..."
    # packaging
    cd build/"$config"-iphoneos || die "no such directory"
    rm -rf Payload
    # rm -f "$appname".*.ipa
    mkdir Payload # creates Payload dir
    cp -Rp "$appname.app" Payload/ # move app to payload
    if [ -f "$project_dir"/iTunesArtwork ] ; then # check if there is any iTunesArtwork
    cp -f "$project_dir"/iTunesArtwork Payload/iTunesArtwork
    fi

    ipaname="$appname.$fullversion.ipa" # new name for the .ipa
    zip -r $ipaname Payload # compress to ipa

    md5checksum=$(md5 -s $ipaname)
    echo "\t $md5checksum" # shows md5 checksum


    echo "\n\n4/6 - Sending ipa to testflightapp..."
    curl http://testflightapp.com/api/builds.json -F file=@"$ipaname" -F api_token=$API_TOKEN -F team_token=$TEAM_TOKEN -F notes="$NOTES" -F notify=$NOTIFY -F distribution_lists="$DISTRIBUTIONLISTS"


    echo "\n\n5/6 - Compressing dSYM..."

    mv $ipaname ~/Desktop # move IPA to desktop
    dsymname="$appname.app.dSYM" # Move zipped dSYM to desktop
    zippedSYM="$dsymname.zip"
    zip -r $zippedSYM $dsymname
    mv $zippedSYM ~/Desktop # move dSYM to desktop
    cd ../../ && rm -rf build # deletes build/ dirs
    echo "\n\n6/6 - Moved ipa to ~/Desktop"
    echo "\n\n\tFinished making $ipaname\n\n"
    open ~/Desktop

    exit 0
    }


    [[ $# -lt 3 ]] && usage # check if param count < 2 and shows an error

    count=`ls -1 | grep ".xcodeproj" | wc -l`
    if [ $count != 0 ]
    then

    if [[ $1 =~ ^[A-z_-]+$ ]] && [[ $2 =~ ^[0-9]+(\.[0-9]+)+$ ]];
    then
    doIt $1 $2 $3;
    else
    usage;
    fi
    else
    echo "\n\n\tWARNING: Not in a project's folder. This file must lay side by side with .xcodeproj\n\n"
    exit 1
    fi