|
3 | 3 | # Set the number of git commits to Xcode build number |
4 | 4 | # The source code is based on https://leenarts.net/2020/02/11/git-based-build-number-in-xcode/ |
5 | 5 |
|
6 | | -git=$(sh /etc/profile; which git) |
7 | | -number_of_commits=$("$git" rev-list HEAD --count) |
| 6 | +GIT=`sh /etc/profile; which git` |
8 | 7 |
|
9 | | -target_plist="$TARGET_BUILD_DIR/$INFOPLIST_PATH" |
10 | | -dsym_plist="$DWARF_DSYM_FOLDER_PATH/$DWARF_DSYM_FILE_NAME/Contents/Info.plist" |
| 8 | +LATEST_TAG=`git describe --tags --abbrev=0 --match "v*.*.*"` |
| 9 | +if [ "${LATEST_TAG}" == "" ]; then |
| 10 | + echo "error: Version tag not found" |
| 11 | + exit 1 |
| 12 | +fi |
| 13 | + |
| 14 | +VERSION=`echo "${LATEST_TAG}" | cut -c 2-` |
| 15 | + |
| 16 | +NUM_COMMITS=`"${GIT}" rev-list HEAD --count` |
| 17 | + |
| 18 | +TARGET_PLIST="${TARGET_BUILD_DIR}/${INFOPLIST_PATH}" |
| 19 | +DSYM_PLIST="${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}/Contents/Info.plist" |
11 | 20 |
|
12 | | -for plist in "$target_plist" "$dsym_plist"; do |
13 | | - if [ -f "$plist" ]; then |
14 | | - /usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${number_of_commits}" "$plist" |
| 21 | +for PLIST in "${TARGET_PLIST}" "${DSYM_PLIST}"; do |
| 22 | + if [ -f "${PLIST}" ]; then |
| 23 | + /usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString ${VERSION}" "${PLIST}" |
| 24 | + /usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${NUM_COMMITS}" "${PLIST}" |
15 | 25 | fi |
16 | 26 | done |
17 | 27 |
|
18 | | -settings_root_plist="$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Settings.bundle/Root.plist" |
| 28 | +ROOT_PLIST="${TARGET_BUILD_DIR}/${PRODUCT_NAME}.app/Settings.bundle/Root.plist" |
19 | 29 |
|
20 | | -if [ -f "$settings_root_plist" ]; then |
21 | | - settingsVersion="$APP_MARKETING_VERSION (${number_of_commits})" |
22 | | - /usr/libexec/PlistBuddy -c "Set :PreferenceSpecifiers:1:DefaultValue $settingsVersion" "$settings_root_plist" |
| 30 | +if [ -f "${ROOT_PLIST}" ]; then |
| 31 | + SETTINGS_VERSION="${APP_MARKETING_VERSION} (${NUM_COMMITS})" |
| 32 | + /usr/libexec/PlistBuddy -c "Set :PreferenceSpecifiers:1:DefaultValue ${SETTINGS_VERSION}" "${ROOT_PLIST}" |
23 | 33 | else |
24 | | - echo "Could not find: $settings_root_plist" |
| 34 | + echo "Could not find: ${ROOT_PLIST}" |
25 | 35 | exit 0 |
26 | 36 | fi |
0 commit comments