Section: Jobs, steps, and conditionals

Run a step only on main

yaml
yaml
- name: Publish
  if: github.ref == 'refs/heads/main'
  run: npm run publish
Explanation

Conditionals help keep a single workflow flexible across branches and events.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Jobs, steps, and conditionals
Run a job only for tags
Gate a full job on a tag-based release.
OpenIn sheetyamlsame section
Check out repository code
Fetch the repo in a workflow job.
OpenIn sheetyamlsame section
Set up Node.js
Install a specific Node.js version for the job.
OpenIn sheetyamlsame section
Allow a non-blocking step
Continue the job even if a step fails.
OpenIn sheetyamlsame section
Test across multiple Node versions
Use a strategy matrix for version coverage.
Run on multiple operating systems
Validate portability across Linux, macOS, and Windows.