Skip to content

Commit 986e648

Browse files
committed
Set version from git tag
1 parent d0d901a commit 986e648

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

scripts/set_build_number.sh

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,34 @@
33
# Set the number of git commits to Xcode build number
44
# The source code is based on https://leenarts.net/2020/02/11/git-based-build-number-in-xcode/
55

6-
git=$(sh /etc/profile; which git)
7-
number_of_commits=$("$git" rev-list HEAD --count)
6+
GIT=`sh /etc/profile; which git`
87

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"
1120

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}"
1525
fi
1626
done
1727

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"
1929

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}"
2333
else
24-
echo "Could not find: $settings_root_plist"
34+
echo "Could not find: ${ROOT_PLIST}"
2535
exit 0
2636
fi

0 commit comments

Comments
 (0)