Skip to content

Commit

Permalink
Project: Add git commit to version output (#103)
Browse files Browse the repository at this point in the history
If a build is done with the `--stamp` and
`--workspace_status_command=Testing/workspace_status.sh` flags, the
current git commit will be added to the Info.plist of every binary. If
those flags aren't set, the commit will be `unset`. These values are
added into a separate key in the Info.plist called `SNTCommitHash`.

```
» santactl version
santad          | 9999.1 (build 1, commit 5a39e87)
santactl        | 9999.1 (build 1, commit 5a39e87)
SantaGUI        | 9999.1 (build 1, commit 5a39e87)
```
  • Loading branch information
russellhancox authored Nov 5, 2024
1 parent 18c721d commit 3aefacb
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 6 deletions.
12 changes: 12 additions & 0 deletions Source/common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -548,3 +548,15 @@ objc_library(
"@com_google_googletest//:gtest",
],
)

genrule(
name = "CommitHash",
outs = ["CommitHash.plist"],
cmd = """
STABLE_GIT_COMMIT=$$(awk '/STABLE_GIT_COMMIT/ { print $$2 }' bazel-out/stable-status.txt)
defaults write $${PWD}/$(@) SNTCommitHash -string $${STABLE_GIT_COMMIT:-unset}
""",
local = 1,
message = "Generating CommitHash.plist",
stamp = 1,
)
5 changes: 4 additions & 1 deletion Source/gui/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ macos_application(
# Non-adhoc builds get thier entitlements from the provisioning profile.
"//conditions:default": None,
}),
infoplists = ["Info.plist"],
infoplists = [
"Info.plist",
"//Source/common:CommitHash",
],
minimum_os_version = "12.0",
provisioning_profile = select({
"//:adhoc_build": None,
Expand Down
5 changes: 4 additions & 1 deletion Source/santabundleservice/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ macos_command_line_application(
"--force",
"--options library,kill,runtime",
],
infoplists = ["Info.plist"],
infoplists = [
"Info.plist",
"//Source/common:CommitHash",
],
minimum_os_version = "12.0",
provisioning_profile = select({
"//:adhoc_build": None,
Expand Down
5 changes: 4 additions & 1 deletion Source/santactl/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ macos_command_line_application(
"--force",
"--options library,kill,runtime",
],
infoplists = ["Info.plist"],
infoplists = [
"Info.plist",
"//Source/common:CommitHash",
],
minimum_os_version = "12.0",
provisioning_profile = select({
"//:adhoc_build": None,
Expand Down
9 changes: 8 additions & 1 deletion Source/santactl/Commands/SNTCommandVersion.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,14 @@ - (NSString *)composeVersionsFromDict:(NSDictionary *)dict {
if (!dict[@"CFBundleVersion"]) return @"";
NSString *productVersion = dict[@"CFBundleShortVersionString"];
NSString *buildVersion = [[dict[@"CFBundleVersion"] componentsSeparatedByString:@"."] lastObject];
return [NSString stringWithFormat:@"%@ (build %@)", productVersion, buildVersion];

NSString *commitHash = dict[@"SNTCommitHash"];
if (commitHash.length > 8) {
commitHash = [commitHash substringToIndex:8];
}

return [NSString
stringWithFormat:@"%@ (build %@, commit %@)", productVersion, buildVersion, commitHash];
}

- (NSString *)santadVersion {
Expand Down
5 changes: 4 additions & 1 deletion Source/santad/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,10 @@ macos_bundle(
# Non-adhoc builds get their entitlements from the provisioning profile.
"//conditions:default": None,
}),
infoplists = ["Info.plist"],
infoplists = [
"Info.plist",
"//Source/common:CommitHash",
],
linkopts = ["-execute"],
minimum_os_version = "12.0",
provisioning_profile = select({
Expand Down
5 changes: 4 additions & 1 deletion Source/santametricservice/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ macos_command_line_application(
"--force",
"--options library,kill,runtime",
],
infoplists = ["Info.plist"],
infoplists = [
"Info.plist",
"//Source/common:CommitHash",
],
minimum_os_version = "12.0",
provisioning_profile = select({
"//:adhoc_build": None,
Expand Down
3 changes: 3 additions & 0 deletions Testing/workspace_status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

echo "STABLE_GIT_COMMIT $(git rev-parse HEAD)"

0 comments on commit 3aefacb

Please sign in to comment.