美文网首页
初识fastlane

初识fastlane

作者: 追风筝的荧火虫 | 来源:发表于2019-08-14 14:09 被阅读0次

    fastlane

    fastlane is the easiest way to automate beta deployments and releases for your iOS and Android apps. 🚀 It handles all tedious tasks, like generating screenshots, dealing with code signing, and releasing your application.

    举个例子,在项目根目录创建包含以下内容的Fastfile文件:

    lane :beta do
      increment_build_number
      build_app
      upload_to_testflight
    end
    
    lane :release do
      capture_screenshots
      build_app
      upload_to_app_store       # Upload the screenshots     and the binary to iTunes
      slack                     # Let your team-mates know the     new version is live
    end
    

    这是两段fastlane的命令集

    然后,需要执行哪段命令只需要 操作命令 fastlane beta/release即可让程序自动有序地执行所有操作。


    Getting Started for iOS

    Install the latest Xcode command line tools:

    xcode-select --install
    

    Install fastlane using

    # Using RubyGems
    sudo gem install fastlane -NV
    
    # Alternatively using Homebrew
    brew cask install fastlane
    

    Navigate to your iOS app and run

    fastlane init
    

    fastlane will automatically detect your project, and ask for any missing information.

    gz-tankmm:TestForImage tank$ fastlane init
    [✔] 🚀 
    [✔] Looking for iOS and Android projects in     current directory...
    [12:28:02]: Created new folder './fastlane'.
    [12:28:02]: Detected an iOS/macOS project in the   current directory: 'TestForImage.xcworkspace'
    [12:28:02]: -----------------------------
    [12:28:02]: --- Welcome to fastlane 🚀 ---
    [12:28:02]: -----------------------------
    [12:28:02]: fastlane can help you with all kinds of automation for your mobile app
    [12:28:02]: We recommend automating one task     first, and then gradually automating more over time
    [12:28:02]: What would you like to use fastlane for?
    1. 📸  Automate screenshots
    2. 👩‍✈️  Automate beta distribution to TestFlight
    3. 🚀  Automate App Store distribution
    4. 🛠  Manual setup - manually setup your project to automate your tasks
    ?  
    

    命令执行会生成fastlane文件夹,并需要一步步跟着配置fastlane, 以及根据需求相应地配置该项目设置。
    根据用户作出的不同需求选择,会在该文件夹生成不同的配置文件。其中最重要的是fastlane/Fastfile这个文件,里面包含了所有需要配置项目的信息。

    比如以上选择了 1. 📸 Automate screenshots则会需求手动配置项目:

    [12:31:40]: Parsing your local Xcode project to find     the available schemes and the app identifier
    [12:31:40]: $ xcodebuild -showBuildSettings -workspace TestForImage.xcworkspace -scheme   TestForImage
    ✅  Successfully created SnapshotHelper.swift './fastlane/SnapshotHelper.swift'
    ✅  Successfully created new Snapfile at './fastlane/Snapfile'
    -------------------------------------------------------
    Open your Xcode project and make sure to do the     following:
    1) Add a new UI Test target to your project
    2) Add the ./fastlane/SnapshotHelper.swift to your UI Test target
       You can move the file anywhere you want
    3) Call `setupSnapshot(app)` when launching your app
    
        let app = XCUIApplication()
        setupSnapshot(app)
        app.launch()
    
    4) Add `snapshot("0Launch")` to wherever you want to trigger screenshots
    5) Add a new Xcode scheme for the newly created UITest target
    6) Add a Check to enable the `Shared` box of the newly created scheme
    

    这时候可以看到fastlane/Fastfile长这样的:

    fastlane/Fastfile

    里面包含了截图并上传到appstore的相关命令,随后只需要在项目路径下执行fastlane screenshots就可以自动执行这些操作了。

    在配置fastlane的过程中,也会自动在项目根目录下生成Gemfile以及Gemfile.lock文件,里面定义了fastlane的版本和依赖,这会提高使用fastlane的速度,这也是官方推荐的。

    更多的自动命令集参考 https://docs.fastlane.tools/actions/

    自定义动作

    除了fastlane官方预置的动作外,更多的是使用自定义的适合自己的动作:


    自定义fastlane命令集

    这里创建了一个build_qa的脚本,使用fastlane build_qa启动执行,进行触发bitrise build qa .ipa的一系列操作。

    更多参考官方文档

    相关文章

      网友评论

          本文标题:初识fastlane

          本文链接:https://www.haomeiwen.com/subject/brkgjctx.html