How astral-sh/setup-uv works
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: setup-uv.ts Setup orchestration · action.yml Action contract · resolve.ts Version resolution · download-version.ts Binary download
Components 20
GitHub Action
- Action contract · Declares setup, post-cache, and checksum-update entrypoints.
action.yml - Setup orchestration · Coordinates inputs, resolution, install, outputs, activation, and cache restore.
src/setup-uv.ts - Workflow inputs
src/utils/inputs.ts - Setup bundle
dist/setup/index.cjs
Version Resolution
- Version requests · Derives requests from explicit input and project files.
src/version/version-request-resolver.ts - Project file parsers · Reads uv.toml, pyproject.toml, .tool-versions, requirements, and uv.lock.
src/version/file-parser.ts - Version resolution · Applies selection strategy and resolves latest from release metadata.
src/version/resolve.ts
Acquisition & Verification
- Release manifest · Uses the default versions source or a custom manifest.
src/download/manifest.ts - Artifact selection · Maps runner platform and architecture to a release artifact.
src/download/variant-selection.ts - Binary download · Downloads the selected uv release from GitHub or an Astral mirror.
src/download/download-version.ts - Checksum verification · Validates downloads against supplied or known checksums.
src/download/checksum/checksum.ts - Known checksum catalog
src/download/checksum/known-checksums.json - Checksum updater · Updates the committed known-version checksum catalog.
src/download/checksum/known-version.ts
Cache Lifecycle
- Dependency cache restore · Restores uv dependency and Python data during setup.
src/cache/restore-cache.ts - Post-job cache save · Persists uv dependency and Python data after the job.
src/save-cache.ts - Dependency hashing · Builds cache keys from configured dependency globs.
src/hash/hash-files.ts
External Boundaries
- GitHub Actions Toolkit · Provides tool cache, cache APIs, PATH/environment, outputs, and logging.
- Release sources · Astral versions manifest, GitHub Releases, and optional Astral mirror.
- Installed uv CLI · Installed on the runner and invoked for optional environment activation.
- Node.js bundle runtime · TypeScript is bundled as CommonJS for GitHub Actions.
package.json
Connections 25
- 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