Interview's MateAI Engineering
Interview's Mate

AI Engineering

LLMs, RAG, agents & evals

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
AI Engineering topics
Lesson 125/ 160
07. Deployment

GitHub Actions

Workflow YAML for PR checks, eval gates, image builds, and deploys.

BeginnerWorkflows · Jobs3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

GitHub Actions runs your tests, evals and deployments automatically whenever you push code or open a pull request.

Think of it like…

A set of standing orders for a team's robot assistant: "when someone opens a pull request, do these checks; when code reaches main, build and ship; every night, run the long tests", with strict rules about which keys the robot may carry.

Where you’ve seen it

A repo has three workflows. ci.yml triggers on pull_request with path filters (src/**, prompts/**, tools/**, Dockerfile) and concurrency: group: ci-${{ github.ref }}, cancel-in-progress: true, so new pushes cancel stale runs. It runs lint and unit tests in a matrix over Python 3.11 and 3.12 with a pip cache, then a smoke eval job (needs: tests) that reads the provider key from a secret and uploads a results artefact. release.yml runs on pushes to main: it builds the image with BuildKit cache, tags it with the commit SHA, pushes to the registry using OIDC to assume a cloud role (no stored cloud keys), then deploys to a staging environment and waits for a required reviewer before production. nightly-evals.yml runs on a schedule cron and executes the 300-case suite. Every workflow sets permissions: contents: read at the top and widens it per job only where needed; third-party actions are pinned to commit SHAs. Usage arithmetic: 25 PRs a day × 2 pushes × 13 minutes = 650 runner-minutes a day; at about $0.008 per Linux minute that's roughly $5.20 a day (about $156 a month) before free-tier minutes; path filters and caching cut it by 40%, to about $94.

Words you’ll hear

Workflow / job / step
A YAML pipeline, its parallel units of work, and the commands within a job.
Runner
The machine that executes a job (hosted or self-hosted).
OIDC federation
Short-lived cloud credentials issued to a workflow without stored keys.
Environment protection
Required reviewers and secrets scoped to a deployment target.

Visual diagram

Loading interactive diagram

Theory & deep dive

Workflow anatomy and efficiency

A workflow file declares name, on (events, branches, paths filters), optional concurrency, permissions, env, and jobs. Each job has runs-on (ubuntu-latest or a self-hosted label), needs (dependencies on other jobs), optional strategy.matrix (run across Python versions or operating systems), environment and steps. Steps use uses: for actions (actions/checkout, actions/setup-python, actions/cache, docker/build-push-action) or run: for shell commands. Pass data between jobs with artifacts and outputs. Caching (actions/cache, setup actions with cache: pip, Docker layer caching via cache-from/cache-to) typically halves build time. Concurrency groups with cancel-in-progress stop outdated runs, and path filters skip workflows when irrelevant files change (documentation-only PRs).

Cost and speed: hosted Linux runners are billed per minute (about $0.008 for a standard 2-core runner after the free allowance; check current pricing), so 25 PRs a day × 2 pushes × 13 minutes = 650 minutes ≈ $5.20 a day. Reduce with caching, matrix pruning, cancel-in-progress, running expensive evals only when prompts/** or model config changes and splitting fast and slow jobs. Reusable workflows (workflow_call) and composite actions remove duplication across repositories. For GPU or large-memory jobs use larger or self-hosted runners, and isolate self-hosted runners carefully (ephemeral, no persistent credentials) because they execute repository code.

Concurrency and path filters

on: pull_request: paths: ["src/**", "prompts/**", "Dockerfile"] and concurrency: {group: ci-${{ github.ref }}, cancel-in-progress: true}. A docs-only PR skips the workflow; a second push to the same branch cancels the first run.

Key takeaway: Use triggers, path filters, caching and concurrency to keep workflows fast and cheap.

Security, secrets and deployments

Treat workflows as production code. Set permissions: contents: read at the workflow level and grant extra scopes per job (id-token: write for OIDC, packages: write to push images). Secrets are available to jobs by name; never echo them, avoid passing them via command-line arguments and don't expose them to pull requests from forks (pull_request from forks gets no secrets, which is the safe default; pull_request_target runs with secrets and must not check out untrusted code). Use OIDC so the workflow assumes a cloud role with a short-lived token (trust policy limited to the repo, branch and environment) instead of storing cloud keys. Pin third-party actions to full commit SHAs (tags can be moved) and review updates (Dependabot can raise PRs for actions).

For deployments, use environments (staging, production) with required reviewers, wait timers and environment-scoped secrets and variables; the release.yml job targeting production pauses for approval. Tag images with the commit SHA, deploy the same artefact built earlier and add smoke tests after deploy. For AI evals: run the smoke suite on PRs and the full suite nightly (schedule), upload results as artefacts, post a summary comment on the PR (per-tag diffs) and fail the check when gates are breached (see eval gates). Keep provider keys in environment secrets and set provider-side spend caps; log which workflow used them. Finally, monitor workflow health (duration, failure rate, flaky jobs) and delete unused workflows and secrets.

Least-privilege job

permissions: {contents: read, id-token: write} on the deploy job only. The job assumes arn:aws:iam::…:role/deploy-staging through OIDC (trust limited to repo acme/assistant, environment staging) and gets credentials that expire in 15 minutes.

Key takeaway: Use least-privilege permissions, OIDC, pinned actions and protected environments; keep secrets away from forks.

How it works, step by step

Step 1 of 4
Engineer

1. Create the CI workflow

Trigger on pull requests with path filters, cache dependencies, run a test matrix and cancel stale runs.

paths: src/, prompts/
Key numbers at this step
Permissions
contents: read

When to use it & trade-offs

What it is

GitHub Actions is GitHub's built-in automation platform. A workflow is a YAML file in .github/workflows/ that runs on events (pull_request, push, schedule, workflow_dispatch); it contains jobs that run on runners (GitHub-hosted or self-hosted machines), each made of steps that run shell commands or reusable actions. Useful features include matrix builds, caching, artifacts, environments with required reviewers, secrets and variables, OIDC federation to cloud providers (no long-lived keys), concurrency groups, path filters, reusable workflows and least-privilege permissions. For AI applications it runs unit tests, builds and pushes images, executes eval gates, deploys and runs scheduled full evaluations.

Why it matters: Most AI teams already host code on GitHub, so Actions is the lowest-friction place to enforce quality, safety and cost checks on every change. But workflows run code with access to secrets and deployment rights, so they are also a security boundary: a careless trigger or a compromised third-party action can leak provider keys or ship malicious images. Writing workflows that are fast, cheap and least-privilege matters as much as making them pass.

When to reach for it

  • PR checks and eval gates
  • Building, scanning and publishing images
  • Scheduled full evaluations and reports

When to avoid or be careful

  • Using pull_request_target with untrusted code
  • Long-lived cloud keys stored as secrets
  • Unpinned third-party actions

Runner choices

GitHub-hosted runners
Best for: Most CI and deployment jobs

Strengths: No maintenance; clean VM each run.

Watch out: Per-minute cost; limited hardware.

Larger hosted runners
Best for: Heavy builds and tests

Strengths: More CPU and memory without self-hosting.

Watch out: Higher cost per minute.

Self-hosted (ephemeral) runners
Best for: GPUs, private networks and special hardware

Strengths: Custom hardware; access to internal systems.

Watch out: Security and maintenance burden.

Interview signals & numbers to know

When this topic comes up

  • “Add a GitHub Action for evals”
  • OIDC to AWS or GCP
  • concurrency cancel-in-progress
  • Environment protection rules
  • Pinned action SHAs

Benchmarks & rules of thumb

~$0.008/min -
approximate hosted Linux runner price (check current rates)
650 min/day ≈ $5.20 -
usage at 25 PRs × 2 pushes × 13 min
15 minutes -
example lifetime of OIDC-issued credentials

Common mistakes & follow-ups

Common interview mistakes

  • Letting every job have write permissions by default.
  • Running evals on forked PRs with secrets exposed.
  • Not cancelling superseded runs, paying for stale work.

Likely interviewer follow-ups

  • How would you gate a pull request on LLM eval results in GitHub Actions?
  • Why use OIDC instead of stored cloud keys?
  • How do you keep Actions costs under control?
Interview tip: Mention permissions, OIDC and SHA pinning. They show you treat workflows as a security boundary.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply GitHub Actions with generative AI interview Q&A and hands-on practice.

Open Generative AI Q&A →Tech Learn Q&A
Previous topic
CI/CD Pipelines
Next topic
Eval Gates in CI