Test suite workflow (jowilf/starlette-admin)
The Test suite workflow from jowilf/starlette-admin, explained and optimized by Latchkey.
CI health: C - fair
Point runs-on at Latchkey and get run de-duplication, job timeouts, SHA-pinned actions, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the Test suite workflow from the jowilf/starlette-admin 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
name: Test suite
on:
workflow_dispatch:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
tests:
name: "Python ${{ matrix.python-version }}"
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.9", "3.10", "3.11", "3.12", "3.13" ]
services:
mongodb:
image: mongo
ports:
- 27017:27017
options: --health-cmd "mongosh mongodb://localhost:27017" --health-interval 10s --health-timeout 5s --health-retries 10
minio:
image: bitnamilegacy/minio
env:
MINIO_ROOT_USER: minioadmin
MINIO_ROOT_PASSWORD: minioadmin
ports:
- 9000:9000
options: --health-cmd "curl http://localhost:9000/minio/health/live" --health-interval 10s --health-timeout 5s --health-retries 10
postgres:
image: postgres:17-alpine
env:
POSTGRES_USER: username
POSTGRES_PASSWORD: password
POSTGRES_DB: test_db
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
mysql:
image: mysql:8
env:
MYSQL_ROOT_PASSWORD: password
MYSQL_USER: username
MYSQL_PASSWORD: password
MYSQL_DATABASE: test_db
ports:
- 3306:3306
options: --health-cmd "mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 10
steps:
- uses: actions/checkout@v6
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
- name: Install Dependencies
run: pip install hatch
- name: Lint
run: hatch run test:lint
- name: Test sqla(postgresql) with LocalStorage & mongodb
env:
SQLA_ENGINE: 'postgresql+psycopg2://username:password@localhost:5432/test_db'
SQLA_ASYNC_ENGINE: 'postgresql+asyncpg://username:password@localhost:5432/test_db'
STORAGE_PROVIDER: 'LOCAL'
LOCAL_PATH: '/tmp/storage'
MONGO_URI: 'mongodb://localhost:27017/'
MONGO_DATABASE: 'test_db'
run: hatch run test:all
- name: Test LocalStorage & mysql
env:
SQLA_ENGINE: 'mysql+pymysql://username:password@localhost:3306/test_db'
SQLA_ASYNC_ENGINE: 'mysql+aiomysql://username:password@localhost:3306/test_db'
STORAGE_PROVIDER: 'LOCAL'
LOCAL_PATH: '/tmp/storage'
run: hatch run test:sqla
- name: Test Minio Storage provider & sqlite memory
env:
SQLA_ENGINE: 'sqlite:///test.db?check_same_thread=False'
SQLA_ASYNC_ENGINE: 'sqlite+aiosqlite:///test.db?check_same_thread=False'
STORAGE_PROVIDER: 'MINIO'
MINIO_KEY: 'minioadmin'
MINIO_SECRET: 'minioadmin'
MINIO_HOST: 'localhost'
MINIO_PORT: 9000
MINIO_SECURE: false
run: hatch run test:sqla
- name: store coverage files
uses: actions/upload-artifact@v7
with:
name: coverage-${{ matrix.python-version }}
path: .coverage*
retention-days: 1
include-hidden-files: true
coverage:
needs:
- tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: "3.10"
cache: "pip"
- name: get coverage files
uses: actions/download-artifact@v8
with:
pattern: coverage*
merge-multiple: true
- name: Install Dependencies
run: pip install hatch
- name: Coverage Report
run: hatch run cov:report
- name: Upload coverage
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
name: Test suite on: workflow_dispatch: push: branches: [ "main" ] pull_request: branches: [ "main" ] concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: tests: timeout-minutes: 30 name: "Python ${{ matrix.python-version }}" runs-on: latchkey-small strategy: matrix: python-version: [ "3.9", "3.10", "3.11", "3.12", "3.13" ] services: mongodb: image: mongo ports: - 27017:27017 options: --health-cmd "mongosh mongodb://localhost:27017" --health-interval 10s --health-timeout 5s --health-retries 10 minio: image: bitnamilegacy/minio env: MINIO_ROOT_USER: minioadmin MINIO_ROOT_PASSWORD: minioadmin ports: - 9000:9000 options: --health-cmd "curl http://localhost:9000/minio/health/live" --health-interval 10s --health-timeout 5s --health-retries 10 postgres: image: postgres:17-alpine env: POSTGRES_USER: username POSTGRES_PASSWORD: password POSTGRES_DB: test_db ports: - 5432:5432 options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 mysql: image: mysql:8 env: MYSQL_ROOT_PASSWORD: password MYSQL_USER: username MYSQL_PASSWORD: password MYSQL_DATABASE: test_db ports: - 3306:3306 options: --health-cmd "mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 10 steps: - uses: actions/checkout@v6 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v6 with: python-version: ${{ matrix.python-version }} cache: "pip" - name: Install Dependencies run: pip install hatch - name: Lint run: hatch run test:lint - name: Test sqla(postgresql) with LocalStorage & mongodb env: SQLA_ENGINE: 'postgresql+psycopg2://username:password@localhost:5432/test_db' SQLA_ASYNC_ENGINE: 'postgresql+asyncpg://username:password@localhost:5432/test_db' STORAGE_PROVIDER: 'LOCAL' LOCAL_PATH: '/tmp/storage' MONGO_URI: 'mongodb://localhost:27017/' MONGO_DATABASE: 'test_db' run: hatch run test:all - name: Test LocalStorage & mysql env: SQLA_ENGINE: 'mysql+pymysql://username:password@localhost:3306/test_db' SQLA_ASYNC_ENGINE: 'mysql+aiomysql://username:password@localhost:3306/test_db' STORAGE_PROVIDER: 'LOCAL' LOCAL_PATH: '/tmp/storage' run: hatch run test:sqla - name: Test Minio Storage provider & sqlite memory env: SQLA_ENGINE: 'sqlite:///test.db?check_same_thread=False' SQLA_ASYNC_ENGINE: 'sqlite+aiosqlite:///test.db?check_same_thread=False' STORAGE_PROVIDER: 'MINIO' MINIO_KEY: 'minioadmin' MINIO_SECRET: 'minioadmin' MINIO_HOST: 'localhost' MINIO_PORT: 9000 MINIO_SECURE: false run: hatch run test:sqla - name: store coverage files uses: actions/upload-artifact@v7 with: name: coverage-${{ matrix.python-version }} path: .coverage* retention-days: 1 include-hidden-files: true coverage: timeout-minutes: 30 needs: - tests runs-on: latchkey-small steps: - uses: actions/checkout@v6 - uses: actions/setup-python@v6 with: python-version: "3.10" cache: "pip" - name: get coverage files uses: actions/download-artifact@v8 with: pattern: coverage* merge-multiple: true - name: Install Dependencies run: pip install hatch - name: Coverage Report run: hatch run cov:report - name: Upload coverage uses: codecov/codecov-action@v5 with: token: ${{ secrets.CODECOV_TOKEN }}
What changed
- Run on Latchkey managed runners with one line (
runs-on), which apply the fixes below automatically and self-heal transient failures. This example useslatchkey-small; pick the runner size that fits the job. - Cancel superseded runs when a branch or PR gets a newer push.
- Add a job timeout so a hung step cannot burn hours of runner time.
1 third-party action is referenced by a movable tag. Pin it to the commit SHA (Latchkey resolves and applies this automatically) so a repointed tag cannot change what runs.
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:
- Dependency installs
This workflow runs 2 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.