GitHub Actions let us define matrices to launch several variations of a single job. For instance for starting a job on two operating systems:
name: Build
on:
push
branches: [ main ]
jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- (…)
GitHub Actions also let us use a Docker container on Linux:
name: Build
on:
push
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
container: my-docker/container:0.1.0
steps:
- (…)
Is it possible to use both at the same time: running a job on several operating systems using matrices, and using a Docker container specifically for Linux? Something among the lines of (this code is invalid):
name: Build
on:
push
branches: [ main ]
jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
container:
if: matrix.os == 'ubuntu-latest'
image: my-docker/container:0.1.0
steps:
- (…)
This code is not correct because container
cannot have a if
keyword. If I remove the if
, the code is correct but the job will fail on macOS runners (which cannot run Docker). How do I enable container
for Linux and disable it for everything else? I found no information at all about this use case in the documentation.