G
GuideDevOps
Lesson 3 of 11

GitHub Actions

Part of the CI/CD Pipelines tutorial series.

GitHub Actions allows you to create workflows that are triggered by events in your repository, like a push, a pull_request, or even a manual trigger.

1. The Workflow File

Workflows are defined in YAML files inside the .github/workflows/ directory.

example-workflow.yaml:

name: CI Pipeline
 
on:
  push:
    branches: [ main ]
 
jobs:
  build-and-test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v3
 
      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: '3.9'
 
      - name: Install dependencies
        run: pip install -r requirements.txt
 
      - name: Run tests
        run: pytest

2. Running the Workflow

Trigger the Action

Action:

git add .
git commit -m "feat: add ci pipeline"
git push origin main

Check the Result

Result: Go to the Actions tab in your GitHub repository. You will see a live log:

✓ Checkout code
✓ Set up Python
✓ Install dependencies
✓ Run tests
  - pytest results: 12 passed, 0 failed
Workflow Status: Success

3. GitHub Actions Terminology

TermDescription
WorkflowThe automated process (the YAML file).
EventWhat triggers the workflow (e.g., push).
JobA set of steps that run on the same runner.
StepAn individual task (running a script or an Action).
ActionA reusable application (e.g., actions/checkout).
RunnerThe server that executes the workflow (e.g., ubuntu-latest).

4. Using Secrets

You should never put passwords or API keys in your YAML. Use GitHub Secrets.

Action (Manifest snippet):

      - name: Deploy to Production
        env:
          API_KEY: ${{ secrets.PROD_API_KEY }}
        run: ./deploy.sh

Summary

  • YAML based: Workflows live in your repo.
  • Event driven: Push, PR, or Cron.
  • Reusable: Use community actions from the GitHub Marketplace.
  • Free for Public Repos: Great for open source and small teams.