Stasis

Conditions

Run steps conditionally

Conditions

Conditions let you control when steps run. You can skip steps based on the branch, the result of previous steps, or custom expressions.

Basic Conditions

if — Run Only When True

steps:
  - name: Deploy
    if: github.ref == 'refs/heads/main'
    run: ./deploy.sh

This step only runs on the main branch.

when — Run Based on Previous Steps

steps:
  - name: Build
    run: make build

  - name: Notify on failure
    when: on_failure
    run: echo "Build failed!"
ValueDescription
alwaysRun regardless of previous steps
on_successRun only if all previous steps succeeded (default)
on_failureRun only if a previous step failed

Examples

Deploy Only on Main

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Build
        run: make build

      - name: Deploy
        if: github.ref == 'refs/heads/main'
        run: ./deploy.sh

Run Cleanup Always

steps:
  - name: Run tests
    run: npm test

  - name: Cleanup
    when: always
    run: rm -rf /tmp/test-data

Skip on Pull Requests

steps:
  - name: Publish
    if: github.event_name == 'push'
    run: npm publish

Multiple Conditions

steps:
  - name: Deploy to production
    if: github.ref == 'refs/heads/main' && github.event_name == 'push'
    run: ./deploy-production.sh

Environment Variables in Conditions

You can use environment variables in conditions:

steps:
  - name: Set environment
    run: echo "DEPLOY=true" >> $GITHUB_ENV

  - name: Deploy
    if: env.DEPLOY == 'true'
    run: ./deploy.sh

Next Steps

On this page