How to Run Different Steps per OS in a Matrix in GitHub Actions
Gate steps on runner.os (or matrix.os) so each platform in the matrix runs its own commands.
In an OS matrix, runner.os is Linux, Windows, or macOS. Add if: runner.os == '...' to each platform-specific step.
Steps
- Define an
osmatrix and setruns-on: ${{ matrix.os }}. - Gate platform steps with
if: runner.os == 'Windows'etc. - Use
runner.osfor portability across runner labels.
Workflow
.github/workflows/ci.yml
jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Linux setup
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y libssl-dev
- name: Windows setup
if: runner.os == 'Windows'
run: choco install openssl -yGotchas
runner.osvalues areLinux,Windows,macOS, case-sensitive.- Prefer
runner.osover parsingmatrix.os, since runner labels can vary.
Related guides
How to Run a Step Only if a Condition Is True in GitHub ActionsGuard a single GitHub Actions step with a step-level if expression so it runs only when the condition evaluat…
How to Compare Two Strings in an if Condition in GitHub ActionsCompare strings in a GitHub Actions if using == and !=, understanding case sensitivity and how the expression…