Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
187 changes: 185 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,24 @@ jobs:

# Both Mac architectures from one Apple Silicon runner. Only the native one
# can be smoke tested; the Intel build is checked to be the right kind of file.
#
# With signing set up (see "macOS: signing and notarization" in
# packaging/README.md), the programs, the app and the dmgs are signed with
# the Developer ID certificate under the hardened runtime, and the dmgs and
# the CLI are notarized; the dmgs get the ticket stapled. Without it, the
# signing steps are skipped and the app is signed ad hoc, as before.
macos:
name: macos
runs-on: macos-15
timeout-minutes: 30
# Room for four notarization requests, which usually take minutes.
timeout-minutes: 240
env:
# Tags are signed only when the variable SIGN_MACOS is true, dry runs
# only when SIGN_DRY_RUNS is, and either only when every secret is set.
MACOS_SIGNING: ${{ ((startsWith(github.ref, 'refs/tags/') && vars.SIGN_MACOS == 'true') || (!startsWith(github.ref, 'refs/tags/') && vars.SIGN_DRY_RUNS == 'true')) && secrets.MACOS_CERT_P12 != '' && secrets.MACOS_CERT_PASSWORD != '' && secrets.APPLE_API_KEY_P8 != '' && secrets.APPLE_API_KEY_ID != '' && secrets.APPLE_API_ISSUER_ID != '' && vars.APPLE_TEAM_ID != '' }}
# A tag with SIGN_MACOS on must not quietly ship unsigned because a
# secret is missing.
MACOS_SIGNING_REQUIRED: ${{ startsWith(github.ref, 'refs/tags/') && vars.SIGN_MACOS == 'true' }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
Expand All @@ -352,6 +366,63 @@ jobs:
cargo build --release --locked -p hatchzip -p hatchzip-gui --features rar --target x86_64-apple-darwin
file target/x86_64-apple-darwin/release/hatchzip | grep -q x86_64
file target/x86_64-apple-darwin/release/hatchzip-gui | grep -q x86_64
- name: signing
run: |
if [ "$MACOS_SIGNING" = true ]; then
echo "signing with the Developer ID certificate and notarizing"
elif [ "$MACOS_SIGNING_REQUIRED" = true ]; then
echo "::error::SIGN_MACOS is true, but a macOS signing secret or APPLE_TEAM_ID is missing"
exit 1
else
echo "signing ad hoc, Developer ID signing is not set up for this run"
fi

# A keychain of its own, with a random password nobody sees, alone in
# the search list so codesign finds the certificate. Deleted at the end.
- name: import the Developer ID certificate
if: env.MACOS_SIGNING == 'true'
env:
MACOS_CERT_P12: ${{ secrets.MACOS_CERT_P12 }}
MACOS_CERT_PASSWORD: ${{ secrets.MACOS_CERT_PASSWORD }}
APPLE_TEAM_ID: ${{ vars.APPLE_TEAM_ID }}
run: |
keychain="$RUNNER_TEMP/hatchzip-signing.keychain-db"
p12="$RUNNER_TEMP/hatchzip-signing.p12"
password=$(openssl rand -hex 32)
echo "::add-mask::$password"
(umask 077 && printf '%s' "$MACOS_CERT_P12" | base64 --decode > "$p12")
security create-keychain -p "$password" "$keychain"
echo "MACOS_KEYCHAIN=$keychain" >> "$GITHUB_ENV"
security set-keychain-settings -lut 21600 "$keychain"
security unlock-keychain -p "$password" "$keychain"
security import "$p12" -k "$keychain" -f pkcs12 -P "$MACOS_CERT_PASSWORD" -T /usr/bin/codesign
rm -f "$p12"
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$password" "$keychain" > /dev/null
security list-keychains -d user -s "$keychain"
security default-keychain -d user -s "$keychain"
# The identity by its SHA-1, so two certificates with one name
# can't be mixed up, and only one of this team's.
found=$(security find-identity -v -p codesigning "$keychain" | grep -F '"Developer ID Application: ' | grep -F "($APPLE_TEAM_ID)\"" || true)
if [ "$(printf '%s\n' "$found" | grep -c .)" != 1 ]; then
echo "::error::expected one Developer ID Application identity of team $APPLE_TEAM_ID in MACOS_CERT_P12"
security find-identity -v -p codesigning "$keychain"
exit 1
fi
echo "signing as $(printf '%s' "$found" | sed 's/^[^"]*//')"
echo "MACOS_SIGN_IDENTITY=$(printf '%s' "$found" | awk '{print $2}')" >> "$GITHUB_ENV"
# Before the tests and the packaging, so both run the signed programs
# and the tarballs and their checksums hold them. build-dmg.sh signs
# its copies inside the app again, as part of the bundle.
- name: sign the programs
if: env.MACOS_SIGNING == 'true'
run: |
for arch in aarch64 x86_64; do
for bin in hatchzip hatchzip-gui; do
codesign --force --timestamp --options runtime --sign "$MACOS_SIGN_IDENTITY" "target/$arch-apple-darwin/release/$bin"
codesign --verify --strict --verbose=2 "target/$arch-apple-darwin/release/$bin"
done
done

