hex/.github/workflows/build-macos.yml

168 lines
7.7 KiB
YAML

name: Build macOS release
# Builds the release Hex.app from one exact commit, signs it with Anomaly's
# Developer ID (team 5NZ4Q7NXJ4), notarizes and staples the app and its DMG,
# and extends the live Sparkle appcast with an EdDSA-signed item for this
# version, all through scripts/release-app.sh prepare. Uploads one artifact,
# hex-macos-arm64: HEX-<version>-arm64.dmg, HEX-<version>-arm64.zip (the
# Sparkle archive, root HEX.app), and appcast.xml. Publishes nothing; the
# caller uploads the archives first and appcast.xml last.
on:
workflow_call:
inputs:
sha:
type: string
required: true
version:
type: string
required: true
download-base:
description: Origin the release is served from, e.g. https://downloads.hex.anoma.ly or its staging/<run> prefix
type: string
required: true
require-newer:
description: Refuse a build that is not newer than the appcast's (off only for staging rehearsals)
type: boolean
default: true
permissions:
contents: read
jobs:
build:
name: macOS arm64 (Developer ID)
runs-on: macos-26
environment: release
timeout-minutes: 120
env:
VOICE_CONTROL_TEAM_ID: 5NZ4Q7NXJ4
HEX_VERSION: ${{ inputs.version }}
HEX_RELEASE_BASE_URL: ${{ inputs.download-base }}
HEX_RELEASE_REQUIRE_NEWER: ${{ inputs.require-newer && '1' || '0' }}
LIVE_APPCAST: https://downloads.hex.anoma.ly/appcast.xml
steps:
- name: Require the signing secrets
env:
APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }}
APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
APPLE_API_KEY_PATH: ${{ secrets.APPLE_API_KEY_PATH }}
APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }}
APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
SPARKLE_ED_PRIVATE_KEY: ${{ secrets.SPARKLE_ED_PRIVATE_KEY }}
run: |
missing=
for name in APPLE_CERTIFICATE APPLE_CERTIFICATE_PASSWORD APPLE_API_KEY_PATH \
APPLE_API_KEY APPLE_API_ISSUER SPARKLE_ED_PRIVATE_KEY; do
eval "value=\${$name}"
[ -n "$value" ] || missing="$missing $name"
done
if [ -n "$missing" ]; then
echo "::error::The release environment lacks:$missing. See docs/plans/macos-signing.md."
exit 1
fi
- uses: actions/checkout@v7
with:
ref: ${{ inputs.sha }}
persist-credentials: false
- name: Check the version
run: |
actual=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')
if [ "$actual" != "$HEX_VERSION" ]; then
echo "::error::$(git rev-parse --short HEAD) is version $actual, not $HEX_VERSION."
exit 1
fi
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
key: signed-build
cache-on-failure: true
- uses: astral-sh/setup-uv@v6
- uses: oven-sh/setup-bun@v2
- name: Install the Metal toolchain
run: xcrun --sdk macosx metal --version || xcodebuild -downloadComponent MetalToolchain
- uses: apple-actions/import-codesign-certs@8f3fb608891dd2244cdab3d69cd68c0d37a7fe93 # v2.0.0
with:
keychain: build
p12-file-base64: ${{ secrets.APPLE_CERTIFICATE }}
p12-password: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
- name: Select the signing identity, notary key, Sparkle key, and appcast
env:
APPLE_API_KEY_PATH: ${{ secrets.APPLE_API_KEY_PATH }}
SPARKLE_ED_PRIVATE_KEY: ${{ secrets.SPARKLE_ED_PRIVATE_KEY }}
run: |
identity=$(security find-identity -v -p codesigning build.keychain \
| sed -n "s/.*\"\(Developer ID Application:.*($VOICE_CONTROL_TEAM_ID)\)\"/\1/p" | head -1)
if [ -z "$identity" ]; then
echo "::error::No Developer ID Application identity for team $VOICE_CONTROL_TEAM_ID in APPLE_CERTIFICATE."
exit 1
fi
(
umask 077
printf '%s\n' "$APPLE_API_KEY_PATH" > "$RUNNER_TEMP/notary-key.p8"
printf '%s\n' "$SPARKLE_ED_PRIVATE_KEY" > "$RUNNER_TEMP/sparkle-ed25519.key"
)
# A fresh staging prefix has no appcast yet; extend the live one.
appcast="$HEX_RELEASE_BASE_URL/appcast.xml"
if ! curl --fail --silent --head --location "$appcast" > /dev/null; then
appcast=$LIVE_APPCAST
fi
echo "Extending $appcast" >> "$GITHUB_STEP_SUMMARY"
{
echo "VOICE_CONTROL_CODESIGN_IDENTITY=$identity"
echo "HEX_NOTARY_KEY=$RUNNER_TEMP/notary-key.p8"
echo "HEX_SPARKLE_KEY_FILE=$RUNNER_TEMP/sparkle-ed25519.key"
echo "HEX_RELEASE_APPCAST_URL=$appcast"
} >> "$GITHUB_ENV"
- name: Build, sign, notarize, and sign the appcast
env:
HEX_NOTARY_KEY_ID: ${{ secrets.APPLE_API_KEY }}
HEX_NOTARY_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
run: |
scripts/setup.sh
scripts/release-app.sh prepare
- name: Remove the keys
if: always()
run: rm -f "$RUNNER_TEMP/notary-key.p8" "$RUNNER_TEMP/sparkle-ed25519.key"
- name: Check the prepared release
run: |
dmg="dist/HEX-$HEX_VERSION-arm64.dmg"
zip="dist/HEX-$HEX_VERSION-arm64.zip"
xcrun stapler validate "$dmg"
spctl --assess --type open --context context:primary-signature --verbose=2 "$dmg"
check=$(mktemp -d)
hdiutil attach -quiet -nobrowse -readonly -mountpoint "$check/dmg" "$dmg"
/usr/bin/ditto -x -k "$zip" "$check/update"
build=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleVersion' "$check/dmg/Hex.app/Contents/Info.plist")
scripts/validate-app.sh "$check/dmg/Hex.app" Hex.app "$HEX_VERSION" "$build"
scripts/validate-app.sh "$check/update/HEX.app" HEX.app "$HEX_VERSION" "$build"
xcrun stapler validate "$check/update/HEX.app"
spctl --assess --type execute --verbose=2 "$check/dmg/Hex.app"
diff -qr "$check/dmg/Hex.app" "$check/update/HEX.app"
scripts/smoke-macos-app.sh "$check/dmg/Hex.app"
# The new item must verify against the public key the app ships, or
# every installed Hex would reject the update.
uv run --no-project --with cryptography python3 - "$check/dmg/Hex.app/Contents/Info.plist" \
dist/updates/appcast.xml "$HEX_RELEASE_BASE_URL/releases/HEX-$HEX_VERSION-arm64.zip" "$zip" <<'EOF'
import base64, plistlib, sys, xml.etree.ElementTree as ET
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PublicKey
info, appcast, url, archive = sys.argv[1:]
sparkle = "{http://www.andymatuschak.org/xml-namespaces/sparkle}"
key = Ed25519PublicKey.from_public_bytes(
base64.b64decode(plistlib.load(open(info, "rb"))["SUPublicEDKey"]))
items = [e for e in ET.parse(appcast).iter("enclosure") if e.get("url") == url]
assert len(items) == 1, f"expected one enclosure for {url}, found {len(items)}"
data = open(archive, "rb").read()
assert int(items[0].get("length")) == len(data), "enclosure length mismatch"
key.verify(base64.b64decode(items[0].get(sparkle + "edSignature")), data)
print(f"{url} verifies against SUPublicEDKey")
EOF
hdiutil detach -quiet "$check/dmg"
mkdir -p release
cp "$dmg" "$zip" dist/updates/appcast.xml release/
ls -l release >> "$GITHUB_STEP_SUMMARY"
- uses: actions/upload-artifact@v7
with:
name: hex-macos-arm64
path: release/
retention-days: 30
if-no-files-found: error