CI workflow (asteroid-team/asteroid)
The CI workflow from asteroid-team/asteroid, explained and optimized by Latchkey.
CI health: D - needs work
Point runs-on at Latchkey and get caching, run de-duplication, SHA-pinned actions, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the CI workflow from the asteroid-team/asteroid 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
name: CI
# see: https://help.github.com/en/actions/reference/events-that-trigger-workflows
# Trigger the workflow on push or pull request
on: [push, pull_request]
jobs:
src-test:
name: unit-tests
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.13] #, 3.7, 3.8]
pytorch-version: ["2.8.0", "nightly"]
# Timeout: https://stackoverflow.com/a/59076067/4521646
timeout-minutes: 10
steps:
- uses: actions/checkout@v5
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install libnsdfile
run: |
sudo apt update
sudo apt install libsndfile1-dev libsndfile1
- name: Install python dependencies
env:
TORCH_INSTALL: ${{ matrix.pytorch-version }}
run: |
python -m pip install --upgrade --user pip --quiet
python -m pip install numpy Cython --upgrade-strategy only-if-needed --quiet
if [ $TORCH_INSTALL == "1.8.0" ]; then
INSTALL="torch==2.8.0+cpu torchaudio==2.8.0 -f https://download.pytorch.org/whl/torch_stable.html"
else
INSTALL="--pre torch torchvision torchaudio -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html"
fi
python -m pip install $INSTALL
python -m pip install -r requirements/dev.txt --upgrade-strategy only-if-needed --quiet
python --version
pip --version
python -m pip list
shell: bash
- name: Source code tests
run: |
coverage run -a -m pytest tests --ignore tests/models/publish_test.py
chmod +x ./tests/cli_test.sh
./tests/cli_test.sh
# This tends to fail despite the code works, when Zenodo is slow.
- name: Model-sharing tests
run: |
coverage run -a -m pytest tests/models/publish_test.py
env:
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
- name: CLI tests
run: |
chmod +x ./tests/cli_test.sh
./tests/cli_test.sh
env:
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
- name: Coverage report
run: |
coverage report -m
coverage xml -o coverage.xml
- name: Codecov upload
uses: codecov/codecov-action@v1
with:
file: ./coverage.xml
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: CI # see: https://help.github.com/en/actions/reference/events-that-trigger-workflows # Trigger the workflow on push or pull request on: [push, pull_request] concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: src-test: name: unit-tests runs-on: latchkey-small strategy: matrix: python-version: [3.13] #, 3.7, 3.8] pytorch-version: ["2.8.0", "nightly"] # Timeout: https://stackoverflow.com/a/59076067/4521646 timeout-minutes: 10 steps: - uses: actions/checkout@v5 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v6 with: cache: 'pip' python-version: ${{ matrix.python-version }} - name: Install libnsdfile run: | sudo apt update sudo apt install libsndfile1-dev libsndfile1 - name: Install python dependencies env: TORCH_INSTALL: ${{ matrix.pytorch-version }} run: | python -m pip install --upgrade --user pip --quiet python -m pip install numpy Cython --upgrade-strategy only-if-needed --quiet if [ $TORCH_INSTALL == "1.8.0" ]; then INSTALL="torch==2.8.0+cpu torchaudio==2.8.0 -f https://download.pytorch.org/whl/torch_stable.html" else INSTALL="--pre torch torchvision torchaudio -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html" fi python -m pip install $INSTALL python -m pip install -r requirements/dev.txt --upgrade-strategy only-if-needed --quiet python --version pip --version python -m pip list shell: bash - name: Source code tests run: | coverage run -a -m pytest tests --ignore tests/models/publish_test.py chmod +x ./tests/cli_test.sh ./tests/cli_test.sh # This tends to fail despite the code works, when Zenodo is slow. - name: Model-sharing tests run: | coverage run -a -m pytest tests/models/publish_test.py env: ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} - name: CLI tests run: | chmod +x ./tests/cli_test.sh ./tests/cli_test.sh env: ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} - name: Coverage report run: | coverage report -m coverage xml -o coverage.xml - name: Codecov upload uses: codecov/codecov-action@v1 with: file: ./coverage.xml
What changed
- Run on Latchkey managed runners with one line (
runs-on), which apply the fixes below automatically and self-heal transient failures. This example useslatchkey-small; pick the runner size that fits the job. - Cancel superseded runs when a branch or PR gets a newer push.
- Cache dependency installs on the setup step so they are served from cache.
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:
- Dependency installs
This workflow runs 1 job (2 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.