Skip to content

Instantly share code, notes, and snippets.

@kevindelord
Created September 7, 2015 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevindelord/4e9d7174fac085fb38c7 to your computer and use it in GitHub Desktop.
Save kevindelord/4e9d7174fac085fb38c7 to your computer and use it in GitHub Desktop.
Build, archive and push a new iOS app version
#!/usr/bin/python
import sys
import argparse
import os
import subprocess
parser = argparse.ArgumentParser(description='Build, archive and push a new iOS app version!')
parser.add_argument('-w','--workspace', help='Path to workspace', required=True, default=None)
parser.add_argument('-s','--scheme', help='Scheme name to build', required=True, default=None)
parser.add_argument('-i','--increment_build', help='Specify to increment the build number', required=False, default=False, action='store_true')
parser.add_argument('-p','--pod_install', help='Specify to run pod install', required=False, default=False, action='store_true')
parser.add_argument('-g','--git_push', help='Specify to commit and push the changes', required=False, default=False, action='store_true')
parser.add_argument('-v','--verbose', help='Specify to log the xcodebuild', required=False, default=False, action='store_true')
args = vars(parser.parse_args())
hockey_api_token = 'YOU_HOCKEY_API_TOKEN'
print args
if args['workspace'] != None and args['scheme'] != None:
current_path = os.popen('pwd').read().rstrip()
print "---- Jump to project folder ----"
project_path = args['workspace'] + "/.."
os.chdir(project_path)
print os.popen('pwd').read().rstrip()
if args['increment_build'] == True:
print "---- Update build version ----"
os.system('agvtool next-version -all')
if args['pod_install'] == True:
print "---- Run Pod install ----"
os.system('pod install')
print "---- Remove previous build files ----"
os.system('rm -rf %s.xcarchive' % args['scheme'])
print "---- Build .app file ----"
build_command = 'xcodebuild -workspace %s -scheme %s -configuration "Release" -archivePath %s.xcarchive archive' % (args['workspace'], args['scheme'], args['scheme'])
if args['verbose'] == False:
build_command += ' 1>/dev/null'
print build_command
os.system(build_command)
if os.path.exists(project_path + '/' + args['scheme'] + '.xcarchive') == False:
print "Archive Failed. Abort deploy process"
os.chdir(current_path)
sys.exit()
print "---- Get HockeyAppId ----"
plist_path = os.popen('xcodebuild -scheme "%s" -configuration "release" -showBuildSettings | grep -e "INFOPLIST_FILE" | sed "s/ INFOPLIST_FILE = //g"' % args['scheme']).read().rstrip()
print "Current target Info.Plist path: '%s'" % plist_path
hockey_app_id = os.popen('/usr/libexec/PlistBuddy -c Print:HockeyAppId %s' % plist_path).read().rstrip()
print "Current Target HockeyAppId: '%s'" % hockey_app_id
print "---- Upload ipa to HockeyApp ----"
hockey_command = 'puck -submit=auto -download=true -collect_notes_type=jenkins_aggregate -collect_notes_path="." -notes_type=markdown -source_path="."'
hockey_command += ' -api_token=%s' % hockey_api_token
hockey_command += ' -app_id=%s' % hockey_app_id
hockey_command += ' %s.xcarchive' % args['scheme']
os.system(hockey_command)
print "---- Remove current build files ----"
os.system('rm -rf %s.xcarchive' % args['scheme'])
if args['git_push'] == True:
print "---- Git push changes ----"
os.system('git commit -am "Increment Build Number" ; git push')
print "---- Jump to orignal folder ----"
os.chdir(current_path)
print os.popen('pwd').read().rstrip()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment