-
-
Save Berhtulf/ab3fb663187e7644410c0401b207aa45 to your computer and use it in GitHub Desktop.
# 1. Create 'ci_scripts' folder in your main project directory | |
# 2. Create 'ci_post_xcodebuild.sh' inside of it | |
# 3. Make it an executable by running 'chmod +x $ci_post_xcodebuild.sh' | |
set -e # fails build if any command fails | |
if [ ${CI_XCODEBUILD_EXIT_CODE} != 0 ] | |
then | |
exit 1 | |
fi | |
if [[ -n $CI_APP_STORE_SIGNED_APP_PATH ]]; # checks if there is an AppStore signed archive after running xcodebuild | |
then | |
BUILD_TAG=${CI_BUILD_NUMBER} | |
VERSION=$(cat ../${CI_PRODUCT}.xcodeproj/project.pbxproj | grep -m1 'MARKETING_VERSION' | cut -d'=' -f2 | tr -d ';' | tr -d ' ') | |
git tag ${CI_PRODUCT}/Release/$VERSION\($BUILD_TAG\) | |
git push --tags https://${GIT_AUTH}@github.com/USER_NAME/REPOSITORY.git | |
fi | |
# use workflow Environment to configure your GIT_AUTH variable - username:personalAccessToken |
Thanks for bringing that up @gsbernstein. This is actually something I have encountered myself long time ago, after using this script. Bellow is my current version. It has an extra check for Xcode exit status. It is by no means final or without more hidden bugs :) I am fixing it as I run into more issues.
set -e
if [ ${CI_XCODEBUILD_EXIT_CODE} != 0 ]
then
exit 1
fi
#if we have successfully archived a build, then we can mark it with a tag
if [[ -d "$CI_APP_STORE_SIGNED_APP_PATH" ]]
then
...
fi
Thanks for the reply! I see you also changed -n
(check if string is empty) to -d
(check if directory exists) in that snippet (but not in the gist?). I had coincidentally noticed that Apple's post-build script sample for something else used -d
, so I tried making that change alone, which seemed to work well enough without the CI_XCODEBUILD_EXIT_CODE
check. Before that, I had been trying to check if an IPA existed within that directory, but that seems like overkill now:
if [[ -n "$CI_APP_STORE_SIGNED_APP_PATH" ]] && ls "$CI_APP_STORE_SIGNED_APP_PATH" | grep -q "Vida.ipa"; then
Funny that CI_XCODEBUILD_EXIT_CODE
does seem like a much more direct way of checking this, to where you probably wouldn't even need to look at CI_APP_STORE_SIGNED_APP_PATH
. Wonder why Apple doesn't use it?
I'm seeing
CI_APP_STORE_SIGNED_APP_PATH
as set to/Volumes/workspace/appstoreexport
whether or not the archive succeeded, so this is posting even on failed builds. Might need to add something to check for an xcarchive in that directory?