scripts/release-mac.sh
122 lines · 6246 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; }
31! grep -q 'publicKey = .*// placeholder' Sources/OrgApp/LicenseKey.swift ||
32 { echo "Run packaging/license-issuer/keygen.sh first: the license public key is a placeholder." >&2; exit 1; }
33# The Sparkle public key; its private half is in the release Mac's login keychain (generate_keys).
34export ORGSTAR_ED_PUBLIC_KEY="${ORGSTAR_ED_PUBLIC_KEY:-StvsRDaDoGd4S/G66l7XHAcd3KPlpJlu0Gsv9GemsSo=}"
35notes="Universal (Apple silicon and Intel), macOS 26 or later. Notarized."
36for file in "${ORGSTAR_NOTES:-}" "${ORGSTAR_RELEASE_NOTES:-}"; do
37 [ -z "$file" ] || [ -f "$file" ] || { echo "No notes file $file." >&2; exit 1; }
38done
39
40if [ "$publish" != 0 ]; then
41 [ -z "$(git status --porcelain)" ] || { echo "The working tree has changes." >&2; exit 1; }
42 [ "$(git branch --show-current)" = main ] || { echo "Release from main." >&2; exit 1; }
43fi
44
45# The build number counts commits, so each release's is higher than the last's.
46build="$(git rev-list --count HEAD)"
47ORGSTAR_SIGN="$sign" ORGSTAR_ARCHS="arm64 x86_64" sh scripts/build-app.sh "$version" "$build" > /dev/null
48app=".build/app/orgstar.app"
49codesign --verify --strict --deep "$app"
50
51out=".build/release"
52dmg="$out/orgstar-$version.dmg"
53rm -rf "${out:?}"
54mkdir -p "$out/dmg"
55ditto "$app" "$out/dmg/orgstar.app"
56ln -s /Applications "$out/dmg/Applications"
57hdiutil create -quiet -volname "orgstar $version" -srcfolder "$out/dmg" -format UDZO -fs HFS+ "$dmg"
58codesign --sign "$sign" --timestamp "$dmg"
59
60# Notarizing the DMG covers the app inside it; stapling both lets them open offline.
61xcrun notarytool submit "$dmg" --keychain-profile "$notary" --wait
62xcrun stapler staple "$dmg"
63xcrun stapler staple "$app"
64spctl --assess --type open --context context:primary-signature -v "$dmg"
65sha="$(shasum -a 256 "$dmg" | cut -d' ' -f1)"
66echo "$dmg $sha"
67if [ -n "${ORGSTAR_NOTES:-}" ]; then
68 { cat "$ORGSTAR_NOTES"; printf '<p>%s</p>\n' "$notes"; } > "$out/notes.txt"
69else
70 printf '%s\n' "$notes" > "$out/notes.txt"
71fi
72
73if [ "$publish" = 0 ]; then
74 # The appcast entry on a copy, so a dry run shows the signature.
75 cp docs/manual/appcast.xml "$out/appcast.xml"
76 sh scripts/appcast-add.sh "$out/appcast.xml" "$version" "$build" "$dmg" "$out/notes.txt"
77 exit 0
78fi
79
80git tag -s "$tag" -m "orgstar $version"
81git push origin "$tag"
82if [ -n "${ORGSTAR_RELEASE_NOTES:-}" ]; then
83 { cat "$ORGSTAR_RELEASE_NOTES"; printf '\n%s\n' "$notes"; } | gitbay release create krz/orgstar "$tag" --title "orgstar $version" --file -
84else
85 gitbay release create krz/orgstar "$tag" --title "orgstar $version" --notes "$notes"
86fi
87gitbay release asset add krz/orgstar "$tag" "orgstar-$version.dmg" < "$dmg"
88# The public download, which the appcast and the cask point at.
89rsync -a "$dmg" "$files/"
90
91# The appcast goes in through a merge request, as every change to main does, after the DMG
92# it points at is up; then the manual, which serves it, is published.
93branch="appcast-$version"
94git switch -q -c "$branch"
95sh scripts/appcast-add.sh docs/manual/appcast.xml "$version" "$build" "$dmg" "$out/notes.txt"
96git add docs/manual/appcast.xml
97git commit -q -m "Appcast for $version"
98git push -q -u origin "$branch"
99mr="$(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')"
100gitbay mr merge "$mr" --strategy ff
101git switch -q main
102git pull -q --ff-only
103git branch -d "$branch"
104git push -q origin --delete "$branch"
105sh scripts/publish-docs.sh
106
107# The cask goes in through a merge request, as every change to the tap's main does.
108branch="orgstar-$version"
109git -C "$tap" switch -q main
110git -C "$tap" pull -q --ff-only
111git -C "$tap" switch -q -c "$branch"
112sed -e "s/@VERSION@/$version/" -e "s/@SHA256@/$sha/" packaging/orgstar.rb > "$tap/Casks/orgstar.rb"
113git -C "$tap" add Casks/orgstar.rb
114git -C "$tap" commit -q -m "orgstar $version"
115git -C "$tap" push -q -u origin "$branch"
116mr="$(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')"
117(cd "$tap" && gitbay mr merge "$mr" --strategy ff)
118git -C "$tap" switch -q main
119git -C "$tap" pull -q --ff-only
120git -C "$tap" branch -d "$branch"
121git -C "$tap" push -q origin --delete "$branch"
122echo "Released $tag; cask merged in krz/homebrew-tap!$mr"