Skip to content

Instantly share code, notes, and snippets.

@dlo
Last active February 2, 2024 02:18
Show Gist options
  • Select an option

  • Save dlo/1568eb5d3317d8b98bc393e58b0f84b2 to your computer and use it in GitHub Desktop.

Select an option

Save dlo/1568eb5d3317d8b98bc393e58b0f84b2 to your computer and use it in GitHub Desktop.
Xcode script that automatically uploads builds to iTunes Connect after archive

Description

This script will automatically upload Xcode archives to iTunes Connect after a successful build. After doing this about a million times manually, clicking on "Upload to App Store", waiting for teams to load, etc., I decided I'd had enough. Now, I just hit "Archive", sip my margherita, and kick up my feet while the world marvels at my genius. Or I'll take the dog out. Either way, it's pretty awesome.

To make this work, open up the build scheme you use to submit your App Store builds, go to "Archive", and then "Post-actions". Click the "+" and "Add Run Script Action". Then, paste in the contents of post_action.sh, replacing "[email protected]" with your iTunes Connect username.

Lastly, place iTunesExportOptions.plist in your project directory. Depending on your needs (e.g., if you want to distribute enterprise builds) you may need to tweak it. See xcodebuild -help for more details. By default, it assumes you just want to submit the build to the App Store / TestFlight.

Dependencies

pilot from fastlane.

gem install pilot

You may want to use it one time interactively on the command line so that your credentials are saved for future pushes.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>method</key>
<string>app-store</string>
</dict>
</plist>
IPA_EXPORT_DIR=$(mktemp -d)
ITUNES_USERNAME="[email protected]"
xcodebuild -exportArchive -exportOptionsPlist "${PROJECT_DIR}/iTunesExportOptions.plist" -archivePath "${ARCHIVE_PATH}" -exportPath "${IPA_EXPORT_DIR}"
pilot upload --skip_waiting_for_build_processing --username $ITUNES_USERNAME -i "${IPA_EXPORT_DIR}/${PRODUCT_NAME}.ipa"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment