Skip to content

A local-first personal finance app

[AI] Publish the iOS app to App Store Connect from CI (#9314)

Matiss Janis Aboltins03d175cb1b5e
diff --git a/.github/workflows/publish-ios.yml b/.github/workflows/publish-ios.yml
new file mode 100644
index 0000000000..5b43e0fa79
--- /dev/null
+++ b/.github/workflows/publish-ios.yml
@@ -0,0 +1,128 @@
+name: Publish iOS
+
+# Uploads the Capacitor iOS 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_TEAM_ID: developer.apple.com -> Membership details -> Team ID.
+# Shared with the Electron notarization workflows.
+# - APPLE_SIGNING_P12_BASE64 / APPLE_SIGNING_P12_PASSWORD: an "Apple
+# Distribution" certificate plus its private key. Create one in Xcode
+# (Settings -> Accounts -> Manage Certificates -> "+") or at
+# developer.apple.com/account/resources/certificates, then in Keychain
+# Access export the certificate (with its key) as a .p12 protected by a
+# password. The secret is `base64 -i <file>.p12` and that password.
+# - APP_STORE_CONNECT_API_KEY_ID / APP_STORE_CONNECT_API_ISSUER_ID /
+# APP_STORE_CONNECT_API_KEY_P8: an App Store Connect API team key.
+# appstoreconnect.apple.com -> Users and Access -> Integrations ->
+# App Store Connect API -> Team Keys -> "+", role "App Manager". The
+# Issuer ID is shown above the key list, the Key ID in the row, and the
+# .p8 file (downloadable only once) is the P8 secret's full contents.
+
+on:
+ push:
+ branches:
+ - master
+ paths-ignore:
+ # Packages that are not part of the mobile app bundle.
+ - 'packages/api/**'
+ - 'packages/ci-actions/**'
+ - 'packages/cli/**'
+ - 'packages/desktop-electron/**'
+ - 'packages/docs/**'
+ - 'packages/eslint-plugin-actual/**'
+ - 'packages/sync-server/**'
+ - '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-ios
+ # 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-ios:
+ runs-on: depot-macos-latest
+ environment: release
+ timeout-minutes: 60
+ steps:
+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
+ with:
+ persist-credentials: false
+
+ - 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
+ run: yarn build:browser
+
+ - name: Import signing certificates
+ env:
+ P12_BASE64: ${{ secrets.APPLE_SIGNING_P12_BASE64 }}
+ P12_PASSWORD: ${{ secrets.APPLE_SIGNING_P12_PASSWORD }}
+ run: |
+ KEYCHAIN="$RUNNER_TEMP/publish-ios.keychain-db"
+ KEYCHAIN_PASSWORD="$(openssl rand -base64 32)"
+ echo "$P12_BASE64" | base64 --decode > "$RUNNER_TEMP/signing.p12"
+
+ security create-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN"
+ security set-keychain-settings -lut 21600 "$KEYCHAIN"
+ security unlock-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN"
+ security import "$RUNNER_TEMP/signing.p12" -k "$KEYCHAIN" -P "$P12_PASSWORD" \
+ -T /usr/bin/codesign -T /usr/bin/security -T /usr/bin/xcodebuild
+ # Let codesign use the keys without a UI prompt.
+ security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$KEYCHAIN_PASSWORD" "$KEYCHAIN" > /dev/null
+ security list-keychains -d user -s "$KEYCHAIN" login.keychain-db
+ rm -f "$RUNNER_TEMP/signing.p12"
+
+ security find-identity -v -p codesigning "$KEYCHAIN"
+
+ - name: Write App Store Connect API key
+ env:
+ API_KEY_P8: ${{ secrets.APP_STORE_CONNECT_API_KEY_P8 }}
+ run: |
+ printf '%s\n' "$API_KEY_P8" > "$RUNNER_TEMP/AuthKey.p8"
+ chmod 600 "$RUNNER_TEMP/AuthKey.p8"
+
+ - name: Archive and upload to App Store Connect
+ env:
+ APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
+ API_KEY_ID: ${{ secrets.APP_STORE_CONNECT_API_KEY_ID }}
+ API_ISSUER_ID: ${{ secrets.APP_STORE_CONNECT_API_ISSUER_ID }}
+ run: |
+ export XCODEBUILD_AUTH_ARGS="-authenticationKeyPath $RUNNER_TEMP/AuthKey.p8 -authenticationKeyID $API_KEY_ID -authenticationKeyIssuerID $API_ISSUER_ID"
+ yarn workspace mobile-client release:ios
+
+ - name: Summarize uploaded build
+ run: |
+ PLIST=packages/mobile-client/build/App.xcarchive/Products/Applications/App.app/Info.plist
+ VERSION="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "$PLIST")"
+ BUILD="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleVersion' "$PLIST")"
+ {
+ echo "## iOS 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: |
+ security delete-keychain "$RUNNER_TEMP/publish-ios.keychain-db" 2>/dev/null || true
+ rm -f "$RUNNER_TEMP/AuthKey.p8" "$RUNNER_TEMP/signing.p12"
diff --git a/upcoming-release-notes/publish-ios-from-ci.md b/upcoming-release-notes/publish-ios-from-ci.md
new file mode 100644
index 0000000000..efa967cfaa
--- /dev/null
+++ b/upcoming-release-notes/publish-ios-from-ci.md
@@ -0,0 +1,6 @@
+---
+category: Maintenance
+authors: [MatissJanis]
+---
+
+Publish iOS app builds to TestFlight from CI on every master merge, release, or manual run