A simple function that returns a random color in TypeScript for use in React, Vue, Angular, or any other JavaScript project.
Easily automate your version and build numbers incrementally in Xcode and use git hooks to ensure version consistency. This is a great way to ensure that your versioning is consistent across all of your projects without all the manual hassles.
Build Number: You can auto-increment the build number using a Run Script Phase in Xcode.
Build Phases.+ to add a New Run Script Phase.buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"
Version Number: Xcode doesn't have native support for semantic versioning auto-increment, but you can modify the script to fit semantic rules manually.
.git/hooks.pre-commit (no file extension).chmod +x pre-commit.CFBundleShortVersionString and CFBundleVersion from Info.plist and checks or modifies them as needed.For example, a simple script could read the Info.plist and prevent a commit if the version number hasn't been incremented.
Below is an example pre-commit shell script that reads the CFBundleShortVersionString and CFBundleVersion from . It will prevent the commit if the version is not greater than the previously stored version.
Info.plistCreate a file named .last_version to keep track of the last version.
#!/bin/sh
# pre-commit
# Define the path to your Info.plist file
infoPlistPath="./YourProject/Info.plist"
# Read the current version and build number from Info.plist
currentVersion=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$infoPlistPath")
currentBuild=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$infoPlistPath")
# Read the last committed version and build number
lastVersion=$(cat .last_version)
lastBuild=$(cat .last_build)
# Logic to check if the version or build number has been incremented
if [[ "$currentVersion" > "$lastVersion" ]] || [[ "$currentBuild" > "$lastBuild" ]]; then
echo "Version or build number has been incremented."
# Store the new version and build number
echo $currentVersion > .last_version
echo $currentBuild > .last_build
# Add .last_version and .last_build to the commit
git add .last_version
git add .last_build
exit 0
else
echo "Error: You must increment the version or build number to commit."
exit 1
fi
Replace YourProject/Info.plist with the relative path to your project's Info.plist.
This is a simple example and could be extended to follow more complex semantic versioning rules.
By combining Xcode Run Scripts and Git hooks, you can have a robust automated versioning system.
Please consider Buying Me A Coffee. I work hard to bring you my best content and any support would be greatly appreciated. Thank you for your support!