Skip to content
Latchkey

Run the tests workflow (pyomeca/bioptim)

The Run the tests workflow from pyomeca/bioptim, explained and optimized by Latchkey.

C

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.

Grade your own workflow free or run it on Latchkey →
Source: pyomeca/bioptim.github/workflows/run_tests_linux.ymlLicense MITView source

What it does

This is the Run the tests workflow from the pyomeca/bioptim 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: Run the tests

on: [pull_request]

jobs:
  build:
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest]
        shard: [1, 2, 3, 4, 5, 6]
    name: Tests on ${{ matrix.os }}-shard ${{ matrix.shard }}
    runs-on: ${{ matrix.os }}
    defaults:
      run:
        shell: bash -l {0}

    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Checkout submodules
        if: matrix.shard == 1
        run: git submodule update --init --recursive
        
      - name: Setup environment
        uses: conda-incubator/setup-miniconda@v3
        with:
          miniforge-version: latest
          activate-environment: bioptim
          environment-file: environment.yml

      - name: Print conda info
        run: |
          conda info
          conda list

      - name: Install extra dependencies
        run: | 
          conda install "numpy>=2.4,<3" pip pytest-cov black pytest pytest-cov codecov packaging pytest-mpl -cconda-forge
          sudo apt install -y librhash-dev

      - name: Install ACADOS on Linux
        run: |
          pwd
          cd external
          ./acados_install_linux.sh 4 $CONDA_PREFIX
          cd ..
        if: matrix.shard == 1

      - name: Test installed version of bioptim
        run: |
          pip install .
          cd
          python -c "import bioptim"
        if: matrix.shard == 1

      - name: Run tests with code coverage
        run: pytest -v --color=yes --cov-report term-missing --cov=bioptim tests/shard${{ matrix.shard }} --mpl-baseline-path=bioptim/tests/plot_reference_images
        if: matrix.os == 'ubuntu-latest'

      - name: Archive coverage report
        id: archive
        uses: actions/upload-artifact@v4
        with:
          name: coverage-${{ matrix.shard }}
          path: .coverage
          if-no-files-found: error
          include-hidden-files: true

  merge-coverage:
    needs: build
    runs-on: ubuntu-latest
    defaults:
      run:
        shell: bash -l {0}

    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Install extra dependencies
        run: |
          sudo apt install -y python3-pip
          pip3 install coverage

      - name: Download all workflow run artifacts
        id: download
        uses: actions/download-artifact@v4
        with:
          pattern: coverage-*

      - name: Rename coverage files
        run: |
          for shard in {1,2,3,4,5,6}; do
            mv coverage-${shard}/.coverage .coverage${shard}
          done

      - name: Merge coverage reports
        run: coverage combine .coverage1 .coverage2 .coverage3 .coverage4 .coverage5 .coverage6

      - name: Generate XML report
        run: |
          coverage xml
          coverage report -m

      - uses: codecov/codecov-action@v5
        with:
          files: ./coverage.xml
          flags: unittests
          fail_ci_if_error: true
          verbose: true

The same workflow, on Latchkey

Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.

name: Run the tests
 
on: [pull_request]
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  build:
    timeout-minutes: 30
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest]
        shard: [1, 2, 3, 4, 5, 6]
    name: Tests on ${{ matrix.os }}-shard ${{ matrix.shard }}
    runs-on: ${{ matrix.os }}
    defaults:
      run:
        shell: bash -l {0}
 
    steps:
      - name: Checkout code
        uses: actions/checkout@v3
 
      - name: Checkout submodules
        if: matrix.shard == 1
        run: git submodule update --init --recursive
        
      - name: Setup environment
        uses: conda-incubator/setup-miniconda@v3
        with:
          miniforge-version: latest
          activate-environment: bioptim
          environment-file: environment.yml
 
      - name: Print conda info
        run: |
          conda info
          conda list
 
      - name: Install extra dependencies
        run: | 
          conda install "numpy>=2.4,<3" pip pytest-cov black pytest pytest-cov codecov packaging pytest-mpl -cconda-forge
          sudo apt install -y librhash-dev
 
      - name: Install ACADOS on Linux
        run: |
          pwd
          cd external
          ./acados_install_linux.sh 4 $CONDA_PREFIX
          cd ..
        if: matrix.shard == 1
 
      - name: Test installed version of bioptim
        run: |
          pip install .
          cd
          python -c "import bioptim"
        if: matrix.shard == 1
 
      - name: Run tests with code coverage
        run: pytest -v --color=yes --cov-report term-missing --cov=bioptim tests/shard${{ matrix.shard }} --mpl-baseline-path=bioptim/tests/plot_reference_images
        if: matrix.os == 'ubuntu-latest'
 
      - name: Archive coverage report
        id: archive
        uses: actions/upload-artifact@v4
        with:
          name: coverage-${{ matrix.shard }}
          path: .coverage
          if-no-files-found: error
          include-hidden-files: true
 
  merge-coverage:
    timeout-minutes: 30
    needs: build
    runs-on: latchkey-small
    defaults:
      run:
        shell: bash -l {0}
 
    steps:
      - name: Checkout code
        uses: actions/checkout@v3
 
      - name: Install extra dependencies
        run: |
          sudo apt install -y python3-pip
          pip3 install coverage
 
      - name: Download all workflow run artifacts
        id: download
        uses: actions/download-artifact@v4
        with:
          pattern: coverage-*
 
      - name: Rename coverage files
        run: |
          for shard in {1,2,3,4,5,6}; do
            mv coverage-${shard}/.coverage .coverage${shard}
          done
 
      - name: Merge coverage reports
        run: coverage combine .coverage1 .coverage2 .coverage3 .coverage4 .coverage5 .coverage6
 
      - name: Generate XML report
        run: |
          coverage xml
          coverage report -m
 
      - uses: codecov/codecov-action@v5
        with:
          files: ./coverage.xml
          flags: unittests
          fail_ci_if_error: true
          verbose: true
 

What changed

2 third-party actions are referenced by a movable tag. Pin them 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 2 jobs (7 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