Engenious University.

Post

Share your knowledge.

Engenius Admin.
Dec 05, 2023
Expert Q&A

Automating Build Number Increment and Git Commit for iOS Apps

I'm looking for best practices on how to automate the process of incrementing the build number of an iOS app, and then committing and merging these changes to the main branch. Could you provide a detailed approach or script that can handle the build increment in the info.plist file and automate the subsequent Git operations?

  • CI/CD
0
1
Share
Comments
.

Answers

1
Engenius Admin.
Dec 5 2023, 12:12

Automating the build number increment in iOS/iPadOS apps involves modifying the info.plist file and then committing these changes to your Git repository. Here’s a practical approach using a shell script:

  1. Shell Script for Build Increment:
#!/bin/sh

# Get the current build number
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT_DIR}/${INFO_PLIST_FILE}")

# Increment the build number
newBuildNumber=$(($buildNumber + 1))

# Set the new build number in Info.plist
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $newBuildNumber" "${PROJECT_DIR}/${INFO_PLIST_FILE}"
  1. This script retrieves the current build number from info.plist, increments it, and then writes it back to the info.plist file.

  2. Running the Script in Continuous Integration (CI):

    • Integrate this script into your CI pipeline. Run it each time you make a new build so that it automatically increments the build number.
  3. Automating Git Operations:

    • After the script increments the build number, add the changes to Git, commit them, and push them to the main branch. You can automate this with additional shell commands:
git add "${PROJECT_DIR}/${INFO_PLIST_FILE}"
git commit -m "Increment build number to ${newBuildNumber}"
git push origin main

Note: Adjust the Git commands according to your branch and repository setup.

This automated process ensures that each new build has a unique and incremented build number, and the changes are consistently committed and pushed to your main branch. Integrating this into your CI pipeline simplifies version management and keeps your repository up-to-date with the latest build information.

0
Official Answer
Comments
.

Do you know the answer?

Please log in and share it.

We use cookies to ensure you get the best experience on our website.
More info