Run matrix job on macos and on ubuntu in container

Let’s consider the following workflow:

name: On push

on:
  push:
    branches: master

jobs:
  main:
    strategy:
      matrix:
        os:
          - ubuntu-18.04
          - macos-10.14
    runs-on: ${{ matrix.os }}
    container: linuxbrew/brew
    steps:
      - name: brew config
        run: |
          brew config

Currently the macos job will fail because: “##[error]File not found: ‘docker’”.

What I would want to see is: the macos job would run on macos VM and ubuntu job would run in container.

I know I can workaround this by making 2 separate jobs but I would need to repeat myself and would rather avoid that, granted that this workflow is simple and I can do it easily but it is just an example.

7 Likes

I definitely understand the motivation here.  I’m not sure that just ignoring the container key on macOS runs will necessarily be the solution, but we’ll look at how to simplify this for you so that it’s more DRY.

2 Likes

Just wanted to say this would be very helpful for us as well. Is there anyway currently we can write the yaml so that the container field is included conditionally, only for the linux builds? That would basically solve the issue for us I think.

3 Likes

Yes, the solution here would be for GitHub Actions to allow something like:

container:
  image: debian:stable
  if: matrix.os == ubuntu-latest

for example.

This problem is compounded by the fact that Yaml anchors are not supported - further forcing us to duplicate CI specification code.

1 Like

@pmatos I like your suggestion! It’s concise, clear, explicit, and consistent. @ethomson what do you think?