Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 53 additions & 7 deletions .github/actions/run-service-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ inputs:
uv-version:
description: 'uv version to use'
required: true
save-cache:
description: >-
Save the uv and HuggingFace caches. Only one job per cache key should
save; pass "false" from every other caller, and always from a run that
executes untrusted code.
required: false
default: 'true'
pytest-args:
description: 'Extra arguments passed to pytest through `make test-all`'
required: false
Expand All @@ -16,11 +23,15 @@ inputs:
runs:
using: 'composite'
steps:
- name: Cache HuggingFace Models
uses: actions/cache@v5
# Bump the version suffix to drop a stale model cache; the key is static,
# so a saved cache is never refreshed otherwise. Keep it in sync with the
# restore steps in test.yml.
- name: Restore HuggingFace models
id: hf-cache
uses: actions/cache/restore@v5
with:
path: hf_cache
key: ${{ runner.os }}-hf-cache
key: ${{ runner.os }}-hf-cache-v2

- name: Set HuggingFace token
shell: bash
Expand All @@ -33,15 +44,26 @@ runs:
with:
python-version: ${{ inputs.python-version }}

# Caching is done by the restore/save steps around the install instead of
# by setup-uv, which has no restore-keys fallback. See test.yml.
- name: Install uv
uses: astral-sh/setup-uv@v10.0.0
with:
version: ${{ inputs.uv-version }}
enable-cache: true
enable-cache: false
cache-local-path: ~/.cache/uv # sets UV_CACHE_DIR
python-version: ${{ inputs.python-version }}
cache-dependency-glob: |
pyproject.toml
uv.lock

# The runner OS is hard-coded in the key; callers pin runs-on: ubuntu-24.04.
# Key format is shared with test.yml and lint.yml; keep all three in sync.
- name: Restore uv cache
id: uv-cache
uses: actions/cache/restore@v5
with:
path: ~/.cache/uv
key: uv-v1-ubuntu-24.04-${{ runner.arch }}-py${{ inputs.python-version }}-pruned-${{ hashFiles('pyproject.toml', 'uv.lock') }}
restore-keys: |
uv-v1-ubuntu-24.04-${{ runner.arch }}-py${{ inputs.python-version }}-pruned-

- name: Install required dependencies
shell: bash
Expand All @@ -58,6 +80,20 @@ runs:
run: |
uv sync --all-extras

# Saved before the tests, so a failing test doesn't cost the next run its
# cache. `prune --ci` keeps only wheels built from source.
- name: Prune uv cache
if: inputs.save-cache == 'true' && steps.uv-cache.outputs.cache-hit != 'true'
shell: bash
run: uv cache prune --ci

- name: Save uv cache
if: inputs.save-cache == 'true' && steps.uv-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v5
with:
path: ~/.cache/uv
key: ${{ steps.uv-cache.outputs.cache-primary-key }}

- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v1
with:
Expand All @@ -69,3 +105,13 @@ runs:
PYTEST_ARGS: ${{ inputs.pytest-args }}
run: |
make test-all ARGS="$PYTEST_ARGS"

# After the tests, which download the models. Only on success, because the
# key is static: a cache saved after an early failure would be missing
# models until the key is bumped.
- name: Save HuggingFace models
if: inputs.save-cache == 'true' && steps.hf-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v5
with:
path: hf_cache
key: ${{ steps.hf-cache.outputs.cache-primary-key }}
24 changes: 12 additions & 12 deletions .github/workflows/auto-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ jobs:
uses: astral-sh/setup-uv@v10.0.0
with:
version: ${{ env.UV_VERSION }}
enable-cache: true
# No cache: a release job must not run anything restored from the
# shared cache, and its saves would only compete with the test
# jobs' caches for the repository's 10 GB.
enable-cache: false
python-version: ${{ env.PYTHON_VERSION }}
cache-dependency-glob: |
pyproject.toml
uv.lock

- name: Install dependencies
run: uv sync --frozen
Expand Down Expand Up @@ -194,11 +194,11 @@ jobs:
uses: astral-sh/setup-uv@v10.0.0
with:
version: ${{ env.UV_VERSION }}
enable-cache: true
# No cache: a release job must not run anything restored from the
# shared cache, and its saves would only compete with the test
# jobs' caches for the repository's 10 GB.
enable-cache: false
python-version: ${{ env.PYTHON_VERSION }}
cache-dependency-glob: |
pyproject.toml
uv.lock

