Skip to content

The only downloader you need. 下载器的集大成者。

feat(ci): macOS bundle 重构 + Apple 签名公证

XiaoYouChRc1536d97c09e
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index c43689ba..d536a3f1 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -286,6 +286,8 @@ jobs:
runner: macos-15-intel
openssl_workaround: 'true'
runs-on: ${{ matrix.runner }}
+ env:
+ HAS_APPLE_CERT: ${{ secrets.APPLE_CERTIFICATE != '' && 'true' || 'false' }}
steps:
- name: Checkout
uses: actions/checkout@v7
@@ -333,6 +335,55 @@ jobs:
cp macos/hpatchz "dist/Ghost Downloader.app/Contents/MacOS/"
chmod +x "dist/Ghost Downloader.app/Contents/MacOS/hpatchz"
+ - name: Restructure bundle for signing
+ run: uv run scripts/restructure_macos_bundle.py "dist/Ghost Downloader.app"
+
+ - name: Import signing certificate
+ if: ${{ env.HAS_APPLE_CERT == 'true' }}
+ env:
+ APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }}
+ APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
+ run: |
+ CERT_PATH="$RUNNER_TEMP/certificate.p12"
+ KEYCHAIN_PATH="$RUNNER_TEMP/signing.keychain-db"
+ KEYCHAIN_PASSWORD="$(openssl rand -base64 32)"
+
+ echo "$APPLE_CERTIFICATE" | base64 --decode > "$CERT_PATH"
+
+ security create-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
+ security set-keychain-settings -lut 21600 "$KEYCHAIN_PATH"
+ security unlock-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
+ security import "$CERT_PATH" -P "$APPLE_CERTIFICATE_PASSWORD" \
+ -A -t cert -f pkcs12 -k "$KEYCHAIN_PATH"
+ security set-key-partition-list -S apple-tool:,apple: \
+ -k "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
+ security list-keychains -d user -s "$KEYCHAIN_PATH" login.keychain
+
+ echo "KEYCHAIN_PATH=$KEYCHAIN_PATH" >> "$GITHUB_ENV"
+ rm -f "$CERT_PATH"
+
+ - name: Sign app bundle
+ if: ${{ env.HAS_APPLE_CERT == 'true' }}
+ env:
+ APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
+ run: |
+ IDENTITY="Developer ID Application: ${{ secrets.APPLE_SIGN_NAME }} ($APPLE_TEAM_ID)"
+
+ find "dist/Ghost Downloader.app" -type f | while read -r f; do
+ if file -b "$f" | grep -q "Mach-O"; then
+ codesign --force --options runtime --timestamp \
+ --entitlements scripts/entitlements.plist \
+ --sign "$IDENTITY" "$f"
+ fi
+ done
+
+ codesign --force --options runtime --timestamp \
+ --entitlements scripts/entitlements.plist \
+ --sign "$IDENTITY" "dist/Ghost Downloader.app"
+
+ codesign --verify --deep --strict "dist/Ghost Downloader.app"
+ echo "Signing complete."
+
- name: Reinstall openssl libs
if: ${{ matrix.openssl_workaround == 'true' }}
run: |
@@ -369,6 +420,26 @@ jobs:
"$DMG_NAME" \
"$DMG_SOURCE_DIR"
+ - name: Notarize DMG
+ if: ${{ env.HAS_APPLE_CERT == 'true' }}
+ env:
+ APPLE_ID: ${{ secrets.APPLE_ID }}
+ APPLE_APP_PASSWORD: ${{ secrets.APPLE_APP_PASSWORD }}
+ APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
+ run: |
+ DMG_NAME="Ghost-Downloader-v${{ env.VERSION }}-macOS-${{ matrix.architecture }}.dmg"
+ xcrun notarytool submit "$DMG_NAME" \
+ --apple-id "$APPLE_ID" \
+ --password "$APPLE_APP_PASSWORD" \
+ --team-id "$APPLE_TEAM_ID" \
+ --wait
+ xcrun stapler staple "$DMG_NAME"
+ echo "Notarization complete."
+
+ - name: Cleanup keychain
+ if: ${{ always() && env.HAS_APPLE_CERT == 'true' }}
+ run: security delete-keychain "$KEYCHAIN_PATH" 2>/dev/null || true
+
- name: Generate delta patch
if: ${{ github.event.inputs.create_release == 'true' }}
env:
diff --git a/README.md b/README.md
index 4d8c58c9..4f887725 100644
--- a/README.md
+++ b/README.md
@@ -77,8 +77,10 @@ Visit [Open issues](https://github.com/XiaoYouChR/Ghost-Downloader-3/issues) to
<!-- SPONSOR -->
## Sponsor
-| [![SignPath](https://signpath.org/assets/favicon-50x50.png)](https://signpath.org/) | Free code signing provided by [SignPath.io](https://about.signpath.io/), with certificates by [SignPath Foundation](https://signpath.org/) |
-|-------------------------------------------------------------------------------------|:---------------------------------------------------------------------------------------------------------------------------------------|
+| Logo | Description |
+|------|---|
+| <a href="https://signpath.org/"><img src="https://signpath.org/assets/favicon-50x50.png" width="50" height="50" alt="SignPath" /></a> | Free code signing provided by [SignPath.io](https://about.signpath.io/), with certificates by [SignPath Foundation](https://signpath.org/) |
+| <a href="https://i0ntempest.com/"><img src="https://pbs.twimg.com/profile_images/1970235828552265728/tCvxOrZY_400x400.jpg" width="50" height="50" alt="i0ntempest" /></a> | Free code signing provided by [i0ntempest.com](https://i0ntempest.com/) |
<!-- CONTRIBUTING -->
## Contributing
diff --git a/README_zh.md b/README_zh.md
index feb4520d..5f583eae 100644
--- a/README_zh.md
+++ b/README_zh.md
@@ -78,8 +78,10 @@
<!-- SPONSOR -->
## 赞助商
-| [![SignPath](https://signpath.org/assets/favicon-50x50.png)](https://signpath.org/) | 由 [SignPath.io](https://about.signpath.io/) 提供免费代码签名,由 [SignPath Foundation](https://signpath.org/) 提供证书 |
-|-------------------------------------------------------------------------------------|:---------------------------------------------------------------------------------------------------------|
+| 标志 | 描述 |
+|------|---|
+| <a href="https://signpath.org/"><img src="https://signpath.org/assets/favicon-50x50.png" width="50" height="50" alt="SignPath" /></a> | 由 [SignPath.io](https://about.signpath.io/) 提供免费代码签名,由 [SignPath Foundation](https://signpath.org/) 提供证书 |
+| <a href="https://i0ntempest.com/"><img src="https://pbs.twimg.com/profile_images/1970235828552265728/tCvxOrZY_400x400.jpg" width="50" height="50" alt="i0ntempest" /></a> | 由 [i0ntempest.com](https://i0ntempest.com/) 提供免费代码签名 |
<!-- CONTRIBUTING -->
## 贡献
diff --git a/scripts/entitlements.plist b/scripts/entitlements.plist
new file mode 100644
index 00000000..2a985343
--- /dev/null
+++ b/scripts/entitlements.plist
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>com.apple.security.cs.allow-unsigned-executable-memory</key>
+ <true/>
+ <key>com.apple.security.cs.disable-library-validation</key>
+ <true/>
+ <key>com.apple.security.cs.allow-jit</key>
+ <true/>
+</dict>
+</plist>
diff --git a/scripts/restructure_macos_bundle.py b/scripts/restructure_macos_bundle.py
new file mode 100644
index 00000000..3a9a5d9c
--- /dev/null
+++ b/scripts/restructure_macos_bundle.py
@@ -0,0 +1,52 @@
+"""Move everything except the main binary from Contents/MacOS/ to Contents/Resources/,
+leaving relative symlinks behind. This makes the bundle pass Apple notarization."""
+
+import os
+import plistlib
+import shutil
+import sys
+from pathlib import Path
+
+
+def restructure(appBundle: Path) -> None:
+ contentsDir = appBundle / "Contents"
+ macosDir = contentsDir / "MacOS"
+ resourcesDir = contentsDir / "Resources"
+
+ with open(contentsDir / "Info.plist", "rb") as f:
+ mainExecutable = plistlib.load(f)["CFBundleExecutable"]
+
+ for entry in sorted(macosDir.iterdir()):
+ if entry.name == mainExecutable:
+ continue
+
+ dest = resourcesDir / entry.name
+ if dest.exists():
+ if dest.is_dir():
+ shutil.rmtree(dest)
+ else:
+ dest.unlink()
+
+ shutil.move(str(entry), str(dest))
+ entry.symlink_to(os.path.relpath(dest, macosDir))
+ print(f" {entry.name} → Resources/{entry.name}")
+
+
+def main() -> int:
+ if len(sys.argv) != 2:
+ print(f"usage: {sys.argv[0]} <path/to/App.app>", file=sys.stderr)
+ return 1
+
+ appBundle = Path(sys.argv[1])
+ if not (appBundle / "Contents" / "MacOS").is_dir():
+ print(f"not a valid .app bundle: {appBundle}", file=sys.stderr)
+ return 1
+
+ print(f"Restructuring {appBundle.name} ...")
+ restructure(appBundle)
+ print("Done.")
+ return 0
+
+
+if __name__ == "__main__":
+ raise SystemExit(main())