Skip to content
Merged
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
18 changes: 16 additions & 2 deletions .github/actions/setup-toolchain/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ inputs:
alongside Static Analysis on the same push or pull_request so only one job writes the key.
required: false
default: "true"
compile-bytecode:
description: >-
Whether `uv sync` compiles bytecode. Set to "false" in the test jobs, where xdist workers
compile the modules they import anyway and the sync compile costs 7 to 15 s (#4727).
required: false
default: "true"

runs:
using: composite
Expand Down Expand Up @@ -52,10 +58,18 @@ runs:
tooling-${{ inputs.cache-suffix }}-${{ runner.os }}-

# A fresh runner's environment holds no bytecode: compiling it once here, in parallel, spares
# each xdist worker compiling the same modules while it collects (#1735).
# each xdist worker compiling the same modules while it collects (#1735). The test jobs skip
# the compile, because their workers import most modules once (#4727).
- name: Synchronize dependencies
shell: bash
run: uv sync --locked --all-groups --all-extras --compile-bytecode
env:
COMPILE_BYTECODE: ${{ inputs.compile-bytecode }}
run: |
if [ "$COMPILE_BYTECODE" = "true" ]; then
uv sync --locked --all-groups --all-extras --compile-bytecode
else
uv sync --locked --all-groups --all-extras
fi

- name: Initialize workspace directories
shell: bash
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ jobs:
with:
cache-suffix: test-${{ matrix.shard }}
save-uv-cache: "false"
compile-bytecode: "false"
tooling-cache-paths: |
.pytest_cache

Expand Down Expand Up @@ -396,6 +397,7 @@ jobs:
with:
cache-suffix: job-time
save-uv-cache: "false"
compile-bytecode: "false"

- name: Check the duration of Tests & Coverage
env:
Expand Down Expand Up @@ -770,6 +772,7 @@ jobs:
with:
cache-suffix: changed-tests
save-uv-cache: "false"
compile-bytecode: "false"
tooling-cache-paths: |
.pytest_cache

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/service-image-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ jobs:
uses: ./.github/actions/setup-toolchain
with:
save-uv-cache: "false"
compile-bytecode: "false"
# The suite runs in the image, so no tool of the runner reads a tooling cache.
tooling-cache-paths: ""

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-11-14
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Design

## Context

The compile runs once per job to spare each worker a compile during collection (#1735). A test job runs several workers that import most of the suite, so the compile runs again in each worker.

## Goals

- Remove the sync compile from the test jobs.
- Keep it in the jobs that run one process, such as Static Analysis.

## Decisions

- **An input with a true default.** Jobs opt out, and the other jobs keep the compile.
- **The four test jobs.** They import most modules in several processes.
- **No tooling-cache change.** `.pytest_cache` is used by pytest, and the Service Image Tests restore none already.

## Risks

- The first worker compile adds CPU time at the start. The measured saving is 9 to 11 s per job.

## Tests

- The action holds the input with a true default.
- The four test jobs pass false.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Proposal

## Why

`setup-toolchain` runs `uv sync --compile-bytecode`, and the compile took 7.6 to 14.7 s per job (mean 11.4 s, 10 logs). The xdist workers of a test job import most modules and compile them anyway (#4727).

## What Changes

- `setup-toolchain` takes a `compile-bytecode` input, true by default.
- `test-shard`, `changed-tests`, `job-time` and the Service Image Tests pass `false`.
- The Service Image Tests already restore no tooling cache, so no other input changes.
- The change fits one pull request.

## Capabilities

### New Capabilities

None.

### Modified Capabilities

- `ci-job-time`: The test jobs skip the bytecode compile.

## Impact

- Workflow: `.github/actions/setup-toolchain/action.yml`, `.github/workflows/ci.yml`, `.github/workflows/service-image-test.yml`
- Tests: `tests/invariants/test_workflow_contracts.py`

## Feasibility

- `uv sync` compiles only on request.
- The input changes one step.
- Verification commands: `uv run devops ci test tests/invariants/test_workflow_contracts.py` and `uv run devops ci --check --only lint,format,typecheck`.

## Existing Tool Considered

uv already gives the switch. No new tool.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## ADDED Requirements

### Requirement: The test jobs skip the bytecode compile
`setup-toolchain` SHALL take a `compile-bytecode` input with the default `true`, and the `test-shard`, `changed-tests`, `job-time` and Service Image Tests jobs SHALL pass `false`.

#### Scenario: A test job synchronizes dependencies
- **WHEN** the `test-shard` job runs `setup-toolchain` with `compile-bytecode: "false"`
- **THEN** `uv sync` runs without `--compile-bytecode`

#### Scenario: A job that keeps the compile
- **WHEN** a job calls `setup-toolchain` with no `compile-bytecode`
- **THEN** `uv sync` runs with `--compile-bytecode`
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Tasks

## 1. Skip the sync compile in the test jobs

Reads: `.github/actions/setup-toolchain/action.yml`. Changes: the action, `ci.yml`, `service-image-test.yml`, and the workflow test.

- [x] 1.1 Add the input and the conditional sync.
- [x] 1.2 Pass `false` in the four test jobs.
- [x] 1.3 Add the contract test.
- Verification: `$ uv run devops ci test tests/invariants/test_workflow_contracts.py` passes
11 changes: 11 additions & 0 deletions openspec/specs/ci-job-time/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,14 @@ With `--file-issue`, a mean inside the limit or a short read SHALL make no searc
#### Scenario: Dry run with the issue
- **WHEN** the user runs `devops ci job-time --file-issue --dry-run`
- **THEN** the plan lists the issue search, the comment and the new issue, and GitHub receives no request

### Requirement: The test jobs skip the bytecode compile
`setup-toolchain` SHALL take a `compile-bytecode` input with the default `true`, and the `test-shard`, `changed-tests`, `job-time` and Service Image Tests jobs SHALL pass `false`.

#### Scenario: A test job synchronizes dependencies
- **WHEN** the `test-shard` job runs `setup-toolchain` with `compile-bytecode: "false"`
- **THEN** `uv sync` runs without `--compile-bytecode`

#### Scenario: A job that keeps the compile
- **WHEN** a job calls `setup-toolchain` with no `compile-bytecode`
- **THEN** `uv sync` runs with `--compile-bytecode`
6 changes: 4 additions & 2 deletions tests/commands/test_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,10 +793,12 @@ def test_the_toolchain_compiles_bytecode_when_it_syncs() -> None:
syncs = [
str(step.get("run", ""))
for step in action["runs"]["steps"]
if isinstance(step, dict) and str(step.get("run", "")).startswith("uv sync")
if isinstance(step, dict) and "uv sync" in str(step.get("run", ""))
]

assert (len(syncs), all("--compile-bytecode" in sync for sync in syncs)) == (1, True)
assert len(syncs) == 1
assert "uv sync --locked --all-groups --all-extras --compile-bytecode" in syncs[0]
assert action["inputs"]["compile-bytecode"]["default"] == "true"


def test_ci_workflow_has_tooling_cache_step() -> None:
Expand Down
28 changes: 28 additions & 0 deletions tests/invariants/test_workflow_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2593,3 +2593,31 @@ def test_the_service_image_test_run_has_a_timeout_inside_the_job_limit() -> None
]

assert any("timeout --kill-after=30 900 docker run" in run for run in runs)


def test_the_test_jobs_skip_the_bytecode_compile() -> None:
"""The xdist workers compile what they import, so a sync compile costs each test job 7 to
15 s (#4727)."""
action = _load_workflow(WORKFLOWS_DIR / ".." / "actions" / "setup-toolchain" / "action.yml")
inputs = action["inputs"]

def _uses(job: dict[str, Any]) -> dict[str, str]:
step = next(
s for s in job.get("steps", []) if s.get("uses") == "./.github/actions/setup-toolchain"
)
return step.get("with", {})

jobs = _load_workflow(WORKFLOWS_DIR / "ci.yml")["jobs"]
service = _load_workflow(WORKFLOWS_DIR / "service-image-test.yml")["jobs"]

assert inputs["compile-bytecode"]["default"] == "true"
assert _uses(jobs["test-shard"])["compile-bytecode"] == "false"
assert _uses(jobs["changed-tests"])["compile-bytecode"] == "false"
assert _uses(jobs["job-time"])["compile-bytecode"] == "false"
service_steps = [
step.get("with", {})
for job in service.values()
for step in job.get("steps", [])
if step.get("uses") == "./.github/actions/setup-toolchain"
]
assert [step["compile-bytecode"] for step in service_steps] == ["false"]