docs/plans/2026-10-10-sparkle-updates.md

v1.1.0
orgstar/docs/plans/2026-10-10-sparkle-updates.md rendered · source · history · blame · raw

193 lines · 12340 bytes

  1# Sparkle Updates Implementation Plan
  2
  3> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
  4
  5**Goal:** A Mac build installed from the DMG or the cask learns about the next release and installs it, with Check for Updates… in the app menu and an automatic-checks setting.
  6
  7**Architecture:** Sparkle 2 from its SwiftPM package, linked into the `Orgstar` target and copied into `Contents/Frameworks` by `scripts/build-app.sh`. The appcast is a static file in the manual's site, `docs/manual/appcast.xml`, served at `https://krz.gitbay.site/orgstar/appcast.xml` by `scripts/publish-docs.sh`; `scripts/release-mac.sh` signs the DMG with the EdDSA key, prepends the release to the appcast through a merge request on main, and publishes the manual. Nothing is served from anywhere new.
  8
  9**Tech Stack:** Sparkle 2.7 (SPM binary target), `generate_keys` and `sign_update` from the package's `bin`, `xmllint`.
 10
 11**Spec:** `docs/design.md`, Decisions ▸ Distribution ("Direct download (notarized, Sparkle) and Homebrew cask").
 12
 13## Global constraints
 14
 15- The app stays unsandboxed; Sparkle's XPC services are not used.
 16- Dev builds (`ORGSTAR_SIGN` unset, ad hoc) carry no feed URL, so they never check.
 17- Nothing is pushed to main directly: the appcast change goes in through a merge request, as the cask does.
 18- Release notes in the appcast are the same text `release-mac.sh` gives `gitbay release create --notes`.
 19
 20## Decisions
 21
 22| Question | Decision | Reason |
 23| --- | --- | --- |
 24| Feed host | The `pages` branch, beside the manual | Already published by a script; a fixed URL, unlike release assets which are per tag |
 25| Version Sparkle compares | `CFBundleVersion`, the commit count `release-mac.sh` already sets | Monotonic across releases; `sparkle:shortVersionString` shows the semver |
 26| Automatic checks | Sparkle's own first-run prompt, no `SUEnableAutomaticChecks` key | Asking once is the Sparkle default and needs no UI of our own |
 27| Delta updates | No | One DMG per release is enough at this size |
 28| Private key | The login keychain of the release Mac, where `generate_keys` puts it | `sign_update` finds it there; nothing in the repo |
 29
 30## Review focus
 31
 32- A dev build must not offer updates: without `SUFeedURL` the updater must not start, and the menu item must be disabled, not crash.
 33- The appcast must still validate after many releases: entries are prepended, never rewritten, and `xmllint` runs before the commit.
 34- `release-mac.sh` must upload the DMG before publishing the appcast, or a client can read an entry whose enclosure 404s.
 35- The `pages` publish replaces the whole branch, so the appcast has to live in `docs/manual`, not be written onto `pages` by hand.
 36- Signing: `codesign --verify --strict --deep` on the app must still pass with the framework inside, or notarization fails late.
 37
 38---
 39
 40### Task 1: Link Sparkle and bundle the framework
 41
 42**Files:**
 43- Modify: `Package.swift` (dependencies; `Orgstar` target)
 44- Modify: `scripts/build-app.sh`
 45
 46- [x] Add the dependency and the product to the app target:
 47
 48```swift
 49.package(url: "https://github.com/sparkle-project/Sparkle", from: "2.7.0"),
 50// ...
 51.executableTarget(name: "Orgstar", dependencies: ["OrgApp", "OrgEditorAppKit", "OrgHighlight", .product(name: "Sparkle", package: "Sparkle")]),
 52```
 53
 54- [x] In `build-app.sh`, after copying the binary: copy the framework from the SwiftPM artifact and give the executable an rpath to it.
 55
 56```sh
 57sparkle="$(find .build/artifacts -path '*Sparkle.xcframework/macos-*/Sparkle.framework' -maxdepth 6 | head -1)"
 58[ -n "$sparkle" ] || { echo "Sparkle.framework not in .build/artifacts; run swift build first." >&2; exit 1; }
 59mkdir -p "$app/Contents/Frameworks"
 60ditto "$sparkle" "$app/Contents/Frameworks/Sparkle.framework"
 61install_name_tool -add_rpath @executable_path/../Frameworks "$app/Contents/MacOS/Orgstar"
 62```
 63
 64- [x] Sign Sparkle's inner pieces before the app, with the same identity and flags (Sparkle's documented order), inside the final signing block:
 65
 66```sh
 67fw="$app/Contents/Frameworks/Sparkle.framework/Versions/B"
 68for item in "$fw/XPCServices/Installer.xpc" "$fw/XPCServices/Downloader.xpc" "$fw/Autoupdate" "$fw/Updater.app" "$app/Contents/Frameworks/Sparkle.framework"; do
 69    codesign --force --sign "$sign" $sign_flags "$item"
 70done
 71```
 72
 73- [x] Add `SUFeedURL` and `SUPublicEDKey` to the generated Info.plist only when `sign` is not `-`:
 74
 75```sh
 76if [ "$sign" != "-" ]; then
 77    feed_keys="<key>SUFeedURL</key><string>https://krz.gitbay.site/orgstar/appcast.xml</string><key>SUPublicEDKey</key><string>${ORGSTAR_ED_PUBLIC_KEY:?set ORGSTAR_ED_PUBLIC_KEY}</string>"
 78else
 79    feed_keys=""
 80fi
 81```
 82
 83and `${feed_keys}` in the plist heredoc after `LSMinimumSystemVersion`. The public key is pasted into `scripts/release-mac.sh` as a default for `ORGSTAR_ED_PUBLIC_KEY` once Task 3 generates it.
 84
 85- [x] Verify: `sh scripts/build-app.sh`, then `otool -l .build/app/orgstar.app/Contents/MacOS/Orgstar | grep -A2 LC_RPATH` shows the Frameworks rpath, `open .build/app/orgstar.app` launches, and `codesign --verify --strict --deep .build/app/orgstar.app` passes.
 86- [x] Commit "Link Sparkle and bundle its framework".
 87
 88### Task 2: Check for Updates… and the setting
 89
 90**Files:**
 91- Modify: `Sources/Orgstar/OrgstarApp.swift` (`AppDelegate` at line 151; `.commands`)
 92- Modify: `Sources/Orgstar/OrgstarApp.swift` (`SettingsView`, the General tab at line 551)
 93
 94- [x] In the app delegate, one controller for the process:
 95
 96```swift
 97import Sparkle
 98let updater = SPUStandardUpdaterController(startingUpdater: true, updaterDelegate: nil, userDriverDelegate: nil)
 99```
