Github 操作:尽管安装了 xcpretty 但未找到

Github Actions: xcpretty is not found despite being installed

我正在尝试用 Github Actions 替换我们 iOS 项目糟糕的 Jenkins 设置。我想我已经准备好了所有的部分,但是我遇到了一个我不明白的失败。在我 运行 xcodebuild 构建和测试应用程序的步骤中,我收到一个错误,指出 xcpretty 是一个未知命令,尽管在上一步中是通过捆绑程序安装的。以下是相关文件:

构建并-run.yml

---
name: Build & Test
on:
  # Run tests when a PR merges.
  push:
    branches:
      - develop

  # Run tests when PRs are created or updated.
  pull_request:
    types: [opened, synchronize, reopened]

  # Allow the workflow to be run manually.
  workflow_dispatch:

env:
  DEVELOPER_DIR: /Applications/Xcode_12.app/Contents/Developer

jobs:
  test:
    name: Build & Test
    runs-on: 'macos-latest'

    steps:
      - name: Checkout Project
        uses: actions/checkout@v2
        with:
          ref: develop

      - name: Setup Ruby
        uses: ruby/setup-ruby@v1.46.0
        with:
            ruby-version: 2.7.1

      - name: Restore Ruby Cache
        uses: actions/cache@v1
        with:
          path: vendor/bundle
          key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }}
          restore-keys: |
            ${{ runner.os }}-gem-

      - name: Restore Pod Cache
        uses: actions/cache@v1
        with:
          path: Pods
          key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }}
          restore-keys: |
            ${{ runner.os }}-pods-

      - name: Bundle Install
        run: |
          bundle config path vendor/bundle
          bundle install --without=documentation --jobs 4 --retry 3

      - name: Install Cocoapods
        run: pod install --repo-update

      - name: Show Xcode Version
        run: xcode-select -p

      - name: Show Build Settings
        run: xcodebuild -workspace ./MyApp.xcworkspace -scheme 'MyApp-Test' -destination 'platform=iOS Simulator,name=iPhone 11' -showBuildSettings

      - name: Test MyApp
        run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -workspace MyApp.xcworkspace -scheme MyApp-Test -destination 'platform=iOS Simulator,name=iPhone 11' -enableCodeCoverage YES -derivedDataPath build/derived-data clean test | xcpretty -s

      - name: Run Danger
        env:
          DANGER_GITHUB_API_TOKEN: ${{ secrets.DANGER_GITHUB_API_TOKEN }}
        run: bundle exec danger

Gemfile(我们不在操作中使用 fastlane,但我现在必须将它保存在 Gemfile 中,这样构建就不会在我们的 Jenkins 盒子上中断):

source 'https://rubygems.org'

ruby '2.7.1'

gem 'cocoapods'
gem 'danger'
gem 'fastlane'
gem 'xcpretty'
gem 'danger-slather'
gem 'danger-swiftlint'
gem 'danger-xcode_summary'
gem 'xcpretty-json-formatter'

plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile')
eval_gemfile(plugins_path) if File.exist?(plugins_path)

Bundle Install 步骤中,正在安装 xcpretty gem:

Fetching xcpretty 0.3.0
Installing xcpretty 0.3.0

Install Cocoapods 步骤也可以正常工作(可能是因为预装了 Cocoapods)。当它到达 Test MyApp 步骤时,调用会产生错误:

Run set -o pipefail && env NSUnbufferedIO=YES xcodebuild -workspace MyApp.xcworkspace -scheme MyApp-Test -destination 'platform=iOS Simulator,name=iPhone 11' -enableCodeCoverage YES -derivedDataPath build/derived-data clean test | xcpretty -s

/Users/runner/work/_temp/9d3633bf-6dae-45d7-a303-1c68abb63d53.sh: line 1: xcpretty: command not found

然后工作流挂了很长时间,所以我通常会取消它。知道为什么找不到 xcpretty 吗?我的想法是,安装 gem 的目录不在搜索路径中,但我不确定该怎么做。我确信对此有一个合理的解决方案,但我找不到它并且厌倦了用头撞墙。

不幸的是,我的解决方案一点也不整洁。我必须进入 gem 安装目录并直接引用 gem 可执行文件。值得庆幸的是,相对路径没有改变,所以我可以将它硬编码到测试脚本中。也许有更优雅的解决方案,但一旦我开始使用它,我就放弃了它。

很抱歉,如果你想重现这个,但那是一年多以前我离开了公司,所以我无法访问路径是什么。

Jenkins -> 管理 Jenkins -> 配置系统 -> 全局属性 -> 环境变量 -> 名称:LC_ALL,值:en_US.UTF-8