Gerard Morera
Gerard Morera

Reputation: 859

Ruby and Rails Github Action exit code 16

I am trying to set up a continuous integration workflow with Github actions for a new Rails project. This is the error:

2022-05-21T17:07:01.1242737Z Your bundle only supports platforms ["x86_64-darwin-19", "x86_64-darwin-21"] but
2022-05-21T17:07:01.1243516Z your local platform is x86_64-linux. Add the current platform to the lockfile
2022-05-21T17:07:01.1244782Z with `bundle lock --add-platform x86_64-linux` and try again.
2022-05-21T17:07:01.1294935Z Took   1.38 seconds
2022-05-21T17:07:01.1295823Z ##[endgroup]
2022-05-21T17:07:01.1347744Z ##[error]Error: The process '/opt/hostedtoolcache/Ruby/3.1.2/x64/bin/bundle' failed with exit code 16
    at ExecState._setResult (/home/runner/work/_actions/ruby/setup-ruby/v1/dist/index.js:4918:25)
    at ExecState.CheckComplete (/home/runner/work/_actions/ruby/setup-ruby/v1/dist/index.js:4901:18)
    at ChildProcess.<anonymous> (/home/runner/work/_actions/ruby/setup-ruby/v1/dist/index.js:4795:27)
    at ChildProcess.emit (node:events:390:28)
    at maybeClose (node:internal/child_process:1064:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)

And the configuration file:

name: My workflow
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - uses: ruby/setup-ruby@v1
      with:
        bundler-cache: true
    - run: bundle exec rake

Does anybody know what the issue is?

Upvotes: 23

Views: 7307

Answers (3)

superus8r
superus8r

Reputation: 941

TL;DR

Run this command locally in your project and commit the changes

bundle lock --add-platform x86_64-linux

Why does this work?

The answers from Gerard Morera and Wael Mohammed are correct. Here's more detail to it:

Considering the following Github Actions config for Ruby:

...
  unit-test:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - uses: ruby/setup-ruby@v1
      with:
        ruby-version: '3.0'
        bundler-cache: true
...

The config declares ubuntu-latest platform image for running the job on Github Actions. Github Actions uses x86_64-linux platform for ubuntu. However, the Gemfile.lock is missing that platform leading to exit code 16.

Running the following command locally will add x86_64-linux platform to Gemfile.lock:

bundle lock --add-platform x86_64-linux

After running the command, the final Gemfile.lock looks similar to this:

...
PLATFORMS
  universal-darwin-22
  x64-mingw32
  x86_64-linux

DEPENDENCIES
  fastlane
...

The x86_64-linux is now added under PLATFORMS list in Gemfile.lock, therefore it will run correctly on ubuntu images of Github Actions.

Upvotes: 14

Wael Mohammed
Wael Mohammed

Reputation: 91

The answer provided by Gerard Morera worked fine for me; however, it took me a while to realise that I needed to run bundle lock --add-platform x86_64-linux via PowerShell/command line from within the project (it was a Jekyll project/site on my case).

It may also be helpful to highlight that the reason this issue appeared in my case was that I was bundling the site on Windows 10 while a Linux-powered machine handled the deployment (triggered/controlled by a GitHub workflow.

Upvotes: 9

Gerard Morera
Gerard Morera

Reputation: 859

[ISSUE FIXED]

Solution:

Run bundle lock --add-platform x86_64-linux

Upvotes: 38

Related Questions