Interview Prep/GitHub Actions/Pipeline Design & Triggers

Your team wants preview environments per PR on EKS, destroyed when the PR closes. Design the workflow.

AdvancedScenarioPipeline Design & Triggers
Answer

Situation read → Lifecycle tied to PR events; must be safe for forks.

What I'd do →

  1. Trigger on pull_request types [opened, synchronize, reopened, labeled, closed], run only when label preview exists and the PR is from the same repo:
    if: github.event.pull_request.head.repo.full_name == github.repository && contains(github.event.pull_request.labels.*.name, 'preview')
    
  2. Deploy job (not closed): build image tagged pr-${{ github.event.number }}, helm upgrade --install pr-123 ./chart -n preview-pr-123 --create-namespace, environment preview with url.
  3. Teardown job: if: github.event.action == 'closed', helm uninstall and kubectl delete ns.
  4. concurrency: preview-${{ github.event.number }} without cancel for teardown.
  5. A nightly job deletes namespaces whose PR is closed, in case teardown failed.

Why → Fork PRs have no secrets, so restricting to same-repo PRs avoids failures and abuse.

Interview tip → Always mention the garbage collector job; teardown hooks fail eventually.

All GitHub Actions questions Roadmap: GitHub Actions

More on Pipeline Design & Triggers