- name: smoke test
run: python3 .github/scripts/smoke.py target/aarch64-apple-darwin/release/hatchzip
- name: no networking
Expand All @@ -371,12 +442,119 @@ jobs:
(cd dist && shasum -a 256 "$name.tar.gz" > "$name.tar.gz.sha256")
done
# HatchZip.app in a dmg per architecture, with the CLI from the folder
# the tarball was made from inside it.
# the tarball was made from inside it. Signed with MACOS_SIGN_IDENTITY
# when the import step set it, ad hoc otherwise. dmgbuild lays out the
# window; it is pinned with its dependencies, hashes included, in a
# venv of its own.
- name: dmg
run: |
python3 -m venv "$RUNNER_TEMP/dmgbuild"
"$RUNNER_TEMP/dmgbuild/bin/pip" install --quiet --no-deps --require-hashes -r packaging/macos/requirements-dmg.txt
export DMGBUILD="$RUNNER_TEMP/dmgbuild/bin/dmgbuild"
for arch in aarch64 x86_64; do
sh packaging/macos/build-dmg.sh "$arch" "target/$arch-apple-darwin/release/hatchzip-gui" "dist/hatchzip-$arch-macos"
done

# The dmg is the outermost container, so it's what is notarized: the
# ticket covers the app and the CLI inside it, and is stapled to the
# dmg. The CLI in the tarballs is notarized as a zip of the binary,
# since Apple doesn't take tar.gz; a bare binary can't hold a stapled
# ticket, so Gatekeeper looks that one up online. Stapling changes the
# dmg, so this comes before the tests and the checksums.
- name: notarize
if: env.MACOS_SIGNING == 'true'
env:
APPLE_API_KEY_P8: ${{ secrets.APPLE_API_KEY_P8 }}
APPLE_API_KEY_ID: ${{ secrets.APPLE_API_KEY_ID }}
APPLE_API_ISSUER_ID: ${{ secrets.APPLE_API_ISSUER_ID }}
run: |
key="$RUNNER_TEMP/hatchzip-notary.p8"
trap 'rm -f "$key"' EXIT
(umask 077 && printf '%s\n' "$APPLE_API_KEY_P8" > "$key")
chmod 600 "$key"
auth=(--key "$key" --key-id "$APPLE_API_KEY_ID" --issuer "$APPLE_API_ISSUER_ID")
notarize() {
local out id status
echo "notarizing $(basename "$1")"
out=$(xcrun notarytool submit "$1" "${auth[@]}" --wait --timeout 150m --output-format json) || true
echo "$out"
id=$(jq -r '.id // empty' <<< "$out" 2> /dev/null) || id=""
status=$(jq -r '.status // empty' <<< "$out" 2> /dev/null) || status=""
if [ "$status" != Accepted ]; then
echo "::error::notarization of $(basename "$1") ended with status '${status:-none}'"
if [ -n "$id" ]; then
xcrun notarytool log "$id" "${auth[@]}" || true
fi
exit 1
fi
}
# Three submissions at once: both CLI binaries in one zip, and each
# dmg. Apple's queue, not the upload, is what takes the time; a new
# team's first submissions can wait an hour or more.
cli="$RUNNER_TEMP/hatchzip-cli"
mkdir -p "$cli"
for arch in aarch64 x86_64; do
cp "dist/hatchzip-$arch-macos/hatchzip" "$cli/hatchzip-$arch"
done
zip="$RUNNER_TEMP/hatchzip-macos-cli.zip"
ditto -c -k --keepParent "$cli" "$zip"
pids=()
for file in "$zip" dist/HatchZip-aarch64.dmg dist/HatchZip-x86_64.dmg; do
( notarize "$file" ) &
pids+=($!)
done
failed=0
for pid in "${pids[@]}"; do
wait "$pid" || failed=1
done
rm -rf "$zip" "$cli"
[ "$failed" = 0 ] || exit 1
for arch in aarch64 x86_64; do
xcrun stapler staple "dist/HatchZip-$arch.dmg"
done
# What Gatekeeper sees: the Developer ID and hardened runtime on the
# CLI, the stapled ticket on the dmg, and the app inside it notarized.
- name: check the signatures
if: env.MACOS_SIGNING == 'true'
run: |
# Gatekeeper may be turned off on the runner, which spctl reports
# as an override instead of the source; the ticket is then checked
# by stapler alone.
gatekeeper() {
spctl "$@" 2>&1 | tee "$RUNNER_TEMP/spctl.txt"
if grep -q 'override=security disabled' "$RUNNER_TEMP/spctl.txt"; then
echo "::warning::Gatekeeper is turned off on this runner, so spctl can't check ${*: -1}"
else
grep -q 'source=Notarized Developer ID' "$RUNNER_TEMP/spctl.txt"
fi
}
mnt=$(mktemp -d)
for arch in aarch64 x86_64; do
cli="dist/hatchzip-$arch-macos/hatchzip"
dmg="dist/HatchZip-$arch.dmg"
codesign --verify --strict --verbose=2 "$cli"
info=$(codesign -dvv "$cli" 2>&1)
grep -q '^Authority=Developer ID Application: ' <<< "$info"
grep -q 'flags=0x10000(runtime)' <<< "$info"

