matrix の一部だけ実行する
条件フラグを matrix に載せて exclude する。fromJSON で組み立てる必要はない。
前段 job で JSON を組み立てなくても、matrix 内に条件を置いて exclude できる。
デフォルトブランチ以外で macOS を外す
yaml
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node: [18, 20, 22]
onDefaultBranch: ${{ github.ref_name == github.event.repository.default_branch }}
exclude:
- os: macos-latest
onDefaultBranch: falseexclude に一致する組み合わせはすべて外れる。上の例では node の 18 / 20 / 22 すべてから macOS が消える。
特定の組み合わせだけ残す
if 相当のフラグをアイテムに生やし、false を exclude する。
yaml
strategy:
matrix:
project:
- name: webkit
browser: webkit
if: ${{ env.RUNNER_OS == 'macos-latest' }}
- name: chromium
browser: chromium
if: true
exclude:
- project:
if: falseinclude との順
include は exclude の後に評価される。exclude で外した組み合わせが include で戻ることがある。