Git & GitHub for Developers GitHub Actions: CI/CD Basics
10 / 11
Next
GitHub Actions: CI/CD Basics ~12min

GitHub Actions. CI/CD

GitHub Actions automates tasks that run when events happen in your repo, like testing on every push or deploying on merge to main.

Key concepts

  • Workflow, a YAML file in .github/workflows/
  • Trigger (on). What event starts the workflow (push, PR, schedule)
  • Job. A set of steps that run on a virtual machine
  • Step, a single command or action
  • Action. A reusable unit of work (e.g. actions/checkout)

Example: Run tests on every push

# .github/workflows/test.yml
name: Tests

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

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: "8.2"
      - name: Install dependencies
        run: composer install
      - name: Run tests
        run: ./vendor/bin/phpunit

Common use cases

  • Run unit tests on every PR
  • Deploy to production on merge to main
  • Send Slack notifications on build failure
  • Publish npm packages on tag
Tasks
Preview