scripts/release-mac.sh

d85099bc95bf1766aee990d94671dacda0c0686e
orgstar/scripts/release-mac.sh history · blame · raw

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