Tests Pipeline workflow (xnuinside/codegraph)
The Tests Pipeline workflow from xnuinside/codegraph, 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 Pipeline workflow from the xnuinside/codegraph 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 Pipeline
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
permissions:
contents: read
pages: write
id-token: write
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install flake8
run: |
python -m pip install --upgrade pip
pip install flake8
- name: Run flake8
run: |
flake8 codegraph/ tests/
tests:
runs-on: ubuntu-latest
needs: [lint]
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest pytest-cov matplotlib networkx click
- name: Run tests with coverage
run: |
pytest tests/ -v --cov=codegraph --cov-report=term-missing --cov-report=xml
- name: Upload coverage to Codecov
if: matrix.python-version == '3.12'
uses: codecov/codecov-action@v4
with:
files: ./coverage.xml
fail_ci_if_error: false
package-test:
runs-on: ubuntu-latest
needs: [lint]
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Build package
run: |
python -m pip install --upgrade pip build
python -m build --wheel
- name: Test package without matplotlib
run: |
pip install dist/codegraph-*.whl
pip install pytest
pytest tests/test_package_install.py -v
- name: Test package with matplotlib
run: |
pip install --force-reinstall dist/codegraph-*.whl
pip install matplotlib networkx
pytest tests/ -v
deploy-demo:
runs-on: ubuntu-latest
needs: [tests, package-test]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install codegraph
run: |
python -m pip install --upgrade pip
pip install -e .
- name: Clone simple-ddl-parser for demo
run: |
git clone --depth 1 https://github.com/xnuinside/simple-ddl-parser.git /tmp/simple-ddl-parser
- name: Generate demo page
run: |
mkdir -p docs
codegraph /tmp/simple-ddl-parser/simple_ddl_parser --output docs/index.html
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: 'docs'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4The 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 Pipeline on: push: branches: [ main ] pull_request: branches: [ main ] permissions: contents: read pages: write id-token: write concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: lint: timeout-minutes: 30 runs-on: latchkey-small steps: - uses: actions/checkout@v4 - name: Set up Python 3.12 uses: actions/setup-python@v5 with: cache: 'pip' python-version: "3.12" - name: Install flake8 run: | python -m pip install --upgrade pip pip install flake8 - name: Run flake8 run: | flake8 codegraph/ tests/ tests: timeout-minutes: 30 runs-on: latchkey-small needs: [lint] strategy: fail-fast: false matrix: python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 with: cache: 'pip' python-version: ${{ matrix.python-version }} - name: Install dependencies run: | python -m pip install --upgrade pip pip install pytest pytest-cov matplotlib networkx click - name: Run tests with coverage run: | pytest tests/ -v --cov=codegraph --cov-report=term-missing --cov-report=xml - name: Upload coverage to Codecov if: matrix.python-version == '3.12' uses: codecov/codecov-action@v4 with: files: ./coverage.xml fail_ci_if_error: false package-test: timeout-minutes: 30 runs-on: latchkey-small needs: [lint] strategy: fail-fast: false matrix: python-version: ["3.10", "3.12"] steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 with: cache: 'pip' python-version: ${{ matrix.python-version }} - name: Build package run: | python -m pip install --upgrade pip build python -m build --wheel - name: Test package without matplotlib run: | pip install dist/codegraph-*.whl pip install pytest pytest tests/test_package_install.py -v - name: Test package with matplotlib run: | pip install --force-reinstall dist/codegraph-*.whl pip install matplotlib networkx pytest tests/ -v deploy-demo: timeout-minutes: 30 runs-on: latchkey-small needs: [tests, package-test] if: github.event_name == 'push' && github.ref == 'refs/heads/main' environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }} steps: - uses: actions/checkout@v4 - name: Set up Python 3.12 uses: actions/setup-python@v5 with: cache: 'pip' python-version: "3.12" - name: Install codegraph run: | python -m pip install --upgrade pip pip install -e . - name: Clone simple-ddl-parser for demo run: | git clone --depth 1 https://github.com/xnuinside/simple-ddl-parser.git /tmp/simple-ddl-parser - name: Generate demo page run: | mkdir -p docs codegraph /tmp/simple-ddl-parser/simple_ddl_parser --output docs/index.html - name: Setup Pages uses: actions/configure-pages@v4 - name: Upload artifact uses: actions/upload-pages-artifact@v3 with: path: 'docs' - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v4
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 (9 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.