# astral-sh/setup-uv architecture

> Architecture diagram of the GitHub repository astral-sh/setup-uv, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/astral-sh/setup-uv
- Repository: https://github.com/astral-sh/setup-uv

## Overview

#### Purpose and Entry Points
`setup-uv` is a TypeScript GitHub Action that resolves, downloads, verifies, installs, and exposes the `uv` CLI on a runner. The action contract is defined in `action.yml`; compiled runtime entry points are `dist/setup/index.cjs`, `dist/save-cache/index.cjs`, and `dist/update-known-checksums/index.cjs`. Primary source orchestration is `src/setup-uv.ts`.

#### Action Orchestration
The setup entrypoint reads workflow inputs, establishes the working directory and environment, resolves a uv version, obtains the binary, adds it to PATH, emits outputs, and optionally activates a virtual environment. It also coordinates cache restoration and post-job cache saving.
Paths: `src/setup-uv.ts`, `action.yml`, `src/utils/inputs.ts`.

#### Version Discovery and Resolution
Version selection accepts explicit versions or derives them from project files, including `uv.toml`, `pyproject.toml`, `.tool-versions`, requirements files, and `uv.lock`. Parsers produce version requests; resolution applies highest/lowest strategy and handles “latest” against release metadata.
Paths: `src/version/version-request-resolver.ts`, `src/version/resolve.ts`, `src/version/file-parser.ts`.

#### Manifest, Platform Selection, and Download
The downloader fetches a release manifest (defaulting to Astral’s versions source, with custom-manifest support), chooses the platform/architecture artifact, and downloads uv from GitHub Releases or the Astral mirror. HTTP behavior and runner-platform mapping are isolated utilities.
Paths: `src/download/manifest.ts`, `src/download/variant-selection.ts`, `src/download/download-version.ts`.

#### Supply-Chain Verification
Downloaded executables may be checked against user-provided checksums or the repository’s known-version checksum data. A separate action entrypoint updates the committed checksum catalog, allowing release metadata to be maintained independently from normal setup runs.
Paths: `src/download/checksum/checksum.ts`, `src/download/checksum/known-version.ts`, `src/download/checksum/known-checksums.json`.

#### Cache Lifecycle
Two cache layers exist: the Actions tool cache for installed uv binaries, and optional GitHub Actions cache persistence for uv’s dependency/Python data. Cache keys derive from configured dependency globs and file hashes; restore occurs during setup and save executes as the action’s post phase.
Paths: `src/cache/restore-cache.ts`, `src/save-cache.ts`, `src/hash/hash-files.ts`.

