Tests workflow (laike9m/Cyberbrain)
The Tests workflow from laike9m/Cyberbrain, explained and optimized by Latchkey.
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.
What it does
This is the Tests workflow from the laike9m/Cyberbrain 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: Tests
# Ideally we should trigger different checks based on modified sources.
# For example, ignore Python tests if only js files are modified.
# There's a hacky way: https://stackoverflow.com/a/59608109/2142577
# TODO: Investigate whether GitHub Actions support it.
on:
pull_request:
paths:
- "cyberbrain/*"
- "cyberbrain-vsc/*"
- "test/*"
- ".github/workflows/ci.yml"
- "pdm.lock"
- "tox.ini"
push:
paths:
- "cyberbrain/*"
- "cyberbrain-vsc/*"
- "test/*"
- ".github/workflows/ci.yml"
- "pdm.lock"
- "tox.ini"
workflow_dispatch:
jobs:
PythonLint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.9'
- run: |
python -m pip install black==22.3.0
black --check cyberbrain test
JsLintAndTest:
runs-on: ubuntu-latest
defaults:
run:
working-directory: cyberbrain-vsc
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '14'
- run: npm install
- run: npm run lint
- run: npm run unittest
PythonTest:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: [ 3.7, 3.8, 3.9, "3.10" ]
os: [ ubuntu-latest, macOS-latest, windows-latest ]
steps:
- uses: actions/checkout@v2
- name: Set up PDM
uses: pdm-project/setup-pdm@main
with:
python-version: ${{ matrix.python-version }}
- run: pdm info -v
- name: Install dependencies
run: pdm install -v
- name: Run tests
run: pdm run tox -v
VsCodeTest:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: [ 3.7, 3.8, 3.9, "3.10" ]
os: [ ubuntu-latest, macOS-latest, windows-latest ]
steps:
- uses: actions/checkout@v2
- name: Set up PDM
uses: pdm-project/setup-pdm@main
with:
python-version: ${{ matrix.python-version }}
- run: pdm info -v
- name: Install Node.js
uses: actions/setup-node@v2
with:
node-version: '12'
- name: Install Python dependencies
run: pdm install -v
- name: Install Node.js dependencies
run: npm install
working-directory: cyberbrain-vsc
- name: VSCode Integration tests on Linux
run: xvfb-run -a npm test
if: runner.os == 'Linux'
working-directory: cyberbrain-vsc
- name: VSCode Integration tests on Mac & Win
run: npm test
if: runner.os != 'Linux'
working-directory: cyberbrain-vsc
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 # Ideally we should trigger different checks based on modified sources. # For example, ignore Python tests if only js files are modified. # There's a hacky way: https://stackoverflow.com/a/59608109/2142577 # TODO: Investigate whether GitHub Actions support it. on: pull_request: paths: - "cyberbrain/*" - "cyberbrain-vsc/*" - "test/*" - ".github/workflows/ci.yml" - "pdm.lock" - "tox.ini" push: paths: - "cyberbrain/*" - "cyberbrain-vsc/*" - "test/*" - ".github/workflows/ci.yml" - "pdm.lock" - "tox.ini" workflow_dispatch: concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: PythonLint: timeout-minutes: 30 runs-on: latchkey-small steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 with: python-version: '3.9' - run: | python -m pip install black==22.3.0 black --check cyberbrain test JsLintAndTest: timeout-minutes: 30 runs-on: latchkey-small defaults: run: working-directory: cyberbrain-vsc steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: cache: 'npm' node-version: '14' - run: npm install - run: npm run lint - run: npm run unittest PythonTest: timeout-minutes: 30 runs-on: ${{ matrix.os }} strategy: matrix: python-version: [ 3.7, 3.8, 3.9, "3.10" ] os: [ ubuntu-latest, macOS-latest, windows-latest ] steps: - uses: actions/checkout@v2 - name: Set up PDM uses: pdm-project/setup-pdm@main with: python-version: ${{ matrix.python-version }} - run: pdm info -v - name: Install dependencies run: pdm install -v - name: Run tests run: pdm run tox -v VsCodeTest: timeout-minutes: 30 runs-on: ${{ matrix.os }} strategy: matrix: python-version: [ 3.7, 3.8, 3.9, "3.10" ] os: [ ubuntu-latest, macOS-latest, windows-latest ] steps: - uses: actions/checkout@v2 - name: Set up PDM uses: pdm-project/setup-pdm@main with: python-version: ${{ matrix.python-version }} - run: pdm info -v - name: Install Node.js uses: actions/setup-node@v2 with: cache: 'npm' node-version: '12' - name: Install Python dependencies run: pdm install -v - name: Install Node.js dependencies run: npm install working-directory: cyberbrain-vsc - name: VSCode Integration tests on Linux run: xvfb-run -a npm test if: runner.os == 'Linux' working-directory: cyberbrain-vsc - name: VSCode Integration tests on Mac & Win run: npm test if: runner.os != 'Linux' working-directory: cyberbrain-vsc
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.
- Add a job timeout so a hung step cannot burn hours of runner time.
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 4 jobs (26 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.