[Tuist+Fastlane+GithubAction] App 배포 CI/CD 과정

2024. 4. 28. 00:09🍏/Xcode

이 글은 Tuist와 Fastlane, Github Action을 통하여 앱을 배포한 과정을 큰 맥락으로 공유하고 있습니다. 😊


0. 버전

tuist@3.36.2
fastlane@2.220.0.
ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.arm64e-darwin24]

해당 버전을 쓰고 있습니다.

1. Tuist 설치.

curl -Ls https://install.tuist.io|bash

2. Fastlane 설치 

brew install fastlane

3. Ruby 설치

4. .cer, .p12, mobileprovision 발급 과 master.key를 이용한 tuist singing 아래 블로그 참조, 도움이 너무 많이 됐습니다.

 

Tuist에서 CI/CD 구축하기

Tuist + Fastlane (feat. Github Action)

medium.com

5. Fastlane 설정

# Constants
APP_NAME = "iBox"
SCHEME = "iBox"
BUNDLE_ID = "com.box42.iBox"

KEYCHAIN_NAME = ENV["KEYCHAIN_NAME"]
KEYCHAIN_PASSWORD = ENV["KEYCHAIN_PASSWORD"]

default_platform(:ios)

platform :ios do
  # Keychain
  desc "Save To Keychain"
  lane :set_keychain do |options|
    create_keychain(
      name: "#{KEYCHAIN_NAME}",
      password: "#{KEYCHAIN_PASSWORD}",
      default_keychain: true,
      unlock: true,
      timeout: 3600,
      lock_when_sleeps: true
    )

    import_certificate(
      certificate_path: "Tuist/Signing/release.cer",
      keychain_name: "#{KEYCHAIN_NAME}",
      keychain_password: "#{KEYCHAIN_PASSWORD}"
    )

    import_certificate(
      certificate_path: "Tuist/Signing/release.p12",
      keychain_name: "#{KEYCHAIN_NAME}",
      keychain_password: "#{KEYCHAIN_PASSWORD}"
    )

    install_provisioning_profile(path: "Tuist/Signing/#{APP_NAME}.Release.mobileprovision")
  end

  # Upload TestFlight
  desc "Push to TestFlight"
  lane :tf do |options|
    # AppStore Connect API key
    app_store_connect_api_key(is_key_content_base64: true, in_house: false)

    # BuildNumber Up
    increment_build_number({ build_number: latest_testflight_build_number() + 1 })

    # Build App
    build_app(
      workspace: "#{APP_NAME}.xcworkspace",
      scheme: "#{SCHEME}",
      export_method: "app-store"
    )

    # Upload to TestFlight
    upload_to_testflight(skip_waiting_for_build_processing: true)
  end
end

 

5. Github Token 발급, 설정

6. AppStore Connect API KEY 설정

 

App Store Connect API - Get started - App Store Connect - Help - Apple Developer

 

developer.apple.com

 

7. GitHub Action workflows 설정

# Author by chanhihi
# Date 2024.04.26

name: Deployment

on:
  pull_request:
    branches:
      - main
    types:
      - closed

jobs:
  build:
    name: Deploy on macOS latest - Release for iOS
    runs-on: macos-latest
    env:
      XCODE_VERSION: "16.1.0"
      SWIFT_VERSION: "5.9.2"
      RUBY_VERSION: "2.6.10"
      TUIST_VERSION: "3.36.2"

    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Set up Ruby 2.6
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: ${{ env.RUBY_VERSION }}
          bundler-cache: true

      - name: Set Xcode version
        run: sudo xcode-select -s '/Applications/Xcode_15.2.0.app/Contents/Developer'

      - name: Setup Swift
        uses: swift-actions/setup-swift@v1
        with:
          swift-version: ${{ env.SWIFT_VERSION }}

      - name: .env
        run: touch .env &&
          echo "APP_STORE_CONNECT_API_KEY_KEY_ID=${{ secrets.APP_STORE_CONNECT_API_KEY_KEY_ID }}" >> .env &&
          echo "APP_STORE_CONNECT_API_KEY_ISSUER_ID=${{ secrets.APP_STORE_CONNECT_API_KEY_ISSUER_ID }}" >> .env &&
          echo "APP_STORE_CONNECT_API_KEY_KEY=${{ secrets.APP_STORE_CONNECT_API_KEY_KEY }}" >> .env

      - name: Setting Master Key
        run: | 
          echo "$MASTER_KEY" > Tuist/master.key
        env:
          MASTER_KEY: ${{secrets.MASTER_KEY}}

      - name: Mise
        uses: jdx/mise-action@v2

      - name: Install Tuist
        run: mise install tuist@${{ env.TUIST_VERSION }}

      - name: Tuist version
        run: mise use -g tuist@${{ env.TUIST_VERSION }}

      - name: Install Fastlane
        run: brew install fastlane

      - name: Tuist clean
        run: tuist clean

      - name: Tuist fetch
        run: tuist fetch
      
      - name: Tuist Signing Decrypt
        run: tuist signing decrypt

      - name: Set Keychain
        run: fastlane set_keychain
        env:
            KEYCHAIN_NAME: ${{ secrets.KEYCHAIN_NAME }}
            KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }}

      - name: Generate Xcode project with Tuist
        run: tuist generate

      - name: Fastlane run
        run: fastlane tf

      - name: Tagging
        id: tag_version
        uses: mathieudutour/github-tag-action@v6.1
        with:
          github_token: ${{ secrets.CHANHIHI }}

      - name: Draft Release
        id: draft_release
        uses: release-drafter/release-drafter@v5
        with:
          config-name: Release-note.yml
        env:
          GITHUB_TOKEN: ${{ secrets.CHANHIHI }}

8. main branch로 push

 

9. Test Flight

 

- 2024/11/11 추가
Xcode major version이 올라가면서 github action의 major버전도 대응했습니다.