scripts/release-mac.sh

design-themes-widgets
orgstar/scripts/release-mac.sh history · blame · raw

126 lines · 6530 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
 45ORGSTAR_GATES=1 swift test -c release --filter GateTests || { echo "A performance gate failed." >&2; exit 1; }
 46
 47# The build number counts commits, so each release's is higher than the last's.
 48build="$(git rev-list --count HEAD)"
 49ORGSTAR_SIGN="$sign" ORGSTAR_ARCHS="arm64 x86_64" sh scripts/build-app.sh "$version" "$build" > /dev/null
 50app=".build/app/orgstar.app"
 51codesign --verify --strict --deep "$app"
 52
 53out=".build/release"
 54dmg="$out/orgstar-$version.dmg"
 55rm -rf "${out:?}"
 56mkdir -p "$out/dmg"
 57# The debug symbols of the stripped executables, for symbolicating crash reports; not uploaded.
 58ditto -c -k --keepParent .build/app/dSYMs "$out/orgstar-$version-dSYMs.zip"
 59ditto "$app" "$out/dmg/orgstar.app"
 60ln -s /Applications "$out/dmg/Applications"
 61hdiutil create -quiet -volname "orgstar $version" -srcfolder "$out/dmg" -format UDZO -fs HFS+ "$dmg"
 62codesign --sign "$sign" --timestamp "$dmg"
 63
 64# Notarizing the DMG covers the app inside it; stapling both lets them open offline.
 65xcrun notarytool submit "$dmg" --keychain-profile "$notary" --wait
 66xcrun stapler staple "$dmg"
 67xcrun stapler staple "$app"
 68spctl --assess --type open --context context:primary-signature -v "$dmg"
 69sha="$(shasum -a 256 "$dmg" | cut -d' ' -f1)"
 70echo "$dmg $sha"
 71if [ -n "${ORGSTAR_NOTES:-}" ]; then
 72    { cat "$ORGSTAR_NOTES"; printf '<p>%s</p>\n' "$notes"; } > "$out/notes.txt"
 73else
 74    printf '%s\n' "$notes" > "$out/notes.txt"
 75fi
 76
 77if [ "$publish" = 0 ]; then
 78    # The appcast entry on a copy, so a dry run shows the signature.
 79    cp docs/manual/appcast.xml "$out/appcast.xml"
 80    sh scripts/appcast-add.sh "$out/appcast.xml" "$version" "$build" "$dmg" "$out/notes.txt"
 81    exit 0
 82fi
 83
 84git tag -s "$tag" -m "orgstar $version"
 85git push origin "$tag"
 86if [ -n "${ORGSTAR_RELEASE_NOTES:-}" ]; then
 87    { cat "$ORGSTAR_RELEASE_NOTES"; printf '\n%s\n' "$notes"; } | gitbay release create krz/orgstar "$tag" --title "orgstar $version" --file -
 88else
 89    gitbay release create krz/orgstar "$tag" --title "orgstar $version" --notes "$notes"
 90fi
 91gitbay release asset add krz/orgstar "$tag" "orgstar-$version.dmg" < "$dmg"
 92# The public download, which the appcast and the cask point at.
 93rsync -a "$dmg" "$files/"
 94
 95# The appcast goes in through a merge request, as every change to main does, after the DMG
 96# it points at is up; then the manual, which serves it, is published.
 97branch="appcast-$version"
 98git switch -q -c "$branch"
 99sh scripts/appcast-add.sh docs/manual/appcast.xml "$version" "$build" "$dmg" "$out/notes.txt"
100git add docs/manual/appcast.xml
101git commit -q -m "Appcast for $version"
102git push -q -u origin "$branch"
103mr="$(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')"
104gitbay mr merge "$mr" --strategy ff
105git switch -q main
106git pull -q --ff-only
107git branch -d "$branch"
108git push -q origin --delete "$branch"
109sh scripts/publish-docs.sh
110
111# The cask goes in through a merge request, as every change to the tap's main does.
112branch="orgstar-$version"
113git -C "$tap" switch -q main
114git -C "$tap" pull -q --ff-only
115git -C "$tap" switch -q -c "$branch"
116sed -e "s/@VERSION@/$version/" -e "s/@SHA256@/$sha/" packaging/orgstar.rb > "$tap/Casks/orgstar.rb"
117git -C "$tap" add Casks/orgstar.rb
118git -C "$tap" commit -q -m "orgstar $version"
119git -C "$tap" push -q -u origin "$branch"
120mr="$(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')"
121(cd "$tap" && gitbay mr merge "$mr" --strategy ff)
122git -C "$tap" switch -q main
123git -C "$tap" pull -q --ff-only
124git -C "$tap" branch -d "$branch"
125git -C "$tap" push -q origin --delete "$branch"
126echo "Released $tag; cask merged in krz/homebrew-tap!$mr"