Skip to content
Latchkey

Run Tests workflow (xhtml2pdf/xhtml2pdf)

The Run Tests workflow from xhtml2pdf/xhtml2pdf, explained and optimized by Latchkey.

F

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.

Grade your own workflow free or run it on Latchkey →
Source: xhtml2pdf/xhtml2pdf.github/workflows/tests.ymlLicense Apache-2.0View source

What it does

This is the Run Tests workflow from the xhtml2pdf/xhtml2pdf 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

workflow (.yml)
name: Run Tests
on: push
jobs:
  python:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
    env:
      PYTHON_VERSION: ${{matrix.python-version}}
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python ${{matrix.python-version}}
        uses: actions/setup-python@v5
        with:
          python-version: ${{matrix.python-version}}
          allow-prereleases: true
      - if: matrix.python-version == '3.13'  # For lxml...
        run: |
          sudo apt-get update
          sudo apt-get install --yes libxml2 libxslt-dev
      - name: Install dependencies
        run: |
          sudo apt-get update
          sudo apt-get install --yes ghostscript imagemagick
          sudo sed -i 's#<policy domain="coder" rights="none" pattern="PDF" />#<policy domain="coder" rights="read|write" pattern="PDF" />#' /etc/ImageMagick-6/policy.xml
          python -m pip install --upgrade pip
          python -m pip install .[test]

      - name: run
        run: make test-ref

      - name: Test with tox
        run: tox
        env:
          TOXENV: py${{matrix.python-version}}

      - name: Generate coverage report
        run: coverage xml

      - name: Upload test coverage
        uses: coverallsapp/github-action@v2
        env:
          COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
        with:
          github-token: ${{ github.token }}
          file: "coverage.xml"
          format: "cobertura"

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 Tests
on: push
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  python:
    timeout-minutes: 30
    runs-on: latchkey-small
    strategy:
      fail-fast: false
      matrix:
        python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
    env:
      PYTHON_VERSION: ${{matrix.python-version}}
    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}}
          allow-prereleases: true
      - if: matrix.python-version == '3.13'  # For lxml...
        run: |
          sudo apt-get update
          sudo apt-get install --yes libxml2 libxslt-dev
      - name: Install dependencies
        run: |
          sudo apt-get update
          sudo apt-get install --yes ghostscript imagemagick
          sudo sed -i 's#<policy domain="coder" rights="none" pattern="PDF" />#<policy domain="coder" rights="read|write" pattern="PDF" />#' /etc/ImageMagick-6/policy.xml
          python -m pip install --upgrade pip
          python -m pip install .[test]
 
      - name: run
        run: make test-ref
 
      - name: Test with tox
        run: tox
        env:
          TOXENV: py${{matrix.python-version}}
 
      - name: Generate coverage report
        run: coverage xml
 
      - name: Upload test coverage
        uses: coverallsapp/github-action@v2
        env:
          COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
        with:
          github-token: ${{ github.token }}
          file: "coverage.xml"
          format: "cobertura"
 

What changed

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:

This workflow runs 1 job (6 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.

Actions used in this workflow