Run test suite workflow (patrick-kidger/torchcde)
The Run test suite workflow from patrick-kidger/torchcde, explained and optimized by Latchkey.
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 →What it does
This is the Run test suite workflow from the patrick-kidger/torchcde repository, a real project running GitHub Actions. It is shown here with attribution under its Apache-2.0 license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
name: Run test suite
on: [pull_request]
jobs:
check_version:
strategy:
matrix:
python-version: [ 3.8 ]
os: [ ubuntu-latest ]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Check version
run: |
python -m pip install --upgrade pip
pip install git+https://github.com/patrick-kidger/torchcde.git
master_info=$(pip list | grep torchcde)
master_version=$(echo ${master_info} | cut -d " " -f2)
pip uninstall -y torchcde
python setup.py install
pr_info=$(pip list | grep torchcde)
pr_version=$(echo ${pr_info} | cut -d " " -f2)
python -c "import itertools as it;
import sys;
master_version = sys.argv[1];
pr_version = sys.argv[2];
master_version_ = [int(i) for i in master_version.split('.')];
pr_version_ = [int(i) for i in pr_version.split('.')];
master_version__ = tuple(m for p, m in it.zip_longest(pr_version_, master_version_, fillvalue=0));
pr_version__ = tuple(p for p, m in it.zip_longest(pr_version_, master_version_, fillvalue=0));
sys.exit(pr_version__ <= master_version__)" ${master_version} ${pr_version}
test:
needs: [ check_version ]
strategy:
matrix:
python-version: [ 3.6, 3.8 ]
os: [ ubuntu-latest, macOS-latest, windows-latest ]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
- name: Install torchcde
run: |
python -m pip install torch==1.9.0
python setup.py install
- name: Install Signatory
if: matrix.os != 'macos-latest'
shell: bash
run: |
signatory_version=$(python -c "import re
import subprocess
version_msg = subprocess.run('pip install --use-deprecated=legacy-resolver signatory==', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
version_re = re.compile(rb'from versions: ([0-9\. ,]*)\)')
last_version = version_re.search(version_msg.stderr).group(1).split(b', ')[-1].decode('utf-8').split('.')
assert len(last_version) == 6
last_version = '.'.join(last_version[:3])
print(last_version)")
torch_info=$(pip list | grep '^torch ')
torch_version=$(echo ${torch_info} | cut -d " " -f2)
python -m pip install signatory==${signatory_version}.${torch_version}
- name: Lint with flake8
run: |
python -m flake8 .
- name: Test with pytest
run: |
python -m pytest
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: Run test suite on: [pull_request] concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: check_version: timeout-minutes: 30 strategy: matrix: python-version: [ 3.8 ] os: [ ubuntu-latest ] runs-on: ${{ matrix.os }} steps: - name: Checkout code uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: cache: 'pip' python-version: ${{ matrix.python-version }} - name: Check version run: | python -m pip install --upgrade pip pip install git+https://github.com/patrick-kidger/torchcde.git master_info=$(pip list | grep torchcde) master_version=$(echo ${master_info} | cut -d " " -f2) pip uninstall -y torchcde python setup.py install pr_info=$(pip list | grep torchcde) pr_version=$(echo ${pr_info} | cut -d " " -f2) python -c "import itertools as it; import sys; master_version = sys.argv[1]; pr_version = sys.argv[2]; master_version_ = [int(i) for i in master_version.split('.')]; pr_version_ = [int(i) for i in pr_version.split('.')]; master_version__ = tuple(m for p, m in it.zip_longest(pr_version_, master_version_, fillvalue=0)); pr_version__ = tuple(p for p, m in it.zip_longest(pr_version_, master_version_, fillvalue=0)); sys.exit(pr_version__ <= master_version__)" ${master_version} ${pr_version} test: timeout-minutes: 30 needs: [ check_version ] strategy: matrix: python-version: [ 3.6, 3.8 ] os: [ ubuntu-latest, macOS-latest, windows-latest ] fail-fast: false runs-on: ${{ matrix.os }} steps: - name: Checkout code uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: cache: 'pip' python-version: ${{ matrix.python-version }} - name: Install dependencies run: | python -m pip install --upgrade pip python -m pip install flake8 pytest - name: Install torchcde run: | python -m pip install torch==1.9.0 python setup.py install - name: Install Signatory if: matrix.os != 'macos-latest' shell: bash run: | signatory_version=$(python -c "import re import subprocess version_msg = subprocess.run('pip install --use-deprecated=legacy-resolver signatory==', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) version_re = re.compile(rb'from versions: ([0-9\. ,]*)\)') last_version = version_re.search(version_msg.stderr).group(1).split(b', ')[-1].decode('utf-8').split('.') assert len(last_version) == 6 last_version = '.'.join(last_version[:3]) print(last_version)") torch_info=$(pip list | grep '^torch ') torch_version=$(echo ${torch_info} | cut -d " " -f2) python -m pip install signatory==${signatory_version}.${torch_version} - name: Lint with flake8 run: | python -m flake8 . - name: Test with pytest run: | python -m pytest
What changed
- 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.
- Add a job timeout so a hung step cannot burn hours of runner time.
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 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.