Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Continuous Integration with GitHub Actions

University of Pisa

Why CI


GitHub Actions basics


Minimal Python test workflow

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

jobs:
  pytest:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.11"
      - name: Install deps
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt
      - name: Run tests
        run: pytest -q

Anatomy of a job


Matrix builds

strategy:
  fail-fast: false
  matrix:
    python-version: ["3.10", "3.11", "3.12"]

Caching dependencies


Managing secrets and permissions


Artifacts and test reports


Building and pushing containers

- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
  with:
    registry: ghcr.io
    username: ${{ github.actor }}
    password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v5
  with:
    context: .
    push: true
    tags: ghcr.io/<org>/<image>:${{ github.sha }}

Docs and notebooks in CI


Common triggers and filters

on:
  pull_request:
    paths-ignore: ["docs/**", "*.md"]

Debugging failures


Lab 08 outline