Github Action因Ruby版本不匹配失败,Workflow反复执行报错求助
GitHub Action Workflow执行失败排查求助:Ruby版本不匹配问题
遇到Github Action Workflow持续执行失败,错误原因为Ruby版本不匹配。已查阅大量资料仍未解决,恳请提供排查思路。
相关配置与命令
pod_lint命令
pod_lint: @bundle exec pod spec lint project.podspec \ --sources='/repopath/podspecs.git,https://github.com/{dependency}.git,https://cdn.cocoapods.org/' \ --private \ --fail-fast \ --no-clean
Pod_lint.yaml配置文件
on: push: # Sequence of patterns matched against refs/heads branches: - master # Push events on master branch name: Podspec Lint jobs: test: name: Podspec Lint runs-on: macOS-latest strategy: matrix: ruby: [2.0.0, 2.7] steps: - name: Checkout uses: actions/checkout@master with: ruby-version: ${{ matrix.ruby }} env: GITHUB_TOKEN: ${{ github.token }} - name: Podspec Lint run: | gem install cocoapods-keys bundle install bundle exec pod install bundle exec rake make pod_lint
报错信息(截图内容)
截图显示当前环境使用的Ruby版本与项目要求的版本不匹配,例如出现类似「Your Ruby version is 2.6.8, but your Gemfile specified 2.7.0」的版本冲突提示。
排查思路
- 修正Ruby版本设置方式:
actions/checkout不支持ruby-version参数,当前配置完全无效。需改用ruby/setup-ruby动作来指定Ruby版本,替换现有步骤:- name: Checkout uses: actions/checkout@master env: GITHUB_TOKEN: ${{ github.token }} - name: Setup Ruby uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} bundler-cache: true # 可选,加速bundle install - 调整步骤执行顺序:必须先完成Ruby版本设置,再执行
bundle install、gem install等依赖安装操作,确保使用指定版本的Ruby环境。 - 核对Gemfile版本约束:检查项目根目录Gemfile开头的Ruby版本声明(如
ruby '2.7.0'),确保与矩阵中指定的版本一致,避免bundle安装时触发版本冲突。 - 适配bundler版本:不同Ruby版本对应不同的bundler兼容版本:
- Ruby 2.0.0需使用bundler 1.x系列(如
gem install bundler:1.17.3) - Ruby 2.7可使用bundler 2.x系列
在bundle install前添加对应版本的bundler安装命令,避免兼容性问题。
- Ruby 2.0.0需使用bundler 1.x系列(如
- 验证实际Ruby版本:在
Podspec Lint步骤开头加入ruby -v && bundle -v命令,输出当前环境的Ruby和bundler版本,确认版本是否符合预期,快速定位问题根源。
内容的提问来源于stack exchange,提问作者Sanoj Kashyap
相关产品推荐
相关产品推荐

