Skip to content

Commit 03e3ebc

Browse files
committed
feat: add code signing and notarization steps for macOS packaging
1 parent 6ccf712 commit 03e3ebc

2 files changed

Lines changed: 52 additions & 2 deletions

File tree

.github/scripts/package-macos.sh

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,38 @@ if [ -n "$ICO" ]; then
5656
iconutil -c icns icon.iconset -o FastPack.app/Contents/Resources/AppIcon.icns
5757
fi
5858

59+
# Import Developer ID certificate into a temporary keychain
60+
if [ -n "${APPLE_CERT_P12:-}" ]; then
61+
KEYCHAIN_PATH="$RUNNER_TEMP/signing.keychain-db"
62+
KEYCHAIN_PASS=$(openssl rand -hex 16)
63+
64+
security create-keychain -p "$KEYCHAIN_PASS" "$KEYCHAIN_PATH"
65+
security set-keychain-settings -lut 21600 "$KEYCHAIN_PATH"
66+
security unlock-keychain -p "$KEYCHAIN_PASS" "$KEYCHAIN_PATH"
67+
68+
echo "$APPLE_CERT_P12" | base64 --decode -o "$RUNNER_TEMP/cert.p12"
69+
security import "$RUNNER_TEMP/cert.p12" \
70+
-k "$KEYCHAIN_PATH" \
71+
-P "$APPLE_CERT_PASSWORD" \
72+
-T /usr/bin/codesign
73+
security set-key-partition-list \
74+
-S apple-tool:,apple: \
75+
-s -k "$KEYCHAIN_PASS" "$KEYCHAIN_PATH"
76+
security list-keychains -d user -s "$KEYCHAIN_PATH" login.keychain
77+
78+
codesign --force --options runtime \
79+
--sign "Developer ID Application: $APPLE_TEAM_ID" \
80+
--entitlements /dev/stdin \
81+
FastPack.app << 'ENTITLEMENTS'
82+
<?xml version="1.0" encoding="UTF-8"?>
83+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
84+
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
85+
<plist version="1.0"><dict>
86+
<key>com.apple.security.cs.allow-unsigned-executable-memory</key><false/>
87+
</dict></plist>
88+
ENTITLEMENTS
89+
fi
90+
5991
# Convert DMG background SVG to PNG
6092
BG=$(find assets -name 'dmg-background.svg' -print -quit)
6193
if [ -n "$BG" ]; then
@@ -85,4 +117,16 @@ CONFIG
85117

86118
appdmg appdmg_config.json "$ARTIFACT"
87119

88-
rm -rf FastPack.app dmg-bg appdmg_config.json
120+
if [ -n "${APPLE_CERT_P12:-}" ]; then
121+
codesign --force --sign "Developer ID Application: $APPLE_TEAM_ID" "$ARTIFACT"
122+
123+
xcrun notarytool submit "$ARTIFACT" \
124+
--apple-id "$APPLE_ID" \
125+
--password "$APPLE_APP_PASSWORD" \
126+
--team-id "$APPLE_TEAM_ID" \
127+
--wait
128+
129+
xcrun stapler staple "$ARTIFACT"
130+
fi
131+
132+
rm -rf FastPack.app dmg-bg appdmg_config.json

.github/workflows/release.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,14 @@ jobs:
6868
6969
- name: package macOS DMG
7070
if: runner.os == 'macOS'
71+
env:
72+
APPLE_CERT_P12: ${{ secrets.APPLE_CERT_P12 }}
73+
APPLE_CERT_PASSWORD: ${{ secrets.APPLE_CERT_PASSWORD }}
74+
APPLE_ID: ${{ secrets.APPLE_ID }}
75+
APPLE_APP_PASSWORD: ${{ secrets.APPLE_APP_PASSWORD }}
76+
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
7177
run: |
72-
brew install svg2png
78+
brew install svg2png
7379
bash .github/scripts/package-macos.sh \
7480
"target/${{ matrix.target }}/release/fastpack" \
7581
"${{ matrix.artifact }}"

0 commit comments

Comments
 (0)