- name: Apply release version to pyproject.toml and uv.lock
run: |
Expand Down Expand Up @@ -320,11 +320,11 @@ jobs:
uses: astral-sh/setup-uv@v10.0.0
with:
version: ${{ env.UV_VERSION }}
enable-cache: true
# No cache: a release job must not run anything restored from the
# shared cache, and its saves would only compete with the test
# jobs' caches for the repository's 10 GB.
enable-cache: false
python-version: ${{ env.PYTHON_VERSION }}
cache-dependency-glob: |
pyproject.toml
uv.lock

- name: Install dependencies
run: uv sync --frozen
Expand Down
37 changes: 27 additions & 10 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,33 @@ on:
branches:
- main

# A new push to a PR cancels that PR's previous run; pushes to main are never
# cancelled. Same rule as test.yml.
concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.event.pull_request.number || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

env:
UV_VERSION: "0.13.1"
# The uv cache key below hard-codes the runner OS, so the jobs pin
# `runs-on: ubuntu-24.04` (all of them, for uniformity). Change both together.

jobs:
lock:
name: Check uv.lock is up to date
runs-on: ubuntu-latest
runs-on: ubuntu-24.04

steps:
- name: Check out repository
uses: actions/checkout@v6

# No cache: `uv lock --check` installs nothing, so a cache would only take
# up space.
- name: Install uv
uses: astral-sh/setup-uv@v10.0.0
with:
version: ${{ env.UV_VERSION }}
enable-cache: true
cache-dependency-glob: |
pyproject.toml
uv.lock
enable-cache: false

# Fails a pyproject.toml change that was never locked, before the drift
# lands on main and dirties the next contributor's tree.
Expand All @@ -34,7 +41,7 @@ jobs:

check:
name: Style-check ${{ matrix.python-version }}
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
strategy:
matrix:
python-version:
Expand All @@ -57,11 +64,21 @@ jobs:
uses: astral-sh/setup-uv@v10.0.0
with:
version: ${{ env.UV_VERSION }}
enable-cache: true
enable-cache: false
cache-local-path: ~/.cache/uv # sets UV_CACHE_DIR
python-version: ${{ matrix.python-version }} # sets UV_PYTHON
cache-dependency-glob: |
pyproject.toml
uv.lock

# Restore-only: the Test Suite workflow saves these caches (same key format
# as test.yml; keep them in sync). This job installs the test legs'
# `--all-extras` environment plus the docs group, so it reuses them as
# they are.
- name: Restore uv cache
uses: actions/cache/restore@v5
with:
path: ~/.cache/uv
key: uv-v1-ubuntu-24.04-${{ runner.arch }}-py${{ matrix.python-version }}-pruned-${{ hashFiles('pyproject.toml', 'uv.lock') }}
restore-keys: |
uv-v1-ubuntu-24.04-${{ runner.arch }}-py${{ matrix.python-version }}-pruned-

- name: Install dependencies
run: |
Expand Down
28 changes: 25 additions & 3 deletions .github/workflows/test-fork-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ permissions:
checks: write
pull-requests: read

# No `concurrency` block: cancelling a run would leave the check run created
# below stuck at in_progress on the fork PR.

env:
PYTHON_VERSION: "3.11"
UV_VERSION: "0.13.1"

jobs:
setup:
name: Validate PR
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
outputs:
head_sha: ${{ steps.pr-info.outputs.head_sha }}
head_repo: ${{ steps.pr-info.outputs.head_repo }}
Expand Down Expand Up @@ -59,8 +62,13 @@ jobs:

service-tests:
name: Service Tests
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
needs: setup
# This job runs fork code on the dispatching ref (main), and a cache saved
# here would be restored by every later run on main and by every PR.
# `read` gives the job a cache token that can restore but not save, so
# the cache service refuses a save from any step, fork code included.
cache-mode: read
steps:
- name: Create check run
id: check
Expand All @@ -82,12 +90,26 @@ jobs:
with:
repository: ${{ needs.setup.outputs.head_repo }}
ref: ${{ needs.setup.outputs.head_sha }}
# Keep GITHUB_TOKEN (checks: write) out of .git/config, where the
# fork's code could read it.
persist-credentials: false

# A second guard, in case `cache-mode` is ever not honoured: run the
# action from this repository rather than from the fork checkout, so
# the fork cannot edit away `save-cache: "false"`.
- name: Check out trusted actions
uses: actions/checkout@v6
with:
path: trusted-actions
sparse-checkout: .github/actions
persist-credentials: false

- name: Run service tests
uses: ./.github/actions/run-service-tests
uses: ./trusted-actions/.github/actions/run-service-tests
with:
python-version: ${{ env.PYTHON_VERSION }}
uv-version: ${{ env.UV_VERSION }}
save-cache: "false"
env:
HF_HOME: ${{ github.workspace }}/hf_cache
HF_TOKEN: ${{ secrets.HF_TOKEN }}
Expand Down
Loading
Loading