Repository navigation
feat(cli): fastlane APNs key setup on spaceship - #1995
ArnabChatterjee20k merged 5 commits into
Conversation
The fastlane adapter creates APNs keys with spaceship, fastlane's open-source Apple Developer portal client, through the fastlane the person already has installed: a lane in an embedded Fastfile runs in a private temp folder, so a gem, Homebrew or bundler installation all work and no Ruby ships with the CLI. It needs fastlane 2.226.0 or later, the first to sign in with SRP, and reports apns.ErrUnavailable otherwise. The adapter asks for the Apple ID and password when the request has none and passes them as FASTLANE_USER and FASTLANE_PASSWORD, so fastlane never offers to store them in the Keychain; spaceship asks for the two-factor code on the terminal. The lane calls create_key! directly so the requested environment is honoured (Key.create always asks for all), maps InvalidUserCredentialsError to apns.ErrInvalidCredentials and a full team to apns.MaxKeysError with the team's keys.
Registers the fastlane adapter, picked with --provider fastlane or APPWRITE_APNS_SETUP=fastlane.
2.225.0 (October 2024) is the release that added SRP sign-in, per its notes: earlier versions get 503 from Apple. The minimum was set one release too high.
🟢 Tier S · Ready to merge
Adds a Latest changes: The newest commits make the adapter return
📂 Walkthrough · 5
✅ Fixed since the last review · 1
Reviewed the commits since |
The fastlane setup ran fastlane from PATH in a temporary folder, so a fastlane installed only through a project's Gemfile was reported as unavailable. When the Gemfile in the folder the CLI runs in, or in its ios folder as Flutter and React Native projects keep it, lists fastlane and bundle is installed, the lane now runs with bundle exec fastlane and BUNDLE_GEMFILE pointing at that Gemfile. Otherwise fastlane from PATH is used as before. A Bundler fastlane that does not start asks for bundle install.
When the project's Gemfile lists fastlane but Bundler is missing, the fastlane setup fell back to fastlane from PATH, which can be a different version from the pinned one. It now reports apns.ErrUnavailable naming the Gemfile and how to install Bundler.
53d63b3
into
messaging-provider-cli-apns-adapters
Stacked on #1992 (the APNs key setup adapters). This is the fastlane adapter, built on spaceship, fastlane's open-source (MIT) Apple Developer portal client. spaceship is the most actively maintained of the three implementations, which makes it a good fallback when Apple changes its API.
What
internal/apns/fastlane: anapns.Adapternamedfastlanethat creates the key with the fastlane the person already has installed.appwrite init apns --create-key --provider fastlane # or APPWRITE_APNS_SETUP=fastlane appwrite init apns --create-keyHow
Fastfilewith one lane,create_apns_key, is embedded withgo:embed. On each run it's written tofastlane/Fastfilein a private temp folder and run there withfastlane create_apns_key out:… name:… environment:… [team_id:…]. The CLI ships no Ruby; it uses the fastlane already installed:ios/folder (Flutter and React Native keep it there), lists fastlane andbundleis installed, it runsbundle exec fastlanewithBUNDLE_GEMFILEset to that Gemfile, so the project's pinned fastlane runs from the temp folder.fastlanefrom PATH (a gem or Homebrew installation).apns.ErrUnavailablebefore anything is sent to Apple, withfastlane update_fastlaneadvice.APPWRITE_APPLE_ID/APPWRITE_APPLE_PASSWORDanswer them), and passes them asFASTLANE_USER/FASTLANE_PASSWORD, so fastlane's credentials manager never offers to store them in the Keychain.~/.fastlane/spaceship/) skips two-factor on later runs.Spaceship::Portal.loginselect_team(team_id:), or picks the only team or asksclient.create_key!with{ scope: 'team', environment: <requested> }for the APNs serviceclient.download_keyKey.createhard-codesenvironment: 'all', so the lane calls the client directly to honour--environment.apns.MaxKeysErrorwith the team's keys fromlist_keys.Spaceship::InvalidUserCredentialsErrorbecomesapns.ErrInvalidCredentials.out:.FASTLANE_SKIP_UPDATE_CHECK,FASTLANE_OPT_OUT_USAGEandFASTLANE_HIDE_CHANGELOGkeep fastlane from checking for updates, sending usage data or printing changelogs during the run.Tests
fastlane --versionoutput, including the multi-line installation banner, and the 2.225.0 minimum.fastlane:Fastfileis in placeout:,name:,environment:andteam_id:ios/), ignoring one that doesn't, and runningbundle exec fastlanewithBUNDLE_GEMFILEthrough a stand-inbundle.ruby -con theFastfile.Not yet verified
A real run against Apple with fastlane installed, which wasn't possible on the machine this was written on. The spaceship calls used (
login,select_team,client.create_key!,client.list_keys,client.download_key,client.team_id) were checked against spaceship's current source.Note
Like #1993 and #1994, this adds one line to
apnsAdapters(). Once all three are merged it readsapns.NewRegistry(appwrite.New(), expo.New(), fastlane.New()).