Skip to the workspace
Pebellslearn by building
CI/CD for Machine Learning  ›  Lesson

GitHub Actions for ML Workflows

GitHub Actions 15 minA GitHub Actions workflow is a YAML file of jobs and steps that runs on events such as a pull request, and it can set up Python, fetch data and train or test a model.

mlops / GitHub Actions for ML Workflows

Explore each scene at your own pace.

01 · The rule

The rule

GitHub Actions for ML Workflows

The churn repo lives on GitHub, so the easiest robot to hire is GitHub Actions. You write a YAML file describing when to run and what to run, and every pull request gets a fresh machine that installs, fetches data, tests and trains — then shows a green tick or a red cross.

The rule

Event triggers, runner starts, steps run in order, any failure stops.

A workflow is a file in .github/workflows/:

name: churn-ci
on:
  pull_request:
    branches: [main]
jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.11"
      - run: pip install -r requirements.txt
      - run: dvc pull
        env:
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
      - run: pytest tests/
      - run: dvc repro

Read it top to bottom:

  • on is the event: here, any pull request targeting main. Others include push, a schedule with a cron expression (useful for continuous training), or workflow_dispatch for a manual button.
  • jobs holds one or more jobs; each gets its own runner, a fresh virtual machine. runs-on picks it.
  • steps run in order. uses: pulls in a ready-made action (checkout the code, install Python); run: executes a shell command.
  • secrets are encrypted values stored in the repository settings. The storage keys reach dvc pull as environment variables and are masked in logs. They never appear in the YAML.

If any step exits with an error, later steps are skipped and the check turns red. With branch protection on main, red means the pull request cannot merge.

GitLab CI (.gitlab-ci.yml) and Jenkins (a Jenkinsfile) express the same ideas — triggers, stages, steps, secrets — with different syntax.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.