#### Runtime and External Boundaries
The runtime is Node.js/TypeScript, bundled into CommonJS files for GitHub Actions. It relies on the GitHub Actions Toolkit for runner facilities, cache APIs, PATH/environment mutation, outputs, and logging. External boundaries are GitHub Releases, the `astral-sh/versions` manifest format/source, optional Astral download mirror, and the installed `uv` executable invoked for environment activation.
Paths: `package.json`, `dist/setup/index.cjs`, `src/utils/fetch.ts.

Main entry points: [`src/setup-uv.ts`](https://github.com/astral-sh/setup-uv/blob/main/src/setup-uv.ts) (Setup orchestration), [`action.yml`](https://github.com/astral-sh/setup-uv/blob/main/action.yml) (Action contract), [`src/version/resolve.ts`](https://github.com/astral-sh/setup-uv/blob/main/src/version/resolve.ts) (Version resolution), [`src/download/download-version.ts`](https://github.com/astral-sh/setup-uv/blob/main/src/download/download-version.ts) (Binary download)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_action["GitHub Action"]
  node_contract["Action contract<br/>action metadata<br/>[action.yml]"]
  node_setup["Setup orchestration<br/>TypeScript entrypoint<br/>[setup-uv.ts]"]
  node_inputs["Workflow inputs<br/>input parser<br/>[inputs.ts]"]
  node_setup_bundle["Setup bundle<br/>CommonJS runtime<br/>[index.cjs]"]
end

subgraph group_resolution["Version Resolution"]
  node_version_requests["Version requests<br/>request resolver"]
  node_project_parsers["Project file parsers<br/>version parsers<br/>[file-parser.ts]"]
  node_version_resolution["Version resolution<br/>resolver<br/>[resolve.ts]"]
end

subgraph group_acquisition["Acquisition &amp; Verification"]
  node_manifest["Release manifest<br/>manifest client<br/>[manifest.ts]"]
  node_variant_selection["Artifact selection<br/>platform selector"]
  node_download["Binary download<br/>downloader"]
  node_checksum_verification["Checksum verification<br/>verifier<br/>[checksum.ts]"]
  node_known_checksums["Known checksum catalog<br/>checksum data"]
  node_checksum_update["Checksum updater<br/>maintenance entrypoint<br/>[known-version.ts]"]
end

subgraph group_caching["Cache Lifecycle"]
  node_cache_restore["Dependency cache restore<br/>[restore-cache.ts]"]
  node_cache_save["Post-job cache save<br/>post entrypoint<br/>[save-cache.ts]"]
  node_cache_key_hashing["Dependency hashing<br/>file hasher<br/>[hash-files.ts]"]
end

subgraph group_boundaries["External Boundaries"]
  node_github_runner{{"GitHub Actions Toolkit<br/>runner APIs"}}
  node_release_sources{{"Release sources<br/>external services"}}
  node_uv_cli{{"Installed uv CLI<br/>executable"}}
  node_node_runtime["Node.js bundle runtime<br/>package runtime<br/>[package.json]"]
end

node_contract -->|"runs setup"| node_setup_bundle
node_contract -->|"runs post phase"| node_cache_save
node_contract -->|"runs maintenance"| node_checksum_update
node_setup_bundle -->|"bundles"| node_setup
node_node_runtime -->|"builds runtime"| node_setup_bundle
node_setup -->|"reads"| node_inputs
node_setup -->|"requests version"| node_version_requests
node_project_parsers -->|"supplies discovered versions"| node_version_requests
node_version_requests -->|"selects request"| node_version_resolution
node_version_resolution -->|"resolves latest"| node_manifest
node_version_resolution -->|"selects release"| node_variant_selection
node_manifest -->|"fetches metadata"| node_release_sources
node_variant_selection -->|"chooses artifact"| node_download
node_download -->|"fetches binary"| node_release_sources
node_download -->|"provides executable"| node_checksum_verification
node_known_checksums -->|"provides trusted hashes"| node_checksum_verification
node_checksum_update -->|"updates"| node_known_checksums
node_setup -->|"restores optional cache"| node_cache_restore
node_cache_key_hashing -->|"derives key"| node_cache_restore
node_cache_key_hashing -->|"derives key"| node_cache_save
node_setup -->|"uses runner facilities"| node_github_runner
node_cache_restore -->|"uses cache API"| node_github_runner
node_cache_save -->|"uses cache API"| node_github_runner
node_checksum_verification -->|"installs verified binary"| node_uv_cli
node_setup -->|"exposes and activates"| node_uv_cli

click node_contract "https://github.com/astral-sh/setup-uv/blob/main/action.yml"
click node_setup "https://github.com/astral-sh/setup-uv/blob/main/src/setup-uv.ts"
click node_inputs "https://github.com/astral-sh/setup-uv/blob/main/src/utils/inputs.ts"
click node_setup_bundle "https://github.com/astral-sh/setup-uv/blob/main/dist/setup/index.cjs"
click node_version_requests "https://github.com/astral-sh/setup-uv/blob/main/src/version/version-request-resolver.ts"
click node_project_parsers "https://github.com/astral-sh/setup-uv/blob/main/src/version/file-parser.ts"
click node_version_resolution "https://github.com/astral-sh/setup-uv/blob/main/src/version/resolve.ts"
click node_manifest "https://github.com/astral-sh/setup-uv/blob/main/src/download/manifest.ts"
click node_variant_selection "https://github.com/astral-sh/setup-uv/blob/main/src/download/variant-selection.ts"
click node_download "https://github.com/astral-sh/setup-uv/blob/main/src/download/download-version.ts"
click node_checksum_verification "https://github.com/astral-sh/setup-uv/blob/main/src/download/checksum/checksum.ts"
click node_known_checksums "https://github.com/astral-sh/setup-uv/blob/main/src/download/checksum/known-checksums.json"
click node_checksum_update "https://github.com/astral-sh/setup-uv/blob/main/src/download/checksum/known-version.ts"
click node_cache_restore "https://github.com/astral-sh/setup-uv/blob/main/src/cache/restore-cache.ts"
click node_cache_save "https://github.com/astral-sh/setup-uv/blob/main/src/save-cache.ts"
click node_cache_key_hashing "https://github.com/astral-sh/setup-uv/blob/main/src/hash/hash-files.ts"
click node_node_runtime "https://github.com/astral-sh/setup-uv/blob/main/package.json"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_contract,node_setup,node_inputs,node_setup_bundle toneBlue
class node_version_requests,node_project_parsers,node_version_resolution toneAmber
class node_manifest,node_variant_selection,node_download,node_checksum_verification,node_known_checksums,node_checksum_update toneMint
class node_cache_restore,node_cache_save,node_cache_key_hashing toneRose
class node_github_runner,node_release_sources,node_uv_cli,node_node_runtime toneIndigo
```

## Components

### GitHub Action

- [Action contract](https://github.com/astral-sh/setup-uv/blob/main/action.yml): action metadata · Declares setup, post-cache, and checksum-update entrypoints. · `action.yml`
- [Setup orchestration](https://github.com/astral-sh/setup-uv/blob/main/src/setup-uv.ts): TypeScript entrypoint · Coordinates inputs, resolution, install, outputs, activation, and cache restore. · `src/setup-uv.ts`
- [Workflow inputs](https://github.com/astral-sh/setup-uv/blob/main/src/utils/inputs.ts): input parser · `src/utils/inputs.ts`
- [Setup bundle](https://github.com/astral-sh/setup-uv/blob/main/dist/setup/index.cjs): CommonJS runtime · `dist/setup/index.cjs`

### Version Resolution

- [Version requests](https://github.com/astral-sh/setup-uv/blob/main/src/version/version-request-resolver.ts): request resolver · Derives requests from explicit input and project files. · `src/version/version-request-resolver.ts`
- [Project file parsers](https://github.com/astral-sh/setup-uv/blob/main/src/version/file-parser.ts): version parsers · Reads uv.toml, pyproject.toml, .tool-versions, requirements, and uv.lock. · `src/version/file-parser.ts`
- [Version resolution](https://github.com/astral-sh/setup-uv/blob/main/src/version/resolve.ts): resolver · Applies selection strategy and resolves latest from release metadata. · `src/version/resolve.ts`

### Acquisition & Verification

- [Release manifest](https://github.com/astral-sh/setup-uv/blob/main/src/download/manifest.ts): manifest client · Uses the default versions source or a custom manifest. · `src/download/manifest.ts`
- [Artifact selection](https://github.com/astral-sh/setup-uv/blob/main/src/download/variant-selection.ts): platform selector · Maps runner platform and architecture to a release artifact. · `src/download/variant-selection.ts`
- [Binary download](https://github.com/astral-sh/setup-uv/blob/main/src/download/download-version.ts): downloader · Downloads the selected uv release from GitHub or an Astral mirror. · `src/download/download-version.ts`
- [Checksum verification](https://github.com/astral-sh/setup-uv/blob/main/src/download/checksum/checksum.ts): verifier · Validates downloads against supplied or known checksums. · `src/download/checksum/checksum.ts`
- [Known checksum catalog](https://github.com/astral-sh/setup-uv/blob/main/src/download/checksum/known-checksums.json): checksum data · `src/download/checksum/known-checksums.json`
- [Checksum updater](https://github.com/astral-sh/setup-uv/blob/main/src/download/checksum/known-version.ts): maintenance entrypoint · Updates the committed known-version checksum catalog. · `src/download/checksum/known-version.ts`

### Cache Lifecycle

- [Dependency cache restore](https://github.com/astral-sh/setup-uv/blob/main/src/cache/restore-cache.ts): cache restore · Restores uv dependency and Python data during setup. · `src/cache/restore-cache.ts`
- [Post-job cache save](https://github.com/astral-sh/setup-uv/blob/main/src/save-cache.ts): post entrypoint · Persists uv dependency and Python data after the job. · `src/save-cache.ts`
- [Dependency hashing](https://github.com/astral-sh/setup-uv/blob/main/src/hash/hash-files.ts): file hasher · Builds cache keys from configured dependency globs. · `src/hash/hash-files.ts`

### External Boundaries

- **GitHub Actions Toolkit**: runner APIs · Provides tool cache, cache APIs, PATH/environment, outputs, and logging.
- **Release sources**: external services · Astral versions manifest, GitHub Releases, and optional Astral mirror.
- **Installed uv CLI**: executable · Installed on the runner and invoked for optional environment activation.
- [Node.js bundle runtime](https://github.com/astral-sh/setup-uv/blob/main/package.json): package runtime · TypeScript is bundled as CommonJS for GitHub Actions. · `package.json`

## Connections

- Action contract → Setup bundle: runs setup
- Action contract → Post-job cache save: runs post phase
- Action contract → Checksum updater: runs maintenance
- Setup bundle → Setup orchestration: bundles
- Node.js bundle runtime → Setup bundle: builds runtime
- Setup orchestration → Workflow inputs: reads
- Setup orchestration → Version requests: requests version
- Project file parsers → Version requests: supplies discovered versions
- Version requests → Version resolution: selects request
- Version resolution → Release manifest: resolves latest
- Version resolution → Artifact selection: selects release
- Release manifest → Release sources: fetches metadata
- Artifact selection → Binary download: chooses artifact
- Binary download → Release sources: fetches binary
- Binary download → Checksum verification: provides executable
- Known checksum catalog → Checksum verification: provides trusted hashes
- Checksum updater → Known checksum catalog: updates
- Setup orchestration → Dependency cache restore: restores optional cache
- Dependency hashing → Dependency cache restore: derives key
- Dependency hashing → Post-job cache save: derives key
- Setup orchestration → GitHub Actions Toolkit: uses runner facilities
- Dependency cache restore → GitHub Actions Toolkit: uses cache API
- Post-job cache save → GitHub Actions Toolkit: uses cache API
- Checksum verification → Installed uv CLI: installs verified binary
- Setup orchestration → Installed uv CLI: exposes and activates
