iOS 持续化集成iOS 自动化专题iOS精品文章-持续集成&自动化

[简译] fastlane Tutorial: Getting

2017-01-13  本文已影响214人  coderzcj

fastlane
作者:Felix Krause
开源:fastlane
准备知识:command line, code signing and iTunes Connect
ps: 如果这些不会,可以阅读教程

Getting Started

  1. 下载开始项目
  2. 修改Bundle Identifier
  3. 环境要求:

OS X 10.9 (Mavericks) or newer 自带Ruby 2.0
命令行输入查看:
ruby -v
验证Xcode CLT是否安装:
xcode-select --install
如果已经安装,出现command line tools are already installed, use "Software Update" to install updates.如果没有安装,则提示安装。

  1. 安装fastlane
    命令行输入: sudo gem install -n /usr/local/bin fastlane --verbose

fastlane 安装位置为什么是/usr/local/bin,请阅读About System Integrity Protection on your Mac

The fastlane Toolchain

fastlane包含了下列工具集:

Setting up fastlane

命令行依次输入:

  1. 进入mZone 项目:cd 项目位置
  2. 创建fastlane:fastlane init

如果得到permission denied错误,请在命令前加入sudo

  1. 输入Apple ID 和 密码

如果出现Connection reset by peer - SSL_Connect错误
按照提示更新ruby版本,命令行依次输入:

  1. 相关文件

1.在metadata文件夹只有en-US,如需配置另一种语言,需要复制一份并重新命名,比如fr-FR
2.其他文件根据项目填写
3.创建名为itunes_rating_config.jsonjson文件,让iTunes Connect 知道rating criteria,内容为:

{
  "CARTOON_FANTASY_VIOLENCE": 0,
  "REALISTIC_VIOLENCE": 0,
  "PROLONGED_GRAPHIC_SADISTIC_REALISTIC_VIOLENCE": 0,
  "PROFANITY_CRUDE_HUMOR": 0,
  "MATURE_SUGGESTIVE": 0,
  "HORROR": 0,
  "MEDICAL_TREATMENT_INFO": 0,
  "ALCOHOL_TOBACCO_DRUGS": 0,
  "GAMBLING": 2,
  "SEXUAL_CONTENT_NUDITY": 0,
  "GRAPHIC_SEXUAL_CONTENT_NUDITY": 0,
  "UNRESTRICTED_WEB_ACCESS": 0,
  "GAMBLING_CONTESTS": 0
}

4.向metadata目录添加AppIcon的图片
5.其他fastlane设置 键列表

Creating Certificates and Provisioning Profiles

  1. 修改Fastfile,内容为:
# This is the minimum version number required.
# Update this, if you use features of a newer version
fastlane_version "2.6.0"
default_platform :ios
platform :ios do
  # 1 lane 的描述
  desc "Creating a code signing certificate and provisioning profile"
  # 2 命名这个lane为provision
  lane :provision do
    # 3 在iTunes Connect 和 the Developer Portal 创建app
    produce(
      app_name: 'YOUR_UNIQUE_APP_NAME',
      language: 'English',
      app_version: '1.0',
      sku: '123abc'
    )
    # 4 创建私有密钥和签名请求,下载并安装产生的证书,导入在keychain生成的文件
    cert
    # 5 生成 provisioning profile,force: true表示每次运行都创建provisioning profile,默认为distribution profile。使用sigh(adhoc: true) 创建ad hoc profile, 使用sigh(development: true) 创建 development profile
    sigh(force: true)
  end
  error do |lane, exception|
  # This block is called if there was an error running a lane.
  end
end
  1. 保存文件,命令行输入:
    fastlane provision
  2. 登录 iTunes Connect,可以看到刚才创建的app
  3. 在Xcode 中使用创建的 provisioning profile

1.在Target\Build Settings\Code Signing
设置provisioning profile为新创建的 <app ID> AppStore,选择对应的Code Signing Identity
2.在Target\General
关闭Automatically manage signing,在Signing (Debug) 和 Signing (Release) 选择与刚才相同的 provisioning profile

