-
Notifications
You must be signed in to change notification settings - Fork 646
/
capture-build-details.sh
executable file
·54 lines (41 loc) · 1.86 KB
/
capture-build-details.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/sh -e
# capture-build-details.sh
# LoopFollow
#
# Created by Jonas Björkert on 2024-05-08.
# Enable debugging if needed
#set -x
# Define the base path for the BuildDetails.plist
info_plist_base="${BUILT_PRODUCTS_DIR}/${CONTENTS_FOLDER_PATH}"
# Adjust the path for macOS Catalyst builds to include the Resources directory
if [[ "$PLATFORM_NAME" == *"macosx"* ]]; then
info_plist_base+="/Resources"
fi
info_plist_path="${info_plist_base}/BuildDetails.plist"
# Ensure the path to BuildDetails.plist is valid.
if [ "${info_plist_path}" == "/" -o ! -e "${info_plist_path}" ]; then
echo "$PLATFORM_NAME"
echo "BuildDetails.plist file does not exist at path: ${info_plist_path}" >&2
exit 1
else
echo "Gathering build details..."
# Capture the current date and write it to BuildDetails.plist
formatted_date=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
plutil -replace com-LoopFollow-build-date -string "$formatted_date" "${info_plist_path}"
# Retrieve the current branch
git_branch=$(git symbolic-ref --short -q HEAD 2>/dev/null || echo "")
# Attempt to retrieve the current tag
git_tag=$(git describe --tags --exact-match 2>/dev/null || echo "")
# Retrieve the current SHA of the latest commit
git_commit_sha=$(git log -1 --format="%h" --abbrev=7 2>/dev/null || echo "")
# Determine the branch or tag information, defaulting to "detached" if neither is available
if [ -z "$git_branch" ] && [ -z "$git_tag" ]; then
git_branch_or_tag="detached"
else
git_branch_or_tag="${git_branch:-${git_tag}}"
fi
# Update BuildDetails.plist with the branch or tag information
plutil -replace com-LoopFollow-branch -string "${git_branch_or_tag}" "${info_plist_path}"
# Update BuildDetails.plist with the SHA information
plutil -replace com-LoopFollow-commit-sha -string "${git_commit_sha}" "${info_plist_path}"
fi