Skip to content
Latchkey

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 os matrix and set runs-on: ${{ matrix.os }}.
  • Gate platform steps with if: runner.os == 'Windows' etc.
  • Use runner.os for 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 -y

Gotchas

  • runner.os values are Linux, Windows, macOS, case-sensitive.
  • Prefer runner.os over parsing matrix.os, since runner labels can vary.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →