【发布时间】:2021-01-12 15:33:50
【问题描述】:
我正在尝试用 Github Actions 替换我们 iOS 项目可怕的 Jenkins 设置。我想我已经准备好了所有的部分,但是我遇到了一个我不理解的失败。在我运行xcodebuild 以构建和测试应用程序的步骤中,我收到一个错误,即xcpretty 是一个未知命令,尽管在上一步中是通过捆绑程序安装的。以下是相关文件:
构建和运行.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 的目录不在搜索路径中,但我不确定我会怎么做。我确信有一个合理的解决方案,但我很难找到它,而且我已经厌倦了用头撞墙。
【问题讨论】:
-
嗨 Joshua,你找到这个问题的答案了吗?
-
是的,我必须手动为其设置 ruby gem 安装目录的路径。这是残酷的。我认为一定有比这更优雅的解决方案。
-
@JoshuaSullivan 嘿,详细说明此问题的修复方法?我们现在遇到了同样的问题,但我们的 Github 操作似乎没有任何变化。
标签: ios rubygems github-actions xcodebuild