Skip to content

Commit a29859c

Browse files
committed
Show profile expiration in issue report
1 parent 342f379 commit a29859c

File tree

4 files changed

+92
-10
lines changed

4 files changed

+92
-10
lines changed

Common/Extensions/NSBundle.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,16 @@ extension Bundle {
6161
var xcodeVersion: String? {
6262
return object(forInfoDictionaryKey: "com-loopkit-Loop-xcode-version") as? String
6363
}
64+
65+
var profileExpiration: Date? {
66+
return object(forInfoDictionaryKey: "com-loopkit-Loop-profile-expiration") as? Date
67+
}
68+
69+
var profileExpirationString: String {
70+
if let profileExpiration = profileExpiration {
71+
return "\(profileExpiration)"
72+
} else {
73+
return "N/A"
74+
}
75+
}
6476
}

Loop.xcodeproj/project.pbxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2593,6 +2593,7 @@
25932593
inputFileListPaths = (
25942594
);
25952595
inputPaths = (
2596+
"${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}",
25962597
);
25972598
name = "Capture Build Details";
25982599
outputFileListPaths = (

Loop/Managers/DeviceDataManager.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ final class DeviceDataManager {
213213
let report = [
214214
"## LoopVersion",
215215
"* Version: \(Bundle.main.localizedNameAndVersion)",
216+
"* profileExpiration: \(Bundle.main.profileExpirationString)",
216217
"* gitRevision: \(Bundle.main.gitRevision ?? "N/A")",
217218
"* gitBranch: \(Bundle.main.gitBranch ?? "N/A")",
218219
"* sourceRoot: \(Bundle.main.sourceRoot ?? "N/A")",

Scripts/capture-build-details.sh

Lines changed: 78 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,86 @@
55
#
66
# Copyright © 2019 LoopKit Authors. All rights reserved.
77

8-
echo "Gathering build details in ${SRCROOT}"
9-
cd "${SRCROOT}"
8+
SCRIPT="$(basename "${0}")"
9+
SCRIPT_DIRECTORY="$(dirname "${0}")"
1010

11-
plist="${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}"
11+
error() {
12+
echo "ERROR: ${*}" >&2
13+
echo "Usage: ${SCRIPT} [-r|--git-source-root git-source-root] [-p|--provisioning-profile-path provisioning-profile-path] [-i|--info-plist-path info-plist-path]" >&2
14+
echo "Parameters:" >&2
15+
echo " -r|--git-source-root <git-source-root> root location of git repository to gather information from; optional, defaults to \${WORKSPACE_ROOT} if present, otherwise defaults to \${SRCROOT}" >&2
16+
echo " -p|--provisioning-profile-path <provisioning-profile-path> path to the .mobileprovision provisioning profile file to check for expiration; optional, defaults to \${HOME}/Library/MobileDevice/Provisioning Profiles/\${EXPANDED_PROVISIONING_PROFILE}.mobileprovision" >&2
17+
echo " -i|--info-plist-path <info-plist-path> path to the Info.plist file to modify; optional, defaults to \${BUILT_PRODUCTS_DIR}/\${INFOPLIST_PATH}" >&2
18+
exit 1
19+
}
20+
21+
warn() {
22+
echo "WARN: ${*}" >&2
23+
}
24+
25+
info() {
26+
echo "INFO: ${*}" >&2
27+
}
28+
29+
git_source_root="${WORKSPACE_ROOT:-${SRCROOT}}"
30+
info_plist_path="${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}"
31+
provisioning_profile_path="${HOME}/Library/MobileDevice/Provisioning Profiles/${EXPANDED_PROVISIONING_PROFILE}.mobileprovision"
32+
xcode_build_version=${XCODE_PRODUCT_BUILD_VERSION:-$(xcodebuild -version | grep version | cut -d ' ' -f 3)}
33+
while [[ $# -gt 0 ]]
34+
do
35+
case $1 in
36+
-r|--git-source-root)
37+
git_source_root="${2}"
38+
shift 2
39+
;;
40+
-i|--info-plist-path)
41+
info_plist_path="${2}"
42+
shift 2
43+
;;
44+
-p|--provisioning-profile-path)
45+
provisioning_profile_path="${2}"
46+
shift 2
47+
;;
48+
esac
49+
done
50+
51+
if [ ${#} -ne 0 ]; then
52+
error "Unexpected arguments: ${*}"
53+
fi
54+
55+
if [ -z "${git_source_root}" ]; then
56+
error "Must provide one of --git-source-root, \${WORKSPACE_ROOT}, or \${SRCROOT}."
57+
fi
58+
59+
if [ "${info_plist_path}" == "/" -o ! -e "${info_plist_path}" ]; then
60+
error "Must provide valid --info-plist-path, or have valid \${BUILT_PRODUCTS_DIR} and \${INFOPLIST_PATH} set."
61+
fi
62+
63+
info "Gathering build details in ${git_source_root}"
64+
cd "${git_source_root}"
1265

1366
if [ -e .git ]; then
1467
rev=$(git rev-parse HEAD)
15-
plutil -replace com-loopkit-Loop-git-revision -string ${rev} "${plist}"
16-
branch=$(git branch | grep \* | cut -d ' ' -f2-)
17-
plutil -replace com-loopkit-Loop-git-branch -string "${branch}" "${plist}"
18-
fi;
19-
plutil -replace com-loopkit-Loop-srcroot -string "${SRCROOT}" "${plist}"
20-
plutil -replace com-loopkit-Loop-build-date -string "$(date)" "${plist}"
21-
plutil -replace com-loopkit-Loop-xcode-version -string "${XCODE_PRODUCT_BUILD_VERSION}" "${plist}"
68+
plutil -replace com-loopkit-Loop-git-revision -string ${rev} "${info_plist_path}"
69+
branch=$(git branch --show-current)
70+
if [ -n "$branch" ]; then
71+
plutil -replace com-loopkit-Loop-git-branch -string "${branch}" "${info_plist_path}"
72+
else
73+
warn "No git branch found, not setting com-loopkit-Loop-git-branch"
74+
fi
75+
fi
76+
77+
plutil -replace com-loopkit-Loop-srcroot -string "${git_source_root}" "${info_plist_path}"
78+
plutil -replace com-loopkit-Loop-build-date -string "$(date)" "${info_plist_path}"
79+
plutil -replace com-loopkit-Loop-xcode-version -string "${xcode_build_version}" "${info_plist_path}"
80+
81+
if [ -e "${provisioning_profile_path}" ]; then
82+
profile_expire_date=$(security cms -D -i "${provisioning_profile_path}" | plutil -p - | grep ExpirationDate | cut -b 23-)
83+
# Convert to plutil format
84+
profile_expire_date=$(date -j -f "%Y-%m-%d %H:%M:%S" "${profile_expire_date}" +"%Y-%m-%dT%H:%M:%SZ")
85+
plutil -replace com-loopkit-Loop-profile-expiration -date "${profile_expire_date}" "${info_plist_path}"
86+
else
87+
warn "Invalid provisioning profile path ${provisioning_profile_path}"
88+
fi
2289

90+
info "Added ${profile_expire_date} as profile expiration to ${info_plist_path}"

0 commit comments

Comments
 (0)