DevOps / GitHub Actions Interview Questions
How is a GitHub Actions workflow file structured, and where must it be placed?
Every workflow file must be placed inside the .github/workflows/ directory at the root of your repository and must use the .yml or .yaml extension. GitHub automatically detects any file in that directory and registers it as a workflow.
The top-level keys of a workflow file are:
name:— A human-readable label shown in the GitHub UI (optional but recommended).on:— Declares the event(s) that trigger the workflow (required).env:— Workflow-level environment variables available to all jobs (optional).permissions:— Restricts whatGITHUB_TOKENcan do (optional, security best-practice).jobs:— A map of one or more named jobs (required).
A minimal but realistic example that checks out code and runs tests:
name: CI on: push: branches: [main] pull_request: jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Set up Node.js uses: actions/setup-node@v4 with: node-version: '20' - name: Install dependencies run: npm ci - name: Run tests run: npm test
Each job under jobs: must declare runs-on: (the runner label), and then list its steps:. Step names are optional but make run logs much easier to read. YAML indentation is significant — use spaces, never tabs.
More Related questions...