Skip to content

A local-first personal finance app

[AI] Add a sandboxed Mac App Store build and publish it from CI (#9327)

Matiss Janis Aboltins2ccf885b42db
diff --git a/.github/workflows/publish-mac-app-store.yml b/.github/workflows/publish-mac-app-store.yml
new file mode 100644
index 0000000000..83a8daf8a1
--- /dev/null
+++ b/.github/workflows/publish-mac-app-store.yml
@@ -0,0 +1,123 @@
+name: Publish Mac App Store
+
+# Uploads the sandboxed Electron app to App Store Connect. Every master push
+# produces a TestFlight build; a published release produces the build that
+# a human then submits for App Store review from App Store Connect.
+#
+# Secrets (all in the `release` environment) and how to regenerate them:
+#
+# - APPLE_SIGNING_P12_BASE64 / APPLE_SIGNING_P12_PASSWORD: the "Apple
+# Distribution" certificate, shared with the iOS workflow (see
+# publish-ios.yml for how it is exported).
+# - APPLE_MAS_INSTALLER_P12_BASE64 / APPLE_MAS_INSTALLER_P12_PASSWORD: a
+# "Mac Installer Distribution" certificate plus its private key; it signs
+# the .pkg. Create it at developer.apple.com/account/resources/certificates
+# ("+" -> Mac Installer Distribution, upload a CSR from Keychain Access),
+# then export it from Keychain Access as a password-protected .p12. The
+# secret is `base64 -i <file>.p12` and that password.
+# - APPLE_MAS_PROVISIONING_PROFILE_BASE64: the Mac App Store provisioning
+# profile for com.actualbudget.actual. Create it at
+# developer.apple.com/account/resources/profiles ("+" -> Mac App Store
+# Connect, pick the Apple Distribution certificate). The secret is
+# `base64 -i <file>.provisionprofile`.
+# - APP_STORE_CONNECT_API_KEY_ID / APP_STORE_CONNECT_API_ISSUER_ID /
+# APP_STORE_CONNECT_API_KEY_P8: the Admin App Store Connect API key shared
+# with the iOS workflow.
+
+on:
+ push:
+ branches:
+ - master
+ paths-ignore:
+ # Packages that are not part of the desktop app bundle.
+ - 'packages/api/**'
+ - 'packages/ci-actions/**'
+ - 'packages/cli/**'
+ - 'packages/docs/**'
+ - 'packages/eslint-plugin-actual/**'
+ - 'packages/mobile-client/**'
+ - 'upcoming-release-notes/**'
+ - '**.md'
+ release:
+ types: [published]
+ # Pick the branch or tag to build from the "Use workflow from" selector.
+ workflow_dispatch:
+
+concurrency:
+ group: publish-mac-app-store
+ # Queue every run instead of replacing a pending one, so a release build is
+ # never dropped because a master push arrived right after it.
+ queue: max
+ cancel-in-progress: false
+
+permissions:
+ contents: read
+
+jobs:
+ publish-mac-app-store:
+ runs-on: depot-macos-latest
+ environment: release
+ timeout-minutes: 60
+ steps:
+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
+ with:
+ persist-credentials: false
+
+ # node-gyp needs setuptools to rebuild the native modules.
+ - run: |
+ mkdir .venv
+ python3 -m venv .venv
+ source .venv/bin/activate
+ python3 -m pip install setuptools
+
+ - name: Set up environment
+ uses: ./.github/actions/setup
+ with:
+ # Avoid restoring potentially poisoned caches in release jobs.
+ cache: 'false'
+
+ # Build before any signing material lands on the runner.
+ - name: Build web app and Electron sources
+ run: ./bin/package-electron --skip-translations --skip-exe-build
+
+ - name: Write provisioning profile and App Store Connect API key
+ env:
+ PROFILE_BASE64: ${{ secrets.APPLE_MAS_PROVISIONING_PROFILE_BASE64 }}
+ API_KEY_P8: ${{ secrets.APP_STORE_CONNECT_API_KEY_P8 }}
+ API_KEY_ID: ${{ secrets.APP_STORE_CONNECT_API_KEY_ID }}
+ run: |
+ echo "$PROFILE_BASE64" | base64 --decode > packages/desktop-electron/mas/embedded.provisionprofile
+ mkdir -p "$RUNNER_TEMP/private_keys"
+ printf '%s\n' "$API_KEY_P8" > "$RUNNER_TEMP/private_keys/AuthKey_$API_KEY_ID.p8"
+ chmod 600 "$RUNNER_TEMP/private_keys/AuthKey_$API_KEY_ID.p8"
+
+ - name: Package, sign and upload to App Store Connect
+ env:
+ # electron-builder imports both certificates into a temporary keychain.
+ CSC_LINK: ${{ secrets.APPLE_SIGNING_P12_BASE64 }}
+ CSC_KEY_PASSWORD: ${{ secrets.APPLE_SIGNING_P12_PASSWORD }}
+ CSC_INSTALLER_LINK: ${{ secrets.APPLE_MAS_INSTALLER_P12_BASE64 }}
+ CSC_INSTALLER_KEY_PASSWORD: ${{ secrets.APPLE_MAS_INSTALLER_P12_PASSWORD }}
+ APP_STORE_CONNECT_API_KEY_ID: ${{ secrets.APP_STORE_CONNECT_API_KEY_ID }}
+ APP_STORE_CONNECT_API_ISSUER_ID: ${{ secrets.APP_STORE_CONNECT_API_ISSUER_ID }}
+ API_PRIVATE_KEYS_DIR: ${{ runner.temp }}/private_keys
+ run: yarn workspace desktop-electron release:mas
+
+ - name: Summarize uploaded build
+ run: |
+ PLIST=packages/desktop-electron/dist/mas-arm64/Actual.app/Contents/Info.plist
+ VERSION="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "$PLIST")"
+ BUILD="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleVersion' "$PLIST")"
+ {
+ echo "## Mac App Store build uploaded to App Store Connect"
+ echo
+ echo "| Version | Build |"
+ echo "| --- | --- |"
+ echo "| $VERSION | $BUILD |"
+ } >> "$GITHUB_STEP_SUMMARY"
+
+ - name: Clean up signing material
+ if: always()
+ run: |
+ rm -rf "$RUNNER_TEMP/private_keys"
+ rm -f packages/desktop-electron/mas/embedded.provisionprofile
diff --git a/.gitignore b/.gitignore
index a319133b08..299cf4f0d3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -116,3 +116,6 @@ storybook-static
.actualrc.yaml
.actualrc.yml
actual.config.js
+
+# Mac App Store provisioning profiles, downloaded per machine
+packages/desktop-electron/mas/*.provisionprofile
diff --git a/packages/desktop-electron/mas/README.md b/packages/desktop-electron/mas/README.md
new file mode 100644
index 0000000000..f13de9c147
--- /dev/null
+++ b/packages/desktop-electron/mas/README.md
@@ -0,0 +1,21 @@
+# Mac App Store build
+
+Mac App Store builds run inside the App Sandbox, which needs the entitlements
+in this folder plus an app-group entitlement that electron-builder derives
+from the provisioning profile at signing time. Without the app group Electron
+aborts on launch (`bootstrap_check_in ... MachPortRendezvousServer:
+Permission denied`).
+
+- `yarn workspace desktop-electron build:mas` produces the App Store-signed
+ `.pkg` in `dist/`. It needs the "Apple Distribution" and "Mac Installer
+ Distribution" certificates in the keychain and the Mac App Store
+ provisioning profile for `com.actualbudget.actual` saved here as
+ `embedded.provisionprofile`. App Store-signed builds only launch when
+ installed from TestFlight or the App Store.
+- `yarn workspace desktop-electron build:mas-dev` produces the same sandboxed
+ app signed with the "Apple Development" certificate so it launches
+ locally. It needs a macOS App Development provisioning profile that lists
+ this Mac, saved here as `development.provisionprofile`.
+
+Both profiles are git-ignored; download them from
+developer.apple.com/account/resources/profiles.
diff --git a/packages/desktop-electron/mas/entitlements.mas.inherit.plist b/packages/desktop-electron/mas/entitlements.mas.inherit.plist
new file mode 100644
index 0000000000..999d4b4f45
--- /dev/null
+++ b/packages/desktop-electron/mas/entitlements.mas.inherit.plist
@@ -0,0 +1,11 @@
+<?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>
+ <!-- Helper processes (renderer, GPU, utility) inherit the app's sandbox. -->
+ <key>com.apple.security.app-sandbox</key>
+ <true/>
+ <key>com.apple.security.inherit</key>
+ <true/>
+ </dict>
+</plist>
diff --git a/packages/desktop-electron/mas/entitlements.mas.plist b/packages/desktop-electron/mas/entitlements.mas.plist
new file mode 100644
index 0000000000..2e3b6d039a
--- /dev/null
+++ b/packages/desktop-electron/mas/entitlements.mas.plist
@@ -0,0 +1,21 @@
+<?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>
+ <!-- Mac App Store builds must run in the App Sandbox. The signing step
+ adds the application identifier, team identifier and app group
+ entitlements that Apple derives from the team automatically. -->
+ <key>com.apple.security.app-sandbox</key>
+ <true/>
+ <!-- Talking to a sync server and bank sync providers. -->
+ <key>com.apple.security.network.client</key>
+ <true/>
+ <!-- The bundled sync server and the OpenID login callback listen on a
+ local port. -->
+ <key>com.apple.security.network.server</key>
+ <true/>
+ <!-- Importing, exporting and backing up budgets through file dialogs. -->
+ <key>com.apple.security.files.user-selected.read-write</key>
+ <true/>
+ </dict>
+</plist>
diff --git a/packages/desktop-electron/package.json b/packages/desktop-electron/package.json
index 7143c52831..64f9c44b69 100644
--- a/packages/desktop-electron/package.json
+++ b/packages/desktop-electron/package.json
@@ -13,7 +13,10 @@
"typecheck": "tsgo -b && tsc-strict",
"copy-static-assets": "copyfiles --exclude 'build/**/*' **/*.html icons/**/* build/desktop-electron",
"watch": "yarn build:dist && cross-env ACTUAL_DOCUMENT_DIR=\"../../data\" ACTUAL_DATA_DIR=\"../../data\" electron .",
- "e2e": "npx playwright test"
+ "e2e": "npx playwright test",
+ "build:mas": "electron-builder --mac mas --arm64 --config.mac.bundleVersion=\"$(date -u +%Y%m%d%H%M)\"",
+ "build:mas-dev": "electron-builder --mac mas-dev --arm64",
+ "release:mas": "yarn build:mas && xcrun altool --upload-app -f dist/mas-arm64/Actual-mac-app-store-arm64.pkg --type macos --apiKey \"$APP_STORE_CONNECT_API_KEY_ID\" --apiIssuer \"$APP_STORE_CONNECT_API_ISSUER_ID\""
},
"dependencies": {
"@actual-app/sync-server": "workspace:*",
@@ -68,7 +71,20 @@
"arm64"
]
}
- ]
+ ],
+ "extendInfo": {
+ "ITSAppUsesNonExemptEncryption": false
+ }
+ },
+ "mas": {
+ "artifactName": "${productName}-mac-app-store-${arch}.${ext}",
+ "entitlements": "mas/entitlements.mas.plist",
+ "entitlementsInherit": "mas/entitlements.mas.inherit.plist",
+ "provisioningProfile": "mas/embedded.provisionprofile",
+ "hardenedRuntime": false
+ },
+ "masDev": {
+ "provisioningProfile": "mas/development.provisionprofile"
},
"linux": {
"target": [
diff --git a/upcoming-release-notes/publish-mac-app-store-from-ci.md b/upcoming-release-notes/publish-mac-app-store-from-ci.md
new file mode 100644
index 0000000000..c1b7c84320
--- /dev/null
+++ b/upcoming-release-notes/publish-mac-app-store-from-ci.md
@@ -0,0 +1,6 @@
+---
+category: Maintenance
+authors: [MatissJanis]
+---
+
+Add a sandboxed Mac App Store build of the desktop app and publish it to TestFlight from CI