Static code analysis workflow (python-lsp/python-lsp-server)
The Static code analysis workflow from python-lsp/python-lsp-server, explained and optimized by Latchkey.
CI health: A - excellent
Point runs-on at Latchkey and get caching, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the Static code analysis workflow from the python-lsp/python-lsp-server 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: Static code analysis
on:
push:
branches:
- develop
pull_request:
branches:
- '*'
concurrency:
group: static-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
name: Static code analysis
runs-on: ubuntu-latest
env:
CI: 'true'
OS: 'linux'
timeout-minutes: 2
steps:
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: static-pip-${{ hashFiles('pyproject.toml') }}
restore-keys: static-pip-
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.9'
architecture: 'x64'
- run: python -m pip install --upgrade pip setuptools jsonschema
# If we don't install pycodestyle, pylint will throw an unused-argument error in pylsp/plugins/pycodestyle_lint.py:72
# This error cannot be resolved by adding a pylint: disable=unused-argument comment ...
- run: |
pip install -e .[pylint,pycodestyle]
pip install ruff==0.9.4
- name: ruff linter and code style checks
run: ruff check pylsp test
- name: ruff code formatter check
run: ruff format --check pylsp test
- name: Validate JSON schema
run: echo {} | jsonschema pylsp/config/schema.json
- name: Ensure JSON schema and Markdown docs are in sync
run: |
python scripts/jsonschema2md.py pylsp/config/schema.json EXPECTED_CONFIGURATION.md
diff EXPECTED_CONFIGURATION.md CONFIGURATION.md
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: Static code analysis on: push: branches: - develop pull_request: branches: - '*' concurrency: group: static-${{ github.ref }} cancel-in-progress: true jobs: build: name: Static code analysis runs-on: latchkey-small env: CI: 'true' OS: 'linux' timeout-minutes: 2 steps: - uses: actions/cache@v4 with: path: ~/.cache/pip key: static-pip-${{ hashFiles('pyproject.toml') }} restore-keys: static-pip- - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: cache: 'pip' python-version: '3.9' architecture: 'x64' - run: python -m pip install --upgrade pip setuptools jsonschema # If we don't install pycodestyle, pylint will throw an unused-argument error in pylsp/plugins/pycodestyle_lint.py:72 # This error cannot be resolved by adding a pylint: disable=unused-argument comment ... - run: | pip install -e .[pylint,pycodestyle] pip install ruff==0.9.4 - name: ruff linter and code style checks run: ruff check pylsp test - name: ruff code formatter check run: ruff format --check pylsp test - name: Validate JSON schema run: echo {} | jsonschema pylsp/config/schema.json - name: Ensure JSON schema and Markdown docs are in sync run: | python scripts/jsonschema2md.py pylsp/config/schema.json EXPECTED_CONFIGURATION.md diff EXPECTED_CONFIGURATION.md CONFIGURATION.md
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. - Cache dependency installs on the setup step so they are served from cache.
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 per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.