scripts/release-mac.sh

70 lines · 3387 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
 9set -eu
10
11cd "$(dirname "$0")/.."
12version="${1:?usage: scripts/release-mac.sh <version>}"
13tag="v$version"
14notary="${ORGSTAR_NOTARY:-orgstar}"
15tap="${ORGSTAR_TAP:-../homebrew-tap}"
16publish="${ORGSTAR_PUBLISH:-1}"
17sign="${ORGSTAR_SIGN:-$(security find-identity -v -p codesigning | sed -n 's/.*"\(Developer ID Application: .*\)"/\1/p' | head -1)}"
18[ -n "$sign" ] || { echo "No Developer ID Application identity in the keychain." >&2; exit 1; }
19
20if [ "$publish" != 0 ]; then
21    [ -z "$(git status --porcelain)" ] || { echo "The working tree has changes." >&2; exit 1; }
22    [ "$(git branch --show-current)" = main ] || { echo "Release from main." >&2; exit 1; }
23fi
24
25# The build number counts commits, so each release's is higher than the last's.
26build="$(git rev-list --count HEAD)"
27ORGSTAR_SIGN="$sign" ORGSTAR_ARCHS="arm64 x86_64" sh scripts/build-app.sh "$version" "$build" > /dev/null
28app=".build/app/orgstar.app"
29codesign --verify --strict --deep "$app"
30
31out=".build/release"
32dmg="$out/orgstar-$version.dmg"
33rm -rf "${out:?}"
34mkdir -p "$out/dmg"
35ditto "$app" "$out/dmg/orgstar.app"
36ln -s /Applications "$out/dmg/Applications"
37hdiutil create -quiet -volname "orgstar $version" -srcfolder "$out/dmg" -format UDZO -fs HFS+ "$dmg"
38codesign --sign "$sign" --timestamp "$dmg"
39
40# Notarizing the DMG covers the app inside it; stapling both lets them open offline.
41xcrun notarytool submit "$dmg" --keychain-profile "$notary" --wait
42xcrun stapler staple "$dmg"
43xcrun stapler staple "$app"
44spctl --assess --type open --context context:primary-signature -v "$dmg"
45sha="$(shasum -a 256 "$dmg" | cut -d' ' -f1)"
46echo "$dmg $sha"
47
48[ "$publish" != 0 ] || exit 0
49
50git tag -s "$tag" -m "orgstar $version"
51git push origin "$tag"
52gitbay release create krz/orgstar "$tag" --title "orgstar $version" --notes "Universal (Apple silicon and Intel), macOS 26 or later. Notarized."
53gitbay release asset add krz/orgstar "$tag" "orgstar-$version.dmg" < "$dmg"
54
55# The cask goes in through a merge request, as every change to the tap's main does.
56branch="orgstar-$version"
57git -C "$tap" switch -q main
58git -C "$tap" pull -q --ff-only
59git -C "$tap" switch -q -c "$branch"
60sed -e "s/@VERSION@/$version/" -e "s/@SHA256@/$sha/" packaging/orgstar.rb > "$tap/Casks/orgstar.rb"
61git -C "$tap" add Casks/orgstar.rb
62git -C "$tap" commit -q -m "orgstar $version"
63git -C "$tap" push -q -u origin "$branch"
64mr="$(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')"
65(cd "$tap" && gitbay mr merge "$mr" --strategy ff)
66git -C "$tap" switch -q main
67git -C "$tap" pull -q --ff-only
68git -C "$tap" branch -d "$branch"
69git -C "$tap" push -q origin --delete "$branch"
70echo "Released $tag; cask merged in krz/homebrew-tap!$mr"