Logo

dev-resources.site

for different kinds of informations.

Automatically add new devices to the Apple Developer Portal (GitHub Actions & Fastlane)

Published at
12/24/2022
Categories
cicd
ios
fastlane
github
Author
retyui
Categories
4 categories in total
cicd
open
ios
open
fastlane
open
github
open
Author
6 person written this
retyui
open
Automatically add new devices to the Apple Developer Portal (GitHub Actions & Fastlane)

It's no secret that in order to install Beta/Staging builds on your real iPhone device, you must first register it. You can perform it manually, but you'll need special admin privileges. Automatization is a different strategy to remove a human factor.

The approach must be easy and practical.

  1. Your repository contains a file named devices.txt that lists the allowed "UDIDs."
  2. After the addition of a fresh device to that list, the developer will submit a PR for code review.
  3. A CI/CD job that will run after the PR has been approved and merged to the main branch
  4. That's it. Install the app after being rebuilt with a new provisioning profile.

Now let's review implementation. I'll use GitHub Actions & Fastlane as an example.

First, we require a file called "devices.txt"

the file format is displayed below (or you can view an Apple Sample):

<UDID>tabulation<Name>tabulation<Type: ios or mac>

Example:

Device ID   Device Name Device Platform
a02fc03df7e12c5fb1ec247e8a14e2c3e4b7d68d    My iPhoneX  ios
00006000-000C551C02D2801E   My MacBook  mac
00008120-000C3C262478C09E   My iPhone14 ios
Enter fullscreen mode Exit fullscreen mode

⚠️ Warn: dev.to transforms ^^^ tabulation to spaces (be careful when copy an example above)


Now let's create a new lane in your Fastfile

Our new lane will make use of the actions match and register_devices.

platform :ios do
  desc 'Registers new devices to the Apple Dev Portal and update provisioning profiles'
  lane :register_new_device_id do
    ensure_env_vars(
      env_vars: [
        # a secret variable Git repo encryption password
        'MATCH_PASSWORD',
        # a secret variable used to clone repo of certs 
        # more: https://docs.fastlane.tools/actions/match/
        'MATCH_GIT_BASIC_AUTHORIZATION',
        # your App Store Connect API Key information
        # used by `register_devices` action to authenticate to App Store Connect
        # more: https://docs.fastlane.tools/app-store-connect-api/#using-fastlane-api-key-hash-option
        'APP_STORE_CONNECT_API_KEY_JSON',
      ]
    )

    apiFile = Tempfile.new('api_key')
    apiFile.write(ENV['APP_STORE_CONNECT_API_KEY_JSON'])
    apiFile.close

    # will register iOS/Mac devices with the Developer Portal so that you can include them in your provisioning profiles
    register_devices(
      api_key_path: apiFile.path,
      devices_file: "./devices.txt"
    )

    # Update provisioning profiles after `register_devices`
    match(
      type: "adhoc",
      readonly: false,
      force_for_new_devices: true
    )

    match(
      type: "appstore",
      readonly: false,
      force_for_new_devices: true
    )
  end
end
Enter fullscreen mode Exit fullscreen mode

Next we need to create a new GitHub Actions workflow

Every time a devices.txt file changes in master, the .github/workflows/register_device.yml workflow will execute a job.

name: Mobile Automation

on:
  push:
    branches:
      - master
    paths:
      - '**/devices.txt' 
    # When PR that changing a `devices.txt` file will be merged, this workflow will be triggered

    steps:
      - uses: actions/checkout@v3 # checks-out your repository

      - name: Install Ruby 2.x # Required for Fastlane
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: '2.7.6' # set your version
          bundler-cache: true   # enable caching for bundler

      - name: Install Fastlane
        run: bundle install --jobs 4 --retry 3

      - name: Registers a new device to the Apple Dev Portal
        run: bundle exec fastlane ios register_new_device_id
        env:
          MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
          MATCH_GIT_BASIC_AUTHORIZATION: ${{ secrets.MATCH_GIT_BASIC_AUTHORIZATION }}
          APP_STORE_CONNECT_API_KEY_JSON: ${{ secrets.APP_STORE_CONNECT_API_KEY_JSON }}
Enter fullscreen mode Exit fullscreen mode

That's enough. I this example I omitted the 'match' integration, but there are several guides online that explain how to implement it.

If you have any questions, please feel free to ask them in the comments section.

MurAmur (c)

fastlane Article's
30 articles in total
Favicon
From days to minutes: Build and publish React Native apps using Fastlane and Github Actions
Favicon
[Boost]
Favicon
The Ultimate Guide to Automating Android APK Builds and Firebase Distribution with Fastlane πŸš€
Favicon
From Manual to Automatic: The Magic of CI/CD Pipelines! 🀯
Favicon
Protegendo credenciais em automatização de builds no Fastlane com VariÑveis de Ambiente
Favicon
GUI for fastlane?
Favicon
Steps to Add and Upload testflight Using Fastlane
Favicon
Simplifying Flutter Deployment with FastLane
Favicon
πŸš€ Added new YouTube series on "Flutter CI/CD with GitLab and Fastlane" !
Favicon
Automate publishing your android app to Google Play Store with Fastlane and Github Actions
Favicon
GitHub Actions CI/CD for Flutter Fastlane (iOS) with possible mistakes
Favicon
Criando uma conta e configurando um projeto no CodeMagic
Favicon
Automatically add new devices to the Apple Developer Portal (GitHub Actions & Fastlane)
Favicon
Fastlane: ζ·±ε…₯ζ΅…ε‡ΊδΈ€ηœ‹δ½ ε°±ζ‡‚
Favicon
Fastlane: iOS ε’Œ Android ηš„θ‡ͺεŠ¨εŒ–ζž„ε»Ίε·₯ε…·
Favicon
Fastlane with React Native β€” Part-1
Favicon
Deploy iOS Application to AppCenter via Github Actions (Manual Code SignIn)
Favicon
Single point versioning with Fastlane for React Native
Favicon
Unable to use Fastlane on macOS Monterey 12.1
Favicon
Automating Flutter App Versioning Using Fastlane Plugin
Favicon
How To Automate App Releases using Fastlane and SemVer for Hybrid Applications
Favicon
Building and Deploying Flutter Apps from CI with Fastlane: How to Reuse Code Efficiently
Favicon
How to run Fastlane and GitLab with AppStore Connect API
Favicon
Automating mobile application deployments using Fastlane and CI/CD tools
Favicon
React Native e2e tests and Automatic Deploys (Detox + Fastlane + CircleCI)
Favicon
Deploy React Native app on Playstore with Fastlane and Github Actions ( 1 / 2 )
Favicon
Deploy React Native app on Playstore with Fastlane and Github Actions ( 2 / 2 )
Favicon
CI/CD in iOS Development
Favicon
Como configurar Fastlane para Firebase App Distribution (Android e iOS)
Favicon
Flutter + Fastlane + Github Actions

Featured ones: