---
title: "Build once and share the output with test shards"
description: "Separate the build producer from test consumers and hand the same verified artifact to each shard."
url: https://starsling.dev/ci-playbooks/techniques/build-once-for-shards
canonicalUrl: https://starsling.dev/ci-playbooks/techniques/build-once-for-shards
---

# Build once and share the output with test shards

Separate the build producer from test consumers and hand the same verified artifact to each shard.

## How to choose an approach

Compare the examples by repository setup, prerequisites, and risks before adopting one. Each company implemented this in its own environment; measure each change against your own baseline.

- **[OpenAI](https://starsling.dev/ci-playbooks/openai#build-once)**: Use it when Multiple matrix legs or shards compile the same code before running tests. Check before adopting: Reused artifacts must match the commit, target and toolchain. Artifact transfer can outweigh the build time saved on small jobs.
- **[Stripe](https://starsling.dev/ci-playbooks/stripe#build-once-for-shards)**: Use it when Every test shard repeats the same expensive compilation. Check before adopting: The handoff pays off when transfer costs less than the repeated build. Consume only artifacts from the same commit and a compatible platform.

## Apply this technique

````text
Evaluate and apply this CI technique to my repository: Build once and share the output with test shards.

Separate the build producer from test consumers and hand the same verified artifact to each shard.

Read the technique and its source-backed company examples: https://starsling.dev/ci-playbooks/techniques/build-once-for-shards.md

Inspect this repository’s CI workflows, build and test commands, dependencies, and recent run timings. Identify where this technique applies and explain the expected benefit using this repository’s evidence.
Measure a baseline from recent comparable runs: elapsed time, queue time, runner minutes and failures where available. If data is unavailable, say what cannot be measured.
Compare relevant company approaches, checking prerequisites, platform differences and tradeoffs. Rank applicable options by evidence, fit and measurable opportunity; do not present company results as predictions for this repo.
Recommend the smallest safe change, show what checks and fallback paths remain, and ASK ME WHICH CHANGE TO APPROVE BEFORE EDITING ANY FILES.
Only after approval, work on a new feature branch, make one reversible change, and open a reviewable pull request. Never merge or push to a default or protected branch.
Keep required checks, test coverage, deployment and release behavior intact. Validate the change and compare equivalent runs where possible; report limitations and what should be monitored after merge.
````

## How companies used this technique

Read what each company changed and follow the original sources.

### OpenAI: Build once, test on every shard

Codex builds one nextest archive per platform, uploads it, and has four test shards download it and run their slice of the same binaries. For Windows ARM64 the archive builds on an x64 host while the tests still run on ARM64.

Evidence: Source PR/commit evidence

Built once on x64, tested on native ARM64 shards ([Source](https://github.com/openai/codex/pull/23358))

Use it when: Multiple matrix legs or shards compile the same code before running tests.

Before applying it: Reused artifacts must match the commit, target and toolchain. Artifact transfer can outweigh the build time saved on small jobs.

[Read more in the OpenAI playbook](https://starsling.dev/ci-playbooks/openai#build-once)

[Primary source](https://github.com/openai/codex/pull/23358)

### Stripe: Build once and hand the artifact to every shard

Stripe React Native separated platform app builds from its end-to-end shards, and each shard downloads the matching built app. On GitHub Actions the same handoff uses build artifacts scoped to the run, platform and configuration.

Evidence: Source PR/commit evidence

The full suite went from about 25 to about 14 minutes, together with the move to another CI system. ([Source](https://github.com/stripe/stripe-react-native/pull/2137))

Use it when: Every test shard repeats the same expensive compilation.

Before applying it: The handoff pays off when transfer costs less than the repeated build. Consume only artifacts from the same commit and a compatible platform.

[Read more in the Stripe playbook](https://starsling.dev/ci-playbooks/stripe#build-once-for-shards)

[Primary source](https://github.com/stripe/stripe-react-native/pull/2137)

## CI optimization is continuous work.

Apply this technique yourself, or use StarSling Runners for faster GitHub Actions and optional agent-driven optimization PRs, which teams on eligible paid plans can turn on.

[Get self-improving CI](https://starsling.dev/products/runners)

## Related techniques

### [Prepare shared test inputs once](https://starsling.dev/ci-playbooks/techniques/reuse-shared-test-inputs)

Produce or download common test inputs once and pass them to the jobs that consume them.

2 implementations · 2 companies (Mastra, Stripe)

### [Run shared validation once](https://starsling.dev/ci-playbooks/techniques/avoid-duplicate-validation)

Remove overlapping task or matrix invocations that perform the same check on the same inputs.

4 implementations · 3 companies (DoorDash, Mastra, Stripe)

## Company Playbooks

### [Anthropic](https://starsling.dev/ci-playbooks/anthropic)

Run only affected tests

### [DoorDash](https://starsling.dev/ci-playbooks/doordash)

Run build and test in parallel, sharded across CI agents

### [Linear](https://starsling.dev/ci-playbooks/linear)

Benchmark the same job on faster hardware

### [Mastra](https://starsling.dev/ci-playbooks/mastra)

StarSling runners for the slowest test workflow

### [OpenAI](https://starsling.dev/ci-playbooks/openai)

Rank CI fixes by the minutes they save

### [Ramp](https://starsling.dev/ci-playbooks/ramp)

Move a CPU-bound test suite to a faster CPU

### [Shopify](https://starsling.dev/ci-playbooks/shopify)

Let an agent iterate against one CI metric

### [Spotify](https://starsling.dev/ci-playbooks/spotify)

Build arm64 on native arm64 runners

### [Stripe](https://starsling.dev/ci-playbooks/stripe)

Run only the tests a change can reach

### [Uber](https://starsling.dev/ci-playbooks/uber)

Build the merge-queue speculations most likely to be needed

## Related guides

Implementation guides for this technique.

### [Build once and reuse it across GitHub Actions jobs](https://starsling.dev/github-actions/optimizations/avoid-duplicate-compilation)

Stop rebuilding the same commit twice: drop build steps from lint and typecheck jobs, and share one build across workflows with needs and artifacts.
