Skip to content

4. Artifacts, caches and workflow reuse ​

Home · Full index

MechanismUse it forExample
Job outputA small string in one runImage digest
ArtifactFiles produced by a runWheel, report or checksum
CacheReusable data that makes a later run fasterDependency downloads
RegistryVersioned packages for consumers or deploymentOCI image by digest

4.1 A01 · Build, upload, download and install a wheel ​

GitHub Actions · Full workflow. Requires a buildable uv package with Ruff and pytest in its default dev group. Replace calculator with its importable module. The example assumes the wheel has no third-party runtime dependencies for this import check. For a package with dependencies, install those in the disposable environment too.

yaml
name: Quality and wheel handoff
on: [push, pull_request]
permissions:
  contents: read
jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          persist-credentials: false
      - uses: astral-sh/setup-uv@v6
        with:
          enable-cache: false
      - run: uv run --locked --python 3.12 ruff check .
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          persist-credentials: false
      - uses: astral-sh/setup-uv@v6
        with:
          enable-cache: false
      - run: uv run --locked --python 3.12 python -m pytest -q
  package:
    needs: [lint, test]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          persist-credentials: false
      - uses: astral-sh/setup-uv@v6
        with:
          enable-cache: false
      - run: uv build --python 3.12 --wheel
      - uses: actions/upload-artifact@v4
        with:
          name: wheel
          path: dist/*.whl
          if-no-files-found: error
          retention-days: 7
  install:
    needs: package
    runs-on: ubuntu-latest
    steps:
      - uses: actions/setup-python@v5
        with:
          python-version: '3.12'
      - uses: actions/download-artifact@v4
        with:
          name: wheel
          path: dist
      - run: |
          python -m venv .wheel-venv
          .wheel-venv/bin/python -m pip install --no-deps dist/*.whl
          .wheel-venv/bin/python -I -c 'import calculator'

Verify. The last job imports the installed distribution without checking out source. Confirm the package job was skipped after a deliberate test failure.

4.2 A02 · Keep matrix artifacts distinct ​

GitHub Actions · Steps fragment. Place in the test job from T01. Use a name that includes every dimension that can vary.

yaml
- name: Run tests and write JUnit XML
  run: python -m pytest -q --junitxml=junit.xml
- name: Upload matrix report
  if: '!cancelled()'
  uses: actions/upload-artifact@v4
  with:
    name: junit-python-${{ matrix.python }}
    path: junit.xml
    if-no-files-found: warn

Verify. The run lists one artifact name per Python version. Avoid writing the same artifact name from multiple parallel jobs.

4.3 A03 · Cache uv downloads by dependency changes ​

GitHub Actions · Steps fragment. Run after checkout. The setup action uses the supplied dependency globs to look for cache changes. Use G05 to validate Gitea's cache separately.

yaml
- uses: astral-sh/setup-uv@v6
  with:
    enable-cache: true
    cache-dependency-glob: |
      uv.lock
      pyproject.toml
- run: uv sync --locked --python 3.12
- run: uv run --no-sync python -m pytest -q

Verify. Compare cold and warm run timings before and after modifying the lockfile. Both runs should install and test the locked environment correctly.

4.4 A04 · Reusable workflow with a caller ​

GitHub Actions · Two full files. Save both files under .github/workflows/. Requires a uv project with pytest in the default dev group. A caller invokes a workflow at the job level.

yaml
# .github/workflows/reusable-python.yml
name: Reusable Python tests
on:
  workflow_call:
    inputs:
      python-version:
        required: true
        type: string
permissions:
  contents: read
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          persist-credentials: false
      - uses: astral-sh/setup-uv@v6
        with:
          enable-cache: false
      - env:
          PYTHON_VERSION: ${{ inputs.python-version }}
        run: uv run --locked --python "$PYTHON_VERSION" python -m pytest -q
yaml
# .github/workflows/ci.yml
name: Call shared tests
on: [pull_request]
permissions:
  contents: read
jobs:
  python:
    uses: ./.github/workflows/reusable-python.yml
    with:
      python-version: '3.12'

Verify. A PR shows a called test job. Change the caller input and confirm the setup uses the requested version.

4.5 A05 · Reuse steps with a composite action ​

GitHub Actions · Action metadata and caller steps. Save metadata in .github/actions/python-check/action.yml and check out the repository before calling it. Assume the dev group contains pytest. A composite action runs as a step inside the caller's job.

yaml
name: Python checks
description: Set up uv and run the root project's pytest suite
runs:
  using: composite
  steps:
    - uses: astral-sh/setup-uv@v6
      with:
        enable-cache: false
    - shell: bash
      run: uv run --locked --python 3.12 python -m pytest -q
yaml
- uses: actions/checkout@v4
  with:
    persist-credentials: false
- uses: ./.github/actions/python-check

Verify. Two different jobs can invoke the same action. Compare this with A04, where the chain of jobs can live in the called workflow.

4.6 A06 · Check an artifact transfer with a SHA-256 manifest ​

Linux · Two shell fragments. First run in the build job. Upload all wheels plus SHA256SUMS. Run the second block after downloading them into dist/. This catches file corruption or substitution relative to the supplied manifest. To establish provenance, obtain verification material through a separately trusted path.

bash
cd dist
sha256sum -- *.whl > SHA256SUMS
bash
cd dist
sha256sum --check --strict SHA256SUMS

Verify. Alter one byte in a disposable local copy of a wheel. The check exits nonzero.

Reference · Artifact upload, artifact download, reuse workflows, composite actions.