Skip to content
Latchkey

Linter and Unit Tests Runner workflow (microsoft/archai)

The Linter and Unit Tests Runner workflow from microsoft/archai, explained and optimized by Latchkey.

D

CI health: D - needs work

Run this on Latchkey for self-healing, caching, and up to 58% lower cost.

Grade your own workflow free or run it on Latchkey →
Source: microsoft/archai.github/workflows/lint-run-unit-tests.yamlLicense MITView source

What it does

This is the Linter and Unit Tests Runner workflow from the microsoft/archai 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: Linter and Unit Tests Runner

on:
  push:
    branches:
      - main
    paths:
      - "archai/**"
      - "tests/**"
  pull_request:
    branches:
      - main
    paths:
      - "archai/**"
      - "tests/**"

jobs:
  lint-run-tests:
    name: Lints with `flake8` and run unit tests with `pytest`
    strategy:
      fail-fast: false
      matrix:
        platform: [ windows-latest, ubuntu-latest ]
        python-version: ["3.8", "3.9", "3.10"]
    runs-on: ${{ matrix.platform }}
    steps:
      - name: Pulls the repository
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - name: Sets up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}
      - name: Installs the requirements
        shell: bash -l {0}
        run: |
          python3 -m pip install --user -e .[dev]
      - name: Finds syntax errors and undefined names
        shell: bash -l {0}
        run: |
          # Stops the build if there are syntax errors or undefined names
          flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
      - name: Lints project files
        shell: bash -l {0}
        run: |
          # Exit-zero treats all errors as warnings (GitHub editor is 127 chars wide)
          flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
      - name: Runs unit tests
        shell: bash -l {0}
        run: |
          python3 -m pytest tests

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: Linter and Unit Tests Runner
 
on:
  push:
    branches:
      - main
    paths:
      - "archai/**"
      - "tests/**"
  pull_request:
    branches:
      - main
    paths:
      - "archai/**"
      - "tests/**"
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  lint-run-tests:
    timeout-minutes: 30
    name: Lints with `flake8` and run unit tests with `pytest`
    strategy:
      fail-fast: false
      matrix:
        platform: [ windows-latest, ubuntu-latest ]
        python-version: ["3.8", "3.9", "3.10"]
    runs-on: ${{ matrix.platform }}
    steps:
      - name: Pulls the repository
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - name: Sets up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v4
        with:
          cache: 'pip'
          python-version: ${{ matrix.python-version }}
      - name: Installs the requirements
        shell: bash -l {0}
        run: |
          python3 -m pip install --user -e .[dev]
      - name: Finds syntax errors and undefined names
        shell: bash -l {0}
        run: |
          # Stops the build if there are syntax errors or undefined names
          flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
      - name: Lints project files
        shell: bash -l {0}
        run: |
          # Exit-zero treats all errors as warnings (GitHub editor is 127 chars wide)
          flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
      - name: Runs unit tests
        shell: bash -l {0}
        run: |
          python3 -m pytest tests
 

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 (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