Skip to content
Latchkey

Django Checks workflow (wyemake/mventory)

The Django Checks workflow from wyemake/mventory, explained and optimized by Latchkey.

D

CI health: D - needs work

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

Grade your own workflow free or run it on Latchkey →
Source: wyemake/mventory.github/workflows/django_checks.ymlLicense MITView source

What it does

This is the Django Checks workflow from the wyemake/mventory 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)
# Shamelessly stolen from https://blog.healthchecks.io/2020/11/using-github-actions-to-run-django-tests/
name: Django Checks

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

jobs:
  build:

    runs-on: ubuntu-20.04
    strategy:
      max-parallel: 4
      matrix:
        db: [sqlite, postgres, mysql]
        python-version: [3.6, 3.7, 3.8]
        include:
          - db: postgres
            db_port: 5432
          - db: mysql
            db_port: 3306

    services:
      postgres:
        image: postgres:10
        env:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: hunter2
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
        ports:
          - 5432:5432
      mysql:
        image: mysql:5.7
        env:
          MYSQL_ROOT_PASSWORD: hunter2
        ports:
          - 3306:3306
        options: >-
          --health-cmd="mysqladmin ping"
          --health-interval=10s
          --health-timeout=5s
          --health-retries=3
    steps:
    - uses: actions/checkout@v2
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install Dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements.txt
        pip install braintree mysqlclient apprise
    - name: Run Tests
      env:
        MVENTORY_DB_USER: ${{ matrix.db_user }}
        MVENTORY_DB_NAME: ${{ matrix.db }}
        MVENTORY_DB_HOST: 127.0.0.1
        MVENTORY_DB_PORT: ${{ matrix.db_port }}
        MVENTORY_DB_PASSWORD: hunter2
        MVENTORY_SECRET_KEY: ${{ secrets.MVENTORY_SECRET_KEY }}
        MVENTORY_OCTOPART_API_KEY: ${{ secrets.MVENTORY_OCTOPART_API_KEY }}
      run: |
        python manage.py test -v 2

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.

# Shamelessly stolen from https://blog.healthchecks.io/2020/11/using-github-actions-to-run-django-tests/
name: Django Checks
 
on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  build:
    timeout-minutes: 30
 
    runs-on: latchkey-small
    strategy:
      max-parallel: 4
      matrix:
        db: [sqlite, postgres, mysql]
        python-version: [3.6, 3.7, 3.8]
        include:
          - db: postgres
            db_port: 5432
          - db: mysql
            db_port: 3306
 
    services:
      postgres:
        image: postgres:10
        env:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: hunter2
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
        ports:
          - 5432:5432
      mysql:
        image: mysql:5.7
        env:
          MYSQL_ROOT_PASSWORD: hunter2
        ports:
          - 3306:3306
        options: >-
          --health-cmd="mysqladmin ping"
          --health-interval=10s
          --health-timeout=5s
          --health-retries=3
    steps:
    - uses: actions/checkout@v2
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v2
      with:
        cache: 'pip'
        python-version: ${{ matrix.python-version }}
    - name: Install Dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements.txt
        pip install braintree mysqlclient apprise
    - name: Run Tests
      env:
        MVENTORY_DB_USER: ${{ matrix.db_user }}
        MVENTORY_DB_NAME: ${{ matrix.db }}
        MVENTORY_DB_HOST: 127.0.0.1
        MVENTORY_DB_PORT: ${{ matrix.db_port }}
        MVENTORY_DB_PASSWORD: hunter2
        MVENTORY_SECRET_KEY: ${{ secrets.MVENTORY_SECRET_KEY }}
        MVENTORY_OCTOPART_API_KEY: ${{ secrets.MVENTORY_OCTOPART_API_KEY }}
      run: |
        python manage.py test -v 2
 

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 1 job (9 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