Interview Prep/GitHub Actions/Jobs, Steps, Matrix & Concurrency

How do you run a step only on a specific OS in a cross-platform matrix?

BeginnerConceptJobs, Steps, Matrix & Concurrency
Answer

Use the runner context at step level:

- if: runner.os == 'Windows'
  shell: pwsh
  run: Get-ChildItem env:
- if: runner.os != 'Windows'
  run: env | sort

runner.os is Linux, Windows or macOS; runner.arch is X64 or ARM64.

All GitHub Actions questions Roadmap: GitHub Actions

More on Jobs, Steps, Matrix & Concurrency