test-n-build workflow (plotly/Kaleido)
The test-n-build workflow from plotly/Kaleido, 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 test-n-build workflow from the plotly/Kaleido 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
# .github/workflows/publish_testpypi.yml
---
name: test-n-build
on:
workflow_dispatch:
push:
tags:
- v*
jobs:
super-test:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python_v: ['3.8', '3.9', '3.10', '3.12', '3.13', '3.14']
# chrome_v: ['-1']
defaults:
run:
working-directory: ./src/py/
name: Build and Test
runs-on: ${{ matrix.os }}
env:
UV_PYTHON: ${{ matrix.python_v }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- uses: astral-sh/setup-uv@v5
- name: Install Dependencies
if: ${{ matrix.os == 'ubuntu-latest' }}
run: sudo apt-get update && sudo apt-get install xvfb
timeout-minutes: 1
# must actually checkout for version determination
- run: git checkout ${{ github.ref_name }}
- run: uv python install ${{ matrix.python_v }}
# don't modify sync file! messes up version!
- run: uv sync --all-extras --locked --no-sources
- run: git status
- run: git diff --quiet HEAD || { echo "Working tree dirty"; exit 1; }
- run: uv build
- name: Reinstall from wheel
run: >
uv pip install dist/kaleido-$(uv
run --no-sync --with setuptools-git-versioning
setuptools-git-versioning)-py3-none-any.whl
- run: uv run --no-sync kaleido_get_chrome -v # --i ${{ matrix.chrome_v }}
- name: Diagnose
run: uv run --no-sync choreo_diagnose --no-run
- name: Test mocker
run: >
uv run
--no-sync kaleido_mocker
--random 50
--logistro-level INFO
--n 1
--timeout 200
--output ${{ github.workspace }}/src/py/integration_tests/renders/
--input ${{ github.workspace }}/src/py/integration_tests/mocks/
- name: Test
if: ${{ ! runner.debug && matrix.os != 'ubuntu-latest' }}
run: uv run --no-sync poe test
timeout-minutes: 8
- name: Test (Linux)
if: ${{ ! runner.debug && matrix.os == 'ubuntu-latest' }}
run: xvfb-run uv run --no-sync poe test
timeout-minutes: 8
- name: Test (Debug)
if: runner.debug
run: uv run --no-sync poe debug-test
timeout-minutes: 20
- name: Test (Debug, Linux)
if: ${{ runner.debug && matrix.os == 'ubuntu-latest' }}
run: xvfb-run uv run --no-sync poe debug-test
timeout-minutes: 8
testpypi-publish:
defaults:
run:
working-directory: ./src/py/
name: Upload release to TestPyPI
needs: super-test
if: ${{ !cancelled() &&
!failure() &&
github.event_name == 'push' &&
github.run_attempt == 1 }}
runs-on: ubuntu-latest
environment:
name: testpypi
url: https://test.pypi.org/p/kaleido
# Signs this workflow so pypi trusts it
permissions:
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v5
- uses: actions/setup-python@v5
with:
python-version-file: "./src/py/pyproject.toml"
- run: git checkout ${{ github.ref_name }}
- run: uv sync --frozen --all-extras
- run: uv build
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/.
packages-dir: src/py/dist
verbose: true
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.
# .github/workflows/publish_testpypi.yml --- name: test-n-build on: workflow_dispatch: push: tags: - v* concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: super-test: timeout-minutes: 30 strategy: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest] python_v: ['3.8', '3.9', '3.10', '3.12', '3.13', '3.14'] # chrome_v: ['-1'] defaults: run: working-directory: ./src/py/ name: Build and Test runs-on: ${{ matrix.os }} env: UV_PYTHON: ${{ matrix.python_v }} steps: - uses: actions/checkout@v4 with: fetch-depth: 1 - uses: astral-sh/setup-uv@v5 - name: Install Dependencies if: ${{ matrix.os == 'ubuntu-latest' }} run: sudo apt-get update && sudo apt-get install xvfb timeout-minutes: 1 # must actually checkout for version determination - run: git checkout ${{ github.ref_name }} - run: uv python install ${{ matrix.python_v }} # don't modify sync file! messes up version! - run: uv sync --all-extras --locked --no-sources - run: git status - run: git diff --quiet HEAD || { echo "Working tree dirty"; exit 1; } - run: uv build - name: Reinstall from wheel run: > uv pip install dist/kaleido-$(uv run --no-sync --with setuptools-git-versioning setuptools-git-versioning)-py3-none-any.whl - run: uv run --no-sync kaleido_get_chrome -v # --i ${{ matrix.chrome_v }} - name: Diagnose run: uv run --no-sync choreo_diagnose --no-run - name: Test mocker run: > uv run --no-sync kaleido_mocker --random 50 --logistro-level INFO --n 1 --timeout 200 --output ${{ github.workspace }}/src/py/integration_tests/renders/ --input ${{ github.workspace }}/src/py/integration_tests/mocks/ - name: Test if: ${{ ! runner.debug && matrix.os != 'ubuntu-latest' }} run: uv run --no-sync poe test timeout-minutes: 8 - name: Test (Linux) if: ${{ ! runner.debug && matrix.os == 'ubuntu-latest' }} run: xvfb-run uv run --no-sync poe test timeout-minutes: 8 - name: Test (Debug) if: runner.debug run: uv run --no-sync poe debug-test timeout-minutes: 20 - name: Test (Debug, Linux) if: ${{ runner.debug && matrix.os == 'ubuntu-latest' }} run: xvfb-run uv run --no-sync poe debug-test timeout-minutes: 8 testpypi-publish: timeout-minutes: 30 defaults: run: working-directory: ./src/py/ name: Upload release to TestPyPI needs: super-test if: ${{ !cancelled() && !failure() && github.event_name == 'push' && github.run_attempt == 1 }} runs-on: latchkey-small environment: name: testpypi url: https://test.pypi.org/p/kaleido # Signs this workflow so pypi trusts it permissions: id-token: write steps: - name: Checkout uses: actions/checkout@v4 - uses: astral-sh/setup-uv@v5 - uses: actions/setup-python@v5 with: cache: 'pip' python-version-file: "./src/py/pyproject.toml" - run: git checkout ${{ github.ref_name }} - run: uv sync --frozen --all-extras - run: uv build - name: Publish package distributions to PyPI uses: pypa/gh-action-pypi-publish@release/v1 with: repository-url: https://test.pypi.org/legacy/. packages-dir: src/py/dist verbose: true
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.
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:
- Dependency installs
This workflow runs 2 jobs (19 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.