How do I not run a job instance based on conditional

My Github Actions YAML file looks like this -

jobs:
  build:
    name: ${{ matrix.name }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:

        include:
          - name: macos-foo
            os: macos-latest
            compiler: clang

How do I only run this job instance if a certain conditional matches?

For eg, only for a specific branch -

steps:
- uses: nelonoel/branch-name@v1.0.1
- name: Check branch name
  if: $BRANCH_NAME == "bar"
  run: ...

I can cancel the job instance based on a certain conditional, but I want to include the conditional in the matrix itself so that the job instance does not execute at all (as opposed to being cancelled).

If skipping matrix jobs isn’t good enough, then the only option I know is to construct the matrix dynamically. You basically need a job that generates the matrix as JSON string, set it as job output, and use that as matrix in a subsequent job like matrix: ${{ fromJSON(needs.generate-matrix.outputs.matrix }}.

There’s an example in the documentation about fromJSON(): Context and expression syntax for GitHub Actions - GitHub Docs