I do not want an Archive build to succeed unless my working directory is clean. Therefore, I want to add a "Run Script" build phase (or something similar) to my Xcode project such that:
IF I am performing an Archive build...
AND there are uncommitted changes in my source directory
THEN the build fails with an error.
I'm working with Xcode 4 and git 1.7.
What's a good, concise, reusable script that will do the job?
When Xcode finishes building, the Archives window will open with the result. Xcode created your archive. The actual . xcarchive folder resides on your Mac in ~/Library/Developer/Xcode/Archives.
It archives your Xcode project by running the xcodebuild archive command and exports the archive into an . ipa file with the xcodebuild -exportArchive command. This . ipa file can be shared and installed on test devices, or uploaded to App Store Connect.
Navigate to your project's settings. Under iOS (or the target you want to build your app for) > Identity, you'll want to increment the Build number. For example, if the Build number was 1, you'll want to set it to 2. Then, in the top menu, under Product, click on Archive.
Archive your App In Xcode with your project open, select the simulator (button near the top of the window next to your project name, typically named as a specific type of iPhone) – change it to Generic iOS Device. Open the Product menu and choose Archive. You will see the archive information. Click Validate App.
Here's the script I've come up with:
#!/bin/sh
if [ -z "$(git status --porcelain)" ]; then
TAG=`date +xcarchive-%Y%m%d-%H%M%S`
echo "Working directory clean, creating tag ${TAG}"
git tag -a -m "Xcode Archive created" ${TAG}
exit 0
else
echo "error: Working directory dirty, stopping build"
exit 1
fi
As a bonus, it creates a tag if the working copy is clean.
The clean/dirty check is based on this question (which I forgot I had proposed an answer for).
If you don't want to create a tag, remove the git tag
line.
If you don't want to stop the build, remove the exit 1
line.
To install this in a project:
ArchiveHousekeeper.sh
) and make sure the executable bit is set (chmod +x
)./ArchiveHousekeeper.sh
It would be nice if Xcode 4 Pre- and Post- actions could be used for this (so you don't need to create a "fake" target), but they don't seem able to affect the build, and also I have no idea in what directory they are executed, what environment variables are available, or where their output goes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With