scripts/release-mac.sh
128 lines · 6763 bytes · executable
1#!/bin/sh
2# Builds, signs, notarizes and publishes a Mac release: a universal orgstar.app in a DMG,
3# copied to files.krz.sh/orgstar/ (and the tag's gitbay release), and the cask in
4# krz/homebrew-tap updated.
5# Usage: scripts/release-mac.sh <version> e.g. 0.2.0, for the tag v0.2.0 on HEAD
6# ORGSTAR_SIGN Developer ID Application identity (default: the keychain's only one)
7# ORGSTAR_NOTARY notarytool keychain profile (default: orgstar)
8# ORGSTAR_TAP the homebrew-tap checkout (default: ../homebrew-tap)
9# ORGSTAR_FILES rsync destination served at https://files.krz.sh/orgstar/
10# (default: homelab:/var/www/files/orgstar)
11# ORGSTAR_PUBLISH 0 builds and notarizes without tagging, uploading or touching the tap
12# ORGSTAR_NOTES an HTML file of release notes for the appcast entry, which Sparkle's
13# update window shows; the platform line is added after it
14# ORGSTAR_RELEASE_NOTES a Markdown file of release notes for the gitbay release
15# ORGSTAR_ED_PUBLIC_KEY the Sparkle public key (default: the one whose private half is in the
16# release Mac's login keychain, from generate_keys); passed on to build-app.sh
17#
18# Updates: after the DMG is uploaded, the release goes into docs/manual/appcast.xml through a
19# merge request on main, and the manual is published, which serves the appcast.
20set -eu
21
22cd "$(dirname "$0")/.."
23version="${1:?usage: scripts/release-mac.sh <version>}"
24tag="v$version"
25notary="${ORGSTAR_NOTARY:-orgstar}"
26tap="${ORGSTAR_TAP:-../homebrew-tap}"
27files="${ORGSTAR_FILES:-homelab:/var/www/files/orgstar}"
28publish="${ORGSTAR_PUBLISH:-1}"
29sign="${ORGSTAR_SIGN:-$(security find-identity -v -p codesigning | sed -n 's/.*"\(Developer ID Application: .*\)"/\1/p' | head -1)}"
30[ -n "$sign" ] || { echo "No Developer ID Application identity in the keychain." >&2; exit 1; }
31profile="${ORGSTAR_PROFILE:-$HOME/Library/MobileDevice/Provisioning Profiles/orgstar_dev_id.provisionprofile}"
32[ -f "$profile" ] || { echo "No Developer ID provisioning profile at $profile." >&2; exit 1; }
33! grep -q 'publicKey = .*// placeholder' Sources/OrgApp/LicenseKey.swift ||
34 { echo "Run packaging/license-issuer/keygen.sh first: the license public key is a placeholder." >&2; exit 1; }
35# The Sparkle public key; its private half is in the release Mac's login keychain (generate_keys).
36export ORGSTAR_ED_PUBLIC_KEY="${ORGSTAR_ED_PUBLIC_KEY:-StvsRDaDoGd4S/G66l7XHAcd3KPlpJlu0Gsv9GemsSo=}"
37notes="Universal (Apple silicon and Intel), macOS 26 or later. Notarized."
38for file in "${ORGSTAR_NOTES:-}" "${ORGSTAR_RELEASE_NOTES:-}"; do
39 [ -z "$file" ] || [ -f "$file" ] || { echo "No notes file $file." >&2; exit 1; }
40done
41
42if [ "$publish" != 0 ]; then
43 [ -z "$(git status --porcelain)" ] || { echo "The working tree has changes." >&2; exit 1; }
44 [ "$(git branch --show-current)" = main ] || { echo "Release from main." >&2; exit 1; }
45fi
46
47ORGSTAR_GATES=1 swift test -c release --filter GateTests || { echo "A performance gate failed." >&2; exit 1; }
48
49# The build number counts commits, so each release's is higher than the last's.
50build="$(git rev-list --count HEAD)"
51ORGSTAR_SIGN="$sign" ORGSTAR_PROFILE="$profile" ORGSTAR_ARCHS="arm64 x86_64" sh scripts/build-app.sh "$version" "$build" > /dev/null
52app=".build/app/orgstar.app"
53codesign --verify --strict --deep "$app"
54
55out=".build/release"
56dmg="$out/orgstar-$version.dmg"
57rm -rf "${out:?}"
58mkdir -p "$out/dmg"
59# The debug symbols of the stripped executables, for symbolicating crash reports; not uploaded.
60ditto -c -k --keepParent .build/app/dSYMs "$out/orgstar-$version-dSYMs.zip"
61ditto "$app" "$out/dmg/orgstar.app"
62ln -s /Applications "$out/dmg/Applications"
63hdiutil create -quiet -volname "orgstar $version" -srcfolder "$out/dmg" -format UDZO -fs HFS+ "$dmg"
64codesign --sign "$sign" --timestamp "$dmg"
65
66# Notarizing the DMG covers the app inside it; stapling both lets them open offline.
67xcrun notarytool submit "$dmg" --keychain-profile "$notary" --wait
68xcrun stapler staple "$dmg"
69xcrun stapler staple "$app"
70spctl --assess --type open --context context:primary-signature -v "$dmg"
71sha="$(shasum -a 256 "$dmg" | cut -d' ' -f1)"
72echo "$dmg $sha"
73if [ -n "${ORGSTAR_NOTES:-}" ]; then
74 { cat "$ORGSTAR_NOTES"; printf '<p>%s</p>\n' "$notes"; } > "$out/notes.txt"
75else
76 printf '%s\n' "$notes" > "$out/notes.txt"
77fi
78
79if [ "$publish" = 0 ]; then
80 # The appcast entry on a copy, so a dry run shows the signature.
81 cp docs/manual/appcast.xml "$out/appcast.xml"
82 sh scripts/appcast-add.sh "$out/appcast.xml" "$version" "$build" "$dmg" "$out/notes.txt"
83 exit 0
84fi
85
86git tag -s "$tag" -m "orgstar $version"
87git push origin "$tag"
88if [ -n "${ORGSTAR_RELEASE_NOTES:-}" ]; then
89 { cat "$ORGSTAR_RELEASE_NOTES"; printf '\n%s\n' "$notes"; } | gitbay release create krz/orgstar "$tag" --title "orgstar $version" --file -
90else
91 gitbay release create krz/orgstar "$tag" --title "orgstar $version" --notes "$notes"
92fi
93gitbay release asset add krz/orgstar "$tag" "orgstar-$version.dmg" < "$dmg"
94# The public download, which the appcast and the cask point at.
95rsync -a "$dmg" "$files/"
96
97# The appcast goes in through a merge request, as every change to main does, after the DMG
98# it points at is up; then the manual, which serves it, is published.
99branch="appcast-$version"
100git switch -q -c "$branch"
101sh scripts/appcast-add.sh docs/manual/appcast.xml "$version" "$build" "$dmg" "$out/notes.txt"
102git add docs/manual/appcast.xml
103git commit -q -m "Appcast for $version"
104git push -q -u origin "$branch"
105mr="$(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')"
106gitbay mr merge "$mr" --strategy ff
107git switch -q main
108git pull -q --ff-only
109git branch -d "$branch"
110git push -q origin --delete "$branch"
111sh scripts/publish-docs.sh
112
113# The cask goes in through a merge request, as every change to the tap's main does.
114branch="orgstar-$version"
115git -C "$tap" switch -q main
116git -C "$tap" pull -q --ff-only
117git -C "$tap" switch -q -c "$branch"
118sed -e "s/@VERSION@/$version/" -e "s/@SHA256@/$sha/" packaging/orgstar.rb > "$tap/Casks/orgstar.rb"
119git -C "$tap" add Casks/orgstar.rb
120git -C "$tap" commit -q -m "orgstar $version"
121git -C "$tap" push -q -u origin "$branch"
122mr="$(cd "$tap" && gitbay mr create --source "$branch" --target main --title "orgstar $version" --body "Cask for orgstar $version." --json | sed -n 's/.*"number":\([0-9]*\).*/\1/p')"
123(cd "$tap" && gitbay mr merge "$mr" --strategy ff)
124git -C "$tap" switch -q main
125git -C "$tap" pull -q --ff-only
126git -C "$tap" branch -d "$branch"
127git -C "$tap" push -q origin --delete "$branch"
128echo "Released $tag; cask merged in krz/homebrew-tap!$mr"