Skip to content
Latchkey

Modal tests workflow (learning-at-home/hivemind)

The Modal tests workflow from learning-at-home/hivemind, explained and optimized by Latchkey.

A

CI health: A - excellent

Point runs-on at Latchkey and get caching, self-healing for flaky steps, and up to 58% lower cost, applied automatically.

Grade your own workflow free or run it on Latchkey →
Source: learning-at-home/hivemind.github/workflows/run-tests-on-modal.ymlLicense MITView source

What it does

This is the Modal tests workflow from the learning-at-home/hivemind repository, a real project running GitHub Actions. It is shown here with attribution under its MIT license.

Below, Latchkey shows a faster, safer version produced by its optimization engine.

The workflow

workflow (.yml)
name: Modal tests

on:
  push:
    branches: [master]
  pull_request:

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

jobs:
  run_tests:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ["3.9", "3.10", "3.11", "3.12"]
      fail-fast: false
    env:
      MODAL_TOKEN_ID: ${{ secrets.MODAL_TOKEN_ID }}
      MODAL_TOKEN_SECRET: ${{ secrets.MODAL_TOKEN_SECRET }}
      PYTHON_VERSION: ${{ matrix.python-version }}
    timeout-minutes: 15
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v4

      - name: Install Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.12"

      - name: Cache dependencies
        uses: actions/cache@v4
        with:
          path: ~/.cache/pip
          key: Key-v1-3.12-modal

      - name: Install build dependencies
        run: |
          python -m pip install --upgrade pip
          pip install modal==0.73.32

      - name: Run tests
        run: |
          modal run modal_ci.py::run_tests

  measure_coverage:
    runs-on: ubuntu-latest
    env:
      MODAL_TOKEN_ID: ${{ secrets.MODAL_TOKEN_ID }}
      MODAL_TOKEN_SECRET: ${{ secrets.MODAL_TOKEN_SECRET }}
      CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
      GITHUB_EVENT_NAME: ${{ github.event_name }}
      GITHUB_EVENT_NUMBER: ${{ github.event.number }}
      GITHUB_EVENT_PULL_REQUEST_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
      PYTHON_VERSION: "3.11"
    timeout-minutes: 15
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v4

      - name: Install Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.12"

      - name: Cache dependencies
        uses: actions/cache@v4
        with:
          path: ~/.cache/pip
          key: Key-v1-3.12-modal

      - name: Install build dependencies
        run: |
          python -m pip install --upgrade pip
          pip install modal==0.73.32

      - name: Measure and upload coverage
        run: |
          modal run modal_ci.py::run_codecov

  build_and_test_p2pd:
    runs-on: ubuntu-latest
    env:
      MODAL_TOKEN_ID: ${{ secrets.MODAL_TOKEN_ID }}
      MODAL_TOKEN_SECRET: ${{ secrets.MODAL_TOKEN_SECRET }}
      PYTHON_VERSION: "3.11"
    timeout-minutes: 10
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v4

      - name: Install Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.12"

      - name: Cache dependencies
        uses: actions/cache@v4
        with:
          path: ~/.cache/pip
          key: Key-v1-3.12-modal

      - name: Install build dependencies
        run: |
          python -m pip install --upgrade pip
          pip install modal==0.73.32

      - name: Run p2pd tests
        run: |
          modal run modal_ci.py::build_and_test_p2pd

The same workflow, on Latchkey

Estimated ~20% faster on cache hits, plus fewer wasted runs and a safer supply chain. Added and changed lines are highlighted.

name: Modal tests
 
on:
  push:
    branches: [master]
  pull_request:
 
concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true
 
jobs:
  run_tests:
    runs-on: latchkey-small
    strategy:
      matrix:
        python-version: ["3.9", "3.10", "3.11", "3.12"]
      fail-fast: false
    env:
      MODAL_TOKEN_ID: ${{ secrets.MODAL_TOKEN_ID }}
      MODAL_TOKEN_SECRET: ${{ secrets.MODAL_TOKEN_SECRET }}
      PYTHON_VERSION: ${{ matrix.python-version }}
    timeout-minutes: 15
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v4
 
      - name: Install Python
        uses: actions/setup-python@v5
        with:
          cache: 'pip'
          python-version: "3.12"
 
      - name: Cache dependencies
        uses: actions/cache@v4
        with:
          path: ~/.cache/pip
          key: Key-v1-3.12-modal
 
      - name: Install build dependencies
        run: |
          python -m pip install --upgrade pip
          pip install modal==0.73.32
 
      - name: Run tests
        run: |
          modal run modal_ci.py::run_tests
 
  measure_coverage:
    runs-on: latchkey-small
    env:
      MODAL_TOKEN_ID: ${{ secrets.MODAL_TOKEN_ID }}
      MODAL_TOKEN_SECRET: ${{ secrets.MODAL_TOKEN_SECRET }}
      CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
      GITHUB_EVENT_NAME: ${{ github.event_name }}
      GITHUB_EVENT_NUMBER: ${{ github.event.number }}
      GITHUB_EVENT_PULL_REQUEST_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
      PYTHON_VERSION: "3.11"
    timeout-minutes: 15
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v4
 
      - name: Install Python
        uses: actions/setup-python@v5
        with:
          cache: 'pip'
          python-version: "3.12"
 
      - name: Cache dependencies
        uses: actions/cache@v4
        with:
          path: ~/.cache/pip
          key: Key-v1-3.12-modal
 
      - name: Install build dependencies
        run: |
          python -m pip install --upgrade pip
          pip install modal==0.73.32
 
      - name: Measure and upload coverage
        run: |
          modal run modal_ci.py::run_codecov
 
  build_and_test_p2pd:
    runs-on: latchkey-small
    env:
      MODAL_TOKEN_ID: ${{ secrets.MODAL_TOKEN_ID }}
      MODAL_TOKEN_SECRET: ${{ secrets.MODAL_TOKEN_SECRET }}
      PYTHON_VERSION: "3.11"
    timeout-minutes: 10
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v4
 
      - name: Install Python
        uses: actions/setup-python@v5
        with:
          cache: 'pip'
          python-version: "3.12"
 
      - name: Cache dependencies
        uses: actions/cache@v4
        with:
          path: ~/.cache/pip
          key: Key-v1-3.12-modal
 
      - name: Install build dependencies
        run: |
          python -m pip install --upgrade pip
          pip install modal==0.73.32
 
      - name: Run p2pd tests
        run: |
          modal run modal_ci.py::build_and_test_p2pd
 

What changed

What Latchkey heals here

This workflow has steps that commonly fail on transient issues (network, registries, flaky browsers). On Latchkey managed runners they are detected, retried, and self-healed instead of failing your build:

This workflow runs 3 jobs (6 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.

Actions used in this workflow