Skip to content
Latchkey

Tests workflow (bethgelab/foolbox)

The Tests workflow from bethgelab/foolbox, explained and optimized by Latchkey.

F

CI health: F - at risk

Point runs-on at Latchkey and get caching, 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: bethgelab/foolbox.github/workflows/tests.ymlLicense MITView source

What it does

This is the Tests workflow from the bethgelab/foolbox 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: Tests

on:
  push:
    branches:
      - master
  pull_request:

jobs:
  build:

    runs-on: ubuntu-latest
    strategy:
      max-parallel: 20
      matrix:
        python-version: ['3.9', '3.10']
        backend: ["none", "pytorch", "tensorflow", "jax", "numpy"]

    steps:
    - uses: actions/checkout@v2
    - uses: actions/cache@v1
      with:
        path: ~/.cache/pip
        key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
        restore-keys: |
          ${{ runner.os }}-pip-
    - uses: actions/cache@v1
      with:
        path: ~/.cache/torch
        key: ${{ runner.os }}-cache-torch
    - uses: actions/cache@v1
      with:
        path: ~/.torch
        key: ${{ runner.os }}-torch
    - uses: actions/cache@v1
      with:
        path: ~/.keras
        key: ${{ runner.os }}-keras
#   - name: debugging
#     run: |
#       python3 -c 'from urllib.request import urlopen; r = urlopen("https://download.pytorch.org/models/resnet18-5c106cde.pth"); print(r.status, r.reason, r.msg)' || true
#   - name: workaround for https://github.com/pytorch/vision/issues/1876
#     uses: wei/wget@v1
#     with:
#         args: https://download.pytorch.org/models/resnet18-5c106cde.pth
#   - name: workaround (step 2)
#     run: |
#       mkdir -p ~/.cache/torch/checkpoints || true
#       mv resnet18-5c106cde.pth ~/.cache/torch/checkpoints || true
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v1
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install requirements.txt
      run: |
        function retry-with-backoff() {
          for BACKOFF in 0 1 2 4 8 16 32 64; do
            sleep $BACKOFF
            if "$@"; then
              return 0
            fi
          done
          return 1
        }

        python -m pip install --upgrade pip setuptools wheel
        retry-with-backoff pip install -r requirements.txt
    - name: flake8
      run: |
        flake8 . --count --show-source --statistics
    - name: black
      run: |
        black --check --verbose .
    - name: Install package
      run: |
        pip install -e .
    - name: Install tests/requirements.txt
      run: |
        function retry-with-backoff() {
          for BACKOFF in 0 1 2 4 8 16 32 64; do
            sleep $BACKOFF
            if "$@"; then
              return 0
            fi
          done
          return 1
        }

        retry-with-backoff pip install -r tests/requirements.txt
    - name: mypy (package)
      run: |
        mypy --install-types --non-interactive foolbox/
        mypy -p foolbox
    - name: mypy (tests)
      run: |
        mypy tests/
    - name: Test with pytest (backend ${{ matrix.backend }})
      run: |
        pytest --durations=0 --cov-report term-missing --cov=foolbox --verbose --backend ${{ matrix.backend }}
    - name: Codecov
      continue-on-error: true
      env:
          CODECOV_TOKEN: "60c0d7ac-8ec1-47c6-b3b1-ac2ad2dea76f"
      run: |
        codecov
    - name: Coveralls
      continue-on-error: true
      env:
        COVERALLS_REPO_TOKEN: "2r76Cn01kW1sSkEirJ3SRpp478NJtPNdA"
      run: |
        coveralls

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: Tests
 
on:
  push:
    branches:
      - master
  pull_request:
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  build:
    timeout-minutes: 30
 
    runs-on: latchkey-small
    strategy:
      max-parallel: 20
      matrix:
        python-version: ['3.9', '3.10']
        backend: ["none", "pytorch", "tensorflow", "jax", "numpy"]
 
    steps:
    - uses: actions/checkout@v2
    - uses: actions/cache@v1
      with:
        path: ~/.cache/pip
        key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
        restore-keys: |
          ${{ runner.os }}-pip-
    - uses: actions/cache@v1
      with:
        path: ~/.cache/torch
        key: ${{ runner.os }}-cache-torch
    - uses: actions/cache@v1
      with:
        path: ~/.torch
        key: ${{ runner.os }}-torch
    - uses: actions/cache@v1
      with:
        path: ~/.keras
        key: ${{ runner.os }}-keras
#   - name: debugging
#     run: |
#       python3 -c 'from urllib.request import urlopen; r = urlopen("https://download.pytorch.org/models/resnet18-5c106cde.pth"); print(r.status, r.reason, r.msg)' || true
#   - name: workaround for https://github.com/pytorch/vision/issues/1876
#     uses: wei/wget@v1
#     with:
#         args: https://download.pytorch.org/models/resnet18-5c106cde.pth
#   - name: workaround (step 2)
#     run: |
#       mkdir -p ~/.cache/torch/checkpoints || true
#       mv resnet18-5c106cde.pth ~/.cache/torch/checkpoints || true
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v1
      with:
        cache: 'pip'
        python-version: ${{ matrix.python-version }}
    - name: Install requirements.txt
      run: |
        function retry-with-backoff() {
          for BACKOFF in 0 1 2 4 8 16 32 64; do
            sleep $BACKOFF
            if "$@"; then
              return 0
            fi
          done
          return 1
        }
 
        python -m pip install --upgrade pip setuptools wheel
        retry-with-backoff pip install -r requirements.txt
    - name: flake8
      run: |
        flake8 . --count --show-source --statistics
    - name: black
      run: |
        black --check --verbose .
    - name: Install package
      run: |
        pip install -e .
    - name: Install tests/requirements.txt
      run: |
        function retry-with-backoff() {
          for BACKOFF in 0 1 2 4 8 16 32 64; do
            sleep $BACKOFF
            if "$@"; then
              return 0
            fi
          done
          return 1
        }
 
        retry-with-backoff pip install -r tests/requirements.txt
    - name: mypy (package)
      run: |
        mypy --install-types --non-interactive foolbox/
        mypy -p foolbox
    - name: mypy (tests)
      run: |
        mypy tests/
    - name: Test with pytest (backend ${{ matrix.backend }})
      run: |
        pytest --durations=0 --cov-report term-missing --cov=foolbox --verbose --backend ${{ matrix.backend }}
    - name: Codecov
      continue-on-error: true
      env:
          CODECOV_TOKEN: "60c0d7ac-8ec1-47c6-b3b1-ac2ad2dea76f"
      run: |
        codecov
    - name: Coveralls
      continue-on-error: true
      env:
        COVERALLS_REPO_TOKEN: "2r76Cn01kW1sSkEirJ3SRpp478NJtPNdA"
      run: |
        coveralls
 

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