Skip to content
Latchkey

unit tests workflow (hatchet/hatchet)

The unit tests workflow from hatchet/hatchet, explained and optimized by Latchkey.

F

CI health: F - at risk

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: hatchet/hatchet.github/workflows/unit-tests.yamlLicense MITView source

What it does

This is the unit tests workflow from the hatchet/hatchet 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: unit tests

on:
  push:
    branches: [ develop ]
  pull_request:
    branches: [ develop, releases/** ]

jobs:
  ubuntu:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest]
        python-version: ["3.9", "3.10", "3.11", "3.12"]

    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}

    - name: Install Python3 packages
      run: |
        pip install --upgrade pip pytest
        pip install -r requirements.txt
        # Optional Dependency for HDF Checkpointing
        pip install tables
        python setup.py install
        python setup.py build_ext --inplace
        python -m pip list

    - name: Lint and format check with flake8 and black
      if: ${{ matrix.python-version == 3.9 }}
      run: |
        pip install --upgrade click
        pip install --upgrade black
        pip install --upgrade flake8
        black -t py39 --diff --check .
        flake8

    - name: Update coverage
      if: ${{ matrix.python-version == 3.12 }}
      run: |
        pip install --upgrade coverage

    - name: Clone Caliper
      uses: actions/checkout@v2
      with:
        repository: LLNL/Caliper
        path: Caliper
        token: ${{ secrets.GITHUB_TOKEN }}

    - name: Build Caliper
      working-directory: Caliper
      run: |
        mkdir build && mkdir install
        cd build
        cmake -DCMAKE_INSTALL_PREFIX=../install ../
        make VERBOSE=1
        make install
        export PATH=$(pwd)/../install/bin:${PATH}
        cd $GITHUB_WORKSPACE
        which cali-query

    - name: Basic test with pytest
      if: ${{ matrix.python-version != 3.9 }}
      run: |
        PYTHONPATH=. $(which pytest)

    - name: Basic test with pytest
      if: ${{ matrix.python-version == 3.12 }}
      run: |
        PYTHONPATH=. coverage run $(which pytest)

    - name: Upload coverage to Codecov
      if: ${{ matrix.python-version == 3.12 }}
      uses: codecov/codecov-action@v4
      env:
        CODECOV_TOKEN: ${{ secrets.HATCHET_CODECOV_TOKEN }}
      with:
        directory: ./coverage/reports
        env_vars: OS,PYTHON
        files: /home/runner/work/hatchet/hatchet/coverage.xml
        flags: unittests
        verbose: true
        fail_ci_if_error: true

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: unit tests
 
on:
  push:
    branches: [ develop ]
  pull_request:
    branches: [ develop, releases/** ]
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  ubuntu:
    timeout-minutes: 30
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest]
        python-version: ["3.9", "3.10", "3.11", "3.12"]
 
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-python@v2
      with:
        cache: 'pip'
        python-version: ${{ matrix.python-version }}
 
    - name: Install Python3 packages
      run: |
        pip install --upgrade pip pytest
        pip install -r requirements.txt
        # Optional Dependency for HDF Checkpointing
        pip install tables
        python setup.py install
        python setup.py build_ext --inplace
        python -m pip list
 
    - name: Lint and format check with flake8 and black
      if: ${{ matrix.python-version == 3.9 }}
      run: |
        pip install --upgrade click
        pip install --upgrade black
        pip install --upgrade flake8
        black -t py39 --diff --check .
        flake8
 
    - name: Update coverage
      if: ${{ matrix.python-version == 3.12 }}
      run: |
        pip install --upgrade coverage
 
    - name: Clone Caliper
      uses: actions/checkout@v2
      with:
        repository: LLNL/Caliper
        path: Caliper
        token: ${{ secrets.GITHUB_TOKEN }}
 
    - name: Build Caliper
      working-directory: Caliper
      run: |
        mkdir build && mkdir install
        cd build
        cmake -DCMAKE_INSTALL_PREFIX=../install ../
        make VERBOSE=1
        make install
        export PATH=$(pwd)/../install/bin:${PATH}
        cd $GITHUB_WORKSPACE
        which cali-query
 
    - name: Basic test with pytest
      if: ${{ matrix.python-version != 3.9 }}
      run: |
        PYTHONPATH=. $(which pytest)
 
    - name: Basic test with pytest
      if: ${{ matrix.python-version == 3.12 }}
      run: |
        PYTHONPATH=. coverage run $(which pytest)
 
    - name: Upload coverage to Codecov
      if: ${{ matrix.python-version == 3.12 }}
      uses: codecov/codecov-action@v4
      env:
        CODECOV_TOKEN: ${{ secrets.HATCHET_CODECOV_TOKEN }}
      with:
        directory: ./coverage/reports
        env_vars: OS,PYTHON
        files: /home/runner/work/hatchet/hatchet/coverage.xml
        flags: unittests
        verbose: true
        fail_ci_if_error: true
 

What changed

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:

This workflow runs 1 job (4 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