fastlane iOS Auto Packaging

fastlane package is used for unattended submission of application packages to TestFlight, dandelion, fir.im and other third-party platforms. I feel that the speed may be slower, but the advantage is

  • Unattended
  • Automatically pull the latest code
  • Automatic clean to ensure that the code has no cache interference
  • tag automatically

install

Personal suggestion: use a computer to pack. mac supports remote control, or use a well configured computer to build a user for you. You can use his computer without delaying each other's work( How to share screens)

Installation preparation

  • xcode plug-in installation or update: xcode select -- install
  • It's better to update ruby with the latest version

Formal installation

  1. sudo gem install fastlane -NV (execute if there is an error: sudo gem install fastlane -n /usr/local/bin)
  2. Fastlane init (if it is swift:fastlane init swift)
  3. And then wait

Use

The following is the configuration file below, which supports publishing different environments to different platforms

# This file is used for command line packing, and automatically pull add, commit, auto upload to (testflash, fir.im, PGY)
# 1. cd to the corresponding project
# 2. Execute the corresponding command
# a. Published to dandelion: (development environment) fastlane pgy
# b. Publish to fir.im: (test environment) fastlane fir env:dev/test/prelive/release
# c. Publish to testFlight: (pre production environment) fastlane tf
# d. Publish to testFlight: (official environment) fastlane store
# f. Published to testfly and fir.im Fastlane tf_fir at the same time
# e. Publish to all environments at the same time
#
#
#
#
#
#
#


default_platform(:ios)
platform :ios do
  
  lane :release_ready do
    UI.message("----------release_ready----------")
    ensure_git_status_clean ## Ensure that the current code has been committed
    git_pull
    increment_build_number # Self increasing build
    commit_version_bump # Check build
    push_to_git_remote
  end


  lane :release_finsh do
    UI.message("----------release_finsh----------")
    
    push_git_tags
  end


  lane :pgy do
    UI.message("----------Release a dandelion development version----------")
    release_ready

    sync_code_signing(type: "adhoc")
    build_app(
      workspace: "WeTalk.xcworkspace",
      scheme: "WeTalk",
      export_method: "ad-hoc",
      configuration: "Debug",# Debug, Test,Prelive, ,Release
      silent: true,
      clean: true,
    )
    pgyer(api_key: "you api key", user_key: "your user key")
    add_git_tag(tag:"dev/#{get_version_number}(#{get_build_number})")

    release_finsh
  end


  lane :fir do |options|
    UI.message("----------Publish a fir.im Test version----------")
    release_ready
    env = options[:env]
    config = "Test"
    message = "testing environment"
    
    if env == "dev"
      config = "Debug"
      message = "development environment"

    elsif env == "test"
      config = "Test"
      message = "testing environment"

    elsif env == "prelive"
      config = "Prelive"
      message = "Pre production environment"

    elsif env == "release"
      config = "Release"
      message = "Formal environment"
    else
      config = "Test"
      message = "testing environment"
    end

    sync_code_signing(type: "adhoc")
    build_app(
      workspace: "WeTalk.xcworkspace",
      scheme: "WeTalk",
      export_method: "ad-hoc",
      configuration: config,
      silent: true,
      clean: true,
    )
    firim(firim_api_token: "your token",app_changelog:message)
    add_git_tag(tag:"#{env}/#{get_version_number}(#{get_build_number})")

    release_finsh
  end
  

  lane :tf do
    UI.message("----------Publish a testfligth Pre production version----------")
    release_ready

    sync_code_signing(type: "appstore")
    build_app(
      workspace: "WeTalk.xcworkspace",
      scheme: "WeTalk",
      configuration: "Prelive",
      silent: true,
      clean: true,
      changelog:"Pre production environment"
      )
    upload_to_testflight
    add_git_tag(tag:"prelive/#{get_version_number}(#{get_build_number})")

    release_finsh
  end
  
  lane :store do
    UI.message("----------Publish a appStore Pre production version----------")
    release_ready

    sync_code_signing(type: "appstore")
    build_app(
      workspace: "WeTalk.xcworkspace",
      scheme: "WeTalk",
      configuration: "Release",
      silent: true,
      clean: true,
      changelog:"Formal environment"
      )
    upload_to_testflight
    add_git_tag(tag:"release/#{get_version_number}(#{get_build_number})")

    release_finsh
  end


  lane :tf_fir do
    UI.message("----------Simultaneous release testFlight and fir.im Edition----------")
    fir # fir.im test environment
    tf # Testflash pre production environment
  end


  lane :all do
    UI.message("----------Publish all versions----------")
    pgy # Dandelion, development environment
    fir # fir.im test environment
    tf # Testflash pre production environment
    store # Formal environment
  end

Expand

Configuration of different environments

During development, we will encounter many environments, such as development environment, test environment, pre production environment and production environment. Obviously, Xcode's default Debug and release are not enough. Fortunately, we can extend them as follows:

  1. To add the configuration you want, you can duplicate the debug or release of the system. If you want to release the application, it is recommended to select duplicate release, because the release will have more optimized configurations
  2. Set their corresponding macro definitions. By default, there is only one DEBUG
  3. Configure different environments
#ifdef DEBUG / / development environment
   your code 
#elif TEST / / test environment
   your code 
#elif PRELIVE / / pre production environment
   your code 
#elif RELEASE / / formal environment
   your code 
#else / / it is also the official environment by default
   your code 
#endif
  1. As a result, you can switch freely during development or release without modifying any code

Make executable script

  1. Create a. sh suffix script file
  2. Use the command: sudo chmod 777 yourfile.sh to modify permissions
  3. Write the script you want to execute
  4. To modify the double-click opening method:
  5. Finish work, double click to try

Problem record

Enclosure

The other fastlane scripts I configured before are all here, which may help you github address

Reference material

  • Official website address: > https://docs.fastlane.tools/getting-started/ios/setup/
Published 42 original articles, won 1 praise and 30000 visitors+
Private letter follow

Tags: xcode sudo iOS Swift

Posted on Thu, 16 Jan 2020 06:25:16 -0500 by shiznatix