Interview Prep/GitHub Actions/Pipeline Design & Triggers

Your deploy job must run only for pushes to `main` and for `v*` tags, never for PRs. Write the conditions.

BeginnerScenarioPipeline Design & Triggers
Answer

Situation read → Routing logic at job level.

What I'd do →

  1. Trigger on both:
    on:
      pull_request:
      push:
        branches: [main]
        tags: ["v*"]
    
  2. Gate the deploy job:
    deploy:
      needs: build
      if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
    
  3. Back it with environment deployment branch policies so the YAML is not the only protection.

Why → Defence in depth: someone can edit the YAML in a branch, but not the environment policy.

Interview tip → "Conditions are routing, environments are enforcement."

All GitHub Actions questions Roadmap: GitHub Actions

More on Pipeline Design & Triggers