scripts/release-mac.sh

114 lines · 5738 bytes · executable

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