Getting Started with Fastlane.swift (beta)
Fastlane.swift 入门(测试版)

Welcome to Fastlane.swift. Fastlane.swift allows you to write your fastlane configuration using Xcode, in Swift - the language you have come to know and love from the world of iOS development.
欢迎使用 Fastlane.swift。Fastlane.swift 允许您使用 Xcode 以 Swift 语言编写 fastlane 配置,Swift 是您在 iOS 开发世界中熟悉并喜爱的语言。

Fastlane.swift is currently in beta. Please provide feedback by opening an issue in the fastlane repo.
Fastlane.swift 目前处于测试阶段。请在 fastlane 软件仓库中提交反馈意见。

Currently Supported 目前支持

Fastlane.swift currently supports all built-in fastlane actions and 3rd party plugins. Make sure to update to the most recent fastlane release to try these features.
Fastlane.swift 目前支持所有内置的 fastlane 操作和第三方插件。请确保更新到最新的 fastlane 版本,以试用这些功能。

Get Started (Xcode) 开始 (Xcode)

Step 1 步骤 1

Run the following command in your terminal:

fastlane init swift

Step 2 步骤 2

Open the file located at [project]/fastlane/swift/FastlaneSwiftRunner/FastlaneSwiftRunner.xcodeproj to configure your lanes in Fastfile.swift.
打开位于 [project]/fastlane/swift/FastlaneSwiftRunner/FastlaneSwiftRunner.xcodeproj 的文件,在 Fastfile.swift 中配置您的车道。

func betaLane() {
    desc("Submit a new Beta Build to Apple TestFlight. This will also make sure the profile is up to date")

    syncCodeSigning(gitUrl: "URL/for/your/git/repo", appIdentifier: [appIdentifier], username: appleID)
    // Build your app - more options available
    buildIosApp(scheme: "SchemeName")
    uploadToTestflight(username: appleID)
    // You can also use other beta testing services here (run `fastlane actions`)

Step 3 步骤 3

Run fastlane <laneName> in your terminal to execute fastlane.
在终端运行 fastlane <laneName> 执行 fastlane。

Step 4 步骤 4


Get Started (SPM) (Beta)
开始 (SPM) (测试版)

Swift Package Manager (SPM) support adds the ability to distribute fastlane as a Swift Package Manager package, which allows other packages to integrate with the toolset.
Swift 软件包管理器 (SPM) 支持增加了将 fastlane 作为 Swift 软件包管理器软件包发布的功能,这样其他软件包就可以与工具集集成。

Step 1 步骤 1

Create an executable Swift Package Manager project with swift package init --type executable.
swift package init --type executable 创建一个可执行的 Swift 包管理器项目。

Step 2 步骤 2

Add the fastlane dependency to your Package.swift.
将 fastlane 依赖关系添加到 Package.swift .

.package(name: "Fastlane", url: "", from: "2.179.0")

A full example of a working package description would be the following.

// swift-tools-version:5.2

import PackageDescription

let package = Package(
    name: "fastlaneRunner",
    products: [
        .executable(name: "fastlaneRunner", targets: ["fastlaneRunner"])
    dependencies: [
        .package(name: "Fastlane", url: "", from: "2.179.0")
    targets: [
            name: "fastlaneRunner",
            dependencies: ["Fastlane"],
            path: "Sources/Thingy"

Step 3 步骤 3

Create your Fastfile.swift file in your package and add the desired lanes, as follows.
在软件包中创建 Fastfile.swift 文件,并添加所需的车道,如下所示。

import Fastlane

// Create a class with: 
class FastFile: LaneFile {
    // Your lanes goes here.

Step 4 步骤 4

Add an entry point (@main) or a main.swift file (mandatory for executable SPM packages) and don't forget to start the fastlane runloop as follows:
添加一个入口点 ( @main ) 或一个 main.swift 文件(可执行的 SPM 软件包必须添加),不要忘记按如下步骤启动 fastlane 运行循环:

import Fastlane

Main().run(with: Fastfile())

Step 5 步骤 5

Modify the target of your executable to have executable arguments lane myLane or add them in the call after making swift build.
修改可执行文件的目标,使其具有可执行参数 lane myLane 或在调用 swift build 后添加这些参数。

myExecutable lane myLane
Notes: 备注
  • You can edit the created Package.swift file to add your desired dependencies so you can use them in the Fastfile.
    您可以编辑已创建的 Package.swift 文件,添加所需的依赖项,以便在 Fastfile 中使用它们。
  • If you want to just push your Package.swift and Package.resolved to the repo, you'd need to swift build the package to create your executable again which can be found in the .debug or .release folders, depending on how you built the package (.debug by default).
    如果你只想把 Package.swiftPackage.resolved 推送到 repo,你需要 swift build 软件包来再次创建可执行文件,可执行文件可以在 .debug.release 文件夹中找到,这取决于你是如何构建软件包的(默认情况下是 .debug )。

Defining Lanes 定义车道

Lanes are defined with functions that end with Lane within the class Fastfile: LaneFile.
车道由 class Fastfile: LaneFile 内以 Lane 结尾的函数定义。

class Fastfile: LaneFile {
    func testLane() {
        desc("This is a lane")

    func helper() {
        // This is not a lane but can be called from a lane

Passing Parameters 传递参数

To pass parameters from the command line to your lane, use the following syntax:

fastlane [lane] key:value key2:value2

fastlane deploy submit:false build_number:24

To access those values, change your lane declaration to also include withOptions options:[String: String]?
要访问这些值,请更改您的车道声明,使其也包含 withOptions options:[String: String]?

class Fastfile: LaneFile {
    func deployLane(withOptions options:[String: String]?) {
        // ...
        if let submit = options?["submit"], submit == "true" {
            // Only when submit is true
        // ...
        incrementBuildNumber(buildNumber: options?["build_number"])
        // ...

Using Plugins 使用插件

Once you add a plugin, fastlane will automatically generate the corresponding API and make it available in fastlane/swift/Plugins.swift.
添加插件后,fastlane 会自动生成相应的应用程序接口,并在 fastlane/swift/Plugins.swift 中提供。

Example: 例如

bundle exec fastlane add_plugin ascii_art

The fastlane/swift/Plugins.swift file should now contain the function asciiArt(), and you can access it in your lanes in fastlane/Fastlane.swift.
现在, fastlane/swift/Plugins.swift 文件应该包含函数 asciiArt() ,您可以在 fastlane/Fastlane.swift 的 lanes 中访问它。

Run Parallel 平行运行

Fastlane Swift uses socket internally. Therefore, for several Lanes to run in parallel at the same time, each Lane must be specified different socket port (lane's default socket port is 2000)
Fastlane Swift 内部使用套接字。因此,要同时并行运行多个 Lane s,每个 Lane 必须指定不同的 socket port (lane 的默认 socket port2000 )。

To specify socket port from the command line to your lane, use the following syntax:
要从命令行指定 socket port 到您的车道,请使用以下语法:

fastlane [lane] --swift_server_port [socket port]

We Would Love Your Feedback

Please feel free to open an issue on GitHub to report any problems you are having with Fastlane.swift and we will respond as quickly as possible.
如果您在使用 Fastlane.swift 时遇到任何问题,请随时在 GitHub 上打开问题报告,我们将尽快回复。