Android CI/CD 使用 Fastlane 和 GitHub 操作:"fastlane" 在主分支中找不到命令

Android CI/CD with Fastlane and GitHub Actions: "fastlane" command not found at master branch

我正在尝试使用 Github Actions 和 Fastlane 为我的 Android 项目实施 CI/CD 工作流程。我创建了一个工作流程来构建 APK 文件并将其上传到 Firebase App Distribution。当我推送到我的开发分支并按预期将 APK 文件上传到 Firebase App Distribution 时,我的工作流程被触发并成功。

但是相同的工作流在 master 分支上失败(没有任何代码更改)并出现错误:“bundler: command not found: fastlane”

当我在我的本地设备上调用相同的 fastlane 操作时,它会工作并将 APK 上传到 Firebase App Distribution。

这是我的车道:

    lane :beta do |options|

        version = options[:versionChange]
        runUnitTests = options[:runUnitTests]
        gitUserMail = options[:gitUserMail]
        gitUserName = options[:gitUserName]

        # 1- Make version code and name incrementation

        if version.nil? || version == 'patch'
            gradle(task: "doPatchVersionIncrement")
        end

        if version == 'major'
            gradle(task: "doMajorVersionIncrement")
        end

        if version == 'minor'
            gradle(task: "doMinorVersionIncrement")
        end

        gradle(task: "doBuildNumberIncrement")
        gradle(task: "doBuildNumberBetaIncrementValueIncrement")

        # 2- Run unit tests for all variants
        if runUnitTests.nil? && runUnitTests != 'false'
                gradle(task: "clean")
                gradle(task: "test")
        end

        # 3- Build Release APK
                gradle(task: "clean")
                gradle(task: 'assemble', build_type: 'Release')

        # 4- push version bump commit

        properties = property_file_read(file: "app/version.properties")
        versionMajor = properties['VERSION_NAME_MAJOR']
        versionMinor = properties['VERSION_NAME_MINOR']
        versionPatch = properties['VERSION_NAME_PATCH']
        versionCode = properties['VERSION_CODE']
        versionName = "#{versionMajor}.#{versionMinor}.#{versionPatch}"

        if !gitUserMail.nil? && !gitUserMail.empty? && !gitUserName.nil? && !gitUserName.empty?
              sh "git config --global user.email #{gitUserMail}; git config --global user.name #{gitUserName}"
        end

        sh "git add .. ; git commit -m 'Version bump : versionCode = #{versionCode} | versionName = #{versionName}'"
        push_to_git_remote

        # 5- Send APK to Firebase
        firebase_app_distribution(app: "MY_FIREBASE_APP_ID", groups: "qa-team")
  end

这是我的 GitHub 操作的 .yml 文件:

name: Deploy Release APK to Firebase App Distribution

on:
  push:
    branches:
      - "**"
  pull_request:
    branches:
      - master

  workflow_dispatch:

jobs:
  upload_firebase_app_distribution:
    name: Upload to Release Apk to Firebase App Distribution
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2.3.3

      - uses: ruby/setup-ruby@v1
        with:
          ruby-version: '2.6'
          bundler-cache: true

      - name: Distribute app with  App Distribution 
        run: bundle exec fastlane beta version:patch runUnitTests:false gitUserMail:user@company.com gitUserName:user_name
  1. 已更新 Ruby 版本
  2. 在 Ruby
  3. 之后安装了 Fastlane
  4. 在“fastlane”命令后添加了“android”命令

那么问题就解决了。这是固定的工作流程:

name: Deploy Release APK to Firebase App Distribution
on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master

  workflow_dispatch:

jobs:
  deploy_to_beta:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Setup Ruby
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: '2.7.2'

      - name: Setup Fastlane
        run: bundle install

      - name: Deploy to Firebase
        run: bundle exec fastlane android beta version:patch runUnitTests:false gitUserMail:user@company.com gitUserName:user_name