Screenshots Made Easy

  1. 命令行输入:
    fastlane snapshot init
  2. 生成名为Snapfile的文件,修改内容为:
# A list of devices you want to take the screenshots from
devices([
  "iPhone 5",
  "iPhone 6",
  "iPhone 6 Plus"
])
# A list of supported languages
languages([
  'en-US',
  'fr-FR'
])
# Where should the resulting screenshots be stored?
output_directory "./fastlane/screenshots"
# Clears previous screenshots
clear_previous_screenshots true
# Latest version of iOS
ios_version '10.1'

为什么没有 iPhone 7 和 iPhone 7 Plus 呢?
因为与 iPhone 6 and iPhone 6 Plus 相同

  1. 保存并关闭文件,回到终端,按照提示依次:
  2. 添加一个新的 UI Test target
  3. 将 SnapshotHelper.swift 文件拖入 UI Test target
  4. 打开mZone_PokerUITests.swift文件,删除 setUp 和 tearDown 方法,在testExample方法添加以下代码:
  // 1
  let app = XCUIApplication()
  setupSnapshot(app)
  app.launch()
  // 2
  let chipCountTextField = app.textFields["chip count"]
  chipCountTextField.tap()
  chipCountTextField.typeText("10")
  // 3
  let bigBlindTextField = app.textFields["big blind"]
  bigBlindTextField.tap()
  bigBlindTextField.typeText("100")
  // 4
  snapshot("01UserEntries")    
  // 5
  app.buttons["what should i do"].tap()
  snapshot("02Suggestion")
  1. 在Fastfile添加:
  desc "Take screenshots"
  lane :screenshot do
    snapshot
  end
  1. 保存并退出,打开终端输入:
    fastlane screenshot
  2. 完成后,自动打开screenshots.html文件查看

Creating the IPA file

  1. 在Fastfile文件添加:
  desc "Create ipa"
  lane :build do
    increment_build_number
    gym
  end
  1. 保存并退出,打开终端输入:
    fastlane build

Seamless Delivery

  1. 在Fastfile文件添加:
  desc "Upload to App Store"
  lane :upload do
    deliver
  end
  1. 保存并退出,打开终端输入:
    fastlane upload
  2. 预览 HTML,“Does the Preview on path ‘./Preview.html’ look okay for you? (y/n)”,没问题了就选y
  3. 登录iTunes Connect查看,点击Submit for Review

直接上传:

  1. 修改lane
  desc "Upload to App Store and submit for review"
  lane :upload do
    deliver(
      submit_for_review: true
    )
  end
  1. 修改Deliverfile文件内容为:
# 1 免费app
price_tier 0
# 2 review 信息
app_review_information(
  first_name: "YOUR_FIRST_NAME",
  last_name: "YOUR_LAST_NAME",
  phone_number: "YOUR_PHONE_NUMBER",
  email_address: "YOUR_EMAIL_ADDRESS",
  demo_user: "N/A",
  demo_password: "N/A",
  notes: "No demo account needed"
)
# 3 提交信息
submission_information({    
    export_compliance_encryption_updated: false,
    export_compliance_uses_encryption: false,
    content_rights_contains_third_party_content: false,
    add_id_info_uses_idfa: false
})
# 4 审核通过后手动release
automatic_release false
# 5 提供app icon 文件
app_icon './fastlane/metadata/AppIcon.png'
# 6 提供 iTunes Rating Configuration 文件
app_rating_config_path "./fastlane/metadata/itunes_rating_config.json"
  1. 命令行输入:
    fastlane upload

Putting it All Together

  1. Fastfile文件添加内容:
 desc "Provision, take screenshots, build and upload to App Store"
  lane :do_everything do
    provision
    screenshot
    build
    upload
  end
  1. 命令行输入:
    fastlane do_everything
上一篇 下一篇

猜你喜欢

热点阅读