100
101Without a feed URL (dev builds) the updater logs that it can't start and `canCheckForUpdates` stays false; that is the intended dev behaviour.
102
103- [x] Menu item after About, following Sparkle's SwiftUI sample:
104
105```swift
106CommandGroup(after: .appInfo) {
107    Button("Check for Updates…") { delegate.updater.updater.checkForUpdates() }
108        .disabled(!delegate.updater.updater.canCheckForUpdates)
109}
110```
111
112`canCheckForUpdates` is KVO-observable; wrap the updater in a small `@Observable` holder that observes it, so the button enables once the updater starts.
113
114- [x] Settings ▸ General: a toggle bound to `updater.automaticallyChecksForUpdates`, shown only when `canCheckForUpdates` is true, labelled "Check for updates automatically".
115- [x] Test by hand: a dev build shows the item disabled and no toggle; a `ORGSTAR_SIGN=<Developer ID>` build with a local feed (Task 4) shows both.
116- [x] Commit "Check for Updates… and automatic checks".
117
118### Task 3: Keys and the appcast file
119
120**Files:**
121- Create: `docs/manual/appcast.xml`
122- Create: `scripts/appcast-add.sh`
123- Modify: `docs/manual/orgo.toml` only if orgo needs the file listed to copy it (check with `scripts/publish-docs.sh --dry-run` and `ls` of the built site; `favicon.svg` and `style.css` are copied today, so it should not)
124
125- [x] Generate the key pair once on the release Mac (done 2026-10-11; the public key is `release-mac.sh`'s default): `"$(find .build/artifacts -name generate_keys -type f | head -1)"`. The private key goes to the login keychain; paste the printed public key as the `ORGSTAR_ED_PUBLIC_KEY` default in `release-mac.sh`.
126- [x] The empty appcast:
127
128```xml
129<?xml version="1.0" encoding="utf-8"?>
130<rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle">
131  <channel>
132    <title>orgstar</title>
133    <link>https://gitbay.org/krz/orgstar</link>
134  </channel>
135</rss>
136```
137
138- [x] `scripts/appcast-add.sh <appcast> <version> <build> <dmg> <notes-file>`: runs `sign_update "$dmg"` (found under `.build/artifacts` like `generate_keys`), which prints `sparkle:edSignature="…" length="…"`, and inserts after `<link>…</link>` in the channel:
139
140```xml
141    <item>
142      <title>orgstar VERSION</title>
143      <link>https://gitbay.org/krz/orgstar/releases/tag/vVERSION</link>
144      <sparkle:version>BUILD</sparkle:version>
145      <sparkle:shortVersionString>VERSION</sparkle:shortVersionString>
146      <sparkle:minimumSystemVersion>26.0</sparkle:minimumSystemVersion>
147      <pubDate>RFC 2822 date</pubDate>
148      <description><![CDATA[NOTES]]></description>
149      <enclosure url="https://gitbay.org/krz/orgstar/releases/download/vVERSION/orgstar-VERSION.dmg" type="application/octet-stream" sparkle:edSignature="…" length="…"/>
150    </item>
151```
152
153Insertion is a `sed`/`awk` on the first `</link>` after `<channel>`; the script refuses a version already present (`grep -q "<sparkle:shortVersionString>$version<"`) and ends with `xmllint --noout "$appcast"`.
154
155- [x] Verify with a throwaway copy: `scripts/appcast-add.sh /tmp/a.xml 0.2.0 365 .build/release/orgstar-0.2.0.dmg notes.txt` twice; the second run exits non-zero naming the version.
156- [x] Commit "Appcast file and appcast-add.sh".
157
158### Task 4: Release script and cask
159
160**Files:**
161- Modify: `scripts/release-mac.sh`
162- Modify: `packaging/orgstar.rb`
163
164- [x] After `gitbay release asset add` and before the tap section, add the appcast entry through a merge request, mirroring the tap block:
165
166```sh
167notes="Universal (Apple silicon and Intel), macOS 26 or later. Notarized."
168printf '%s\n' "$notes" > "$out/notes.txt"
169branch="appcast-$version"
170git switch -q -c "$branch"
171sh scripts/appcast-add.sh docs/manual/appcast.xml "$version" "$build" "$dmg" "$out/notes.txt"
172git add docs/manual/appcast.xml
173git commit -q -m "Appcast for $version"
174git push -q -u origin "$branch"
175mr="$(gitbay mr create --source "$branch" --target main --title "Appcast for $version" --body "Sparkle entry for orgstar $version." --json | sed -n 's/.*"number":\([0-9]*\).*/\1/p')"
176gitbay mr merge "$mr" --strategy ff
177git switch -q main && git pull -q --ff-only && git branch -d "$branch" && git push -q origin --delete "$branch"
178sh scripts/publish-docs.sh
179```
180
181`$notes` replaces the literal string already passed to `gitbay release create`. With `ORGSTAR_PUBLISH=0` the script runs `appcast-add.sh` on a copy under `$out` and prints the entry instead, so a dry run shows the signature.
182
183- [x] Cask: add `auto_updates true` after `desc`, so `brew upgrade` leaves updating to the app.
184- [ ] End-to-end check before the first real release (needs a Developer ID build and the key): build with a Developer ID, point a running copy at a local appcast with `defaults write sh.krz.orgstar SUFeedURL file:///tmp/a.xml` (Sparkle reads the feed from user defaults ahead of Info.plist), Check for Updates… offers the entry and installs the DMG; then `defaults delete sh.krz.orgstar SUFeedURL`.
185- [x] Manual: `docs/manual/guide/01-files-and-folders.org` or `install.org` gets a paragraph on updates (menu item, the setting, that the cask has `auto_updates`).
186- [x] Commit "Release script writes the appcast; cask auto_updates".
187
188## As built
189
190- Sparkle 2.10 from its SwiftPM package. `scripts/build-app.sh` copies the framework into `Contents/Frameworks`, adds the rpath, and for signed builds writes `SUFeedURL` and `SUPublicEDKey` (from `ORGSTAR_ED_PUBLIC_KEY`) into the Info.plist; a dev build has neither, so `Updates.start()` doesn't start the updater and Check for Updates… stays disabled.
191- `Sources/Orgstar/Updates.swift` holds the `SPUStandardUpdaterController`, `canCheck` through Sparkle's KVO publisher, and the automatic-checks setting, shown in Settings ▸ General only when the updater runs.
192- `scripts/appcast-add.sh` signs the DMG with `sign_update` and prepends the item; `SIGN_UPDATE` names another signer for a dry run. `scripts/release-mac.sh` runs it on a copy with `ORGSTAR_PUBLISH=0`, and for real after the DMG upload, through a merge request, then publishes the manual, which carries `docs/manual/appcast.xml`.
193- Checked: the dev bundle launches with the framework and passes `codesign --verify --strict --deep`; the appcast script with a stub signer, twice (the second run refuses the version); `release-mac.sh` parses. With the key generated: a Developer ID build carries `SUFeedURL` and `SUPublicEDKey`, verifies strictly with Sparkle signed inside it, and `sign_update` signs a DMG from the keychain, `--verify` accepts the signature, and `appcast-add.sh` writes the real entry. Not checked: the update dialog itself, which needs a second build to offer.