Skip to content
6 min read·Lesson 8 of 10

Introduction to GitHub Actions

Learn how GitHub Actions works — workflows, triggers, jobs, steps, and runners — and build your first CI workflow that lints and tests on every pull request.

GitHub Actions is the built-in CI/CD and automation platform for GitHub repositories. With a YAML file in your repository, you can automatically run tests on every pull request, build and push Docker images on merge, deploy to production on a tag, or run any script on a schedule.

Key Concepts

ConceptDescription
WorkflowA YAML file in .github/workflows/. Defines what to run and when.
Event (trigger)What causes the workflow to run: push, pull_request, schedule, workflow_dispatch.
JobA set of steps that run on the same runner. Jobs run in parallel by default.
StepAn individual task within a job — either a shell command (run) or an Action (uses).
ActionA reusable unit of work. Published to the GitHub Marketplace.
RunnerThe machine that executes the job. GitHub provides hosted runners (Ubuntu, Windows, macOS).

Your First Workflow — CI for a Node.js Project

name: CI

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
      - name: Check out code
        uses: actions/checkout@v4

      - name: Set up Node.js
        uses: actions/setup-node@v4
        with:
          node-version: "20"
          cache: "npm"

      - name: Install dependencies
        run: npm ci

      - name: Run linter
        run: npm run lint

      - name: Run tests
        run: npm test

Save this as .github/workflows/ci.yml. Every push to main or PR targeting main will now automatically run your lint and test suite.

Triggers (on:)

# Run on push to main or any release/* branch
on:
  push:
    branches: [main, "release/*"]

# Run on any PR targeting main
on:
  pull_request:
    branches: [main]

# Run every day at 06:00 UTC
on:
  schedule:
    - cron: "0 6 * * *"

# Allow manual trigger from the GitHub UI
on:
  workflow_dispatch:
    inputs:
      environment:
        description: "Target environment"
        required: true
        default: "staging"

Secrets and Environment Variables

Store sensitive values in GitHub repository secrets (Settings → Secrets and variables → Actions). Access them in workflows via the secrets context:

      - name: Deploy to production
        env:
          API_KEY: ${{ secrets.DEPLOY_API_KEY }}
        run: ./scripts/deploy.sh

Secrets are masked in logs — GitHub replaces them with ***. Never print secrets with echo or store them in environment variables that get logged.

Job Dependencies

By default jobs run in parallel. Use needs to create a dependency chain:

jobs:
  test:
    runs-on: ubuntu-latest
    steps: [...]

  build:
    needs: test
    runs-on: ubuntu-latest
    steps: [...]

  deploy:
    needs: build
    runs-on: ubuntu-latest
    steps: [...]

Popular Actions from the Marketplace

ActionPurpose
actions/checkoutClone the repository into the runner
actions/setup-nodeInstall a specific Node.js version with optional caching
actions/setup-pythonInstall a Python version
docker/build-push-actionBuild and push Docker images to a registry
aws-actions/configure-aws-credentialsConfigure AWS credentials for deployment steps
github/codeql-actionRun CodeQL static analysis for security scanning

GitHub Actions is covered in more depth in the DevOps and SRE Fundamentals course — this lesson gives you the foundation to understand CI/CD pipelines in a GitHub context.

Key Takeaways

  • A GitHub Actions workflow is a YAML file in .github/workflows/ that defines automated tasks.
  • Workflows are triggered by events: push, pull_request, schedule, workflow_dispatch, and more.
  • A workflow contains one or more jobs; jobs contain steps; steps run shell commands or Actions.
  • Actions are reusable units of work from the GitHub Marketplace (e.g., actions/checkout, actions/setup-node).
  • Secrets are stored in repository or organisation settings and accessed via the secrets context.

Test your knowledge

Try exam-style practice questions to reinforce what you've learned.

Practice Questions →