diff --git a/docs/QUALITY.md b/docs/QUALITY.md
new file mode 100644
index 00000000..9e18ec47
--- /dev/null
+++ b/docs/QUALITY.md
@@ -0,0 +1,10 @@
+# Quality requirements
+
+Each entry names a scenario, the required response, how it is measured, and the check that proves it.
+
+## Release
+
+| ID | Attribute | Scenario | Response | Measure | Check |
+|---|---|---|---|---|---|
+| Q-REL-1 | security | a full `scripts/release.sh` run | no ASC API key or Sparkle EdDSA private key value appears in stdout, stderr, `checks.md`, or any file left under `--out` or the temp dir after exit | 0 hits | the "No key material left" row of every `checks.md`; `secrets-cleanup-on-failure`, `leak-scan-detects` and `refuse-xtrace` in `scripts/test-release.sh` |
+| Q-REL-2 | integrity | a release run with N published prior appcast items | the new appcast holds N+1 items, each prior item byte-identical, each enclosure signature valid against the shipped `SUPublicEDKey` | N of N identical, N+1 of N+1 VALID | the "Prior items verbatim" and "Enclosure" rows of `checks.md`; the `appcast-*` and `cut-cmp-*` cases in `scripts/test-release.sh` |
diff --git a/docs/RUNBOOK.md b/docs/RUNBOOK.md
index 655a512c..45e2561c 100644
--- a/docs/RUNBOOK.md
+++ b/docs/RUNBOOK.md
@@ -106,15 +106,35 @@ the real `/Applications`). Never judge arrow or hiding behaviour on a copy outsi
(every occurrence: the App Store target's four configurations plus the
Direct target's four; `grep -c MARKETING_VERSION` must match the count you
edited).
-3. Archive the GitHub build with the **Hidden Bar** scheme
- (`Release-Direct`; builds the **Hidden Bar Direct** target), then notarize (Developer ID), staple, zip, and publish a
- GitHub release with notes listing closed issues. The **Hidden Bar App Store**
- scheme archives `Release`, the sandboxed App Store build, which cannot hide
- on macOS 27. v1.11 shipped that build to GitHub by mistake. Before zipping,
- confirm the app is unsandboxed:
+3. Build the GitHub release artifacts with one command, on the Mac mini, from a
+ clean tree at the release commit:
```sh
- codesign -d --entitlements - 'Hidden Bar.app' | grep app-sandbox # must print nothing
+ scripts/release.sh --notes notes.html #
for the appcast item
+ ```
+
+ It runs the tests, archives the **Hidden Bar** scheme (`Release-Direct`;
+ builds the **Hidden Bar Direct** target), checks the app, notarizes,
+ staples, zips, EdDSA-signs, builds `appcast.xml`, smoke-tests the zip with
+ a host restore, and writes `build/release-/checks.md` with one row
+ per check. It never tags, uploads or publishes; `checks.md` ends with the
+ publish commands as text. `scripts/release.sh --check-app ` runs the
+ app checks alone on any bundle; `bash scripts/test-release.sh` tests the
+ script offline. The steps below are what the script does, for a manual
+ run or when the script is broken on release day.
+
+ The **Hidden Bar App Store** scheme archives `Release`, the sandboxed App
+ Store build, which cannot hide on macOS 27. v1.11 shipped that build to
+ GitHub by mistake. Before zipping, confirm the app is signed Developer ID
+ first, then that it is unsandboxed. The order matters: an ad-hoc or
+ unsigned build has no entitlements, so the sandbox grep alone prints
+ nothing and passes on the wrong build.
+
+ ```sh
+ codesign -dvv 'Hidden Bar.app' 2>&1 | grep -E '^Authority=Developer ID Application: .*\(W777S7V8TN\)$|^Timestamp=|flags=.*runtime'
+ # must print 3 lines: the Developer ID authority, a Timestamp, and runtime flags
+ codesign -d --entitlements - --xml 'Hidden Bar.app' # must print a plist ...
+ codesign -d --entitlements - --xml 'Hidden Bar.app' | grep -c app-sandbox # ... and this must print 0
```
The target signs automatically for development, so a plain archive fails
@@ -151,6 +171,15 @@ lives in 1Password (`dfoundation-prod`, item "Hidden Bar Sparkle EdDSA private
key"); only the public key (`SUPublicEDKey`) is in the repo. Losing the key
means no installed copy can ever verify another update, so never regenerate it.
+`scripts/release.sh` does steps 1 to 3 below and writes the zips and
+`appcast.xml` under `build/release-/`: it signs with `sign_update`
+from the pinned Sparkle tarball (sha256 checked every run), verifies every
+enclosure against `SUPublicEDKey` (pinned in the script), and builds the
+appcast by prepending the new item to the latest published `appcast.xml`, so
+every prior item stays byte-identical (it does not use `generate_appcast`,
+which rewrites prior items). Steps 4 and 5, the upload and publish, stay
+manual; `checks.md` prints them. The manual commands, for reference:
+
Sparkle's `sign_update` and `generate_appcast` come from the Sparkle release
tarball matching the pinned package version (2.10.1, `Sparkle-.tar.xz`
under `bin/`). Run from a folder that holds only the zip(s) to publish:
diff --git a/scripts/fixtures/release/item-1.12.0.expected b/scripts/fixtures/release/item-1.12.0.expected
new file mode 100644
index 00000000..95c88c57
--- /dev/null
+++ b/scripts/fixtures/release/item-1.12.0.expected
@@ -0,0 +1,18 @@
+ -
+
Version 1.12.0
+ Sun, 15 Nov 2026 16:33:08 GMT
+ 19
+ 1.12.0
+ 13.0
+ https://github.com/dwarvesf/hidden/releases/tag/v1.12.0
+
+A redesigned Settings window.
+Hiding works again while an app keeps the microphone open (Wispr Flow, Krisp, Discord...).
+Switching from the App Store version offers to import your settings.
+macOS 27: pinned sections (beta) keep icons where you put them after apps restart.
+Fixes for macOS 26 and earlier.
+
+]]>
+
+
diff --git a/scripts/fixtures/release/notes-1.12.0.html b/scripts/fixtures/release/notes-1.12.0.html
new file mode 100644
index 00000000..51037f46
--- /dev/null
+++ b/scripts/fixtures/release/notes-1.12.0.html
@@ -0,0 +1,7 @@
+
+A redesigned Settings window.
+Hiding works again while an app keeps the microphone open (Wispr Flow, Krisp, Discord...).
+Switching from the App Store version offers to import your settings.
+macOS 27: pinned sections (beta) keep icons where you put them after apps restart.
+Fixes for macOS 26 and earlier.
+
diff --git a/scripts/fixtures/release/payload.bin b/scripts/fixtures/release/payload.bin
new file mode 100644
index 00000000..957287fd
--- /dev/null
+++ b/scripts/fixtures/release/payload.bin
@@ -0,0 +1 @@
+Hidden Bar release-script fixture payload
diff --git a/scripts/fixtures/release/payload.sig.b64 b/scripts/fixtures/release/payload.sig.b64
new file mode 100644
index 00000000..b4b8ae5c
--- /dev/null
+++ b/scripts/fixtures/release/payload.sig.b64
@@ -0,0 +1 @@
+qAsECvbmtEMdTEWB3C8crQ3PZy4JhXBRbEfZjgZ3rYmzYP+WKIJJXoH6PxsYag7/J+yKZH79EuU5mlNfe6zTBQ==
diff --git a/scripts/fixtures/release/prior-1.xml b/scripts/fixtures/release/prior-1.xml
new file mode 100644
index 00000000..429f89dd
--- /dev/null
+++ b/scripts/fixtures/release/prior-1.xml
@@ -0,0 +1,26 @@
+
+
+
+ Hidden Bar
+ https://github.com/dwarvesf/hidden
+ Hidden Bar updates
+ en
+ -
+
Version 1.11.2
+ Sun, 15 Nov 2026 06:50:21 GMT
+ 17
+ 1.11.2
+ 13.0
+ https://github.com/dwarvesf/hidden/releases/tag/v1.11.2
+
+macOS 27: clicking the clock opens Notification Center again.
+Icons you keep right of the arrow stay visible.
+Microphone and camera indicators are no longer hidden.
+Multi-display fixes, auto-update, and Turkish, Ukrainian and Italian translations.
+
+]]>
+
+
+
+
diff --git a/scripts/fixtures/release/prior-2.xml b/scripts/fixtures/release/prior-2.xml
new file mode 100644
index 00000000..66a06907
--- /dev/null
+++ b/scripts/fixtures/release/prior-2.xml
@@ -0,0 +1,44 @@
+
+
+
+ Hidden Bar
+ https://github.com/dwarvesf/hidden
+ Hidden Bar updates
+ en
+ -
+
Version 1.12.0
+ Sun, 15 Nov 2026 16:33:08 GMT
+ 19
+ 1.12.0
+ 13.0
+ https://github.com/dwarvesf/hidden/releases/tag/v1.12.0
+
+A redesigned Settings window.
+Hiding works again while an app keeps the microphone open (Wispr Flow, Krisp, Discord...).
+Switching from the App Store version offers to import your settings.
+macOS 27: pinned sections (beta) keep icons where you put them after apps restart.
+Fixes for macOS 26 and earlier.
+
+]]>
+
+
+ -
+
Version 1.11.2
+ Sun, 15 Nov 2026 06:50:21 GMT
+ 17
+ 1.11.2
+ 13.0
+ https://github.com/dwarvesf/hidden/releases/tag/v1.11.2
+
+macOS 27: clicking the clock opens Notification Center again.
+Icons you keep right of the arrow stay visible.
+Microphone and camera indicators are no longer hidden.
+Multi-display fixes, auto-update, and Turkish, Ukrainian and Italian translations.
+
+]]>
+
+
+
+
diff --git a/scripts/fixtures/release/pub.b64 b/scripts/fixtures/release/pub.b64
new file mode 100644
index 00000000..7e2ae45d
--- /dev/null
+++ b/scripts/fixtures/release/pub.b64
@@ -0,0 +1 @@
+W7SukNcz0ZbDXDm/XnJgtc8RTz7s9OrSWaST/rz6EmU=
diff --git a/scripts/fixtures/release/wrongkey.pub.b64 b/scripts/fixtures/release/wrongkey.pub.b64
new file mode 100644
index 00000000..ae0f5b58
--- /dev/null
+++ b/scripts/fixtures/release/wrongkey.pub.b64
@@ -0,0 +1 @@
+4wa+sFG3gaWUVoA5U9Tru+uTFe/x+r4eSx9I7cI0Md4=
diff --git a/scripts/release-helper.swift b/scripts/release-helper.swift
new file mode 100644
index 00000000..cce092c8
--- /dev/null
+++ b/scripts/release-helper.swift
@@ -0,0 +1,254 @@
+// scripts/release-helper.swift : the release jobs bash does badly.
+//
+// verify Ed25519 check. Exit 0 VALID, 1 INVALID, 2 bad input.
+// item --version --short --min-os --notes --url
+// --length --sig --pubdate --link
+// print the new appcast - text.
+// appcast --prior
--item --out
+// prepend the item; every prior item stays byte-identical.
+// Exit 1 on a version collision, 2 on an unexpected feed shape.
+// sigs one "version TAB short TAB url TAB length TAB signature"
+// line per item, file mode 600.
+//
+// Run as `swift scripts/release-helper.swift ...` or compile once with swiftc.
+import CryptoKit
+import Foundation
+
+func fail(_ code: Int32, _ message: String) -> Never {
+ FileHandle.standardError.write(("release-helper: " + message + "\n").data(using: .utf8)!)
+ exit(code)
+}
+
+func readText(_ path: String) -> String {
+ guard let data = FileManager.default.contents(atPath: path) else { fail(2, "cannot read \(path)") }
+ guard let text = String(data: data, encoding: .utf8) else { fail(2, "\(path) is not UTF-8") }
+ return text
+}
+
+func options(_ args: ArraySlice, _ names: [String]) -> [String: String] {
+ var out: [String: String] = [:]
+ var it = args.makeIterator()
+ while let key = it.next() {
+ guard key.hasPrefix("--"), names.contains(String(key.dropFirst(2))) else { fail(2, "unknown option \(key)") }
+ guard let value = it.next() else { fail(2, "\(key) needs a value") }
+ out[String(key.dropFirst(2))] = value
+ }
+ for name in names where out[name] == nil { fail(2, "missing --\(name)") }
+ return out
+}
+
+// MARK: feed parsing
+
+let itemOpen = " - "
+let itemClose = "
"
+
+struct Item {
+ let range: Range // from the start of the - line to the end of the
line
+ var text: Substring
+}
+
+/// Find each item as the lines that are exactly ` - ` and `
`, outside CDATA.
+/// Refuses (exit 2) a feed whose shape it would have to guess at.
+func items(in feed: String, name: String) -> [Item] {
+ if feed.contains("\r") { fail(2, "\(name): CR bytes (CRLF line endings) are not supported") }
+ var found: [Item] = []
+ var inCDATA = false
+ var start: String.Index?
+ var lineStart = feed.startIndex
+ while lineStart < feed.endIndex {
+ let lineEnd = feed[lineStart...].firstIndex(of: "\n").map { feed.index(after: $0) } ?? feed.endIndex
+ let line = feed[lineStart.. opened twice without ") }
+ start = lineStart
+ } else if bare == itemClose {
+ guard let s = start else { fail(2, "\(name): without - ") }
+ found.append(Item(range: s..
tag at an unexpected indent: \(bare.trimmingCharacters(in: .whitespaces))")
+ }
+ }
+ inCDATA = cdataStateAfter(line, startingIn: inCDATA)
+ lineStart = lineEnd
+ }
+ if start != nil { fail(2, "\(name): - never closed") }
+ if inCDATA { fail(2, "\(name): CDATA never closed") }
+ return found
+}
+
+/// The text of one line that is outside CDATA, assuming the line starts outside CDATA.
+func outsideCDATA(_ line: Substring) -> String {
+ var out = ""
+ var rest = line
+ while let open = rest.range(of: "") else { return out }
+ rest = rest[close.upperBound...]
+ }
+ return out + rest
+}
+
+func cdataStateAfter(_ line: Substring, startingIn inside: Bool) -> Bool {
+ var inside = inside
+ var rest = line
+ while true {
+ let marker = inside ? "]]>" : " String {
+ var out = ""
+ var rest = text
+ while let open = rest.range(of: "") else { return out }
+ rest = rest[close.upperBound...]
+ }
+ return out + rest
+}
+
+func element(_ name: String, in text: String) -> String? {
+ guard let open = text.range(of: "<\(name)>"),
+ let close = text.range(of: "\(name)>", range: open.upperBound..
String? {
+ guard let enc = text.range(of: "") else { return nil }
+ let tag = " " + tail[.. "9", "1.10" > "1.9").
+func compareVersions(_ a: String, _ b: String) -> Int {
+ let pa = a.split(separator: ".").map { Int($0) ?? -1 }
+ let pb = b.split(separator: ".").map { Int($0) ?? -1 }
+ for i in 0.. String {
+ s.replacingOccurrences(of: "&", with: "&").replacingOccurrences(of: "<", with: "<")
+ .replacingOccurrences(of: ">", with: ">").replacingOccurrences(of: "\"", with: """)
+}
+
+func requireMatch(_ value: String, _ pattern: String, _ what: String) {
+ if value.range(of: pattern, options: .regularExpression) == nil { fail(2, "\(what) '\(value)' does not match \(pattern)") }
+}
+
+// MARK: subcommands
+
+let args = CommandLine.arguments
+guard args.count >= 2 else { fail(2, "usage: release-helper verify|item|appcast|sigs ...") }
+
+switch args[1] {
+case "verify":
+ guard args.count == 5,
+ let data = FileManager.default.contents(atPath: args[2]),
+ let sig = Data(base64Encoded: args[3]),
+ let pubRaw = Data(base64Encoded: args[4]),
+ let pub = try? Curve25519.Signing.PublicKey(rawRepresentation: pubRaw) else {
+ print("release-helper verify: bad input"); exit(2)
+ }
+ let ok = pub.isValidSignature(sig, for: data)
+ print(ok ? "VALID" : "INVALID")
+ exit(ok ? 0 : 1)
+
+case "item":
+ let o = options(args.dropFirst(2), ["version", "short", "min-os", "notes", "url", "length", "sig", "pubdate", "link"])
+ requireMatch(o["version"]!, "^[0-9]+(\\.[0-9]+)*$", "--version")
+ requireMatch(o["short"]!, "^[0-9]+\\.[0-9]+(\\.[0-9]+)?$", "--short")
+ requireMatch(o["min-os"]!, "^[0-9]+(\\.[0-9]+)*$", "--min-os")
+ requireMatch(o["length"]!, "^[0-9]+$", "--length")
+ requireMatch(o["sig"]!, "^[A-Za-z0-9+/]+={0,2}$", "--sig")
+ requireMatch(o["url"]!, "^https://[A-Za-z0-9./_-]+$", "--url")
+ requireMatch(o["link"]!, "^https://[A-Za-z0-9./_-]+$", "--link")
+ requireMatch(o["pubdate"]!, "^[A-Z][a-z]{2}, [0-9]{2} [A-Z][a-z]{2} [0-9]{4} [0-9]{2}:[0-9]{2}:[0-9]{2} GMT$", "--pubdate")
+ var notes = readText(o["notes"]!)
+ if notes.contains("]]>") { fail(2, "notes contain ]]>, which would end the CDATA") }
+ if notes.contains("- tag") }
+ if notes.contains("\r") { fail(2, "notes contain CR bytes") }
+ while notes.hasSuffix("\n") { notes.removeLast() }
+ if notes.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { fail(2, "notes are empty") }
+ let short = o["short"]!
+ print("""
+
-
+
Version \(short)
+ \(o["pubdate"]!)
+ \(o["version"]!)
+ \(short)
+ \(o["min-os"]!)
+ \(xmlEscape(o["link"]!))
+
+
+
+ """)
+
+case "appcast":
+ let o = options(args.dropFirst(2), ["prior", "item", "out"])
+ let prior = readText(o["prior"]!)
+ let newItemText = readText(o["item"]!)
+ let priorItems = items(in: prior, name: "prior appcast")
+ if priorItems.isEmpty { fail(2, "prior appcast has no items; refusing to start a feed from nothing") }
+ let newItems = items(in: newItemText, name: "new item")
+ guard newItems.count == 1, newItems[0].range.lowerBound == newItemText.startIndex,
+ newItems[0].range.upperBound == newItemText.endIndex else { fail(2, "new item file must hold exactly one item and nothing else") }
+ let newFields = stripCDATA(newItems[0].text)
+ guard let newBuild = element("sparkle:version", in: newFields),
+ let newShort = element("sparkle:shortVersionString", in: newFields) else { fail(2, "new item lacks sparkle:version or shortVersionString") }
+ for item in priorItems {
+ let fields = stripCDATA(item.text)
+ guard let build = element("sparkle:version", in: fields),
+ let short = element("sparkle:shortVersionString", in: fields) else { fail(2, "a prior item lacks sparkle:version or shortVersionString") }
+ if compareVersions(newBuild, build) <= 0 {
+ fail(1, "new build \(newBuild) is not above prior item \(short) (build \(build))")
+ }
+ if newShort == short { fail(1, "prior item already has shortVersionString \(short) (build \(build))") }
+ }
+ let insertAt = priorItems[0].range.lowerBound
+ let out = String(prior[.. ") }
+ let feed = readText(args[2])
+ var lines = ""
+ for item in items(in: feed, name: args[2]) {
+ let fields = stripCDATA(item.text)
+ let row = [element("sparkle:version", in: fields), element("sparkle:shortVersionString", in: fields),
+ enclosureAttribute("url", in: fields), enclosureAttribute("length", in: fields),
+ enclosureAttribute("sparkle:edSignature", in: fields)]
+ let values = row.compactMap { $0 }
+ if values.count != 5 { fail(2, "an item lacks a version, url, length or signature") }
+ if values.contains(where: { $0.rangeOfCharacter(from: .controlCharacters) != nil || $0.isEmpty }) {
+ fail(2, "an item field is empty or holds a control character")
+ }
+ lines += values.joined(separator: "\t") + "\n"
+ }
+ let fm = FileManager.default
+ if !fm.createFile(atPath: args[3], contents: lines.data(using: .utf8), attributes: [.posixPermissions: 0o600]) {
+ fail(2, "cannot write \(args[3])")
+ }
+
+default:
+ fail(2, "unknown subcommand \(args[1])")
+}
diff --git a/scripts/release.sh b/scripts/release.sh
new file mode 100755
index 00000000..a508c323
--- /dev/null
+++ b/scripts/release.sh
@@ -0,0 +1,887 @@
+#!/bin/bash
+# scripts/release.sh : build and verify the direct (GitHub, Sparkle) release artifacts.
+#
+# scripts/release.sh --notes [--out ] [--skip-tests] [--no-smoke]
+# scripts/release.sh --check-app
+# scripts/release.sh --guard-selftest
+# scripts/release.sh --help
+#
+# Stages: preflight, tests, archive + export, app checks, notarize, zips, EdDSA sign,
+# appcast, smoke test (with host restore), report. Output under --out (default
+# build/release-/): both zips, appcast.xml, checks.md, SHA256SUMS, notary JSON.
+#
+# It never tags, pushes, creates, uploads or publishes: `gh` and `git` are wrapped to allow
+# read verbs only. The publish steps are printed as text at the end of checks.md.
+#
+# Secrets: the ASC API key lives only in a mode 700 temp dir (files 600) and is truncated as
+# soon as notarytool is done; the Sparkle EdDSA key is streamed to sign_update by process
+# substitution and never written to disk. Both come from 1Password, local Connect first.
+#
+# Exit: 0 every check passed (or was skipped on request) | 1 a check failed (checks.md says
+# which) | 2 usage or preflight error.
+#
+# Test seam: RELEASE_SH_SOURCE_ONLY=1 source scripts/release.sh defines the functions and
+# runs nothing (scripts/test-release.sh). Bash 3.2 compatible (macOS /bin/bash).
+
+case "$-" in *x*) echo "release.sh: refusing to run with xtrace on (it would print secrets)" >&2; exit 2 ;; esac
+case ":${SHELLOPTS:-}:" in *:xtrace:*) echo "release.sh: refusing to run with SHELLOPTS=xtrace" >&2; exit 2 ;; esac
+
+set -u -o pipefail
+umask 077
+
+ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
+PROJECT="$ROOT/Hidden Bar.xcodeproj"
+PBXPROJ="$PROJECT/project.pbxproj"
+PKG_RESOLVED="$PROJECT/project.xcworkspace/xcshareddata/swiftpm/Package.resolved"
+CHANGELOG="$ROOT/CHANGELOG.md"
+HELPER_SRC="$ROOT/scripts/release-helper.swift"
+
+REPO_SLUG="consolelabs/hidden"
+TEAM_ID="W777S7V8TN"
+BUNDLE_ID="com.dwarvesv.minimalbar"
+INSTALLED_APP="${HB_INSTALLED_APP:-/Applications/Hidden Bar.app}"
+# Pinned: change only in a reviewed commit. Installed copies trust exactly this key and feed.
+PINNED_FEED_URL="https://github.com/consolelabs/hidden/releases/latest/download/appcast.xml"
+PINNED_PUBKEY="C7MH2NS46vKD4nNh9i4BmFzXLSAbP2jM5qZcaPw9u3w="
+VAULT="dfoundation-prod"
+ASC_TITLE_SUFFIX="Hacker Bar Release"
+EDDSA_TITLE="Hidden Bar Sparkle EdDSA private key"
+EDDSA_REF="op://$VAULT/$EDDSA_TITLE/password"
+CONNECT_HOST="http://127.0.0.1:8090"
+CONNECT_TOKEN_FILE="$HOME/op-connect/.connect-token"
+SPARKLE_CACHE_ROOT="${HB_SPARKLE_CACHE:-$HOME/.cache/hidden-bar/sparkle}"
+PEM_MARK="-----BEGIN PRIVATE"" KEY-----"
+LSREGISTER="/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister"
+
+# The sha256 GitHub reports for the Sparkle release tarball (trust on first use of GitHub's
+# own asset digest). sign_update receives the EdDSA key, so an unpinned version stops the run.
+sparkle_pinned_digest() {
+ case "$1" in
+ 2.10.1) echo "1a856d2a9edb8e628de88121d7be04cf0e2167f8641650b78fca00b14244cf27" ;;
+ *) return 1 ;;
+ esac
+}
+
+# ---- read-only guards ---------------------------------------------------------------------
+
+guard_refuse() { echo "release.sh: refused (read-only guard): $*" >&2; exit 2; }
+guard_pass() { if [ -n "${GUARD_DRY:-}" ]; then echo "allowed: $*"; return 0; fi; command "$@"; }
+
+gh() {
+ local a
+ case "${1:-} ${2:-}" in
+ "release view"|"release list") ;;
+ "release download")
+ for a in "$@"; do case "$a" in --clobber|--skip-existing) guard_refuse gh "$@" ;; esac; done ;;
+ api\ *)
+ for a in "$@"; do
+ case "$a" in -X*|--method*|-f*|-F*|--field*|--raw-field*|--input*|graphql) guard_refuse gh "$@" ;; esac
+ done ;;
+ *) guard_refuse gh "$@" ;;
+ esac
+ guard_pass gh "$@"
+}
+
+git() {
+ local a
+ case "${1:-}" in status|rev-parse|log|diff|describe|ls-files) ;; *) guard_refuse git "$@" ;; esac
+ for a in "$@"; do case "$a" in --output*|--ext-diff|-c|-C) guard_refuse git "$@" ;; esac; done
+ guard_pass git "$@"
+}
+
+guard_selftest() {
+ local ok=1 rc case_
+ echo "| Command | Expected | Got |"
+ echo "|---|---|---|"
+ while IFS= read -r case_; do
+ [ -n "$case_" ] || continue
+ ( GUARD_DRY=1; eval "$case_" ) >/dev/null 2>&1; rc=$?
+ if [ "$rc" = 2 ]; then echo "| \`$case_\` | refused (2) | refused (2) |"
+ else echo "| \`$case_\` | refused (2) | ALLOWED ($rc) |"; ok=0; fi
+ done <<'EOF'
+gh release upload v0.0.0 x.zip
+gh release create v0.0.0
+gh release edit v0.0.0 --draft=false
+gh release delete v0.0.0
+gh release download v0.0.0 --clobber
+gh api -X POST repos/dwarvesf/hidden/releases
+gh api -f tag_name=v0 repos/dwarvesf/hidden/releases
+gh api graphql -f query=x
+gh pr create
+git tag v0.0.0
+git push origin HEAD
+git -C . push
+git commit -m x
+git checkout develop
+git diff --output=/tmp/x
+EOF
+ while IFS= read -r case_; do
+ [ -n "$case_" ] || continue
+ ( GUARD_DRY=1; eval "$case_" ) >/dev/null 2>&1; rc=$?
+ if [ "$rc" = 0 ]; then echo "| \`$case_\` | allowed (0) | allowed (0) |"
+ else echo "| \`$case_\` | allowed (0) | REFUSED ($rc) |"; ok=0; fi
+ done <<'EOF'
+gh release view v1.12.0 -R dwarvesf/hidden
+gh release download v1.11.2 -R dwarvesf/hidden --pattern appcast.xml
+gh release list -R dwarvesf/hidden
+gh api repos/dwarvesf/hidden/releases/latest
+git status --porcelain
+git rev-parse HEAD
+EOF
+ [ "$ok" = 1 ] && { echo "guard-selftest: every write refused, every read allowed"; return 0; }
+ echo "guard-selftest: FAILED"; return 1
+}
+
+# ---- rows and the report ------------------------------------------------------------------
+
+T=""; OUT=""; ROWS_FILE=""; N=0; FAILED=0; SKIPPED=""
+VER=""; BUILD=""; HEAD_SHA=""; TREE_NOTE=""; PRIOR_TAG=""; DRAFT_NOTE=""
+EDKEY=""; OP_SOURCE=""; ASC_KEY_ID=""; ASC_ISSUER=""
+SMOKE_STARTED=0; SMOKE_RESTORED=0; SMOKE_DIR=""
+
+cell() { printf '%s' "$1" | tr '\n' ' ' | sed 's/|/\\|/g'; }
+
+row() { # check, command, result
+ N=$((N + 1))
+ [ -z "$ROWS_FILE" ] || printf '| %s | %s | `%s` | %s |\n' "$N" "$(cell "$1")" "$(cell "$2")" "$(cell "$3")" >> "$ROWS_FILE"
+ printf 'release.sh: [%s] %s: %s\n' "$N" "$1" "$3"
+}
+
+fail_row() { row "$1" "$2" "FAIL: $3"; FAILED=1; }
+
+# capture CMD... : run CMD in this shell (so the globals it sets persist), its output into R
+R=""
+capture() {
+ local rc
+ "$@" > "$T/capture.txt" 2>&1; rc=$?
+ R="$(cat "$T/capture.txt")"; : > "$T/capture.txt"
+ return "$rc"
+}
+
+make_tmp() {
+ T="$(mktemp -d "${TMPDIR:-/tmp}/hb-release.XXXXXX")" || { echo "release.sh: mktemp failed" >&2; exit 2; }
+ T="$(cd "$T" && pwd -P)"
+ chmod 700 "$T"; mkdir -m 700 "$T/secret"
+ ROWS_FILE="$T/rows.md"; : > "$ROWS_FILE"
+}
+
+secrets_wipe() {
+ local f
+ [ -n "$T" ] && [ -d "$T/secret" ] || return 0
+ for f in "$T/secret"/* "$T/secret"/.[!.]*; do [ -f "$f" ] && : > "$f"; done
+ return 0
+}
+
+tmp_dispose() {
+ local dest
+ [ -n "$T" ] && [ -d "$T" ] || return 0
+ secrets_wipe
+ if trash "$T" >/dev/null 2>&1; then T=""; return 0; fi
+ if [ -n "$OUT" ] && [ -d "$OUT" ]; then dest="$OUT/.discard-$(basename "$T")"; else dest="$ROOT/build/.discard-$(basename "$T")"; mkdir -p "$ROOT/build"; fi
+ mv "$T" "$dest" 2>/dev/null || echo "release.sh: could not trash or move $T (its secret files are truncated)" >&2
+ T=""
+}
+
+unregister_scratch_copies() {
+ local app
+ [ -n "$OUT" ] && [ -x "$LSREGISTER" ] || return 0
+ for app in "$OUT/export/Hidden Bar.app" "$OUT/unzip/Hidden Bar.app" "$OUT/HiddenBar.xcarchive/Products/Applications/Hidden Bar.app"; do
+ [ -d "$app" ] && "$LSREGISTER" -u "$app" >/dev/null 2>&1
+ done
+ return 0
+}
+
+on_exit() {
+ if [ "$SMOKE_STARTED" = 1 ] && [ "$SMOKE_RESTORED" = 0 ]; then smoke_restore >/dev/null 2>&1; fi
+ unregister_scratch_copies
+ tmp_dispose
+}
+
+setup_traps() {
+ trap on_exit EXIT
+ trap 'exit 130' INT
+ trap 'exit 143' TERM
+ trap 'exit 129' HUP
+}
+
+leak_scan() { # paths... : prints "clean" (rc 0) or the files holding key material (rc 1)
+ local hits=""
+ hits="$(grep -rlF -- "$PEM_MARK" "$@" 2>/dev/null)"
+ if [ -n "$EDKEY" ]; then hits="$hits$(grep -rlF -f <(printf '%s\n' "$EDKEY") "$@" 2>/dev/null)"; fi
+ if [ -z "$hits" ]; then echo clean; return 0; fi
+ printf '%s\n' "$hits" | sort -u | tr '\n' ' '; return 1
+}
+
+write_report() { # exit-code
+ local code="$1" scan
+ [ -n "$OUT" ] && [ -d "$OUT" ] || return 0
+ if scan="$(leak_scan "$OUT")"; then
+ row "No key material left" "grep -rlF and over --out and the run log" "0 hits"
+ else
+ fail_row "No key material left" "grep -rlF over --out" "key material found in: $scan"; code=1
+ fi
+ if [ -f "$OUT/appcast.xml" ]; then
+ ( cd "$OUT" && shasum -a 256 Hidden-Bar-v"$VER"-macos.zip Hidden-Bar-macos.zip appcast.xml release-notes.html > SHA256SUMS 2>/dev/null )
+ fi
+ {
+ echo "# Hidden Bar v$VER release checks"
+ echo
+ printf 'Built %s on %s (macOS %s, %s), branch `%s`, HEAD `%s` (%s). Build %s. Nothing was tagged or uploaded.' \
+ "$(LC_ALL=C date -u '+%Y-%m-%d %H:%M UTC')" "$(scutil --get ComputerName 2>/dev/null || hostname)" "$(sw_vers -productVersion)" \
+ "$(xcodebuild -version 2>/dev/null | head -1)" "$(cd "$ROOT" && git rev-parse --abbrev-ref HEAD 2>/dev/null)" "${HEAD_SHA:-?}" "${TREE_NOTE:-tree not checked}" "${BUILD:-?}"
+ [ -z "$SKIPPED" ] || printf ' SKIPPED on request:%s.' "$SKIPPED"
+ echo
+ echo
+ echo "| # | Check | Command | Result |"
+ echo "|---|---|---|---|"
+ cat "$ROWS_FILE"
+ echo
+ if [ "$code" = 0 ]; then
+ echo "Result: every check passed${SKIPPED:+ (skipped:$SKIPPED)}. Checksums: \`SHA256SUMS\`."
+ else
+ echo "Result: FAILED (exit $code). Do not publish anything from this folder."
+ fi
+ echo
+ echo "## Notes for the publish step"
+ echo
+ echo "- Valid only while the latest published release is \`${PRIOR_TAG:-?}\` (the appcast keeps its items). If another release was published since, rerun."
+ echo "- Tag the release commit \`v$VER\` (HEAD above), then create the release as a draft: \`gh release create v$VER --draft --title 'v$VER' -R $REPO_SLUG\`.${DRAFT_NOTE:+ $DRAFT_NOTE}"
+ echo "- Upload three assets to the draft: \`gh release upload v$VER Hidden-Bar-v$VER-macos.zip Hidden-Bar-macos.zip appcast.xml -R $REPO_SLUG\`."
+ echo "- Publish the draft, then check \`curl -sIL $PINNED_FEED_URL\` ends in 200 and \`curl -sIL https://github.com/$REPO_SLUG/releases/download/v$VER/Hidden-Bar-v$VER-macos.zip\` ends in 200."
+ echo "- The appcast pubDate is the build time; Sparkle orders by build number, so a later publish time does not matter."
+ echo "- Homebrew cask and App Store are separate, manual steps."
+ } > "$OUT/checks.md"
+ return "$code"
+}
+
+finish() { # exit-code
+ local code="$1"
+ [ "$code" = 0 ] && [ "$FAILED" = 1 ] && code=1
+ write_report "$code" || code=$?
+ [ -z "$OUT" ] || echo "release.sh: wrote $OUT/checks.md (exit $code)"
+ exit "$code"
+}
+
+# ---- inputs -------------------------------------------------------------------------------
+
+read_versions() { # pbxproj : prints " ", rc 1 with the distinct values when they disagree
+ local mv cv
+ mv="$(grep -o 'MARKETING_VERSION = [^;]*;' "$1" | sed 's/.*= //; s/;$//' | sort | uniq -c)"
+ cv="$(grep -o 'CURRENT_PROJECT_VERSION = [^;]*;' "$1" | sed 's/.*= //; s/;$//' | sort | uniq -c)"
+ if [ "$(printf '%s\n' "$mv" | grep -c .)" != 1 ] || [ "$(printf '%s\n' "$cv" | grep -c .)" != 1 ]; then
+ echo "versions disagree: MARKETING_VERSION [$(echo $mv)], CURRENT_PROJECT_VERSION [$(echo $cv)]"; return 1
+ fi
+ mv="$(echo $mv | awk '{print $2}')"; cv="$(echo $cv | awk '{print $2}')"
+ case "$mv" in *[!0-9.]*|"") echo "MARKETING_VERSION '$mv' is not numeric"; return 1 ;; esac
+ case "$cv" in *[!0-9]*|"") echo "CURRENT_PROJECT_VERSION '$cv' is not an integer"; return 1 ;; esac
+ echo "$mv $cv"
+}
+
+check_changelog() { # file version
+ grep -qE "^## v${2//./\\.}([[:space:]]|\$)" "$1"
+}
+
+check_notes() { # file : prints the reason and rc 1 when unusable
+ [ -f "$1" ] || { echo "notes file $1 not found"; return 1; }
+ grep -q '[^[:space:]]' "$1" || { echo "notes file is empty"; return 1; }
+ if grep -qF ']]>' "$1"; then echo "notes contain ]]>, which would end the CDATA"; return 1; fi
+ if grep -qE '?item' "$1"; then echo "notes contain an - tag"; return 1; fi
+ if LC_ALL=C grep -q $'\r' "$1"; then echo "notes contain CR bytes"; return 1; fi
+ return 0
+}
+
+check_clean_tree() { # dir : prints the dirty paths, rc 1 when dirty
+ local st
+ st="$(cd "$1" && git status --porcelain --untracked-files=all)" || { echo "git status failed"; return 1; }
+ [ -z "$st" ] && return 0
+ printf '%s\n' "$st" | head -10 | tr '\n' ';'; return 1
+}
+
+tree_state() { # dir : "
"
+ (cd "$1" && printf '%s %s\n' "$(git rev-parse HEAD)" "$(git status --porcelain --untracked-files=all | shasum -a 256 | cut -c1-16)")
+}
+
+check_tree_unchanged() { # dir expected-state : rc 1 and the changed paths when HEAD or the tree moved
+ local now
+ now="$(tree_state "$1")"
+ [ "$now" = "$2" ] && return 0
+ echo "HEAD or tree changed since preflight (was ${2%% *}, now ${now%% *}): $(cd "$1" && git status --porcelain --untracked-files=all | head -5 | tr '\n' ';')"
+ return 1
+}
+
+check_tag_state() { # version : rc 0 absent, 0 + DRAFT_NOTE draft, 1 published, 3 GitHub error
+ local out rc
+ out="$(gh release view "v$1" -R "$REPO_SLUG" --json isDraft --jq .isDraft 2>&1)"; rc=$?
+ if [ "$rc" = 0 ]; then
+ case "$out" in
+ true) DRAFT_NOTE="A draft release v$1 already exists; upload to it instead of creating one."; return 0 ;;
+ false) return 1 ;;
+ esac
+ return 3
+ fi
+ case "$out" in *"release not found"*|*"Not Found"*) return 0 ;; esac
+ echo "$out" | head -2; return 3
+}
+
+fetch_prior_appcast() { # dest-file : the latest published release's appcast.xml; sets PRIOR_TAG
+ local info tag draft has dir
+ info="$(gh release view -R "$REPO_SLUG" --json tagName,isDraft,assets \
+ --jq '[.tagName, (.isDraft|tostring), (([.assets[].name] | index("appcast.xml")) != null | tostring)] | join(" ")' 2>&1)" \
+ || { echo "gh release view (latest) failed: $(echo "$info" | head -1)"; return 3; }
+ read -r tag draft has </dev/null 2>&1 \
+ || { echo "could not download appcast.xml from $tag"; return 3; }
+ mv "$dir/appcast.xml" "$1" || return 3
+ PRIOR_TAG="$tag"
+}
+
+sparkle_version() { # Package.resolved : the pinned Sparkle version
+ local i=0 id
+ while id="$(plutil -extract "pins.$i.identity" raw -o - "$1" 2>/dev/null)"; do
+ [ "$id" = sparkle ] && { plutil -extract "pins.$i.state.version" raw -o - "$1"; return; }
+ i=$((i + 1))
+ done
+ return 1
+}
+
+sparkle_tools() { # version [extract-dir] : check the cached tarball (download once); extract sign_update fresh
+ local ver="$1" dest="${2:-}" want got cache tb copy
+ want="$(sparkle_pinned_digest "$ver")" || { echo "no pinned digest for Sparkle $ver; pin it in release.sh after checking GitHub's asset digest"; return 2; }
+ cache="$SPARKLE_CACHE_ROOT/$ver"; tb="$cache/Sparkle-$ver.tar.xz"
+ if [ ! -f "$tb" ]; then
+ mkdir -p "$cache"
+ gh release download "$ver" -R sparkle-project/Sparkle --pattern "Sparkle-$ver.tar.xz" --dir "$cache" >/dev/null 2>&1 \
+ || { echo "could not download Sparkle-$ver.tar.xz"; return 2; }
+ fi
+ copy="$tb"
+ if [ -n "$dest" ]; then mkdir -p "$dest"; copy="$dest/Sparkle-$ver.tar.xz"; cp "$tb" "$copy" || return 2; fi
+ got="$(shasum -a 256 "$copy" | awk '{print $1}')"
+ [ "$got" = "$want" ] || { echo "Sparkle-$ver.tar.xz digest mismatch (cache: $tb); refusing to run its sign_update"; return 2; }
+ [ -z "$dest" ] && return 0
+ tar -xJf "$copy" -C "$dest" ./bin/sign_update 2>/dev/null && [ -x "$dest/bin/sign_update" ] \
+ || { echo "sign_update not found in Sparkle-$ver.tar.xz"; return 2; }
+}
+
+# ---- 1Password (Connect first, then the ambient service account) ---------------------------
+
+op_connect() { OP_CONNECT_HOST="$CONNECT_HOST" OP_CONNECT_TOKEN="$(cat "$CONNECT_TOKEN_FILE" 2>/dev/null)" command op "$@"; }
+op_sa() { env -u OP_CONNECT_HOST -u OP_CONNECT_TOKEN op "$@"; }
+op_run() {
+ case "$OP_SOURCE" in
+ connect) op_connect "$@" ;;
+ service-account) op_sa "$@" ;;
+ *) return 1 ;;
+ esac
+}
+
+op_select_source() { # items-json-out : sets OP_SOURCE, writes the vault item list (metadata only)
+ if curl -sf --max-time 3 -o /dev/null "$CONNECT_HOST/heartbeat" 2>/dev/null \
+ && op_connect item list --vault "$VAULT" --format json > "$1" 2>/dev/null; then
+ OP_SOURCE=connect; return 0
+ fi
+ if op_sa item list --vault "$VAULT" --format json > "$1" 2>/dev/null; then OP_SOURCE=service-account; return 0; fi
+ OP_SOURCE=""; return 1
+}
+
+item_ids_matching() { # items-json mode(suffix|exact) text : one id per matching title
+ local i=0 title
+ while title="$(plutil -extract "$i.title" raw -o - "$1" 2>/dev/null)"; do
+ case "$2" in
+ suffix) case "$title" in *"$3") plutil -extract "$i.id" raw -o - "$1"; echo ;; esac ;;
+ exact) [ "$title" = "$3" ] && { plutil -extract "$i.id" raw -o - "$1"; echo; } ;;
+ esac
+ i=$((i + 1))
+ done
+}
+
+asc_fetch() { # writes $T/secret/AuthKey.p8, sets ASC_KEY_ID and ASC_ISSUER; prints a reason on failure
+ local list="$T/secret/items.json" item="$T/secret/item.json" ids id i=0 label f
+ op_run item list --vault "$VAULT" --format json > "$list" 2>/dev/null || { echo "item list failed via $OP_SOURCE"; return 1; }
+ ids="$(item_ids_matching "$list" suffix "$ASC_TITLE_SUFFIX" | grep .)"
+ [ "$(printf '%s\n' "$ids" | grep -c .)" = 1 ] || { echo "expected exactly one item titled '*$ASC_TITLE_SUFFIX'"; return 1; }
+ id="$ids"
+ op_run item get "$id" --vault "$VAULT" --format json > "$item" 2>/dev/null || { echo "item get failed"; return 1; } # raw-op-ok: one read per release, Connect first
+ ASC_KEY_ID=""; ASC_ISSUER=""
+ while plutil -extract "fields.$i" raw -o - "$item" >/dev/null 2>&1; do
+ label="$(plutil -extract "fields.$i.label" raw -o - "$item" 2>/dev/null) $(plutil -extract "fields.$i.id" raw -o - "$item" 2>/dev/null)"
+ f="$T/secret/field.$i"
+ if plutil -extract "fields.$i.value" raw -o "$f" "$item" >/dev/null 2>&1; then
+ if grep -qF -- "$PEM_MARK" "$f"; then cat "$f" > "$T/secret/AuthKey.p8"
+ elif printf '%s' "$label" | grep -qiE 'key ?id'; then ASC_KEY_ID="$(cat "$f")"
+ elif printf '%s' "$label" | grep -qi 'issuer'; then ASC_ISSUER="$(cat "$f")"
+ fi
+ : > "$f"
+ fi
+ i=$((i + 1))
+ done
+ : > "$item"; : > "$list"
+ [ -s "$T/secret/AuthKey.p8" ] && [ -n "$ASC_KEY_ID" ] && [ -n "$ASC_ISSUER" ] \
+ || { echo "ASC item lacks a private key, a key id or an issuer field"; return 1; }
+}
+
+# ---- app checks ---------------------------------------------------------------------------
+
+code_parts() { # app : the app, every nested bundle, and every Mach-O executable
+ local f
+ echo "$1"
+ find "$1/Contents" \( -name '*.app' -o -name '*.xpc' -o -name '*.framework' -o -name '*.appex' \) -type d 2>/dev/null
+ find "$1/Contents" -type f -perm +111 2>/dev/null | while IFS= read -r f; do
+ file -b "$f" 2>/dev/null | grep -q 'Mach-O' && echo "$f"
+ done
+}
+
+check_identity() { # app : rc 0 when every code part is Developer ID (team), timestamped, hardened runtime
+ local part name out bad="" n=0
+ while IFS= read -r part; do
+ [ -n "$part" ] || continue
+ n=$((n + 1))
+ name="${part#"$1"/}"; [ "$part" = "$1" ] && name="app"
+ out="$(codesign -dvv "$part" 2>&1)"
+ if ! printf '%s\n' "$out" | grep -qE "^Authority=Developer ID Application: .*\\($TEAM_ID\\)\$"; then bad="$bad $name (not Developer ID $TEAM_ID)"
+ elif ! printf '%s\n' "$out" | grep -q '^Timestamp='; then bad="$bad $name (no secure timestamp)"
+ elif ! printf '%s\n' "$out" | grep -qE '^CodeDirectory .*flags=0x[0-9a-f]+\([^)]*runtime'; then bad="$bad $name (no hardened runtime)"
+ fi
+ done </dev/null)"
+ if [ -z "$ent" ]; then echo "no entitlements blob: unverifiable"; return 1; fi
+ if printf '%s' "$ent" | grep -q 'com.apple.security.app-sandbox'; then echo "app-sandbox entitlement present"; return 1; fi
+ echo "entitlements present, no app-sandbox"; return 0
+}
+
+plist_get() { /usr/libexec/PlistBuddy -c "Print :$2" "$1/Contents/Info.plist" 2>/dev/null; }
+
+check_pubkey() { # app : the app's SUPublicEDKey equals the pinned key
+ local k; k="$(plist_get "$1" SUPublicEDKey)"
+ [ "$k" = "$PINNED_PUBKEY" ] && { echo "equals the pinned key"; return 0; }
+ echo "SUPublicEDKey differs from the key pinned in release.sh (installed copies would reject updates)"; return 1
+}
+
+check_app() { # app [version build] : every row runs; rc 1 when any row failed
+ local app="$1" ver="${2:-}" build="${3:-}" r id_ok=0 rc=0 v b
+ [ -d "$app/Contents" ] || { fail_row "App bundle" "test -d" "$app is not an app bundle"; return 1; }
+ if r="$(check_identity "$app")"; then id_ok=1; row "Signature: identity, timestamp, runtime" "codesign -dvv on every code part" "$r"
+ else fail_row "Signature: identity, timestamp, runtime" "codesign -dvv on every code part" "$r"; rc=1; fi
+ if r="$(check_sandbox "$app")"; then
+ if [ "$id_ok" = 1 ]; then row "Unsandboxed" "codesign -d --entitlements - --xml" "$r"
+ else fail_row "Unsandboxed" "codesign -d --entitlements - --xml" "$r, not credited: identity failed"; rc=1; fi
+ else fail_row "Unsandboxed" "codesign -d --entitlements - --xml" "$r"; rc=1; fi
+ if r="$(codesign --verify --deep --strict "$app" 2>&1)"; then row "Strict verify" "codesign --verify --deep --strict" "valid"
+ else fail_row "Strict verify" "codesign --verify --deep --strict" "$(printf '%s' "$r" | head -2)"; rc=1; fi
+ if otool -L "$app/Contents/MacOS/$(plist_get "$app" CFBundleExecutable)" 2>/dev/null | grep -q 'Sparkle.framework'; then
+ row "Sparkle linked" "otool -L" "Sparkle.framework linked"
+ else fail_row "Sparkle linked" "otool -L" "Sparkle.framework not linked"; rc=1; fi
+ v="$(plist_get "$app" CFBundleShortVersionString)"; b="$(plist_get "$app" CFBundleVersion)"
+ if [ -n "$ver" ] && { [ "$v" != "$ver" ] || [ "$b" != "$build" ]; }; then
+ fail_row "Versions" "Info.plist vs project.pbxproj" "app $v ($b), project $ver ($build)"; rc=1
+ else row "Versions" "Info.plist vs project.pbxproj" "$v ($b)"; fi
+ if [ "$(plist_get "$app" SUFeedURL)" = "$PINNED_FEED_URL" ]; then row "Feed URL" "Info.plist SUFeedURL vs pinned" "$PINNED_FEED_URL"
+ else fail_row "Feed URL" "Info.plist SUFeedURL vs pinned" "'$(plist_get "$app" SUFeedURL)' is not the pinned feed"; rc=1; fi
+ if r="$(check_pubkey "$app")"; then row "EdDSA public key" "Info.plist SUPublicEDKey vs pinned" "$r"
+ else fail_row "EdDSA public key" "Info.plist SUPublicEDKey vs pinned" "$r"; rc=1; fi
+ return "$rc"
+}
+
+# ---- appcast checks -----------------------------------------------------------------------
+
+first_item() { awk 's==0 && $0==" - "{s=1} s==1{print} s==1 && $0=="
"{exit}' "$1"; }
+
+readback_new_item() { # appcast build short min-os url length : rc 1 and the mismatches
+ local it bad=""
+ it="$(first_item "$1")"
+ printf '%s\n' "$it" | grep -qxF " $2 " || bad="$bad sparkle:version!=$2"
+ printf '%s\n' "$it" | grep -qxF " $3 " || bad="$bad shortVersionString!=$3"
+ printf '%s\n' "$it" | grep -qxF " $4 " || bad="$bad minimumSystemVersion!=$4"
+ printf '%s\n' "$it" | grep -qF " url=\"$5\"" || bad="$bad url!=$5"
+ printf '%s\n' "$it" | grep -qF " length=\"$6\"" || bad="$bad length!=$6"
+ [ -z "$bad" ] && { echo "item 1: $3 ($2), min macOS $4, $6 bytes, $5"; return 0; }
+ echo "item 1 disagrees with the build:$bad"; return 1
+}
+
+cut_cmp_prior() { # new-appcast prior-appcast scratch : the new feed minus its first item is byte-identical to the prior
+ awk 's==0 && $0==" - "{s=1; next} s==1{ if ($0=="
") s=2; next } {print}' "$1" > "$3"
+ cmp -s "$3" "$2"
+}
+
+count_items() { grep -cxF ' - ' "$1"; }
+
+# ---- smoke test helpers -------------------------------------------------------------------
+
+running_exes() { # "pid path" for every process whose executable is a Hidden Bar binary
+ local pid rest
+ ps -axo pid=,comm= 2>/dev/null | while read -r pid rest; do
+ case "$rest" in */"Hidden Bar.app/Contents/MacOS/Hidden Bar") echo "$pid $rest" ;; esac
+ done
+}
+
+pids_of() { # app : pids running that app's executable
+ local pid rest
+ running_exes | while read -r pid rest; do [ "$rest" = "$1/Contents/MacOS/Hidden Bar" ] && echo "$pid"; done
+}
+
+smoke_assert_process() { # pid app build [exe] : the pid is alive, runs the app under test, and is that build
+ local comm b exe="${4:-$2/Contents/MacOS/Hidden Bar}"
+ kill -0 "$1" 2>/dev/null || { echo "pid $1 is not running"; return 1; }
+ comm="$(ps -o comm= -p "$1" 2>/dev/null)"
+ [ "$comm" = "$exe" ] || { echo "pid $1 runs '$comm', not the copy under test"; return 1; }
+ b="$(plist_get "$2" CFBundleVersion)"
+ [ "$b" = "$3" ] || { echo "the copy under test is build '$b', expected $3"; return 1; }
+ echo "pid $1 runs $2 build $b"
+}
+
+quit_pid() { # pid : TERM, wait up to 10 s, then KILL
+ local i=0
+ kill -TERM "$1" 2>/dev/null || return 0
+ while kill -0 "$1" 2>/dev/null && [ "$i" -lt 20 ]; do sleep 0.5; i=$((i + 1)); done
+ kill -0 "$1" 2>/dev/null && kill -KILL "$1" 2>/dev/null
+ return 0
+}
+
+login_item_paths() { # sorted paths of login items named "Hidden Bar", or "unreadable"
+ local raw
+ raw="$(osascript -e 'tell application "System Events" to get the path of every login item whose name is "Hidden Bar"' 2>&1)" \
+ || { echo "unreadable"; return 1; }
+ printf '%s\n' "$raw" | tr ',' '\n' | sed 's/^ *//; s/ *$//' | grep . | sort
+}
+
+installed_cdhash() { [ -d "$INSTALLED_APP" ] && codesign -dvvv "$INSTALLED_APP" 2>&1 | sed -n 's/^CDHash=//p' | head -1; }
+
+smoke_baseline() {
+ mkdir -p "$SMOKE_DIR"
+ installed_cdhash > "$SMOKE_DIR/cdhash-before.txt"
+ login_item_paths > "$SMOKE_DIR/loginitems-before.txt"
+ pids_of "$INSTALLED_APP" > "$SMOKE_DIR/running-before.txt"
+ if defaults read "$BUNDLE_ID" >/dev/null 2>&1; then
+ defaults export "$BUNDLE_ID" "$SMOKE_DIR/prefs-before.plist" && plutil -convert xml1 -o "$SMOKE_DIR/prefs-before.xml" "$SMOKE_DIR/prefs-before.plist"
+ fi
+}
+
+smoke_restore() { # quit the copy under test, restore prefs, relaunch or repair, compare; rc 1 when the host differs
+ local pid was_running diff=""
+ SMOKE_RESTORED=1
+ for pid in $(pids_of "$OUT/unzip/Hidden Bar.app"); do quit_pid "$pid"; done
+ [ -f "$SMOKE_DIR/prefs-before.plist" ] && defaults import "$BUNDLE_ID" "$SMOKE_DIR/prefs-before.plist"
+ was_running="$(grep -c . "$SMOKE_DIR/running-before.txt" 2>/dev/null)"
+ if [ "${was_running:-0}" -gt 0 ] && [ -z "$(pids_of "$INSTALLED_APP")" ]; then open -g "$INSTALLED_APP"; sleep 5; fi
+ login_item_paths > "$SMOKE_DIR/loginitems-after.txt"
+ if ! cmp -s "$SMOKE_DIR/loginitems-before.txt" "$SMOKE_DIR/loginitems-after.txt" && [ -d "$INSTALLED_APP" ]; then
+ open -g "$INSTALLED_APP"; sleep 5 # the installed app re-points its login item at itself
+ if [ "${was_running:-0}" = 0 ]; then for pid in $(pids_of "$INSTALLED_APP"); do quit_pid "$pid"; done; fi
+ login_item_paths > "$SMOKE_DIR/loginitems-after.txt"
+ fi
+ installed_cdhash > "$SMOKE_DIR/cdhash-after.txt"
+ if [ -f "$SMOKE_DIR/prefs-before.plist" ]; then
+ defaults export "$BUNDLE_ID" "$SMOKE_DIR/prefs-after.plist" && plutil -convert xml1 -o "$SMOKE_DIR/prefs-after.xml" "$SMOKE_DIR/prefs-after.plist"
+ cmp -s "$SMOKE_DIR/prefs-before.xml" "$SMOKE_DIR/prefs-after.xml" || diff="$diff prefs"
+ fi
+ cmp -s "$SMOKE_DIR/cdhash-before.txt" "$SMOKE_DIR/cdhash-after.txt" || diff="$diff installed-CDHash"
+ cmp -s "$SMOKE_DIR/loginitems-before.txt" "$SMOKE_DIR/loginitems-after.txt" \
+ || diff="$diff login-items(before: $(tr '\n' ';' < "$SMOKE_DIR/loginitems-before.txt") after: $(tr '\n' ';' < "$SMOKE_DIR/loginitems-after.txt"))"
+ unregister_scratch_copies
+ [ -z "$diff" ] && return 0
+ echo "differs after restore:$diff"; return 1
+}
+
+# ---- stages -------------------------------------------------------------------------------
+
+HELPER=""
+helper() { "$HELPER" "$@"; }
+
+stage_preflight() { # notes-file : exit 2 on any failure
+ local r t v pre missing="" sv
+ for t in xcodebuild xcrun codesign ditto xmllint plutil swiftc gh op curl shasum tar trash spctl otool defaults; do
+ command -v "$t" >/dev/null 2>&1 || missing="$missing $t"
+ done
+ [ "$NO_SMOKE" = 1 ] || command -v osascript >/dev/null 2>&1 || missing="$missing osascript"
+ [ -z "$missing" ] || { fail_row "Tools" "command -v" "missing:$missing"; finish 2; }
+ row "Tools" "command -v" "all present"
+ if r="$(check_clean_tree "$ROOT")"; then :; else fail_row "Clean tree" "git status --porcelain" "dirty: $r"; finish 2; fi
+ pre="$(tree_state "$ROOT")"; HEAD_SHA="${pre%% *}"; PRE_STATE="$pre"; TREE_NOTE="clean at preflight"
+ row "Clean tree" "git status --porcelain" "clean at $HEAD_SHA"
+ row "Versions" "grep MARKETING_VERSION, CURRENT_PROJECT_VERSION in project.pbxproj" "$VER ($BUILD), every value equal"
+ check_changelog "$CHANGELOG" "$VER" || { fail_row "CHANGELOG" "grep '^## v$VER'" "no '## v$VER' section"; finish 2; }
+ row "CHANGELOG" "grep '^## v$VER'" "section present"
+ r="$(check_notes "$1")" || { fail_row "Release notes" "notes file checks" "$r"; finish 2; }
+ cp "$1" "$OUT/release-notes.html"
+ row "Release notes" "notes file checks" "$(grep -c '
' "$1") list items, no ]]>, no item tags"
+ security find-identity -v -p codesigning 2>/dev/null | grep -qE "\"Developer ID Application: .*\\($TEAM_ID\\)\"" \
+ || { fail_row "Signing identity" "security find-identity -v -p codesigning" "no Developer ID Application ($TEAM_ID) identity"; finish 2; }
+ row "Signing identity" "security find-identity -v -p codesigning" "Developer ID Application ($TEAM_ID) present"
+ sv="$(sparkle_version "$PKG_RESOLVED")" || { fail_row "Sparkle pin" "Package.resolved" "no sparkle pin"; finish 2; }
+ SPARKLE_VER="$sv"
+ r="$(sparkle_tools "$sv")" || { fail_row "Sparkle tools" "shasum -a 256 Sparkle-$sv.tar.xz vs pinned" "$r"; finish 2; }
+ row "Sparkle tools" "shasum -a 256 Sparkle-$sv.tar.xz vs pinned" "Sparkle $sv tarball matches the pinned digest"
+ capture check_tag_state "$VER"; v=$?
+ case "$v" in
+ 0) row "Tag" "gh release view v$VER" "${DRAFT_NOTE:-no release v$VER yet}" ;;
+ 1) fail_row "Tag" "gh release view v$VER" "v$VER is already a published release"; finish 2 ;;
+ *) fail_row "Tag" "gh release view v$VER" "GitHub error: $R"; finish 2 ;;
+ esac
+ capture fetch_prior_appcast "$T/prior-appcast.xml" || { fail_row "Prior appcast" "gh release view (latest); gh release download --pattern appcast.xml" "$R"; finish 2; }
+ xmllint --noout "$T/prior-appcast.xml" 2>/dev/null || { fail_row "Prior appcast" "xmllint --noout" "the published feed is not well-formed"; finish 2; }
+ row "Prior appcast" "gh release download $PRIOR_TAG --pattern appcast.xml" "latest published $PRIOR_TAG, $(count_items "$T/prior-appcast.xml") item(s), well-formed"
+ op_select_source "$T/secret/items.json" || { fail_row "1Password" "Connect heartbeat; op item list (metadata)" "neither Connect nor a service account can list $VAULT"; finish 2; }
+ [ "$(item_ids_matching "$T/secret/items.json" suffix "$ASC_TITLE_SUFFIX" | grep -c .)" = 1 ] \
+ || { : > "$T/secret/items.json"; fail_row "1Password" "op item list (metadata)" "not exactly one '*$ASC_TITLE_SUFFIX' item"; finish 2; }
+ [ "$(item_ids_matching "$T/secret/items.json" exact "$EDDSA_TITLE" | grep -c .)" = 1 ] \
+ || { : > "$T/secret/items.json"; fail_row "1Password" "op item list (metadata)" "no '$EDDSA_TITLE' item"; finish 2; }
+ : > "$T/secret/items.json"
+ row "1Password" "op item list --vault $VAULT (titles only)" "via $OP_SOURCE; ASC key item and EdDSA item found"
+ HELPER="$T/release-helper"
+ swiftc -O "$HELPER_SRC" -o "$HELPER" >"$T/helper-build.log" 2>&1 || { fail_row "Helper" "swiftc -O release-helper.swift" "build failed"; finish 2; }
+ row "Helper" "swiftc -O scripts/release-helper.swift" "built"
+}
+
+stage_tests() {
+ if [ "$SKIP_TESTS" = 1 ]; then row "Tests" "scripts/test.sh" "SKIPPED (--skip-tests)"; SKIPPED="$SKIPPED tests"; return 0; fi
+ if bash "$ROOT/scripts/test.sh" > "$OUT/tests.log" 2>&1; then
+ row "Tests" "bash scripts/test.sh" "$(grep -E '^Hidden Bar' "$OUT/tests.log" | awk '{print $(NF-2) " passed " $(NF-1) " failed"}' | tr '\n' ';' | sed 's/;$//'); exit 0"
+ else
+ fail_row "Tests" "bash scripts/test.sh" "failed, see tests.log: $(tail -4 "$OUT/tests.log" | tr '\n' ' ')"; finish 1
+ fi
+}
+
+stage_build() {
+ local archive="$OUT/HiddenBar.xcarchive" r
+ xcodebuild archive -project "$PROJECT" -scheme 'Hidden Bar' -configuration Release-Direct -archivePath "$archive" \
+ -onlyUsePackageVersionsFromResolvedFile CODE_SIGN_STYLE=Manual CODE_SIGN_IDENTITY='Developer ID Application' \
+ DEVELOPMENT_TEAM="$TEAM_ID" OTHER_CODE_SIGN_FLAGS=--timestamp > "$OUT/archive.log" 2>&1 \
+ || { fail_row "Archive" "xcodebuild archive, Release-Direct, manual Developer ID, --timestamp" "failed, see archive.log"; finish 1; }
+ row "Archive" "xcodebuild archive, Release-Direct, manual Developer ID, --timestamp" "ARCHIVE SUCCEEDED"
+ r="$(check_tree_unchanged "$ROOT" "$PRE_STATE")" || { fail_row "Tree after archive" "git rev-parse HEAD; git status --porcelain" "$r"; finish 1; }
+ /usr/libexec/PlistBuddy -c 'Add :method string developer-id' -c 'Add :destination string export' \
+ -c "Add :teamID string $TEAM_ID" -c 'Add :signingStyle string manual' \
+ -c 'Add :signingCertificate string Developer ID Application' "$T/export.plist" >/dev/null
+ xcodebuild -exportArchive -archivePath "$archive" -exportOptionsPlist "$T/export.plist" -exportPath "$OUT/export" > "$OUT/export.log" 2>&1 \
+ || { fail_row "Export" "xcodebuild -exportArchive, method developer-id" "failed, see export.log"; finish 1; }
+ row "Export" "xcodebuild -exportArchive, method developer-id" "EXPORT SUCCEEDED"
+ r="$(check_tree_unchanged "$ROOT" "$PRE_STATE")" || { fail_row "Tree after export" "git rev-parse HEAD; git status --porcelain" "$r"; finish 1; }
+ TREE_NOTE="clean; HEAD and tree re-checked after archive and export"
+ row "Tree after build" "git rev-parse HEAD; git status --porcelain" "unchanged since preflight ($HEAD_SHA)"
+}
+
+stage_notarize() { # app
+ local app="$1" r rc id status summary issues_type i log_ok=0 issues_note
+ capture asc_fetch || { secrets_wipe; fail_row "ASC API key" "op item get (fields by pattern)" "$R"; return 1; }
+ row "ASC API key" "op item get via $OP_SOURCE, fields by pattern" "read into a mode 700 temp dir, key file mode 600"
+ ditto -c -k --keepParent "$app" "$T/submit.zip"
+ xcrun notarytool submit "$T/submit.zip" --key "$T/secret/AuthKey.p8" --key-id "$ASC_KEY_ID" --issuer "$ASC_ISSUER" \
+ --wait --timeout 2h --output-format json > "$OUT/notary-submit.json" 2> "$T/notary-submit.err"; rc=$?
+ id="$(plutil -extract id raw -o - "$OUT/notary-submit.json" 2>/dev/null)"
+ status="$(plutil -extract status raw -o - "$OUT/notary-submit.json" 2>/dev/null)"
+ if [ -n "$id" ]; then
+ for i in 1 2 3; do
+ if xcrun notarytool log "$id" --key "$T/secret/AuthKey.p8" --key-id "$ASC_KEY_ID" --issuer "$ASC_ISSUER" "$OUT/notary-log.json" >/dev/null 2>&1; then log_ok=1; break; fi
+ sleep 10
+ done
+ fi
+ secrets_wipe; ASC_KEY_ID=""; ASC_ISSUER=""
+ if [ "$log_ok" = 1 ]; then issues_note="$(plutil -extract issues json -o - "$OUT/notary-log.json" 2>/dev/null | head -c 300)"
+ else issues_note="notary log unreadable after 3 tries"; fi
+ if [ "$status" != Accepted ]; then
+ fail_row "Notarization" "xcrun notarytool submit --wait --timeout 2h" "submission ${id:-none} status '${status:-none}' (rc $rc); issues: $issues_note"
+ return 1
+ fi
+ [ "$log_ok" = 1 ] || { fail_row "Notarization" "xcrun notarytool log" "submission $id Accepted, but the notary log was unreadable after 3 tries, so its issues are unknown"; return 1; }
+ summary="$(plutil -extract statusSummary raw -o - "$OUT/notary-log.json" 2>/dev/null)"
+ issues_type="$(plutil -type issues "$OUT/notary-log.json" 2>/dev/null)"
+ case "$issues_type" in
+ "(any)"|"") ;;
+ array) [ "$(plutil -extract issues raw -o - "$OUT/notary-log.json" 2>/dev/null)" = 0 ] \
+ || { fail_row "Notarization" "xcrun notarytool log" "Accepted with issues: $(plutil -extract issues json -o - "$OUT/notary-log.json" | head -c 300)"; return 1; } ;;
+ esac
+ row "Notarization" "xcrun notarytool submit --wait (ASC key via $OP_SOURCE, temp files truncated after)" "submission $id: Accepted, ${summary:-no summary}, issues none"
+ for i in 1 2 3; do xcrun stapler staple "$app" >/dev/null 2>&1 && break; sleep 15; done
+ xcrun stapler validate "$app" >/dev/null 2>&1 || { fail_row "Staple" "xcrun stapler staple / validate" "staple failed after 3 tries"; return 1; }
+ row "Staple" "xcrun stapler staple / validate" "worked"
+ r="$(spctl -a -vvv -t exec "$app" 2>&1)"
+ printf '%s\n' "$r" | grep -q '^source=Notarized Developer ID$' || { fail_row "Gatekeeper" "spctl -a -vvv -t exec" "$(printf '%s' "$r" | head -2)"; return 1; }
+ row "Gatekeeper" "spctl -a -vvv -t exec" "accepted, source=Notarized Developer ID"
+}
+
+stage_zips() { # app
+ local app="$1" u="$OUT/unzip/Hidden Bar.app" r
+ ditto -c -k --sequesterRsrc --keepParent "$app" "$VZIP" && cp "$VZIP" "$SZIP" && cmp -s "$VZIP" "$SZIP" \
+ || { fail_row "Zips" "ditto -c -k --sequesterRsrc --keepParent; cp; cmp" "failed"; return 1; }
+ ZIP_LEN="$(stat -f %z "$VZIP")"
+ row "Zips" "ditto -c -k --sequesterRsrc --keepParent; cp; cmp" "$(basename "$VZIP") $ZIP_LEN bytes; $(basename "$SZIP") byte-identical"
+ mkdir -p "$OUT/unzip" && ditto -x -k "$VZIP" "$OUT/unzip" || { fail_row "Zip contents" "ditto -x -k" "unzip failed"; return 1; }
+ r="$(spctl -a -vvv -t exec "$u" 2>&1)"
+ if printf '%s\n' "$r" | grep -q '^source=Notarized Developer ID$' && xcrun stapler validate "$u" >/dev/null 2>&1 \
+ && codesign --verify --deep --strict "$u" >/dev/null 2>&1; then
+ row "Zip contents re-checked" "unzip to a fresh dir; spctl; stapler validate; codesign --verify --deep --strict" "Notarized Developer ID; staple valid; verify ok"
+ else fail_row "Zip contents re-checked" "spctl; stapler validate; codesign --verify" "the unzipped app does not pass"; return 1; fi
+}
+
+stage_sign() {
+ local line sig len pub r
+ r="$(sparkle_tools "$SPARKLE_VER" "$T/sparkle")" || { fail_row "Sparkle tools" "re-hash the tarball; extract sign_update fresh" "$r"; return 1; }
+ EDKEY="$(op_run read "$EDDSA_REF" 2>/dev/null)" # raw-op-ok: one read per release, Connect first
+ [ -n "$EDKEY" ] || { fail_row "EdDSA sign" "op read (via $OP_SOURCE)" "could not read the EdDSA key"; return 1; }
+ line="$("$T/sparkle/bin/sign_update" --ed-key-file <(printf '%s\n' "$EDKEY") "$VZIP" 2>/dev/null)"
+ sig="$(printf '%s' "$line" | sed -n 's/.*sparkle:edSignature="\([^"]*\)".*/\1/p')"
+ len="$(printf '%s' "$line" | sed -n 's/.*length="\([0-9]*\)".*/\1/p')"
+ [ -n "$sig" ] && [ -n "$len" ] || { fail_row "EdDSA sign" "sign_update (Sparkle $SPARKLE_VER)" "no sparkle:edSignature or length in its output"; return 1; }
+ [ "$len" = "$ZIP_LEN" ] || { fail_row "EdDSA sign" "sign_update" "length $len is not the zip size $ZIP_LEN"; return 1; }
+ ZIP_SIG="$sig"
+ row "EdDSA sign" "sign_update (Sparkle $SPARKLE_VER, tarball re-hashed), key streamed from 1Password via $OP_SOURCE" "signed; length $len"
+ pub="$(plist_get "$EXPORT_APP" SUPublicEDKey)"
+ if helper verify "$VZIP" "$sig" "$pub" >/dev/null && helper verify "$SZIP" "$sig" "$pub" >/dev/null; then
+ row "Signature vs app key" "release-helper verify against the built app's SUPublicEDKey (== pinned)" "VALID for both zips"
+ else fail_row "Signature vs app key" "release-helper verify" "INVALID"; return 1; fi
+ cp "$VZIP" "$T/tampered.zip" && printf 'x' >> "$T/tampered.zip"
+ helper verify "$T/tampered.zip" "$sig" "$pub" >/dev/null; r=$?
+ [ "$r" = 1 ] || { fail_row "Negative control" "release-helper verify on the zip + 1 byte" "expected INVALID (exit 1), got exit $r"; return 1; }
+ row "Negative control" "release-helper verify on the zip + 1 byte" "INVALID (exit 1)"
+}
+
+stage_appcast() {
+ local new="$OUT/appcast.xml.unverified" prior="$T/prior-appcast.xml" minos url link pubdate r first=1 v s u l g f n_prior n_new pub
+ minos="$(plist_get "$EXPORT_APP" LSMinimumSystemVersion)"
+ url="https://github.com/$REPO_SLUG/releases/download/v$VER/Hidden-Bar-v$VER-macos.zip"
+ link="https://github.com/$REPO_SLUG/releases/tag/v$VER"
+ pubdate="$(LC_ALL=C date -u '+%a, %d %b %Y %H:%M:%S GMT')"
+ helper item --version "$BUILD" --short "$VER" --min-os "$minos" --notes "$OUT/release-notes.html" --url "$url" \
+ --length "$ZIP_LEN" --sig "$ZIP_SIG" --pubdate "$pubdate" --link "$link" > "$T/new-item.xml" 2> "$T/item.err" \
+ || { fail_row "Appcast item" "release-helper item" "$(cat "$T/item.err")"; return 1; }
+ r="$(helper appcast --prior "$prior" --item "$T/new-item.xml" --out "$new" 2>&1)" \
+ || { fail_row "Appcast merge" "release-helper appcast" "$r"; return 1; }
+ xmllint --noout "$new" 2>/dev/null || { fail_row "Appcast" "xmllint --noout" "not well-formed"; return 1; }
+ n_prior="$(count_items "$prior")"; n_new="$(count_items "$new")"
+ [ "$n_new" = $((n_prior + 1)) ] || { fail_row "Appcast" "item count" "$n_new items, expected $((n_prior + 1))"; return 1; }
+ row "Appcast" "release-helper appcast; xmllint --noout; item count" "well-formed; $n_new items, new item first"
+ r="$(readback_new_item "$new" "$BUILD" "$VER" "$minos" "$url" "$ZIP_LEN")" || { fail_row "New item read-back" "fields vs app, zip, tag" "$r"; return 1; }
+ row "New item read-back" "item 1 fields vs the built app, the zip size and the tag" "$r"
+ cut_cmp_prior "$new" "$prior" "$T/cut.xml" || { fail_row "Prior items verbatim" "awk cut of item 1; cmp with the published feed" "the remaining feed differs from $PRIOR_TAG's appcast.xml"; return 1; }
+ row "Prior items verbatim" "awk cut of item 1; cmp with the published feed" "$n_prior prior item(s) byte-identical to $PRIOR_TAG's appcast.xml"
+ helper sigs "$new" "$T/sigs.tsv" 2>"$T/sigs.err" || { fail_row "Enclosure signatures" "release-helper sigs" "$(cat "$T/sigs.err")"; return 1; }
+ pub="$(plist_get "$EXPORT_APP" SUPublicEDKey)"; mkdir -p "$T/prior"
+ while IFS="$(printf '\t')" read -r v s u l g; do
+ if [ "$u" = "$url" ]; then f="$VZIP"
+ else
+ # older items in the published feed still point at dwarvesf/hidden
+ case "$u" in
+ "https://github.com/$REPO_SLUG/releases/download/"*|"https://github.com/dwarvesf/hidden/releases/download/"*) ;;
+ *) fail_row "Enclosure $s" "url allowlist" "foreign url $u"; return 1 ;; esac
+ case "$s" in ""|*[!0-9A-Za-z._-]*) fail_row "Enclosure (unsafe version)" "shortVersionString charset" "a prior item's shortVersionString is not [0-9A-Za-z._-]+"; return 1 ;; esac
+ f="$T/prior/$s.zip"
+ curl -fsSL --proto '=https' --proto-redir '=https' --max-time 300 -o "$f" "$u" || { fail_row "Enclosure $s" "curl $u" "download failed"; return 1; }
+ [ "$(stat -f %z "$f")" = "$l" ] || { fail_row "Enclosure $s" "size vs length" "downloaded $(stat -f %z "$f") bytes, item says $l"; return 1; }
+ if [ "$first" = 1 ]; then
+ first=0
+ mkdir -p "$T/prior-app" && ditto -x -k "$f" "$T/prior-app" \
+ && r="$(check_pubkey "$T/prior-app/Hidden Bar.app")" \
+ || { fail_row "Prior app key" "SUPublicEDKey of $s (latest published) vs pinned" "${r:-cannot read the prior app}"; return 1; }
+ row "Prior app key" "SUPublicEDKey of the $s app (latest published) vs pinned" "$r"
+ fi
+ fi
+ if helper verify "$f" "$g" "$pub" >/dev/null; then row "Enclosure $s" "release-helper verify (signature from appcast.xml)" "VALID ($l bytes)"
+ else fail_row "Enclosure $s" "release-helper verify" "INVALID"; return 1; fi
+ done < "$T/sigs.tsv"
+ mv "$new" "$OUT/appcast.xml" || { fail_row "Appcast" "mv appcast.xml.unverified appcast.xml" "rename failed"; return 1; }
+}
+
+stage_smoke() {
+ local u="$OUT/unzip/Hidden Bar.app" pid="" i=0 r crash
+ if [ "$NO_SMOKE" = 1 ]; then row "Smoke test" "open -g the unzipped app" "SKIPPED (--no-smoke)"; SKIPPED="$SKIPPED smoke"; return 0; fi
+ SMOKE_DIR="$OUT/smoke"
+ smoke_baseline
+ grep -q unreadable "$SMOKE_DIR/loginitems-before.txt" && { fail_row "Smoke baseline" "System Events login items" "unreadable; rerun in a GUI session or with --no-smoke"; return 1; }
+ row "Smoke baseline" "codesign -dvvv installed; login items named Hidden Bar; defaults export" \
+ "CDHash $(cat "$SMOKE_DIR/cdhash-before.txt"); login items: $(tr '\n' ';' < "$SMOKE_DIR/loginitems-before.txt"); running: $(grep -c . "$SMOKE_DIR/running-before.txt")"
+ SMOKE_STARTED=1
+ for pid in $(pids_of "$INSTALLED_APP"); do quit_pid "$pid"; done
+ : > "$T/smoke-t0"
+ open -g -n "$u"
+ while [ -z "$pid" ] && [ "$i" -lt 20 ]; do sleep 0.5; pid="$(pids_of "$u" | head -1)"; i=$((i + 1)); done
+ if [ -z "$pid" ]; then r="the unzipped copy did not start"
+ elif r="$(smoke_assert_process "$pid" "$u" "$BUILD")"; then
+ sleep 20
+ r="$(smoke_assert_process "$pid" "$u" "$BUILD")" && r="$r; alive after 20 s"
+ fi
+ crash="$(find "$HOME/Library/Logs/DiagnosticReports" -name 'Hidden Bar*' -newer "$T/smoke-t0" 2>/dev/null | head -1)"
+ if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null && [ -z "$crash" ] && printf '%s' "$r" | grep -q 'alive after'; then
+ row "Smoke test" "open -g -n the unzipped app; pid path, build, alive at 20 s; crash reports" "$r; no crash report"
+ else
+ fail_row "Smoke test" "open -g -n the unzipped app" "$r${crash:+; crash report $crash}"
+ fi
+ if r="$(smoke_restore)"; then row "Host restored" "quit by pid; defaults import; relaunch installed; compare" "CDHash, login items and prefs equal the baseline"
+ else
+ sleep 5; SMOKE_RESTORED=0
+ if r="$(smoke_restore)"; then row "Host restored" "restore, one retry" "equal to the baseline after one retry"
+ else fail_row "Host restored" "restore, one retry" "$r"; fi
+ fi
+ SMOKE_RESTORED=1
+ [ "$FAILED" = 0 ]
+}
+
+# ---- main ---------------------------------------------------------------------------------
+
+usage() { sed -n '2,24p' "$0" | sed 's/^# \{0,1\}//'; }
+
+main() {
+ local mode="" notes="" out_arg="" r vb
+ SKIP_TESTS=0; NO_SMOKE=0
+ while [ $# -gt 0 ]; do
+ case "$1" in
+ --notes) [ $# -ge 2 ] || { usage >&2; exit 2; }; notes="$2"; mode=release; shift ;;
+ --out) [ $# -ge 2 ] || { usage >&2; exit 2; }; out_arg="$2"; shift ;;
+ --skip-tests) SKIP_TESTS=1 ;;
+ --no-smoke) NO_SMOKE=1 ;;
+ --check-app) [ $# -ge 2 ] || { usage >&2; exit 2; }; mode=check-app; CHECK_APP="$2"; shift ;;
+ --guard-selftest) mode=guard-selftest ;;
+ -h|--help) usage; exit 0 ;;
+ *) echo "release.sh: unknown argument $1" >&2; usage >&2; exit 2 ;;
+ esac
+ shift
+ done
+ case "$mode" in
+ guard-selftest) guard_selftest; exit $? ;;
+ check-app)
+ make_tmp; setup_traps
+ vb="$(read_versions "$PBXPROJ")" || { echo "release.sh: $vb" >&2; exit 2; }
+ VER="${vb% *}"; BUILD="${vb#* }"
+ if check_app "$CHECK_APP" "$VER" "$BUILD"; then echo "check-app: PASS ($CHECK_APP)"; exit 0; fi
+ echo "check-app: FAIL ($CHECK_APP)"; exit 1 ;;
+ release) ;;
+ *) usage >&2; exit 2 ;;
+ esac
+
+ [ -n "$notes" ] || { echo "release.sh: --notes is required" >&2; exit 2; }
+ case "$notes" in /*) ;; *) notes="$PWD/$notes" ;; esac
+ make_tmp; setup_traps
+ vb="$(read_versions "$PBXPROJ")" || { echo "release.sh: $vb" >&2; exit 2; }
+ VER="${vb% *}"; BUILD="${vb#* }"
+ OUT="${out_arg:-$ROOT/build/release-$VER}"
+ [ -L "$OUT" ] && { echo "release.sh: --out $OUT is a symlink" >&2; exit 2; }
+ if [ -d "$OUT" ] && [ -n "$(ls -A "$OUT" 2>/dev/null)" ]; then echo "release.sh: --out $OUT exists and is not empty; use a new dir" >&2; exit 2; fi
+ mkdir -p "$(dirname "$OUT")" && { mkdir "$OUT" 2>/dev/null || [ -d "$OUT" ]; } || { echo "release.sh: cannot create $OUT" >&2; exit 2; }
+ OUT="$(cd "$OUT" && pwd -P)"
+ exec > >(tee -a "$OUT/release.log") 2>&1
+ VZIP="$OUT/Hidden-Bar-v$VER-macos.zip"; SZIP="$OUT/Hidden-Bar-macos.zip"; EXPORT_APP="$OUT/export/Hidden Bar.app"
+
+ stage_preflight "$notes"
+ stage_tests
+ stage_build
+ check_app "$EXPORT_APP" "$VER" "$BUILD" || finish 1
+ stage_notarize "$EXPORT_APP" || finish 1
+ stage_zips "$EXPORT_APP" || finish 1
+ stage_sign || finish 1
+ stage_appcast || finish 1
+ stage_smoke || finish 1
+ finish 0
+}
+
+if [ -z "${RELEASE_SH_SOURCE_ONLY:-}" ]; then main "$@"; fi
diff --git a/scripts/test-release.sh b/scripts/test-release.sh
new file mode 100755
index 00000000..db365579
--- /dev/null
+++ b/scripts/test-release.sh
@@ -0,0 +1,531 @@
+#!/bin/bash
+# scripts/test-release.sh : offline tests for scripts/release.sh and scripts/release-helper.swift.
+#
+# bash scripts/test-release.sh
+#
+# No network, no secrets, no Xcode build, no Apple notary, no 1Password: every external tool the
+# stages call (gh, op, curl, xcrun, spctl, trash) is a PATH stub, and release.sh is sourced with
+# RELEASE_SH_SOURCE_ONLY=1 so each check runs alone. One PASS/FAIL/SKIP line per case; exit 0
+# only when no case failed. The fixture root is left in $TMPDIR for the OS to clean.
+#
+# Fixtures (scripts/fixtures/release/): payload.bin with a signature by a throwaway Ed25519 key
+# (only its public half is kept), a second unrelated public key, the published v1.11.2 appcast
+# (prior-1.xml) and the 1.12.0 hand-run appcast (prior-2.xml), both with fixture signatures, and
+# the 1.12.0 notes and item as the golden output of `release-helper item`.
+
+ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"
+F="$ROOT/scripts/fixtures/release"
+WORK="$(mktemp -d "${TMPDIR:-/tmp}/hb-release-test.XXXXXX")"
+WORK="$(cd "$WORK" && pwd -P)"
+STUBS="$WORK/stubs"; mkdir -p "$STUBS" "$WORK/trashed"
+export TMPDIR="$WORK"
+PASSED=0; FAILED_N=0; SKIPPED_N=0; FAILED_NAMES=""
+
+H="$WORK/release-helper"
+if ! swiftc -O "$ROOT/scripts/release-helper.swift" -o "$H" >"$WORK/helper-build.log" 2>&1; then
+ echo "FAIL helper-build (see $WORK/helper-build.log)"; exit 1
+fi
+
+stub() { cat > "$STUBS/$1"; chmod +x "$STUBS/$1"; }
+stub trash <<'EOF'
+#!/bin/bash
+mv "$1" "$TMPDIR/trashed/" 2>/dev/null
+EOF
+stub gh <<'EOF'
+#!/bin/bash
+# scenarios from env: STUB_TAG (absent|draft|published|error), STUB_LATEST ("tag draft has-appcast"), STUB_FEED
+case "$*" in
+ "release view v"*"--json isDraft"*)
+ case "${STUB_TAG:-absent}" in
+ absent) echo "release not found" >&2; exit 1 ;;
+ draft) echo true ;;
+ published) echo false ;;
+ *) echo "HTTP 502: Bad Gateway" >&2; exit 1 ;;
+ esac ;;
+ "release view -R"*"--json tagName"*) echo "${STUB_LATEST:-v1.11.2 false true}" ;;
+ "release download"*"--pattern appcast.xml"*)
+ dir=""; prev=""
+ for a in "$@"; do [ "$prev" = "--dir" ] && dir="$a"; prev="$a"; done
+ cp "$STUB_FEED" "$dir/appcast.xml" ;;
+ *) echo "stub gh: unexpected: $*" >&2; exit 9 ;;
+esac
+EOF
+stub curl <<'EOF'
+#!/bin/bash
+# STUB_CURL_RC sets the exit code; STUB_CURL_FILE is copied to the -o target (a download)
+if [ -n "${STUB_CURL_FILE:-}" ]; then
+ out=""; prev=""
+ for a in "$@"; do [ "$prev" = "-o" ] && out="$a"; prev="$a"; done
+ [ -z "$out" ] || cp "$STUB_CURL_FILE" "$out"
+fi
+exit "${STUB_CURL_RC:-0}"
+EOF
+stub op <<'EOF'
+#!/bin/bash
+# fake vault: one ASC item (fake PEM) and the EdDSA item. STUB_OP_RC fails every call.
+[ -z "${STUB_OP_RC:-}" ] || exit "$STUB_OP_RC"
+[ -z "${OP_CONNECT_HOST:-}" ] || echo connect >> "$TMPDIR/op-source.log"
+pem="-----BEGIN PRIVATE"" KEY-----"
+case "$1 $2" in
+ "item list") echo '[{"id":"asc1","title":"Dwarves Hacker Bar Release"},{"id":"ed1","title":"Hidden Bar Sparkle EdDSA private key"}]' ;;
+ "item get") printf '{"id":"asc1","fields":[{"id":"f1","label":"p8","value":"%s\\nFAKEFAKE\\n-----END"},{"id":"f2","label":"key id","value":"KEYID123"},{"id":"f3","label":"issuer","value":"ISSUER-UUID"}]}\n' "$pem" ;;
+ *) exit 1 ;;
+esac
+EOF
+stub xcrun <<'EOF'
+#!/bin/bash
+# notarytool and stapler only. STUB_NOTARY=Accepted|Invalid
+case "$1 $2" in
+ "notarytool submit")
+ key=""; prev=""
+ for a in "$@"; do [ "$prev" = "--key" ] && key="$a"; prev="$a"; done
+ grep -q 'BEGIN PRIVATE' "$key" && echo seen > "$TMPDIR/key-seen-at-submit"
+ printf '{"id":"00000000-0000-0000-0000-000000000001","status":"%s","message":"Processing complete"}\n' "$STUB_NOTARY" ;;
+ "notarytool log")
+ out="${!#}"
+ [ -z "${STUB_NOTARY_LOGFAIL:-}" ] || { echo "Error: could not fetch the log" >&2; exit 1; }
+ if [ "$STUB_NOTARY" = Accepted ]; then echo '{"status":"Accepted","statusSummary":"Ready for distribution","issues":null}' > "$out"
+ else echo '{"status":"Invalid","statusSummary":"Archive contains critical validation errors","issues":[{"message":"The binary is not signed."}]}' > "$out"; fi ;;
+ "stapler staple"|"stapler validate") exit 0 ;;
+ *) exit 1 ;;
+esac
+EOF
+stub spctl <<'EOF'
+#!/bin/bash
+echo "${!#}: accepted"; echo "source=Notarized Developer ID"
+EOF
+
+# The stages must see the stubs, never the real gh/op/xcrun.
+export PATH="$STUBS:$PATH"
+for t in gh op curl xcrun spctl trash; do
+ [ "$(command -v "$t")" = "$STUBS/$t" ] || { echo "FAIL stub-shadowing ($t resolves to $(command -v "$t"))"; exit 1; }
+done
+
+RELEASE_SH_SOURCE_ONLY=1
+# shellcheck source=release.sh
+source "$ROOT/scripts/release.sh"
+set +e +u
+make_tmp
+HELPER="$H"
+CONNECT_TOKEN_FILE="$WORK/fake-connect-token"; echo fake-token > "$CONNECT_TOKEN_FILE"
+SIG="$(cat "$F/payload.sig.b64")"; PUB="$(cat "$F/pub.b64")"
+
+result() { # name rc [reason]
+ if [ "$2" = 0 ]; then echo "PASS $1"; PASSED=$((PASSED + 1))
+ elif [ "$2" = 77 ]; then echo "SKIP $1${3:+: $3}"; SKIPPED_N=$((SKIPPED_N + 1))
+ else echo "FAIL $1${3:+: $3}"; FAILED_N=$((FAILED_N + 1)); FAILED_NAMES="$FAILED_NAMES $1"; fi
+}
+t() { local name="$1"; shift; "$@" >"$WORK/case.log" 2>&1; result "$name" $? "$(tail -1 "$WORK/case.log")"; }
+rc_is() { local want="$1"; shift; "$@"; [ $? = "$want" ]; }
+
+# ---- release-helper verify --------------------------------------------------------------
+
+t verify-valid bash -c '[ "$("$0" verify "$1" "$2" "$3")" = VALID ]' "$H" "$F/payload.bin" "$SIG" "$PUB"
+cp "$F/payload.bin" "$WORK/append.bin"; printf 'x' >> "$WORK/append.bin"
+t verify-tampered-append rc_is 1 "$H" verify "$WORK/append.bin" "$SIG" "$PUB"
+perl -pe 's/^H/h/ if $. == 1' "$F/payload.bin" > "$WORK/flip.bin"
+t verify-tampered-flip bash -c '! cmp -s "$1" "$2" && "$0" verify "$1" "$3" "$4"; [ $? = 1 ]' "$H" "$WORK/flip.bin" "$F/payload.bin" "$SIG" "$PUB"
+t verify-wrong-key rc_is 1 "$H" verify "$F/payload.bin" "$SIG" "$(cat "$F/wrongkey.pub.b64")"
+
+# ---- release-helper item and appcast ----------------------------------------------------
+
+URL12="https://github.com/dwarvesf/hidden/releases/download/v1.12.0/Hidden-Bar-v1.12.0-macos.zip"
+mkitem() { # build short notes out
+ "$H" item --version "$1" --short "$2" --min-os 13.0 --notes "$3" \
+ --url "https://github.com/dwarvesf/hidden/releases/download/v$2/Hidden-Bar-v$2-macos.zip" --length 2174551 \
+ --sig "$SIG" --pubdate 'Sun, 15 Nov 2026 16:33:08 GMT' --link "https://github.com/dwarvesf/hidden/releases/tag/v$2" > "$4"
+}
+item_exact() { mkitem 19 1.12.0 "$F/notes-1.12.0.html" "$WORK/item-19.xml" && cmp "$WORK/item-19.xml" "$F/item-1.12.0.expected"; }
+t item-exact-output item_exact
+printf '\n' > "$WORK/notes-cdata.html"
+t item-refuse-cdata-terminator rc_is 2 mkitem 20 1.13.0 "$WORK/notes-cdata.html" "$WORK/x.xml"
+
+appcast_1() {
+ "$H" appcast --prior "$F/prior-1.xml" --item "$WORK/item-19.xml" --out "$WORK/feed-1.xml" &&
+ [ "$(count_items "$WORK/feed-1.xml")" = 2 ] && first_item "$WORK/feed-1.xml" | grep -q '19<'
+}
+t appcast-1-prior appcast_1
+mkitem 20 1.13.0 "$F/notes-1.12.0.html" "$WORK/item-20.xml"
+appcast_2() {
+ "$H" appcast --prior "$F/prior-2.xml" --item "$WORK/item-20.xml" --out "$WORK/feed-2.xml" &&
+ [ "$(count_items "$WORK/feed-2.xml")" = 3 ] && first_item "$WORK/feed-2.xml" | grep -q '20<'
+}
+t appcast-2-prior appcast_2
+prior_verbatim() {
+ # the 1-prior merge reproduces the 1.12.0 hand-run feed byte for byte, and both merges keep
+ # every prior item: the feed minus item 1 is the prior file
+ cmp "$WORK/feed-1.xml" "$F/prior-2.xml" && cut_cmp_prior "$WORK/feed-1.xml" "$F/prior-1.xml" "$WORK/cut1" &&
+ cut_cmp_prior "$WORK/feed-2.xml" "$F/prior-2.xml" "$WORK/cut2"
+}
+t appcast-prior-verbatim prior_verbatim
+cdata_text() {
+ awk '{print} /^ and - in a note"; print "
"; print " - "; d=1}' "$F/prior-1.xml" > "$WORK/prior-cdata.xml" &&
+ "$H" appcast --prior "$WORK/prior-cdata.xml" --item "$WORK/item-19.xml" --out "$WORK/feed-cdata.xml" &&
+ cut_cmp_prior "$WORK/feed-cdata.xml" "$WORK/prior-cdata.xml" "$WORK/cut3" && xmllint --noout "$WORK/feed-cdata.xml"
+}
+t appcast-cdata-item-text cdata_text
+sed 's/$/\r/' "$F/prior-1.xml" > "$WORK/prior-crlf.xml"
+t appcast-refuse-crlf rc_is 2 "$H" appcast --prior "$WORK/prior-crlf.xml" --item "$WORK/item-19.xml" --out "$WORK/x.xml"
+mkitem 16 1.13.0 "$F/notes-1.12.0.html" "$WORK/item-16.xml"
+refuse_lower() { "$H" appcast --prior "$F/prior-1.xml" --item "$WORK/item-16.xml" --out "$WORK/x.xml" 2>"$WORK/err"; [ $? = 1 ] && grep -q '1.11.2' "$WORK/err"; }
+t appcast-refuse-lower-build refuse_lower
+mkitem 17 1.13.0 "$F/notes-1.12.0.html" "$WORK/item-17.xml"
+t appcast-refuse-same-build rc_is 1 "$H" appcast --prior "$F/prior-1.xml" --item "$WORK/item-17.xml" --out "$WORK/x.xml"
+mkitem 30 1.11.2 "$F/notes-1.12.0.html" "$WORK/item-dup.xml"
+refuse_dup() { "$H" appcast --prior "$F/prior-1.xml" --item "$WORK/item-dup.xml" --out "$WORK/x.xml" 2>"$WORK/err"; [ $? = 1 ] && grep -q 'shortVersionString 1.11.2' "$WORK/err"; }
+t appcast-refuse-dup-short refuse_dup
+numeric_compare() {
+ sed 's|
17<|9<|' "$F/prior-1.xml" > "$WORK/prior-9.xml"
+ sed 's|17<|99<|' "$F/prior-1.xml" > "$WORK/prior-99.xml"
+ mkitem 10 1.13.0 "$F/notes-1.12.0.html" "$WORK/item-10.xml"; mkitem 100 1.13.0 "$F/notes-1.12.0.html" "$WORK/item-100.xml"
+ "$H" appcast --prior "$WORK/prior-9.xml" --item "$WORK/item-10.xml" --out "$WORK/x.xml" &&
+ "$H" appcast --prior "$WORK/prior-99.xml" --item "$WORK/item-100.xml" --out "$WORK/x.xml"
+}
+t appcast-numeric-build-compare numeric_compare
+t appcast-xmllint xmllint --noout "$WORK/feed-1.xml" "$WORK/feed-2.xml"
+
+# ---- read-back and cut-and-compare (shell, independent of the Swift merge) ---------------
+
+t readback-new-item-ok readback_new_item "$WORK/feed-1.xml" 19 1.12.0 13.0 "$URL12" 2174551
+t readback-wrong-url-fails rc_is 1 readback_new_item "$WORK/feed-1.xml" 19 1.12.0 13.0 "${URL12/v1.12.0\//v1.12/}" 2174551
+t readback-wrong-length-fails rc_is 1 readback_new_item "$WORK/feed-1.xml" 19 1.12.0 13.0 "$URL12" 2174552
+altered_prior() {
+ sed 's|Sun, 15 Nov 2026 06:50:21 GMT|Sun, 15 Nov 2026 06:50:22 GMT|' "$WORK/feed-1.xml" > "$WORK/feed-alt.xml"
+ ! cmp -s "$WORK/feed-alt.xml" "$WORK/feed-1.xml" && ! cut_cmp_prior "$WORK/feed-alt.xml" "$F/prior-1.xml" "$WORK/cut4"
+}
+t cut-cmp-detects-altered-prior altered_prior
+
+# ---- app checks on throwaway ad-hoc bundles --------------------------------------------
+
+# What the shipped app declares, read from the real plist and never from the pins: the fixture
+# bundles carry these values, so a pin that drifted from the plist fails the Feed URL and
+# EdDSA rows below instead of being copied into the fixtures.
+REAL_PLIST="$ROOT/hidden/Info-Direct.plist"
+REAL_FEED="$(/usr/libexec/PlistBuddy -c 'Print :SUFeedURL' "$REAL_PLIST" 2>/dev/null)"
+REAL_KEY="$(/usr/libexec/PlistBuddy -c 'Print :SUPublicEDKey' "$REAL_PLIST" 2>/dev/null)"
+
+make_bundle() { # dir pubkey : a minimal app bundle (a copy of /usr/bin/true as its executable)
+ local d="$1/Hidden Bar.app"
+ mkdir -p "$d/Contents/MacOS"
+ cp /usr/bin/true "$d/Contents/MacOS/Hidden Bar"
+ cat > "$d/Contents/Info.plist" <
+
+
+CFBundleExecutable Hidden Bar
+CFBundleIdentifier com.dwarvesv.minimalbar.release-test
+CFBundlePackageType APPL
+CFBundleShortVersionString 1.12.0
+CFBundleVersion 19
+SUFeedURL $REAL_FEED
+SUPublicEDKey $2
+
+PL
+ echo "$d"
+}
+printf '\n\ncom.apple.security.app-sandbox \n' > "$WORK/sandbox.entitlements"
+cp "$ROOT/hidden/Hidden-Direct.entitlements" "$WORK/empty.entitlements"
+APP_SBX="$(make_bundle "$WORK/b-sbx" "$REAL_KEY")"; codesign --force -s - --entitlements "$WORK/sandbox.entitlements" "$APP_SBX" 2>/dev/null
+APP_EMPTY="$(make_bundle "$WORK/b-empty" "$REAL_KEY")"; codesign --force -s - --entitlements "$WORK/empty.entitlements" "$APP_EMPTY" 2>/dev/null
+APP_NONE="$(make_bundle "$WORK/b-none" "$REAL_KEY")"; codesign --force -s - "$APP_NONE" 2>/dev/null
+APP_KEY="$(make_bundle "$WORK/b-key" "$(cat "$F/wrongkey.pub.b64")")"; codesign --force -s - --entitlements "$WORK/empty.entitlements" "$APP_KEY" 2>/dev/null
+
+t check-sandbox-entitled-fails rc_is 1 check_sandbox "$APP_SBX"
+t check-sandbox-empty-dict-passes check_sandbox "$APP_EMPTY"
+t check-sandbox-no-entitlements-fails rc_is 1 check_sandbox "$APP_NONE"
+
+rows_of() { : > "$ROWS_FILE"; N=0; FAILED=0; "$@" >/dev/null 2>&1; local rc=$?; ROWS="$(cat "$ROWS_FILE")"; return $rc; }
+row_has() { printf '%s\n' "$ROWS" | grep -E "^\| [0-9]+ \| $1 \|" | grep -q -- "$2"; }
+adhoc_unsandboxed() {
+ rows_of check_app "$APP_NONE" 1.12.0 19; [ $? = 1 ] &&
+ row_has 'Signature: identity, timestamp, runtime' 'FAIL: .*not Developer ID' && row_has Unsandboxed 'FAIL: no entitlements blob'
+}
+t check-app-adhoc-unsandboxed-fails adhoc_unsandboxed
+adhoc_sandboxed() {
+ rows_of check_app "$APP_SBX" 1.12.0 19; [ $? = 1 ] &&
+ row_has 'Signature: identity, timestamp, runtime' 'FAIL' && row_has Unsandboxed 'FAIL: app-sandbox entitlement present'
+}
+t check-app-adhoc-sandboxed-fails adhoc_sandboxed
+adhoc_not_credited() {
+ rows_of check_app "$APP_EMPTY" 1.12.0 19; [ $? = 1 ] && row_has Unsandboxed 'FAIL: .*not credited: identity failed'
+}
+t check-app-adhoc-empty-dict-not-credited adhoc_not_credited
+wrong_pubkey() { rows_of check_app "$APP_KEY" 1.12.0 19; [ $? = 1 ] && row_has 'EdDSA public key' 'FAIL: SUPublicEDKey differs'; }
+t check-app-wrong-pubkey-fails wrong_pubkey
+devid_sandboxed() {
+ local app ident
+ ident="$(security find-identity -v -p codesigning 2>/dev/null | sed -n 's/.*"\(Developer ID Application: .*(W777S7V8TN)\)".*/\1/p' | head -1)"
+ [ -n "$ident" ] || { echo "no Developer ID identity"; return 77; }
+ app="$(make_bundle "$WORK/b-devid" "$REAL_KEY")"
+ perl -e 'alarm 90; exec @ARGV' codesign --force --sign "$ident" --timestamp --options runtime \
+ --entitlements "$WORK/sandbox.entitlements" "$app" >/dev/null 2>&1 || { echo "Developer ID signing with --timestamp failed (offline or locked keychain)"; return 77; }
+ rows_of check_app "$app" 1.12.0 19; [ $? = 1 ] &&
+ row_has 'Signature: identity, timestamp, runtime' '[0-9] parts: Developer ID' && row_has Unsandboxed 'FAIL: app-sandbox entitlement present' ||
+ { echo "rows: $(printf '%s' "$ROWS" | head -2 | tr '\n' ' ')"; return 1; }
+}
+devid_sandboxed >"$WORK/case.log" 2>&1; result check-app-devid-sandboxed-fails $? "$(tail -1 "$WORK/case.log")"
+pin_matches_plist() { # what: the pin in release.sh equals the shipped plist value, both non-empty
+ local pin="$2" real="$3"
+ [ -n "$real" ] || { echo "$1: hidden/Info-Direct.plist has no value"; return 1; }
+ [ "$pin" = "$real" ] || { echo "$1 drifted: release.sh pins '$pin', hidden/Info-Direct.plist has '$real'"; return 1; }
+}
+t pin-feed-url-matches-plist pin_matches_plist SUFeedURL "$PINNED_FEED_URL" "$REAL_FEED"
+t pin-pubkey-matches-plist pin_matches_plist SUPublicEDKey "$PINNED_PUBKEY" "$REAL_KEY"
+fixture_rows_pass() { # fixtures built from the real plist pass the Feed URL and EdDSA rows against the pins
+ rows_of check_app "$APP_EMPTY" 1.12.0 19
+ row_has 'Feed URL' "$REAL_FEED" && ! row_has 'Feed URL' FAIL && row_has 'EdDSA public key' 'equals the pinned key'
+}
+t check-app-fixture-rows-match-pins fixture_rows_pass
+key_check() { rc_is 1 check_pubkey "$APP_KEY" && check_pubkey "$APP_EMPTY"; }
+t check-pubkey-rejects-other-key key_check
+
+# ---- guards and shell safety ------------------------------------------------------------
+
+t guard-refuses-writes guard_selftest
+refuse_xtrace() {
+ rc_is 2 /bin/bash -x "$ROOT/scripts/release.sh" --help && rc_is 2 env SHELLOPTS=xtrace /bin/bash "$ROOT/scripts/release.sh" --help &&
+ /bin/bash "$ROOT/scripts/release.sh" --help >/dev/null
+}
+t refuse-xtrace refuse_xtrace
+
+# ---- preflight edge cases ---------------------------------------------------------------
+
+REPO="$WORK/repo"; mkdir -p "$REPO"
+( cd "$REPO" && command git init -q --template= && echo a > tracked.txt && command git add tracked.txt &&
+ command git -c user.email=t@t -c user.name=t commit -qm init )
+dirty_tree() { check_clean_tree "$REPO" && echo b > "$REPO/untracked.txt" && rc_is 1 check_clean_tree "$REPO"; }
+t preflight-dirty-tree dirty_tree
+versions() {
+ printf 'MARKETING_VERSION = 1.12.0;\nMARKETING_VERSION = 1.12.0;\nCURRENT_PROJECT_VERSION = 19;\nCURRENT_PROJECT_VERSION = 19;\n' > "$WORK/ok.pbxproj"
+ printf 'MARKETING_VERSION = 1.12.0;\nMARKETING_VERSION = 1.11.0;\nCURRENT_PROJECT_VERSION = 19;\nCURRENT_PROJECT_VERSION = 19;\n' > "$WORK/bad.pbxproj"
+ local bad
+ [ "$(read_versions "$WORK/ok.pbxproj")" = "1.12.0 19" ] && rc_is 1 read_versions "$WORK/bad.pbxproj" &&
+ bad="$(read_versions "$WORK/bad.pbxproj")"; case "$bad" in *"1 1.11.0 1 1.12.0"*) ;; *) return 1 ;; esac
+ [ "$(read_versions "$PBXPROJ" | wc -w | tr -d ' ')" = 2 ]
+}
+t preflight-versions-disagree versions
+changelog() {
+ printf '# Changelog\n\n## v1.12.0 (2026-11-15)\n\n- x\n' > "$WORK/CHANGELOG.md"
+ check_changelog "$WORK/CHANGELOG.md" 1.12.0 && rc_is 1 check_changelog "$WORK/CHANGELOG.md" 1.13.0 && rc_is 1 check_changelog "$WORK/CHANGELOG.md" 1.12
+}
+t preflight-no-changelog changelog
+tag_state() {
+ STUB_TAG=absent check_tag_state 1.12.0 && STUB_TAG=published rc_is 1 check_tag_state 1.12.0 &&
+ STUB_TAG=error rc_is 3 check_tag_state 1.12.0 && { DRAFT_NOTE=""; STUB_TAG=draft check_tag_state 1.12.0; } && [ -n "$DRAFT_NOTE" ]
+}
+t preflight-tag-published tag_state
+no_asset() {
+ STUB_LATEST="v1.11.2 false false" rc_is 1 fetch_prior_appcast "$WORK/p.xml" &&
+ STUB_LATEST="v1.11.2 false true" STUB_FEED="$F/prior-1.xml" fetch_prior_appcast "$WORK/p.xml" &&
+ cmp -s "$WORK/p.xml" "$F/prior-1.xml" && [ "$PRIOR_TAG" = v1.11.2 ]
+}
+t preflight-no-appcast-asset no_asset
+notes_case() { rc_is 1 check_notes "$WORK/notes-cdata.html" && check_notes "$F/notes-1.12.0.html"; }
+t preflight-notes-cdata notes_case
+no_1password() {
+ : > "$TMPDIR/op-source.log"
+ STUB_CURL_RC=7 STUB_OP_RC=1 rc_is 1 op_select_source "$WORK/items.json" && [ -z "$OP_SOURCE" ] &&
+ STUB_CURL_RC=7 op_select_source "$WORK/items.json" && [ "$OP_SOURCE" = service-account ] &&
+ op_select_source "$WORK/items.json" && [ "$OP_SOURCE" = connect ] && grep -q connect "$TMPDIR/op-source.log"
+}
+t preflight-no-1password no_1password
+tree_drift() {
+ local s; s="$(tree_state "$REPO")"
+ check_tree_unchanged "$REPO" "$s" && echo changed >> "$REPO/tracked.txt" && rc_is 1 check_tree_unchanged "$REPO" "$s"
+}
+t tree-drift-detected tree_drift
+
+# ---- secrets handling, notarization (stubbed xcrun and op) ------------------------------
+
+make_bundle "$WORK/notary-app" "$REAL_KEY" >/dev/null
+notarize_run() { # case-name [STUB_NOTARY value, default the case name] [log-fails] : runs the stage in a subshell with the real EXIT trap
+ local case_dir="$WORK/notary-$1"
+ mkdir -p "$case_dir/out" "$case_dir/tmp" "$case_dir/tmp/trashed"
+ ( export TMPDIR="$case_dir/tmp" STUB_NOTARY="${2:-$1}" STUB_NOTARY_LOGFAIL="${3:-}"; T=""; make_tmp; setup_traps; OUT="$case_dir/out"; OP_SOURCE=connect
+ sleep() { :; } # the log retries wait 10 s each in a real run
+ stage_notarize "$WORK/notary-app/Hidden Bar.app" ) > "$case_dir/stdout" 2>&1
+ echo $? > "$case_dir/rc"
+}
+no_key_left() { # case dir : the fake PEM is nowhere on disk, and it did exist at submit time
+ [ -f "$1/tmp/key-seen-at-submit" ] && ! grep -rqF -- "$PEM_MARK" "$1" && [ -z "$(find "$1/tmp" -maxdepth 1 -name 'hb-release.*')" ]
+}
+notarize_run Invalid
+invalid() { [ "$(cat "$WORK/notary-Invalid/rc")" = 1 ] && grep -q "Notarization: FAIL: .*status 'Invalid'.*not signed" "$WORK/notary-Invalid/stdout"; }
+t notarize-invalid-fails invalid
+t secrets-cleanup-on-failure no_key_left "$WORK/notary-Invalid"
+notarize_run Accepted
+accepted() {
+ local o="$WORK/notary-Accepted/stdout"
+ [ "$(cat "$WORK/notary-Accepted/rc")" = 0 ] && grep -q 'Notarization: submission .*: Accepted, Ready for distribution' "$o" &&
+ grep -q 'Staple: worked' "$o" && grep -q 'Gatekeeper: accepted' "$o" && no_key_left "$WORK/notary-Accepted"
+}
+t notarize-accepted-passes accepted
+notarize_run AcceptedNoLog Accepted 1
+log_unreadable() { # Accepted but the log never arrives: a FAILED row, never "issues none"
+ local o="$WORK/notary-AcceptedNoLog/stdout"
+ [ "$(cat "$WORK/notary-AcceptedNoLog/rc")" = 1 ] && grep -q 'Notarization: FAIL: .*Accepted, but the notary log was unreadable' "$o" &&
+ ! grep -q 'issues none' "$o" && no_key_left "$WORK/notary-AcceptedNoLog"
+}
+t notarize-log-unreadable-fails log_unreadable
+leak_detects() {
+ mkdir -p "$WORK/leak/clean" "$WORK/leak/pem" "$WORK/leak/ed"
+ echo nothing > "$WORK/leak/clean/a.txt"; printf 'x\n%s\n' "$PEM_MARK" > "$WORK/leak/pem/a.txt"
+ echo "prefix FAKE-EDDSA-KEY-VALUE suffix" > "$WORK/leak/ed/a.txt"
+ EDKEY="FAKE-EDDSA-KEY-VALUE"
+ [ "$(leak_scan "$WORK/leak/clean")" = clean ] && rc_is 1 leak_scan "$WORK/leak/pem" && rc_is 1 leak_scan "$WORK/leak/ed"
+ local rc=$?; EDKEY=""; return $rc
+}
+t leak-scan-detects leak_detects
+
+# ---- Sparkle tool pin -------------------------------------------------------------------
+
+digest_mismatch() {
+ local sp="$WORK/sp"
+ mkdir -p "$sp/2.10.1" "$WORK/fake-sparkle/bin"
+ printf '#!/bin/bash\ntouch "%s/fake-sign-update-ran"\n' "$WORK" > "$WORK/fake-sparkle/bin/sign_update"; chmod +x "$WORK/fake-sparkle/bin/sign_update"
+ tar -cJf "$sp/2.10.1/Sparkle-2.10.1.tar.xz" -C "$WORK/fake-sparkle" ./bin/sign_update
+ SPARKLE_CACHE_ROOT="$sp" rc_is 2 sparkle_tools 2.10.1 "$WORK/sp-extract" &&
+ [ ! -e "$WORK/sp-extract/bin/sign_update" ] && [ ! -e "$WORK/fake-sign-update-ran" ]
+}
+t sparkle-digest-mismatch-refuses digest_mismatch
+unknown_version() {
+ SPARKLE_CACHE_ROOT="$WORK/sp" rc_is 2 sparkle_tools 9.9.9 "$WORK/sp-x" || return 1
+ local real="$HOME/.cache/hidden-bar/sparkle/2.10.1/Sparkle-2.10.1.tar.xz"
+ [ -f "$real" ] || return 0 # positive control only where the real tarball is cached
+ sparkle_tools 2.10.1 "$WORK/sp-real" && [ -x "$WORK/sp-real/bin/sign_update" ]
+}
+t sparkle-unknown-version-refuses unknown_version
+
+# ---- smoke assertions -------------------------------------------------------------------
+
+dead_pid() { sleep 0 & local p=$!; wait "$p"; rc_is 1 smoke_assert_process "$p" "$WORK/notary-app/Hidden Bar.app" 19; }
+t smoke-assert-dead-pid-fails dead_pid
+wrong_path() {
+ sleep 30 & local p=$! rc
+ rc_is 1 smoke_assert_process "$p" "$WORK/notary-app/Hidden Bar.app" 19; rc=$?
+ kill "$p" 2>/dev/null; wait "$p" 2>/dev/null; return $rc
+}
+t smoke-assert-wrong-path-fails wrong_path
+# Positive control without launching any app bundle: /bin/sleep stands in as the executable
+# (the 4th argument), the fixture bundle only supplies the build number. Tests never launch,
+# open or exec anything inside an .app bundle.
+live_process() {
+ local p rc
+ /bin/sleep 30 & p=$!
+ sleep 0.3; smoke_assert_process "$p" "$APP_EMPTY" 19 /bin/sleep; rc=$?
+ kill "$p" 2>/dev/null; wait "$p" 2>/dev/null; return $rc
+}
+t smoke-assert-live-process-passes live_process
+
+# ---- stages through stubs ---------------------------------------------------------------
+
+# stage_appcast end to end on fixtures: the built zip is payload.bin (signed by the fixture key,
+# which the fixture export app declares), and curl is a stub that serves a prior-release zip
+# holding a fixture app with the key under test. Nothing is launched; the zip is only unpacked.
+appcast_run() { # case-name prior-app-key [verify-ok|bad-version] : leaves rc, stdout and out/ under $WORK/ac-
+ local d="$WORK/ac-$1" prior_len
+ mkdir -p "$d/out" "$d/tmp/trashed" "$d/src"
+ make_bundle "$d/src" "$2" >/dev/null
+ ditto -c -k --keepParent "$d/src/Hidden Bar.app" "$d/prior.zip"
+ prior_len="$(stat -f %z "$d/prior.zip")"
+ ( export TMPDIR="$d/tmp" STUB_CURL_FILE="$d/prior.zip"
+ T=""; make_tmp; setup_traps
+ OUT="$d/out"; OP_SOURCE=connect; VER=1.12.0; BUILD=19; PRIOR_TAG=v1.11.2; HELPER="$H"
+ EXPORT_APP="$(make_bundle "$d/export" "$PUB")"
+ /usr/libexec/PlistBuddy -c 'Add :LSMinimumSystemVersion string 13.0' "$EXPORT_APP/Contents/Info.plist"
+ cp "$F/notes-1.12.0.html" "$OUT/release-notes.html"
+ VZIP="$OUT/Hidden-Bar-v$VER-macos.zip"; cp "$F/payload.bin" "$VZIP"; ZIP_LEN="$(stat -f %z "$VZIP")"; ZIP_SIG="$SIG"
+ sed "s|length=\"2026759\"|length=\"$prior_len\"|" "$F/prior-1.xml" > "$T/prior-appcast.xml"
+ [ "${3:-}" != bad-version ] || sed -i '' 's|1.11.2<|../x<|' "$T/prior-appcast.xml"
+ if [ "${3:-}" = verify-ok ]; then helper() { if [ "$1" = verify ]; then return 0; fi; "$HELPER" "$@"; }; fi # the fixture cannot sign a prior zip
+ stage_appcast ) > "$d/stdout" 2>&1
+ echo $? > "$d/rc"
+}
+appcast_run key-differs "$(cat "$F/wrongkey.pub.b64")"
+prior_key_differs() { # the prior-zip branch ran and refused: the latest published app has another key
+ local o="$WORK/ac-key-differs/stdout"
+ [ "$(cat "$WORK/ac-key-differs/rc")" = 1 ] && grep -q 'Prior app key: FAIL: SUPublicEDKey differs' "$o" &&
+ ! grep -q 'Enclosure 1.11.2' "$o" && [ ! -e "$WORK/ac-key-differs/out/appcast.xml" ] && [ -f "$WORK/ac-key-differs/out/appcast.xml.unverified" ]
+}
+t pubkey-differs-from-prior-fails prior_key_differs
+appcast_run key-same "$PINNED_PUBKEY"
+prior_key_same() { # positive control: the same branch accepts the pinned key and moves on to the next check
+ local o="$WORK/ac-key-same/stdout"
+ grep -q 'Prior app key: equals the pinned key' "$o" && ! grep -q 'Prior app key: FAIL' "$o" && grep -q 'Enclosure 1.11.2: FAIL' "$o"
+}
+t pubkey-equals-prior-passes prior_key_same
+appcast_run verified "$PINNED_PUBKEY" verify-ok
+appcast_published_after_checks() { # appcast.xml appears only once every check passed
+ local d="$WORK/ac-verified"
+ [ "$(cat "$d/rc")" = 0 ] && [ -f "$d/out/appcast.xml" ] && [ ! -e "$d/out/appcast.xml.unverified" ] ||
+ { echo "rc $(cat "$d/rc"); $(ls "$d/out" | tr '\n' ' ')"; return 1; }
+}
+t appcast-named-only-after-checks appcast_published_after_checks
+appcast_run bad-version "$PINNED_PUBKEY" bad-version
+unsafe_version() { # a prior item's shortVersionString never reaches a path or a download
+ local o="$WORK/ac-bad-version/stdout"
+ [ "$(cat "$WORK/ac-bad-version/rc")" = 1 ] && grep -q "FAIL: a prior item's shortVersionString is not" "$o" &&
+ ! grep -q 'Prior app key' "$o"
+}
+t appcast-unsafe-short-version-refused unsafe_version
+
+# main() with every stage that builds, signs or notarizes replaced by a marker stub, so only
+# the orchestration is real: the order of stages, the exit code and the report.
+main_run() { # case-name check_app-outcome(pass|fail) : rc, stdout and out/ under $WORK/main-
+ local d="$WORK/main-$1" outcome="$2"
+ mkdir -p "$d/tmp/trashed" "$d/marks"
+ ( export TMPDIR="$d/tmp"
+ FAILED=0; N=0; SKIPPED=""; DRAFT_NOTE=""; EDKEY="" # globals earlier cases left behind
+ stage_preflight() { PRE_STATE=stub; HEAD_SHA=abc1234; TREE_NOTE="stubbed"; row "Preflight" "stub" "stubbed"; }
+ stage_tests() { row "Tests" "stub" "SKIPPED (stub)"; }
+ stage_build() { mkdir -p "$OUT/export"; cp -R "$APP_NONE" "$OUT/export/"; : > "$d/marks/build"; }
+ stage_notarize() { : > "$d/marks/notarize"; return 0; }
+ stage_zips() { : > "$d/marks/zips"; return 0; }
+ stage_sign() { : > "$d/marks/sign"; return 0; }
+ stage_appcast() { : > "$d/marks/appcast"; return 0; }
+ stage_smoke() { : > "$d/marks/smoke"; return 0; }
+ if [ "$outcome" = pass ]; then check_app() { row "App checks" "stub" "ok"; return 0; }; fi
+ main --notes "$d/notes.html" --out "$d/out" ) > "$d/stdout" 2>&1
+ echo $? > "$d/rc"
+}
+main_run check-app-fails fail
+main_check_app_fails() {
+ local d="$WORK/main-check-app-fails" c
+ c="$d/out/checks.md"
+ [ "$(cat "$d/rc")" = 1 ] && [ -f "$d/marks/build" ] && grep -q '^| [0-9]* | Signature: identity, timestamp, runtime | .* | FAIL: ' "$c" &&
+ grep -q '^Result: FAILED (exit 1)' "$c" && ! grep -q 'Result: every check passed' "$c" &&
+ [ -z "$(ls "$d/marks" | grep -v '^build$')" ]
+}
+t main-check-app-failure-exits-1 main_check_app_fails
+main_run all-pass pass
+main_all_pass() { # positive control: the same harness exits 0 and runs every later stage when check_app passes
+ local d="$WORK/main-all-pass"
+ [ "$(cat "$d/rc")" = 0 ] && grep -q '^Result: every check passed' "$d/out/checks.md" &&
+ [ "$(ls "$d/marks" | tr '\n' ' ')" = "appcast build notarize sign smoke zips " ]
+}
+t main-all-stages-pass-exits-0 main_all_pass
+
+# ---- report -----------------------------------------------------------------------------
+
+report_shape() {
+ local o="$WORK/report"; mkdir -p "$o"
+ OUT="$o"; VER=1.12.0; BUILD=19; HEAD_SHA=abc1234; TREE_NOTE="clean"; PRIOR_TAG=v1.11.2; : > "$ROWS_FILE"; N=0; FAILED=0
+ row "Versions" "grep" "1.12.0 (19)"
+ write_report 0 >/dev/null && local c="$o/checks.md" &&
+ head -1 "$c" | grep -qx '# Hidden Bar v1.12.0 release checks' && grep -q 'Nothing was tagged or uploaded.' "$c" &&
+ grep -qx '| # | Check | Command | Result |' "$c" && grep -q '^| 2 | No key material left | .* | 0 hits |$' "$c" &&
+ grep -qx '## Notes for the publish step' "$c" && grep -q 'gh release upload v1.12.0 Hidden-Bar-v1.12.0-macos.zip Hidden-Bar-macos.zip appcast.xml' "$c"
+ local rc=$?; OUT=""; return $rc
+}
+t report-shape report_shape
+report_branch() { # the branch line comes from the repo root, whatever the working directory
+ local o="$WORK/report-cwd" want
+ want="$(command git -C "$ROOT" rev-parse --abbrev-ref HEAD)"; mkdir -p "$o"
+ ( cd "$WORK" && OUT="$o"; VER=1.12.0; HEAD_SHA=abc1234; : > "$ROWS_FILE"; write_report 0 >/dev/null )
+ grep -qF "branch \`$want\`," "$o/checks.md"
+}
+t report-branch-from-repo-root report_branch
+
+echo
+echo "test-release: $PASSED passed, $FAILED_N failed, $SKIPPED_N skipped${FAILED_NAMES:+ (failed:$FAILED_NAMES)}"
+[ "$FAILED_N" = 0 ]