GitHub Actions
GitHub Actions
GitHub Actions Command Handbook:
1. GitHub CLI Installation & Configuration
# Check GitHub CLI version gh --version # Display help gh help # Display help for a specific command gh help workflow gh help run gh help secret # Check authentication status gh auth status # Authenticate with GitHub gh auth login # Authenticate using a token gh auth login --with-token # Log out gh auth logout # Display current GitHub account gh api user # Display current repository gh repo view
2. GitHub Repository Management
# Display repository information gh repo view # Display repository in browser gh repo view --web # Clone repository gh repo clone OWNER/REPOSITORY # Create repository gh repo create my-project # Create public repository gh repo create my-project --public # Create private repository gh repo create my-project --private # Fork repository gh repo fork OWNER/REPOSITORY # List repositories gh repo list # List repositories for an organization gh repo list ORGANIZATION # Display repository branches gh api repos/OWNER/REPOSITORY/branches # Display repository settings gh repo view OWNER/REPOSITORY --json name,visibility,url
3. GitHub Actions Workflow Initialization
# Create workflow directory mkdir -p .github/workflows # Create workflow file touch .github/workflows/ci.yml # List workflow files ls -la .github/workflows/ # Display workflow configuration cat .github/workflows/ci.yml # Check GitHub CLI workflow support gh workflow --help # List available workflows gh workflow list # Validate workflow YAML locally yamllint .github/workflows/ci.yml
Example basic workflow:
name: CI Pipeline
on:
push:
branches:
- main
pull_request:
branches:
- main
permissions:
contents: read
jobs:
build:
name: Build Application
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Display environment
run: |
echo "Building application"
echo "Repository: $GITHUB_REPOSITORY"
echo "Branch: $GITHUB_REF_NAME"
4. Workflow Triggers & Events
Common workflow triggers:
# Trigger on push
on:
push:
branches:
- main
- develop
# Trigger on pull requests
on:
pull_request:
branches:
- main
# Trigger on release
on:
release:
types: [published]
# Trigger manually
on:
workflow_dispatch:
# Trigger on schedule
on:
schedule:
- cron: "0 2 * * *"
# Trigger on tags
on:
push:
tags:
- "v*"
# Trigger on issue creation
on:
issues:
types: [opened]
# Trigger on deployment
on:
deployment:
# Trigger when another workflow completes
on:
workflow_run:
workflows: ["CI Pipeline"]
types: [completed]
Combined trigger example:
name: Application CI
on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
workflow_dispatch:
schedule:
- cron: "0 3 * * 1"
Useful event filters:
| Option | Purpose |
| --- | --- |
| `branches` | Include specific branches |
| `branches-ignore` | Exclude branches |
| `tags` | Include specific tags |
| `paths` | Trigger when specified files change |
| `paths-ignore` | Ignore specified file changes |
| `types` | Select event activity types |
| `cron` | Define scheduled execution |
| `workflowdispatch` | Enable manual execution |
5. Workflow Execution & Monitoring
# List workflows gh workflow list # Display workflow details gh workflow view # Display a specific workflow gh workflow view ci.yml # Display workflow in browser gh workflow view ci.yml --web # Run workflow manually gh workflow run ci.yml # Run workflow on a specific branch gh workflow run ci.yml --ref develop # Run workflow with input parameters gh workflow run deploy.yml \ -f environment=staging \ -f version=1.0.0 # List workflow runs gh run list # List runs for a specific workflow gh run list --workflow ci.yml # List runs for a specific branch gh run list --branch main # List failed runs gh run list --status failure # List successful runs gh run list --status success # View latest workflow run gh run view # View a specific run gh run view RUN_ID # View run in browser gh run view RUN_ID --web # Watch workflow execution gh run watch RUN_ID # Display workflow logs gh run view RUN_ID --log # Display failed step logs gh run view RUN_ID --log-failed
Useful workflow commands:
| Command | Purpose |
| --- | --- |
| `gh workflow list` | List workflows |
| `gh workflow view` | Display workflow details |
| `gh workflow run` | Manually trigger workflow |
| `gh workflow enable` | Enable workflow |
| `gh workflow disable` | Disable workflow |
| `gh run list` | List workflow executions |
| `gh run view` | Inspect execution |
| `gh run watch` | Monitor execution |
| `gh run rerun` | Rerun execution |
| `gh run cancel` | Cancel execution |
| `gh run delete` | Delete execution |
6. Workflow Jobs & Steps Configuration
Example workflow with multiple jobs:
name: Build and Test
on:
push:
branches: [main]
permissions:
contents: read
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build application
run: |
echo "Building application"
test:
name: Test
runs-on: ubuntu-latest
needs: build
steps:
- name: Run tests
run: |
echo "Running tests"
deploy:
name: Deploy
runs-on: ubuntu-latest
needs: test
steps:
- name: Deploy application
run: |
echo "Deploying application"
Useful job configuration:
| Option | Purpose |
| --- | --- |
| `name` | Set workflow or job name |
| `runs-on` | Select runner |
| `needs` | Define job dependencies |
| `steps` | Define job execution steps |
| `if` | Conditional execution |
| `env` | Define environment variables |
| `timeout-minutes` | Set execution timeout |
| `continue-on-error` | Continue after a step failure |
| `strategy` | Configure job execution strategy |
| `container` | Run job inside a container |
| `services` | Define service containers |
| `outputs` | Export job outputs |
| `permissions` | Configure token permissions |
7. Environment Variables & Contexts
name: Environment Variables
on:
push:
env:
APP_NAME: my-application
ENVIRONMENT: development
jobs:
build:
runs-on: ubuntu-latest
env:
BUILD_VERSION: 1.0.0
steps:
- name: Display variables
env:
MESSAGE: "Hello GitHub Actions"
run: |
echo "$APP_NAME"
echo "$ENVIRONMENT"
echo "$BUILD_VERSION"
echo "$MESSAGE"
Useful GitHub-provided environment variables:
| Variable | Purpose |
| --- | --- |
| `GITHUBREPOSITORY` | Repository name |
| `GITHUBREPOSITORYOWNER` | Repository owner |
| `GITHUBWORKSPACE` | Workspace directory |
| `GITHUBSHA` | Commit SHA |
| `GITHUBREF` | Full Git reference |
| `GITHUBREFNAME` | Branch or tag name |
| `GITHUBRUNID` | Workflow run ID |
| `GITHUBRUNNUMBER` | Workflow run number |
| `GITHUBACTOR` | User or application that initiated the run |
| `GITHUBEVENTNAME` | Triggering event |
| `GITHUBJOB` | Current job ID |
| `RUNNEROS` | Runner operating system |
| `RUNNERTEMP` | Temporary directory |
Common contexts:
${{ github.repository }}
${{ github.ref }}
${{ github.sha }}
${{ github.actor }}
${{ github.event_name }}
${{ github.workflow }}
${{ github.run_id }}
${{ github.job }}
${{ runner.os }}
${{ runner.arch }}
${{ job.status }}
${{ steps.build.outcome }}
${{ needs.build.result }}
${{ vars.APP_ENVIRONMENT }}
${{ secrets.DEPLOY_TOKEN }}
${{ inputs.environment }}
8. Secrets & Variables Management
GitHub CLI commands:
# List repository secrets gh secret list # Create repository secret interactively gh secret set DEPLOY_TOKEN # Create secret from environment variable gh secret set DEPLOY_TOKEN --body "$DEPLOY_TOKEN" # Create organization secret gh secret set DEPLOY_TOKEN --org ORGANIZATION # Delete repository secret gh secret delete DEPLOY_TOKEN # List repository variables gh variable list # Create repository variable gh variable set APP_ENVIRONMENT --body "production" # Create organization variable gh variable set APP_ENVIRONMENT \ --org ORGANIZATION \ --body "production" # Delete repository variable gh variable delete APP_ENVIRONMENT
Example workflow:
name: Deploy Application
on:
workflow_dispatch:
permissions:
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Deploy
env:
DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
APP_ENVIRONMENT: ${{ vars.APP_ENVIRONMENT }}
run: |
echo "Deploying to $APP_ENVIRONMENT"
./deploy.sh
Secret and variable scopes:
| Scope | Description |
| --- | --- |
| Repository | Available to a specific repository |
| Environment | Available to jobs using a configured environment |
| Organization | Shared across authorized repositories |
Note: Never print secrets in workflow logs. Prefer environment-scoped secrets and restrict access to deployment credentials.
9. Artifacts & Build Management
name: Build Artifacts
on:
push:
branches: [main]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build application
run: |
mkdir -p dist
echo "Application build" > dist/app.txt
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: application-build
path: dist/
retention-days: 7
Download artifact example:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: application-build
path: dist/
- name: Display artifact
run: ls -la dist/
Artifact commands:
# List workflow runs gh run list # View run details gh run view RUN_ID # Download all artifacts from a run gh run download RUN_ID # Download a specific artifact gh run download RUN_ID -n application-build # Download artifact to a directory gh run download RUN_ID -n application-build -D ./artifacts
10. Dependency Caching
Example Node.js dependency caching:
name: Node.js CI
on:
push:
branches: [main]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
Manual cache configuration:
- name: Cache dependencies
uses: actions/cache@v4
with:
path: ~/.npm
key: npm-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
restore-keys: |
npm-${{ runner.os }}-
Common cache options:
| Option | Purpose |
| --- | --- |
| `path` | Files or directories to cache |
| `key` | Unique cache identifier |
| `restore-keys` | Fallback cache keys |
| `enableCrossOsArchive` | Enable cross-OS archive support |
11. Matrix Builds & Parallel Execution
Matrix builds allow the same job to run against multiple versions or operating systems.
name: Multi-Version Testing
on:
push:
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: [20, 22, 24]
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Run tests
run: npm test
Useful matrix options:
| Option | Purpose |
| --- | --- |
| `matrix` | Define combinations |
| `fail-fast` | Cancel remaining jobs after failure |
| `max-parallel` | Limit concurrent jobs |
| `include` | Add specific combinations |
| `exclude` | Remove combinations |
Example include and exclude:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
node: [20, 22]
exclude:
- os: windows-latest
node: 20
include:
- os: ubuntu-latest
node: 24
12. Reusable Workflows & Composite Actions
Reusable workflows help standardize CI/CD pipelines across repositories.
Reusable workflow:
# .github/workflows/reusable-build.yml
name: Reusable Build
on:
workflow_call:
inputs:
node-version:
required: true
type: string
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
- name: Install and build
run: |
npm ci
npm run build
Calling reusable workflow:
name: Application CI
on:
push:
jobs:
build:
uses: ./.github/workflows/reusable-build.yml
with:
node-version: "22"
Composite action example:
# .github/actions/setup-project/action.yml
name: Setup Project
description: Install project dependencies
runs:
using: composite
steps:
- name: Install dependencies
shell: bash
run: npm ci
- name: Build project
shell: bash
run: npm run build
Calling composite action:
- name: Setup project uses: ./.github/actions/setup-project
13. Containers & Service Dependencies
Run jobs inside Docker containers:
name: Container CI
on:
push:
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
container:
image: node:22
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
Example with PostgreSQL service:
name: Integration Tests
on:
push:
permissions:
contents: read
jobs:
integration:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16
env:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: app
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U test"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Run integration tests
env:
DATABASE_URL: postgres://test:test@localhost:5432/app
run: npm run test:integration
14. Deployment Environments & Approvals
Example production deployment:
name: Production Deployment
on:
workflow_dispatch:
permissions:
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
environment:
name: production
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Deploy application
env:
DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
run: ./deploy.sh
Environment configuration:
| Feature | Purpose |
| --- | --- |
| Environment name | Identify deployment target |
| Environment secrets | Store environment-specific credentials |
| Environment variables | Store configuration values |
| Required reviewers | Require approval before deployment |
| Deployment branches | Restrict eligible branches |
| Wait timer | Delay deployment |
Create deployment environments through repository Settings → Environments.
15. GitHub Actions Permissions & Security
Example least-privilege configuration:
name: Secure CI
on:
pull_request:
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build
run: npm ci && npm run build
Useful permissions:
| Permission | Purpose |
| --- | --- |
| `contents` | Repository contents |
| `actions` | Workflow and action management |
| `checks` | Check runs |
| `deployments` | Deployment management |
| `issues` | Issue management |
| `packages` | GitHub Packages |
| `pull-requests` | Pull request management |
| `security-events` | Security event management |
| `id-token` | OpenID Connect authentication |
Security recommendations:
- Use minimum required `GITHUBTOKEN` permissions.
- Pin third-party actions to full commit SHAs.
- Avoid exposing secrets to untrusted pull request code.
- Use GitHub Environments for production deployments.
- Prefer OpenID Connect over long-lived cloud credentials.
- Restrict deployment permissions.
- Review third-party actions before using them.
- Avoid executing untrusted expressions directly in shell scripts.
- Use Dependabot to monitor GitHub Actions dependencies.
- Audit workflow permissions regularly.
16. OpenID Connect (OIDC) & Cloud Authentication
OIDC enables workflows to authenticate with supported cloud providers without storing long-lived cloud credentials as GitHub secrets.
Example configuration:
name: Cloud Deployment
on:
push:
branches: [main]
permissions:
contents: read
id-token: write
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Authenticate with cloud provider
run: |
echo "Configure cloud provider OIDC authentication here"
- name: Deploy
run: ./deploy.sh
Important OIDC requirements:
| Setting | Purpose |
| --- | --- |
| `id-token: write` | Allow requesting an OIDC token |
| Cloud identity provider | Trust GitHub's OIDC issuer |
| Trust conditions | Restrict repository, branch, or environment |
| Audience | Identify intended token recipient |
Note: The cloud provider must be configured to trust the expected GitHub repository and workflow identity.
17. Workflow Debugging & Troubleshooting
# List recent workflow runs gh run list # List failed runs gh run list --status failure # View failed workflow run gh run view RUN_ID # Display complete logs gh run view RUN_ID --log # Display failed step logs gh run view RUN_ID --log-failed # Watch execution gh run watch RUN_ID # Rerun failed jobs gh run rerun RUN_ID --failed # Rerun entire workflow gh run rerun RUN_ID # Cancel workflow run gh run cancel RUN_ID # Delete workflow run gh run delete RUN_ID # View workflow configuration gh workflow view ci.yml # View workflow in browser gh workflow view ci.yml --web
Common troubleshooting scenarios:
| Problem | Possible solution |
| --- | --- |
| Workflow does not trigger | Check event configuration and branch filters |
| YAML syntax error | Validate indentation and YAML structure |
| Permission denied | Review `permissions` and repository settings |
| Secret unavailable | Verify secret name and scope |
| Dependency installation failure | Review lockfile and package registry access |
| Cache not restored | Check cache key and cache paths |
| Artifact not found | Verify upload/download names and job dependencies |
| Deployment approval pending | Check environment protection rules |
| Workflow timeout | Review `timeout-minutes` and long-running steps |
| Action version failure | Check action version and compatibility |
| Runner unavailable | Verify runner labels and availability |
18. Workflow Automation & Scheduling
name: Scheduled Maintenance
on:
schedule:
# Every day at 02:00 UTC
- cron: "0 2 * * *"
workflow_dispatch:
permissions:
contents: read
jobs:
maintenance:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Run maintenance
run: ./scripts/maintenance.sh
Common cron expressions:
| Expression | Schedule |
| --- | --- |
| `0 * * * *` | Every hour |
| `0 2 * * *` | Every day at 02:00 UTC |
| `0 0 * * 1` | Every Monday |
| `0 0 1 * *` | First day of every month |
| `*/15 * * * *` | Every 15 minutes |
| `30 8 * * 1-5` | Weekdays at 08:30 UTC |
Note: Scheduled workflows use UTC and may be delayed during periods of high GitHub Actions load.
19. GitHub Actions CI/CD Real-World Workflows
Example Node.js CI/CD pipeline:
name: Node.js CI/CD
on:
push:
branches: [main]
pull_request:
branches: [main]
permissions:
contents: read
jobs:
test:
name: Test Application
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
- name: Build
run: npm run build
deploy:
name: Deploy Application
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
environment:
name: production
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Deploy
env:
DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
run: ./deploy.sh
Useful CI/CD workflow patterns:
| Pattern | Purpose |
| --- | --- |
| CI on pull request | Validate changes before merging |
| Build on push | Build application after commits |
| Matrix testing | Test multiple versions and platforms |
| Artifact publishing | Store build outputs |
| Container publishing | Build and publish Docker images |
| Release automation | Publish application releases |
| Environment deployment | Deploy to staging or production |
| Scheduled maintenance | Run automated maintenance tasks |
20. GitHub Actions Commands Every DevOps Engineer Should Memorize
| Command | Purpose |
| --- | --- |
| `gh auth login` | Authenticate GitHub CLI |
| `gh auth status` | Check authentication |
| `gh repo view` | Display repository information |
| `gh workflow list` | List workflows |
| `gh workflow view` | View workflow details |
| `gh workflow run` | Trigger workflow |
| `gh workflow enable` | Enable workflow |
| `gh workflow disable` | Disable workflow |
| `gh run list` | List workflow runs |
| `gh run view` | Inspect workflow run |
| `gh run watch` | Monitor workflow |
| `gh run rerun` | Rerun workflow |
| `gh run cancel` | Cancel workflow |
| `gh run download` | Download workflow artifacts |
| `gh secret list` | List repository secrets |
| `gh secret set` | Create or update secret |
| `gh secret delete` | Delete secret |
| `gh variable list` | List repository variables |
| `gh variable set` | Create or update variable |
| `gh api` | Access GitHub REST or GraphQL APIs |
21. Best Practices for Technical Leads & DevOps Engineers
- Keep workflows organized inside `.github/workflows/`.
- Use descriptive workflow and job names.
- Separate build, test, security scanning, and deployment jobs.
- Use reusable workflows for common CI/CD processes.
- Use composite actions for repeated step sequences.
- Define explicit `GITHUBTOKEN` permissions.
- Pin third-party actions to immutable commit SHAs.
- Use dependency caching to reduce execution time.
- Use artifacts to transfer build outputs between jobs.
- Use matrix builds for multi-version testing.
- Use environments to protect production deployments.
- Require approval for sensitive production deployments.
- Prefer OIDC for cloud authentication.
- Never expose credentials in logs.
- Use concurrency groups to prevent conflicting deployments.
- Set appropriate job and step timeouts.
- Use `if`, `needs`, and status functions carefully.
- Monitor failed workflow runs and execution time.
- Keep workflow dependencies and actions updated.
- Test workflows using pull requests before production rollout.
- Use self-hosted runners only with appropriate isolation and security controls.
- Document reusable workflow inputs and outputs.
- Avoid unnecessary workflow executions using path and branch filters.
- Use Dependabot to maintain action dependencies.
- Regularly review workflow security and deployment permissions.
Beginner
Q1: What is GitHub Actions?
GitHub Actions is GitHub’s automation platform for CI/CD and repository workflows.
Q2: What can GitHub Actions automate?
Builds, tests, releases, deployments, issue/PR workflows, and custom operational tasks.
Q3: What is a workflow?
A YAML-defined automation process stored in .github/workflows/.
Q4: What is an event in Actions?
A trigger that starts workflows (push, pull_request, schedule, workflow_dispatch, etc.).
Q5: What is a job?
A set of steps executed on the same runner.
Q6: What is a step?
An individual task in a job (run command or use action).
Q7: What is an action?
Reusable unit of automation logic used in workflow steps.
Q8: Where are workflow files stored?
In repository path .github/workflows/*.yml.
Q9: What is a runner?
Compute environment that executes workflow jobs.
Q10: Hosted vs self-hosted runner?
GitHub-hosted is managed by GitHub; self-hosted is managed by your team.
Q11: What does runs-on specify?
Runner environment label (e.g., ubuntu-latest).
Q12: Common GitHub-hosted runner images?
Ubuntu, Windows, and macOS variants.
Q13: What is workflow_dispatch?
Manual workflow trigger with optional inputs.
Q14: What is schedule trigger?
Cron-based workflow execution.
Q15: What is push trigger?
Runs workflow when commits are pushed to matching branches/tags.
Q16: What is pull_request trigger?
Runs workflow on PR lifecycle events.
Q17: What is branch filter in workflow?
Limits triggers to selected branches.
Q18: What is path filter?
Triggers workflow only when specific files/paths change.
Q19: Why use path filters?
Reduce unnecessary runs and CI cost.
Q20: What is matrix strategy?
Runs a job across multiple variable combinations (OS, JDK, Node versions).
Q21: Why use matrix builds?
Parallel cross-environment validation.
Q22: What is needs in jobs?
Defines job dependencies and execution order.
Q23: What happens if dependency job fails?
Dependent jobs are skipped unless configured otherwise.
Q24: What is if: condition?
Conditional execution for jobs/steps.
Q25: What is context in Actions?
Structured metadata available in expressions (github, env, job, steps, secrets, etc.).
Q26: What is environment variable in workflow?
Key-value config defined via env at workflow/job/step scope.
Q27: What is secret in GitHub Actions?
Encrypted value injected securely into workflows.
Q28: Where can secrets be defined?
Repository, environment, or organization level.
Q29: What is GITHUB_TOKEN?
Auto-generated token for workflow authentication to GitHub APIs.
Q30: Why limit GITHUB_TOKEN permissions?
Principle of least privilege reduces blast radius.
Q31: What is permissions: block?
Explicitly scopes token permissions for workflow/job.
Q32: What is artifact in Actions?
File bundle uploaded from run for later download/use.
Q33: Artifact vs cache?
Artifacts store run outputs; cache speeds dependency/tool reuse across runs.
Q34: What is cache action used for?
Caching dependencies/build outputs to reduce runtime.
Q35: Common cache keys?
Hash of lockfiles + OS/tool version identifiers.
Q36: What is checkout action?
actions/checkout clones repository into runner workspace.
Q37: What is setup action example?
actions/setup-java, setup-node install/configure toolchains.
Q38: What is workflow log?
Step-by-step output for debugging runs.
Q39: How rerun failed jobs?
Use GitHub UI rerun options (failed jobs/all jobs).
Q40: What is fail-fast in matrix?
Cancel remaining matrix jobs when one fails (configurable).
Q41: What is timeout-minutes?
Maximum allowed runtime for job before forced cancellation.
Q42: Why set timeouts?
Prevent hung jobs and wasted runner cost.
Q43: What is concurrency group?
Limits overlapping workflow/job runs for same key.
Q44: Why use concurrency control?
Avoid duplicate deployments or conflicting operations.
Q45: What is cancel-in-progress?
Cancels previous in-progress run in same concurrency group.
Q46: What is environment protection rule?
Required reviewers/waits/secrets boundary before deployment jobs proceed.
Q47: What is manual approval in Actions?
Environment protection requiring reviewer approval pre-deploy.
Q48: What is reusable workflow?
Workflow invoked by other workflows via workflow_call.
Q49: What is composite action?
Action bundling multiple steps into reusable local/remote unit.
Q50: Composite action vs reusable workflow?
Composite runs as step; reusable workflow orchestrates full jobs.
Q51: What is beginner anti-pattern in Actions?
Single huge workflow doing everything without modularity.
Q52: Another beginner anti-pattern?
Using broad write permissions by default.
Q53: Beginner security baseline?
Pin action versions, least-privilege tokens, protected secrets.
Q54: Why pin action versions?
Prevent unexpected or malicious upstream changes from mutable tags.
Q55: What is immutable pin best practice?
Pin to full commit SHA for strongest integrity.
Q56: Beginner reliability baseline?
Separate build/test/deploy jobs with clear dependencies.
Q57: Beginner performance baseline?
Use caching, path filters, and parallel matrix where useful.
Q58: What is CI vs CD in Actions context?
CI validates code; CD automates delivery/deployment.
Q59: Beginner observability baseline?
Track workflow duration, failure rate, flaky jobs, queue delays.
Q60: What is first workflow usually?
Build + unit test on pull requests.
Q61: What is PR status check?
Workflow result required before merge (branch protection integration).
Q62: Why require status checks?
Prevents merging unvalidated/broken changes.
Q63: What is continue-on-error?
Allows step/job failure without failing entire run (use carefully).
Q64: When use continue-on-error?
Non-blocking experiments or optional checks, clearly labeled.
Q65: Beginner best practice?
Start simple, secure defaults, and iterate with measurable improvements.
Intermediate
Q66: What is workflow_call input/output?
Reusable workflow parameters and returned values to callers.
Q67: Why adopt reusable workflows?
Standardization, DRY pipelines, centralized governance.
Q68: What is composite action best use case?
Share repeated step sequences (setup/lint/package helper logic).
Q69: What is job output?
Named value produced by a job for downstream jobs.
Q70: What is step output?
Value set by step for use later in same job.
Q71: How set outputs in modern Actions?
Write to $GITHUB_OUTPUT file.
Q72: What is environment file mechanism?
Special files (GITHUB_ENV, GITHUB_OUTPUT, etc.) for workflow communication.
Q73: What is expression syntax in Actions?
${{ ..: }} for evaluation of contexts/functions.
Q74: Common expression functions?
contains, startsWith, endsWith, hashFiles, always, failure, success.
Q75: What is always() used for?
Run cleanup/reporting even if previous steps failed.
Q76: What is failure() condition?
Run step only when earlier failure occurred.
Q77: What is hashFiles() use case?
Generate cache key segment from file contents.
Q78: What is dependency caching pitfall?
Overly broad keys causing stale/incompatible cache restores.
Q79: Cache restore-keys purpose?
Fallback matching when exact cache key not found.
Q80: What is artifact retention period?
How long uploaded artifacts are stored before expiry.
Q81: What is self-hosted runner advantage?
Custom hardware/network access and potentially lower cost at scale.
Q82: Self-hosted runner risk?
Security hardening, maintenance, and secret exposure responsibility.
Q83: What is ephemeral self-hosted runner pattern?
Short-lived runner instance per job for isolation.
Q84: Why ephemeral runners improve security?
Reduce persistence of compromised state between jobs.
Q85: What is runner label?
Tag used to route jobs to appropriate self-hosted runners.
Q86: What is service container in Actions?
Sidecar container (e.g., DB/Redis) available during job.
Q87: Why use service containers?
Integration tests with disposable dependencies in CI.
Q88: What is container job?
Run job steps inside specified container image.
Q89: Container job benefit?
Consistent runtime environment across runners.
Q90: What is strategy.max-parallel?
Limits concurrent matrix job executions.
Q91: Why cap matrix parallelism?
Control cost and avoid overloading external systems.
Q92: What is dependency graph of jobs?
DAG defined by needs relationships.
Q93: What is required workflow concept?
Org-level enforced workflows/controls (policy-dependent setup).
Q94: What is CODEOWNERS relation to Actions?
Can require specific reviewers for workflow file changes.
Q95: Why protect workflow files specially?
Pipeline changes can alter security/deployment behavior.
Q96: What is pull_request_target caution?
Runs in base repo context; dangerous with untrusted code if misused.
Q97: Safe use principle for pull_request_target?
Never execute untrusted PR code with elevated tokens/secrets.
Q98: What is OIDC in GitHub Actions?
Federated identity to cloud providers without long-lived static secrets.
Q99: Why prefer OIDC over stored cloud keys?
Short-lived credentials reduce secret leakage risk.
Q100: What is id-token permission?
Required permission to request OIDC tokens.
Q101: What is environment URL in deployments?
Link shown in GitHub deployment UI to target environment.
Q102: What is deployment job pattern?
Build artifact once, then deploy immutable artifact across environments.
Q103: Why immutable artifact promotion?
Consistency between tested and deployed binary.
Q104: What is monorepo CI challenge in Actions?
Unnecessary runs for unaffected components.
Q105: Monorepo optimization strategy?
Path-based workflows, selective matrices, reusable component pipelines.
Q106: What is workflow_run trigger?
Trigger workflow based on completion of another workflow.
Q107: When use workflow_run?
Pipeline chaining with privilege separation (build then deploy).
Q108: What is privilege separation in CI/CD?
Untrusted build job separated from privileged deployment job.
Q109: What is SARIF upload use?
Publish static analysis/security findings in GitHub code scanning.
Q110: What is problem matcher concept?
Parse logs and annotate source lines in PR checks.
Q111: What is intermediate anti-pattern?
Single workflow handles PR CI and production deploy with shared broad secrets.
Q112: Better pipeline architecture?
Separate CI, release, and deploy workflows with scoped permissions.
Q113: What is flaky workflow symptom?
Intermittent failures unrelated to code changes.
Q114: Common flake causes in Actions?
Network instability, race conditions, shared external state, timeouts.
Q115: Flake mitigation baseline?
Retries (targeted), deterministic tests, isolated environments, observability.
Q116: What is concurrency for deployments?
Serialize per environment/service to avoid overlapping releases.
Q117: What is rollback workflow pattern?
Manual/automated workflow to redeploy previous known-good version.
Q118: What is intermediate security baseline?
SHA-pinned actions, OIDC, restricted permissions, protected environments.
Q119: What is intermediate reliability baseline?
Deterministic builds, artifact promotion, guarded deploy gates.
Q120: What is intermediate observability baseline?
DORA-ish metrics: lead time, deployment frequency, MTTR, change failure rate.
Q121: What is workflow performance bottleneck analysis?
Identify longest critical-path jobs and cache misses.
Q122: What is intermediate cost optimization?
Runner right-sizing, reduced duplicate runs, smarter matrix scope.
Q123: Intermediate maturity signal?
Team can explain trust boundaries and token permissions for each workflow.
Q124: Intermediate governance principle?
CI/CD templates with controlled extension points.
Q125: Intermediate DX principle?
Fast PR feedback and clear failure diagnostics.
Q126: What is intermediate release principle?
Tag-driven versioned releases with changelog and provenance.
Q127: What is release artifact signing?
Cryptographically signing binaries/images during pipeline.
Q128: Why sign artifacts?
Integrity verification and supply-chain trust.
Q129: What is intermediate compliance principle?
Audit trail for who approved and deployed what, when.
Q130: Intermediate best practice?
Design workflows as secure software systems, not just YAML scripts.
Advanced
Q131: What is CI/CD platform engineering with Actions?
Providing centralized reusable workflows, runners, policies, and observability for many teams.
Q132: What is workflow template strategy?
Org-standard starter workflows for common stacks/use cases.
Q133: What is reusable workflow versioning model?
Pin callers to tagged/sha versions and roll out updates progressively.
Q134: Why avoid floating main reference for central workflows?
Uncontrolled breaking changes across dependent repositories.
Q135: What is supply-chain risk in GitHub Actions?
Compromised third-party actions, tampered dependencies, malicious workflow changes.
Q136: Core supply-chain mitigations?
SHA pinning, action allowlists, artifact attestations, dependency scanning.
Q137: What is artifact attestation concept?
Cryptographic metadata linking artifact to trusted build process/source.
Q138: Why provenance matters in CI/CD?
Enables verification and incident response for released artifacts.
Q139: What is SLSA relevance to Actions?
Framework for software supply-chain maturity and build integrity controls.
Q140: What is hardened runner baseline?
Ephemeral instances, minimal tools, locked egress, patched OS, least privilege.
Q141: What is network egress control for runners?
Restrict outbound destinations to reduce exfiltration risk.
Q142: What is secret zero challenge in CI/CD?
Securely bootstrapping initial auth without exposing long-lived credentials.
Q143: OIDC trust policy hardening?
Bind cloud role assumptions to repo, branch, workflow, and environment claims.
Q144: What is policy-as-code for workflows?
Automated checks enforcing CI/CD security and compliance rules.
Q145: Example policy checks?
No unpinned actions, no broad write perms, required approvals for prod deploy.
Q146: What is multi-tenant runner isolation issue?
Jobs from different repos/teams may impact each other if isolation weak.
Q147: How isolate multi-tenant workloads?
Ephemeral runners per trust boundary and strict credential separation.
Q148: What is large monorepo scaling pattern?
Change detection graph -> targeted builds/tests -> aggregated required checks.
Q149: What is dynamic matrix generation?
Compute matrix values at runtime from repo metadata/changed components.
Q150: Dynamic matrix risk?
Complexity and harder debugging if generation logic opaque.
Q151: What is pipeline critical path optimization?
Shorten longest dependency chain to reduce total lead time.
Q152: How reduce critical path?
Parallelize independent jobs, prebuild caches, split heavy tests smartly.
Q153: What is remote cache/artifact proxy benefit?
Faster dependency retrieval and reduced external outages impact.
Q154: What is deterministic pipeline principle?
Same commit + inputs should produce same outputs/results.
Q155: Non-determinism sources in Actions?
Floating versions, time-dependent tests, mutable external services.
Q156: What is deployment ring strategy?
Progressive rollout stages (internal, canary, region subsets, full prod).
Q157: What is automated canary analysis concept?
Promotion/rollback based on error/latency/SLO metrics.
Q158: What is progressive delivery with Actions?
Workflows orchestrate staged rollouts with policy gates and observability checks.
Q159: What is rollback automation maturity?
One-click or auto-triggered safe revert using immutable previous artifacts.
Q160: What is incident mode pipeline behavior?
Freeze noncritical deploys, enable emergency fixes with tightened audit path.
Q161: What is break-glass workflow?
Controlled emergency deployment path with extra approvals/logging.
Q162: What is compliance evidence in Actions?
Run logs, approvals, artifact signatures, policy check results, deployment history.
Q163: What is retention strategy for CI evidence?
Store logs/artifacts long enough for audit and incident investigations.
Q164: What is advanced observability stack for Actions?
Workflow metrics, queue times, runner utilization, failure taxonomy, cost dashboards.
Q165: What is DORA metric mapping in Actions?
Use workflow/deployment events to compute lead time, freq, MTTR, CFR.
Q166: What is flaky-test governance model?
Ownership, quarantine SLA, and merge policy impacts.
Q167: Why quarantined tests must expire?
Permanent quarantine hides quality debt and risk.
Q168: What is cross-repo orchestration pattern?
Repository_dispatch/workflow_call/workflow_run to coordinate dependent releases.
Q169: Cross-repo orchestration risk?
Token scope sprawl and event-loop complexity.
Q170: Mitigation for orchestration risk?
Minimal scoped tokens, explicit contracts, idempotent triggers.
Q171: What is GitHub-hosted larger runners concept?
Bigger managed runners for heavier workloads (availability by plan/region).
Q172: When use larger runners?
Large builds/tests requiring higher CPU/RAM/disk throughput.
Q173: Cost control for larger runners?
Use only on bottleneck jobs with measured ROI.
Q174: What is advanced anti-pattern in Actions?
Embedding business-critical deploy logic in ad-hoc scripts with no tests/versioning.
Q175: Better architecture?
Versioned deployment tooling/actions with tests and clear interfaces.
Q176: What is final reliability principle?
Pipelines must be deterministic, observable, and rollback-capable.
Q177: What is final security principle?
Treat workflows as privileged code with strict trust boundaries.
Q178: What is final performance principle?
Continuously optimize critical path and cache effectiveness.
Q179: What is final governance principle?
Central guardrails + reusable standards + auditable exceptions.
Q180: What is final operations principle?
Measure pipeline health like production service health.
Q181: What is final developer-experience principle?
Fast, actionable CI feedback with minimal noise.
Q182: What is final platform principle?
Separate untrusted build from trusted deploy contexts.
Q183: What is final supply-chain principle?
Verify origin and integrity of every dependency and artifact.
Q184: What is final scaling principle?
Design workflows modularly for org-wide reuse and independent evolution.
Q185: Final maturity principle?
GitHub Actions excellence is secure, governed, high-velocity delivery automation.
Example:
# Project structure
.
├─ .github/
│ ├─ workflows/
│ │ ├─ example-java-ci-cd.yml
│ │ └─ example-k8s-helm-cd.yml
│ └─ dependabot.yml
├─ Dockerfile
├─ pom.xml
├─ src/main/java/com/example/App.java
└─ chart/
├─ Chart.yaml
├─ values.yaml
└─ templates/
├─ deployment.yaml
├─ service.yaml
├─ serviceaccount.yaml
├─ networkpolicy.yaml
└─ _helpers.tpl
# ./.github/workflows/example-java-ci-cd.yml
name: example-java-ci-cd
on:
pull_request:
branches: [main]
push:
branches: [main]
workflow_dispatch:
permissions:
contents: read
security-events: write
actions: read
packages: write
id-token: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
dependency-review:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/dependency-review-action@v4
with:
fail-on-severity: high
secret-scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
codeql:
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
steps:
- uses: actions/checkout@v4
- uses: github/codeql-action/init@v3
with:
languages: java-kotlin
- uses: github/codeql-action/autobuild@v3
- uses: github/codeql-action/analyze@v3
build-test-sca:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "21"
cache: maven
- name: Build + tests
run: mvn -B -ntp clean verify
- name: OWASP Dependency Check
run: mvn -B -ntp org.owasp:dependency-check-maven:check -DfailBuildOnCVSS=7
build-scan-sign:
runs-on: ubuntu-latest
needs: [secret-scan, codeql, build-test-sca]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
outputs:
image: ${{ steps.meta.outputs.tags }}
digest: ${{ steps.build.outputs.digest }}
steps:
- uses: actions/checkout@v4
- uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha
type=raw,value=latest,enable={{is_default_branch}}
- id: build
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Trivy image scan
uses: aquasecurity/trivy-action@0.24.0
with:
image-ref: ${{ fromJSON(steps.meta.outputs.json).tags[0] }}
format: sarif
output: trivy-image.sarif
severity: HIGH,CRITICAL
ignore-unfixed: true
exit-code: 1
- uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: trivy-image.sarif
- uses: sigstore/cosign-installer@v3
- name: Sign image (keyless)
run: cosign sign --yes ${{ fromJSON(steps.meta.outputs.json).tags[0] }}@${{ steps.build.outputs.digest }}
# ./.github/workflows/example-k8s-helm-cd.yml
name: example-k8s-helm-cd
on:
push:
branches: [main]
workflow_dispatch:
permissions:
contents: read
id-token: write
security-events: write
jobs:
helm-manifest-security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: azure/setup-helm@v4
with:
version: v3.16.2
- name: Helm lint
run: helm lint ./chart
- name: Render manifests
run: helm template myapp ./chart --namespace production > rendered.yaml
- name: Trivy config scan (IaC misconfig)
uses: aquasecurity/trivy-action@0.24.0
with:
scan-type: config
scan-ref: rendered.yaml
format: sarif
output: trivy-config.sarif
severity: HIGH,CRITICAL
exit-code: 1
- uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: trivy-config.sarif
deploy:
runs-on: ubuntu-latest
needs: helm-manifest-security
environment:
name: production
url: https://your-app.example.com
steps:
- uses: actions/checkout@v4
- uses: azure/setup-helm@v4
with:
version: v3.16.2
# Example: AWS EKS with OIDC auth
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: us-east-1
role-to-assume: arn:aws:iam::123456789012:role/github-actions-eks-deploy
- name: Update kubeconfig
run: aws eks update-kubeconfig --name my-eks-cluster --region us-east-1
- name: Deploy with Helm (atomic + wait)
run: |
helm upgrade --install myapp ./chart \
--namespace production \
--create-namespace \
--atomic \
--wait \
--timeout 10m
# ./.github/dependabot.yml
version: 2
updates:
- package-ecosystem: "maven"
directory: "/"
schedule:
interval: "daily"
labels:
- "dependencies"
- "security"
# ././Dockerfile # build stage FROM maven:3.9.9-eclipse-temurin-21 AS build WORKDIR /app COPY pom.xml . COPY src ./src RUN mvn -B -ntp clean package -DskipTests # runtime stage FROM eclipse-temurin:21-jre-alpine RUN addgroup -S app && adduser -S app -G app WORKDIR /app COPY --from=build /app/target/app.jar /app/app.jar USER app EXPOSE 8080 ENTRYPOINT ["java","-jar","/app/app.jar"]
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>app</artifactId> <version>1.0.0</version> <name>example-java-app</name> <properties> <maven.compiler.release>21</maven.compiler.release> </properties> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>3.3.5</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>3.4.2</version> <configuration> <archive> <manifest> <mainClass>com.example.App</mainClass> </manifest> </archive> </configuration> </plugin> </plugins> </build> </project>
// ./src/main/java/com/example/App.java package com.example; import com.sun.net.httpserver.HttpServer; import java.io.IOException; import java.io.OutputStream; import java.net.InetSocketAddress; public class App { public static void main(String[] args) throws IOException { HttpServer server = HttpServer.create(new InetSocketAddress(8080), 0); server.createContext("/healthz", exchange -> { byte[] body = "ok".getBytes(); exchange.sendResponseHeaders(200, body.length); try (OutputStream os = exchange.getResponseBody()) { os.write(body); } }); server.start(); System.out.println("Server started on :8080"); } }
# ./chart/Chart.yaml apiVersion: v2 name: myapp description: Example Java app chart type: application version: 0.1.0 appVersion: "1.0.0"
# ./chart/values.yaml
replicaCount: 2
image:
repository: ghcr.io/OWNER/REPO
tag: latest
pullPolicy: IfNotPresent
service:
type: ClusterIP
port: 80
targetPort: 8080
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 500m
memory: 512Mi
securityContext:
runAsNonRoot: true
runAsUser: 10001
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: ["ALL"]
# ./chart/templates/_helpers.tpl
{{- define "myapp.name" -}}myapp{{- end -}}
{{- define "myapp.fullname" -}}{{ include "myapp.name" . }}{{- end -}}
# ./chart/templates/serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "myapp.fullname" . }}
# ./chart/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "myapp.fullname" . }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels: { app: {{ include "myapp.name" . }} }
template:
metadata:
labels: { app: {{ include "myapp.name" . }} }
spec:
serviceAccountName: {{ include "myapp.fullname" . }}
automountServiceAccountToken: false
securityContext:
seccompProfile: { type: RuntimeDefault }
containers:
- name: app
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- containerPort: {{ .Values.service.targetPort }}
securityContext:
runAsNonRoot: {{ .Values.securityContext.runAsNonRoot }}
runAsUser: {{ .Values.securityContext.runAsUser }}
allowPrivilegeEscalation: {{ .Values.securityContext.allowPrivilegeEscalation }}
readOnlyRootFilesystem: {{ .Values.securityContext.readOnlyRootFilesystem }}
capabilities:
drop: {{ toJson .Values.securityContext.capabilities.drop }}
readinessProbe:
httpGet: { path: /healthz, port: {{ .Values.service.targetPort }} }
livenessProbe:
httpGet: { path: /healthz, port: {{ .Values.service.targetPort }} }
resources: {{- toYaml .Values.resources | nindent 12 }}
# ./chart/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
name: {{ include "myapp.fullname" . }}
spec:
type: {{ .Values.service.type }}
selector: { app: {{ include "myapp.name" . }} }
ports:
- port: {{ .Values.service.port }}
targetPort: {{ .Values.service.targetPort }}
# ./chart/templates/networkpolicy.yaml
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: {{ include "myapp.fullname" . }}
spec:
podSelector:
matchLabels: { app: {{ include "myapp.name" . }} }
policyTypes: ["Ingress","Egress"]
ingress:
- from: [] # restrict by default; customize for ingress controller/ns
ports:
- protocol: TCP
port: {{ .Values.service.targetPort }}
egress:
- to: []
ports:
- protocol: TCP
port: 443