Skip to content

Commit 58436f4

Browse files
committed
fix: restore plistbuddy version sync for macos release
1 parent 664cd21 commit 58436f4

2 files changed

Lines changed: 76 additions & 1 deletion

File tree

scripts/sync-macos-bundle-version.sh

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

44-
python3 - "${PLIST_PATH}" "${BUNDLE_VERSION}" <<'PY'
44+
if [[ -x /usr/libexec/PlistBuddy ]]; then
45+
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString ${BUNDLE_VERSION}" "${PLIST_PATH}"
46+
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${BUNDLE_VERSION}" "${PLIST_PATH}"
47+
else
48+
python3 - "${PLIST_PATH}" "${BUNDLE_VERSION}" <<'PY'
4549
import plistlib
4650
import sys
4751
from pathlib import Path
@@ -58,5 +62,6 @@ data["CFBundleVersion"] = bundle_version
5862
with plist_path.open("wb") as handle:
5963
plistlib.dump(data, handle, sort_keys=False)
6064
PY
65+
fi
6166

6267
echo "Synced macOS bundle version to ${BUNDLE_VERSION} in ${PLIST_PATH}"
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package main
2+
3+
import (
4+
"os"
5+
"os/exec"
6+
"path/filepath"
7+
"runtime"
8+
"strings"
9+
"testing"
10+
)
11+
12+
func TestSyncMacOSBundleVersionScriptUpdatesBinaryPlist(t *testing.T) {
13+
if runtime.GOOS != "darwin" {
14+
t.Skip("requires macOS plist tooling")
15+
}
16+
17+
appPath := filepath.Join(t.TempDir(), "GetTokens.app")
18+
contentsPath := filepath.Join(appPath, "Contents")
19+
if err := os.MkdirAll(contentsPath, 0o755); err != nil {
20+
t.Fatalf("MkdirAll() error = %v", err)
21+
}
22+
23+
plistPath := filepath.Join(contentsPath, "Info.plist")
24+
plistContent := `<?xml version="1.0" encoding="UTF-8"?>
25+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
26+
<plist version="1.0">
27+
<dict>
28+
<key>CFBundleShortVersionString</key>
29+
<string>0.0.1</string>
30+
<key>CFBundleVersion</key>
31+
<string>0.0.1</string>
32+
</dict>
33+
</plist>
34+
`
35+
if err := os.WriteFile(plistPath, []byte(plistContent), 0o644); err != nil {
36+
t.Fatalf("WriteFile() error = %v", err)
37+
}
38+
39+
convert := exec.Command("plutil", "-convert", "binary1", plistPath)
40+
if output, err := convert.CombinedOutput(); err != nil {
41+
t.Fatalf("plutil convert error = %v, output = %s", err, output)
42+
}
43+
44+
cmd := exec.Command("bash", "scripts/sync-macos-bundle-version.sh", appPath, "v1.2.3")
45+
if output, err := cmd.CombinedOutput(); err != nil {
46+
t.Fatalf("sync-macos-bundle-version.sh error = %v, output = %s", err, output)
47+
}
48+
49+
shortVersion := plistBuddyPrint(t, plistPath, "CFBundleShortVersionString")
50+
if shortVersion != "1.2.3" {
51+
t.Fatalf("CFBundleShortVersionString = %q, want %q", shortVersion, "1.2.3")
52+
}
53+
54+
bundleVersion := plistBuddyPrint(t, plistPath, "CFBundleVersion")
55+
if bundleVersion != "1.2.3" {
56+
t.Fatalf("CFBundleVersion = %q, want %q", bundleVersion, "1.2.3")
57+
}
58+
}
59+
60+
func plistBuddyPrint(t *testing.T, plistPath, key string) string {
61+
t.Helper()
62+
63+
cmd := exec.Command("/usr/libexec/PlistBuddy", "-c", "Print :"+key, plistPath)
64+
output, err := cmd.CombinedOutput()
65+
if err != nil {
66+
t.Fatalf("PlistBuddy print %s error = %v, output = %s", key, err, output)
67+
}
68+
69+
return strings.TrimSpace(string(output))
70+
}

0 commit comments

Comments
 (0)