xcrun stapler validate "$dmg"
gatekeeper -a -t open --context context:primary-signature -vv "$dmg"

hdiutil attach "$dmg" -nobrowse -readonly -mountpoint "$mnt" -quiet
app="$mnt/HatchZip.app"
# Gatekeeper on the app as the dmg has it, hidden extension and
# all; the strict check on a copy without the Finder info that
# flag lives in, which --strict refuses (see test-dmg.sh).
gatekeeper --assess --type execute -vv "$app"
copy="$RUNNER_TEMP/check-$arch/HatchZip.app"
mkdir -p "$(dirname "$copy")"
ditto "$app" "$copy"
xattr -d com.apple.FinderInfo "$copy"
codesign --verify --strict --deep --verbose=2 "$copy"
rm -rf "$(dirname "$copy")"
hdiutil detach "$mnt" -quiet
done

- name: open the dmg and run the app
run: sh packaging/macos/test-dmg.sh dist/HatchZip-aarch64.dmg
- name: checksum the dmgs
Expand All @@ -392,6 +570,11 @@ jobs:
dist/*.tar.gz*
dist/HatchZip-*.dmg*
if-no-files-found: error
- name: delete the signing keychain
if: always() && env.MACOS_KEYCHAIN != ''
run: |
security delete-keychain "$MACOS_KEYCHAIN" || true
rm -f "$RUNNER_TEMP/hatchzip-signing.p12" "$RUNNER_TEMP/hatchzip-notary.p8"

# .deb, .rpm and AppImage of the desktop app, x86_64 only for now. A job of
# its own because the app can't be a static musl build like the CLI: it
Expand Down
Loading
Loading