|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Get the Git commit count |
| 4 | +#commitCount=$(git rev-list --count HEAD) |
| 5 | + |
| 6 | +# Check if commitCount is a valid number |
| 7 | +#if [[ ! $commitCount =~ ^[0-9]+$ ]]; then |
| 8 | +# echo "Failed to get Git commit count." |
| 9 | +# exit 1 |
| 10 | +#fi |
| 11 | + |
1 | 12 | git=`sh /etc/profile; which git`
|
2 | 13 | branchName=`"$git" rev-parse --abbrev-ref HEAD`
|
3 | 14 | buildNumber=$(expr $(git rev-list $branchName --count) - $(git rev-list HEAD..$branchName --count))
|
| 15 | + |
4 | 16 | if [ $CONFIGURATION = "Debug" ] || [ $branchName != "main" ] && [ $branchName != "develop" ];then
|
5 |
| -build=$buildNumber-$branchName |
| 17 | + build=$buildNumber-$branchName |
6 | 18 | else
|
7 |
| -build=$buildNumber |
| 19 | + build=$buildNumber |
8 | 20 | fi
|
9 |
| -/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $build" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}" |
10 |
| -echo "Updated ${TARGET_BUILD_DIR}/${INFOPLIST_PATH}" |
11 |
| -echo "Updated build number to $build using branch '$branchName'" |
12 | 21 |
|
13 |
| -# 把版本号显示在 Setting Bundle |
14 |
| -version=`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"` |
15 |
| -versionBuild="$version\($build\)" |
16 |
| -/usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:0:DefaultValue $versionBuild" "${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}/Settings.bundle/Root.plist" |
17 |
| -echo "Updated Settings.bundle" |
| 22 | +# Set the build number in Info.plist for the main app target |
| 23 | +mainPlistPath="${TARGET_BUILD_DIR}/${INFOPLIST_PATH}" |
| 24 | +echo "Setting build number to $commitCount in $mainPlistPath" |
| 25 | +/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $commitCount" "$mainPlistPath" |
| 26 | + |
| 27 | +# Set the build number in Info.plist for each app extension |
| 28 | +appExtensions=("OpenInAppExtension" "ShareExtension") # Add the names of your app extensions here |
| 29 | +for extension in "${appExtensions[@]}"; do |
| 30 | + extensionPlistPath="${TARGET_BUILD_DIR}/${PRODUCT_NAME}.app/PlugIns/$extension.appex/Info.plist" |
| 31 | + echo "Setting build number to $commitCount in $extensionPlistPath" |
| 32 | + /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $commitCount" "$extensionPlistPath" |
| 33 | +done |
0 commit comments