The model: workflows, jobs, steps and runners
GitHub Actions is the CI/CD system built into GitHub and now the default for many product companies in Bangalore — often alongside or replacing Jenkins. Writing a basic workflow is easy; senior interviews probe the details that matter in production: event types and their security implications, reusable workflows for dozens of repos, OIDC to AWS instead of stored keys, self-hosted runners on Kubernetes, caching, environments with approvals, and hardening against supply-chain and injection attacks.
Building blocks
| Concept | What it is |
|---|---|
| Workflow | A YAML file in .github/workflows/ triggered by events |
| Event | What starts it: push, pull_request, schedule, workflow_dispatch, release... |
| Job | A set of steps that runs on one runner; jobs run in parallel by default |
| Step | A shell command (run:) or an action (uses:) |
| Action | A reusable unit: JavaScript, Docker container, or composite (actions/checkout@v4) |
| Runner | The machine executing a job: GitHub-hosted VM or self-hosted |
Anatomy of a workflow
name: ci
on:
pull_request:
branches: [main]
paths: ["services/orders/**", ".github/workflows/ci.yml"]
push:
branches: [main]
permissions: # least-privilege GITHUB_TOKEN for all jobs
contents: read
concurrency: # cancel superseded runs of the same PR/branch
group: ci-${{ github.ref }}
cancel-in-progress: true
env:
JAVA_VERSION: "21"
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: ${{ env.JAVA_VERSION }}
cache: maven # built-in dependency caching
- run: mvn -B -ntp verify
- uses: actions/upload-artifact@v4
if: always()
with:
name: test-reports
path: target/surefire-reports/
Each job gets a fresh runner (on GitHub-hosted runners): nothing persists between jobs except what you pass via artifacts, caches or job outputs.
Contexts and expressions
${{ ... }} expressions read contexts:
| Context | Examples |
|---|---|
github |
github.sha, github.ref, github.ref_name, github.event_name, github.actor, github.repository, github.event.pull_request.number |
env |
Workflow/job/step environment variables |
vars |
Configuration variables (repo/org/environment) |
secrets |
Encrypted secrets |
inputs |
workflow_dispatch / workflow_call inputs |
needs |
Outputs and results of dependency jobs |
matrix, strategy |
Matrix values |
runner |
runner.os, runner.temp |
steps |
steps.<id>.outputs.<name>, steps.<id>.outcome |
Functions: contains(), startsWith(), format(), toJSON(), fromJSON(), hashFiles() (for cache keys), and status functions success(), failure(), always(), cancelled().
Setting outputs and environment from a step:
- id: meta
run: |
echo "tag=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
echo "BUILD_DATE=$(date -u +%F)" >> "$GITHUB_ENV"
echo "### Built ${GITHUB_SHA::7}" >> "$GITHUB_STEP_SUMMARY"
- run: echo "Image tag is ${{ steps.meta.outputs.tag }}"
(set-output and set-env workflow commands are deprecated — use the $GITHUB_OUTPUT and $GITHUB_ENV files.)