Skip to content

Commit b6e8841

Browse files
authored
Include submodule SHA in LoopWorkspace build details (#2399)
1 parent 6fc8e26 commit b6e8841

3 files changed

Lines changed: 72 additions & 4 deletions

File tree

Common/Models/BuildDetails.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,20 @@ class BuildDetails {
6565
var workspaceGitBranch: String? {
6666
return dict["com-loopkit-LoopWorkspace-git-branch"] as? String
6767
}
68+
69+
/// Returns a dictionary of submodule details.
70+
/// The keys are the submodule names, and the values are tuples (branch, commitSHA).
71+
var submodules: [String: (branch: String, commitSHA: String)] {
72+
guard let subs = dict["com-loopkit-Loop-submodules"] as? [String: [String: Any]] else {
73+
return [:]
74+
}
75+
var result = [String: (branch: String, commitSHA: String)]()
76+
for (name, info) in subs {
77+
let branch = info["branch"] as? String ?? String(localized: "Unknown")
78+
let commitSHA = info["commit_sha"] as? String ?? String(localized: "Unknown")
79+
result[name] = (branch: branch, commitSHA: commitSHA)
80+
}
81+
return result
82+
}
6883
}
6984

Loop/Managers/DeviceDataManager.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,17 +1700,24 @@ extension DeviceDataManager: DeviceSupportDelegate {
17001700
deviceLogReport = entries.map { "* \($0.timestamp) \($0.managerIdentifier) \($0.deviceIdentifier ?? "") \($0.type) \($0.message)" }.joined(separator: "\n")
17011701
}
17021702

1703+
let submodulesInfo = BuildDetails.default.submodules
1704+
.sorted(by: { $0.key < $1.key })
1705+
.map { key, value in
1706+
"* \(key): \(value.branch), \(value.commitSHA)"
1707+
}
1708+
.joined(separator: "\n")
1709+
17031710
let report = [
17041711
"## Build Details",
17051712
"* appNameAndVersion: \(Bundle.main.localizedNameAndVersion)",
17061713
"* profileExpiration: \(BuildDetails.default.profileExpirationString)",
1707-
"* gitRevision: \(BuildDetails.default.gitRevision ?? "N/A")",
1708-
"* gitBranch: \(BuildDetails.default.gitBranch ?? "N/A")",
1709-
"* workspaceGitRevision: \(BuildDetails.default.workspaceGitRevision ?? "N/A")",
1710-
"* workspaceGitBranch: \(BuildDetails.default.workspaceGitBranch ?? "N/A")",
17111714
"* sourceRoot: \(BuildDetails.default.sourceRoot ?? "N/A")",
17121715
"* buildDateString: \(BuildDetails.default.buildDateString ?? "N/A")",
17131716
"* xcodeVersion: \(BuildDetails.default.xcodeVersion ?? "N/A")",
1717+
"* Workspace branch: \(BuildDetails.default.workspaceGitBranch ?? "N/A")",
1718+
"* Workspace SHA: \(BuildDetails.default.workspaceGitRevision ?? "N/A")",
1719+
"* Submodule name: branch, SHA",
1720+
"\(submodulesInfo)",
17141721
"",
17151722
"## FeatureFlags",
17161723
"\(FeatureFlags)",

Scripts/capture-build-details.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,49 @@ then
100100
fi
101101
popd . > /dev/null
102102
fi
103+
104+
# --- Root repo details ---
105+
# Retrieve current branch (or tag) and commit SHA.
106+
git_branch=$(git symbolic-ref --short -q HEAD || echo "")
107+
git_tag=$(git describe --tags --exact-match 2>/dev/null || echo "")
108+
git_commit_sha=$(git log -1 --format="%h" --abbrev=7)
109+
git_branch_or_tag="${git_branch:-${git_tag}}"
110+
if [ -z "${git_branch_or_tag}" ]; then
111+
git_branch_or_tag="detached"
112+
fi
113+
114+
plutil -replace com-loopkit-Loop-branch -string "${git_branch_or_tag}" "${info_plist_path}"
115+
plutil -replace com-loopkit-Loop-commit-sha -string "${git_commit_sha}" "${info_plist_path}"
116+
117+
# --- Submodule details ---
118+
# Remove an existing submodules key if it exists, then create an empty dictionary.
119+
# (Using PlistBuddy, which is available on macOS)
120+
submodules_key="com-loopkit-Loop-submodules"
121+
if /usr/libexec/PlistBuddy -c "Print :${submodules_key}" "${info_plist_path}" 2>/dev/null; then
122+
/usr/libexec/PlistBuddy -c "Delete :${submodules_key}" "${info_plist_path}"
123+
fi
124+
/usr/libexec/PlistBuddy -c "Add :${submodules_key} dict" "${info_plist_path}"
125+
126+
# Gather submodule details.
127+
# We use git submodule foreach to output lines in the form:
128+
# submodule_name|branch_or_tag|commit_sha
129+
submodules_info=$(git submodule foreach --quiet '
130+
sub_git_branch=$(git symbolic-ref --short -q HEAD || echo "")
131+
sub_git_tag=$(git describe --tags --exact-match 2>/dev/null || echo "")
132+
sub_git_commit_sha=$(git log -1 --format="%h" --abbrev=7)
133+
sub_git_branch_or_tag="${sub_git_branch:-${sub_git_tag}}"
134+
if [ -z "${sub_git_branch_or_tag}" ]; then
135+
sub_git_branch_or_tag="detached"
136+
fi
137+
echo "$name|$sub_git_branch_or_tag|$sub_git_commit_sha"
138+
')
139+
140+
# For each line, add a dictionary entry for that submodule.
141+
echo "${submodules_info}" | while IFS="|" read -r submodule_name sub_branch sub_sha; do
142+
# Create a dictionary for this submodule
143+
/usr/libexec/PlistBuddy -c "Add :${submodules_key}:${submodule_name} dict" "${info_plist_path}"
144+
/usr/libexec/PlistBuddy -c "Add :${submodules_key}:${submodule_name}:branch string ${sub_branch}" "${info_plist_path}"
145+
/usr/libexec/PlistBuddy -c "Add :${submodules_key}:${submodule_name}:commit_sha string ${sub_sha}" "${info_plist_path}"
146+
done
147+
148+
echo "BuildDetails.plist has been updated at: ${info_plist_path}"

0 commit comments

Comments
 (0)