GitHub Actions is GitHub’s built-in automation platform. It lets you build, test, and deploy your code right from GitHub.

Key Concepts

  • Workflow: Automated process defined in a YAML file inside .github/workflows/.
  • Event: Trigger that starts a workflow, such as a push, pull request, or schedule.
  • Job: A set of steps executed on the same runner.
  • Step: An individual task in a job that can run commands or actions.
  • Action: Reusable extension that performs a specific task. Actions can come from the marketplace or your repository.
  • Runner: The server that executes your jobs. GitHub-hosted runners cover common environments, or you can use self-hosted runners.

Example Workflow

Create a file named .github/workflows/ci.yml in your repository:

name: CI

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

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '20'
      - run: npm ci
      - run: npm test

This workflow runs whenever code is pushed or a pull request targets the main branch. It checks out the code, installs Node.js, and runs your tests.

Using Secrets

Store sensitive values like API keys in Repository Settings → Secrets and variables → Actions and reference them in workflows:

- run: npm run deploy
  env:
    API_TOKEN: ${{ secrets.API_TOKEN }}

Debugging

Use the workflow run logs to diagnose failures. You can also enable step debugging by setting the ACTIONS_STEP_DEBUG secret to true.

With these basics, you can start automating tasks and building CI/CD pipelines directly in GitHub.