Skip to content

Commit a75c549

Browse files
committed
fix: support binary plist bundle version sync
1 parent 8c78bcd commit a75c549

2 files changed

Lines changed: 31 additions & 17 deletions

File tree

scripts/sync-macos-bundle-version.sh

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,7 @@ print(match.group(1))
4141
PY
4242
)"
4343

44-
python3 - "${PLIST_PATH}" "${BUNDLE_VERSION}" <<'PY'
45-
import plistlib
46-
import sys
47-
from pathlib import Path
48-
49-
plist_path = Path(sys.argv[1])
50-
bundle_version = sys.argv[2]
51-
52-
with plist_path.open("rb") as handle:
53-
data = plistlib.load(handle)
54-
55-
data["CFBundleShortVersionString"] = bundle_version
56-
data["CFBundleVersion"] = bundle_version
57-
58-
with plist_path.open("wb") as handle:
59-
plistlib.dump(data, handle, sort_keys=False)
60-
PY
44+
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString ${BUNDLE_VERSION}" "${PLIST_PATH}"
45+
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${BUNDLE_VERSION}" "${PLIST_PATH}"
6146

6247
echo "Synced macOS bundle version to ${BUNDLE_VERSION} in ${PLIST_PATH}"

scripts_macos_bundle_version_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,25 @@ func TestSyncMacOSBundleVersionScript(t *testing.T) {
3030
}
3131
})
3232

33+
t.Run("syncs binary plist bundle metadata", func(t *testing.T) {
34+
appPath := createTempAppBundle(t)
35+
convertPlistToBinary(t, filepath.Join(appPath, "Contents", "Info.plist"))
36+
37+
cmd := exec.Command("bash", "scripts/sync-macos-bundle-version.sh", appPath, "v0.1.11")
38+
output, err := cmd.CombinedOutput()
39+
if err != nil {
40+
t.Fatalf("sync-macos-bundle-version.sh error = %v, output = %s", err, output)
41+
}
42+
43+
plist := readPlistAsJSON(t, filepath.Join(appPath, "Contents", "Info.plist"))
44+
if got := plist["CFBundleShortVersionString"]; got != "0.1.11" {
45+
t.Fatalf("CFBundleShortVersionString = %#v, want %q", got, "0.1.11")
46+
}
47+
if got := plist["CFBundleVersion"]; got != "0.1.11" {
48+
t.Fatalf("CFBundleVersion = %#v, want %q", got, "0.1.11")
49+
}
50+
})
51+
3352
t.Run("rejects non release version", func(t *testing.T) {
3453
appPath := createTempAppBundle(t)
3554

@@ -91,3 +110,13 @@ func readPlistAsJSON(t *testing.T, plistPath string) map[string]any {
91110

92111
return data
93112
}
113+
114+
func convertPlistToBinary(t *testing.T, plistPath string) {
115+
t.Helper()
116+
117+
cmd := exec.Command("plutil", "-convert", "binary1", plistPath)
118+
output, err := cmd.CombinedOutput()
119+
if err != nil {
120+
t.Fatalf("plutil binary convert error = %v, output = %s", err, output)
121+
}
122+
}

0 commit comments

Comments
 (0)