5
0
mirror of https://github.com/astral-sh/setup-uv.git synced 2025-12-19 11:04:08 +00:00

Compare commits

..

2 Commits

Author SHA1 Message Date
Kevin Stillhammer
cd4ccfa557 Add FAQ on changed cache and cache upload behavior 2025-07-05 11:51:29 +02:00
Kevin Stillhammer
8021b967f0 Do not warn when version not in manifest-file
This will spam the GitHub summary with warnings as soon as a new version is released and no new setup-uv version containing this version in the distributed manifest-file is released
2025-06-25 09:21:00 +02:00
54 changed files with 17829 additions and 38062 deletions

View File

@@ -7,7 +7,3 @@ self-hosted-runner:
# organization. `null` means disabling configuration variables check. # organization. `null` means disabling configuration variables check.
# Empty array means no configuration variable is allowed. # Empty array means no configuration variable is allowed.
config-variables: null config-variables: null
paths:
.github/workflows/test.yml:
ignore:
- 'invalid runner name.+'

View File

@@ -1,225 +0,0 @@
# Copilot Instructions for setup-uv
This document provides essential information for GitHub Copilot coding agents working on the `astral-sh/setup-uv` repository.
## Repository Overview
**setup-uv** is a GitHub Action that sets up the [uv](https://docs.astral.sh/uv/) Python package installer in GitHub Actions workflows. It's a TypeScript-based action that downloads uv binaries, manages caching, handles version resolution, and configures the environment for subsequent workflow steps.
### Key Features
- Downloads and installs specific uv versions from GitHub releases
- Supports version resolution from config files (pyproject.toml, uv.toml, .tool-versions)
- Implements intelligent caching for both uv cache and Python installations
- Provides cross-platform support (Linux, macOS, Windows, including ARM architectures)
- Includes problem matchers for Python error reporting
- Supports environment activation and custom tool directories
## Repository Structure
**Size**: Small-medium repository (~50 source files, ~400 total files including dependencies)
**Languages**: TypeScript (primary), JavaScript (compiled output), JSON (configuration)
**Runtime**: Node.js 24 (GitHub Actions runtime)
**Key Dependencies**: @actions/core, @actions/cache, @actions/tool-cache, @octokit/core
### Core Architecture
```
src/
├── setup-uv.ts # Main entry point and orchestration
├── save-cache.ts # Post-action cache saving logic
├── update-known-versions.ts # Maintenance script for version updates
├── cache/ # Cache management functionality
├── download/ # Version resolution and binary downloading
├── utils/ # Input parsing, platform detection, configuration
└── version/ # Version resolution from various file formats
```
### Key Files and Locations
- **Action Definition**: `action.yml` - Defines all inputs/outputs and entry points
- **Main Source**: `src/setup-uv.ts` - Primary action logic
- **Configuration**: `biome.json` (linting), `tsconfig.json` (TypeScript), `jest.config.js` (testing)
- **Compiled Output**: `dist/` - Contains compiled Node.js bundles (auto-generated, committed)
- **Test Fixtures**: `__tests__/fixtures/` - Sample projects for different configuration scenarios
- **Workflows**: `.github/workflows/test.yml` - Comprehensive CI/CD pipeline
## Build and Development Process
### Prerequisites
- Node.js 24+ (matches GitHub Actions runtime)
- npm (included with Node.js)
### Essential Commands (ALWAYS run in this order)
#### 1. Install Dependencies
```bash
npm install
```
**Timing**: ~20-30 seconds
**Note**: Always run this first after cloning or when package.json changes
#### 2. Build TypeScript
```bash
npm run build
```
**Timing**: ~5-10 seconds
**Purpose**: Compiles TypeScript source to JavaScript in `lib/` directory
#### 3. Lint and Format Code
```bash
npm run check
```
**Timing**: ~2-5 seconds
**Tool**: Biome (replaces ESLint/Prettier)
**Auto-fixes**: Formatting, import organization, basic linting issues
#### 4. Package for Distribution
```bash
npm run package
```
**Timing**: ~20-30 seconds
**Purpose**: Creates bundled distributions in `dist/` using @vercel/ncc
**Critical**: This step MUST be run before committing - the `dist/` files are used by GitHub Actions
#### 5. Run Tests
```bash
npm test
```
**Timing**: ~10-15 seconds
**Framework**: Jest with TypeScript support
**Coverage**: Unit tests for version resolution, input parsing, checksum validation
#### 6. Complete Validation (Recommended)
```bash
npm run all
```
**Timing**: ~60-90 seconds
**Purpose**: Runs build → check → package → test in sequence
**Use**: Before making pull requests or when unsure about build state
### Important Build Notes
**CRITICAL**: Always run `npm run package` after making code changes. The `dist/` directory contains the compiled bundles that GitHub Actions actually executes. Forgetting this step will cause your changes to have no effect.
**TypeScript Warnings**: You may see ts-jest warnings about "isolatedModules" - these are harmless and don't affect functionality.
**Biome**: This project uses Biome instead of ESLint/Prettier. Run `npm run check` to fix formatting and linting issues automatically.
## Testing Strategy
### Unit Tests
- **Location**: `__tests__/` directory
- **Framework**: Jest with ts-jest transformer
- **Coverage**: Version resolution, input parsing, checksum validation, utility functions
### Integration Tests
- **Location**: `.github/workflows/test.yml`
- **Scope**: Full end-to-end testing across multiple platforms and scenarios
- **Key Test Categories**:
- Version installation (specific, latest, semver ranges)
- Cache behavior (setup, restore, invalidation)
- Cross-platform compatibility (Ubuntu, macOS, Windows, ARM)
- Configuration file parsing (pyproject.toml, uv.toml, requirements.txt)
- Error handling and edge cases
### Test Fixtures
Located in `__tests__/fixtures/`, these provide sample projects with different configurations:
- `pyproject-toml-project/` - Standard Python project with uv version specification
- `uv-toml-project/` - Project using uv.toml configuration
- `requirements-txt-project/` - Legacy requirements.txt format
- `cache-dir-defined-project/` - Custom cache directory configuration
## Continuous Integration
### GitHub Workflows
#### Primary Test Suite (`.github/workflows/test.yml`)
- **Triggers**: PRs, pushes to main, manual dispatch
- **Matrix**: Multiple OS (Ubuntu, macOS, Windows), architecture (x64, ARM), and configuration combinations
- **Duration**: ~20-30 minutes for full matrix
- **Key Validations**:
- Cross-platform installation and functionality
- Cache behavior and performance
- Version resolution from various sources
- Tool directory configurations
- Problem matcher functionality
#### Maintenance Workflows
- **CodeQL Analysis**: Security scanning on pushes/PRs
- **Update Known Versions**: Daily job to sync with latest uv releases
- **Dependabot**: Automated dependency updates
### Pre-commit Validation
The CI runs these checks that you should run locally:
1. `npm run all` - Complete build and test suite
2. ActionLint - GitHub Actions workflow validation
3. Change detection - Ensures no uncommitted build artifacts
## Key Configuration Files
### Action Configuration (`action.yml`)
Defines 20+ inputs including version specifications, cache settings, tool directories, and environment options. This file is the authoritative source for understanding available action parameters.
### TypeScript Configuration (`tsconfig.json`)
- Target: ES2024
- Module: nodenext (Node.js modules)
- Strict mode enabled
- Output directory: `lib/`
### Linting Configuration (`biome.json`)
- Formatter and linter combined
- Enforces consistent code style
- Automatically organizes imports and sorts object keys
## Common Development Patterns
### Making Code Changes
1. Edit TypeScript source files in `src/`
2. Run `npm run build` to compile
3. Run `npm run check` to format and lint
4. Run `npm run package` to update distribution bundles
5. Run `npm test` to verify functionality
6. Commit all changes including `dist/` files
### Adding New Features
- Follow existing patterns in `src/utils/inputs.ts` for new action inputs
- Update `action.yml` to declare new inputs/outputs
- Add corresponding tests in `__tests__/`
- Update README.md with usage examples
### Cache-Related Changes
- Cache logic is complex and affects performance significantly
- Test with multiple cache scenarios (hit, miss, invalidation)
- Consider impact on both GitHub-hosted and self-hosted runners
- Validate cache key generation and dependency detection
### Version Resolution Changes
- Version resolution supports multiple file formats and precedence rules
- Test with fixtures in `__tests__/fixtures/`
- Consider backward compatibility with existing projects
- Validate semver and PEP 440 specification handling
## Troubleshooting
### Build Failures
- **"Module not found"**: Run `npm install` to ensure dependencies are installed
- **TypeScript errors**: Check `tsconfig.json` and ensure all imports are valid
- **Test failures**: Check if test fixtures have been modified or if logic changes broke assumptions
### Action Failures in Workflows
- **Changes not taking effect**: Ensure `npm run package` was run and `dist/` files committed
- **Version resolution issues**: Check version specification format and file existence
- **Cache problems**: Verify cache key generation and dependency glob patterns
### Common Gotchas
- **Forgetting to package**: Code changes won't work without running `npm run package`
- **Platform differences**: Windows paths use backslashes, test cross-platform behavior
- **Cache invalidation**: Cache keys are sensitive to dependency file changes
- **Tool directory permissions**: Some platforms require specific directory setups
## Trust These Instructions
These instructions are comprehensive and current. Only search for additional information if:
- You encounter specific error messages not covered here
- You need to understand implementation details of specific functions
- The instructions appear outdated (check repository commit history)
For most development tasks, following the build process and development patterns outlined above will be sufficient.

8
.github/python.json vendored
View File

@@ -4,13 +4,13 @@
"owner": "python", "owner": "python",
"pattern": [ "pattern": [
{ {
"regexp": "^\\s*File\\s\\\"(.*)\\\",\\sline\\s(\\d+),\\sin\\s(.*)$",
"file": 1, "file": 1,
"line": 2, "line": 2
"regexp": "^\\s*File\\s\\\"(.*)\\\",\\sline\\s(\\d+),\\sin\\s(.*)$"
}, },
{ {
"message": 2, "regexp": "^\\s*raise\\s(.*)\\(\\'(.*)\\'\\)$",
"regexp": "^\\s*raise\\s(.*)\\(\\'(.*)\\'\\)$" "message": 2
} }
] ]
} }

View File

@@ -1,16 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var fs = require("node:fs");
var yaml = require("js-yaml");
var workflow = yaml.load(fs.readFileSync("../workflows/test.yml", "utf8"));
var jobs = Object.keys(workflow.jobs);
var allTestsPassed = workflow.jobs["all-tests-passed"];
var needs = allTestsPassed.needs || [];
var expectedNeeds = jobs.filter(function (j) { return j !== "all-tests-passed"; });
var missing = expectedNeeds.filter(function (j) { return !needs.includes(j); });
if (missing.length > 0) {
console.error("Missing jobs in all-tests-passed needs: ".concat(missing.join(", ")));
console.info("Please add the missing jobs to the needs section of all-tests-passed in test.yml.");
process.exit(1);
}
console.log("All jobs in test.yml are in the needs section of all-tests-passed.");

View File

@@ -21,8 +21,6 @@ on:
branches: branches:
- main - main
permissions: {}
jobs: jobs:
analyze: analyze:
name: Analyze name: Analyze
@@ -41,13 +39,11 @@ jobs:
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 uses: actions/checkout@v4
with:
persist-credentials: false
# Initializes the CodeQL tools for scanning. # Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL - name: Initialize CodeQL
uses: github/codeql-action/init@e296a935590eb16afc0c0108289f68c87e2a89a5 # v4.30.7 uses: github/codeql-action/init@v3
with: with:
languages: ${{ matrix.language }} languages: ${{ matrix.language }}
source-root: src source-root: src
@@ -59,7 +55,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below) # If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild - name: Autobuild
uses: github/codeql-action/autobuild@e296a935590eb16afc0c0108289f68c87e2a89a5 # v4.30.7 uses: github/codeql-action/autobuild@v3
# Command-line programs to run using the OS shell. # Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl # 📚 https://git.io/JvXDl
@@ -73,4 +69,4 @@ jobs:
# make release # make release
- name: Perform CodeQL Analysis - name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@e296a935590eb16afc0c0108289f68c87e2a89a5 # v4.30.7 uses: github/codeql-action/analyze@v3

View File

@@ -8,8 +8,6 @@ on:
branches: branches:
- main - main
permissions: {}
jobs: jobs:
update_release_draft: update_release_draft:
name: ✏️ Draft release name: ✏️ Draft release
@@ -19,6 +17,6 @@ jobs:
pull-requests: read pull-requests: read
steps: steps:
- name: 🚀 Run Release Drafter - name: 🚀 Run Release Drafter
uses: release-drafter/release-drafter@b1476f6e6eb133afa41ed8589daba6dc69b4d3f5 # v6.1.0 uses: release-drafter/release-drafter@v6.1.0
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -18,19 +18,13 @@ permissions:
jobs: jobs:
lint: lint:
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions:
security-events: write # for zizmor
steps: steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - uses: actions/checkout@v4
with:
persist-credentials: false
- name: Actionlint - name: Actionlint
uses: eifinger/actionlint-action@23c85443d840cd73bbecb9cddfc933cc21649a38 # v1.9.1 uses: eifinger/actionlint-action@23c85443d840cd73bbecb9cddfc933cc21649a38 # v1.9.1
- name: Run zizmor - uses: actions/setup-node@v4
uses: zizmorcore/zizmor-action@e673c3917a1aef3c65c972347ed84ccd013ecda4 # v0.2.0
- uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
with: with:
node-version: "24" node-version: "20"
- run: | - run: |
npm install npm install
- run: | - run: |
@@ -50,9 +44,7 @@ jobs:
matrix: matrix:
os: [ubuntu-latest, macos-latest, macos-14, windows-latest] os: [ubuntu-latest, macos-latest, macos-14, windows-latest]
steps: steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install latest version - name: Install latest version
id: setup-uv id: setup-uv
uses: ./ uses: ./
@@ -60,150 +52,78 @@ jobs:
working-directory: __tests__/fixtures/uv-project working-directory: __tests__/fixtures/uv-project
shell: bash shell: bash
- name: Check uv-path is set - name: Check uv-path is set
run: | run: ${{ steps.setup-uv.outputs.uv-path }} --version
"${UV_PATH}" --version
shell: bash
env:
UV_PATH: ${{ steps.setup-uv.outputs.uv-path }}
- name: Check uvx-path is set - name: Check uvx-path is set
run: | run: ${{ steps.setup-uv.outputs.uvx-path }} --version
"${UVX_PATH}" --version
shell: bash
env:
UVX_PATH: ${{ steps.setup-uv.outputs.uvx-path }}
test-uv-no-modify-path:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
- name: Install with UV_NO_MODIFY_PATH set
id: setup-uv
uses: ./
env:
UV_NO_MODIFY_PATH: 1
- run: |
"${UV_PATH}" sync
working-directory: __tests__/fixtures/uv-project
shell: bash
env:
UV_PATH: ${{ steps.setup-uv.outputs.uv-path }}
- name: uv is not on PATH
run: |
if command -v uv; then
echo "uv should not be on PATH"
exit 1
fi
test-specific-version: test-specific-version:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
matrix: matrix:
input: uv-version: ["0.3.0", "0.3.2", "0.3", "0.3.x", ">=0.3.0"]
- version-input: "0.3.0"
expected-version: "0.3.0"
- version-input: "0.3.2"
expected-version: "0.3.2"
- version-input: "0.3"
expected-version: "0.3.5"
- version-input: "0.3.x"
expected-version: "0.3.5"
- version-input: ">=0.4.25,<0.5"
expected-version: "0.4.30"
steps: steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - uses: actions/checkout@v4
- name: Install version ${{ matrix.uv-version }}
uses: ./
with: with:
persist-credentials: false version: ${{ matrix.uv-version }}
- name: Install version ${{ matrix.input.version-input }} - run: uv sync
working-directory: __tests__/fixtures/uv-project
test-semver-range:
strategy:
matrix:
os: [ ubuntu-latest, selfhosted-ubuntu-arm64 ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Install version 0.3
id: setup-uv id: setup-uv
uses: ./ uses: ./
with: with:
version: ${{ matrix.input.version-input }} version: "0.3"
- name: Correct version gets installed - name: Correct version gets installed
run: | run: |
if [ "$(uv --version)" != "uv ${{ matrix.input.expected-version }}" ]; then if [ "$(uv --version)" != "uv 0.3.5" ]; then
echo "Wrong uv version: $(uv --version)" echo "Wrong uv version: $(uv --version)"
exit 1 exit 1
fi fi
- name: Output has correct version - name: Output has correct version
run: | run: |
if [ "$UV_VERSION" != "${{ matrix.input.expected-version }}" ]; then if [ "$UV_VERSION" != "0.3.5" ]; then
exit 1 exit 1
fi fi
env: env:
UV_VERSION: ${{ steps.setup-uv.outputs.uv-version }} UV_VERSION: ${{ steps.setup-uv.outputs.uv-version }}
test-latest-version: test-pep440-version:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy:
matrix:
version-input: ["latest", ">=0.8"]
steps: steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - uses: actions/checkout@v4
with: - name: Install version 0.4.30
persist-credentials: false id: setup-uv
- name: Install version ${{ matrix.version-input }}
uses: ./ uses: ./
with: with:
version: ${{ matrix.version-input }} version: ">=0.4.25,<0.5"
- name: Latest version gets installed
run: |
LATEST_VERSION=$(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/astral-sh/uv/releases/latest | jq -r '.tag_name')
echo "Latest version is $LATEST_VERSION"
if [ "$(uv --version)" != "uv $LATEST_VERSION" ]; then
echo "Wrong uv version: $(uv --version)"
exit 1
fi
env:
GH_TOKEN: ${{ github.token }}
test-from-working-directory-version:
runs-on: ubuntu-latest
strategy:
matrix:
input:
- working-directory: "__tests__/fixtures/pyproject-toml-project"
expected-version: "0.5.14"
- working-directory: "__tests__/fixtures/uv-toml-project"
expected-version: "0.5.15"
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
- name: Install version from ${{ matrix.input.working-directory }}
uses: ./
with:
working-directory: ${{ matrix.input.working-directory }}
- name: Correct version gets installed - name: Correct version gets installed
run: | run: |
if [ "$(uv --version)" != "uv ${{ matrix.input.expected-version }}" ]; then if [ "$(uv --version)" != "uv 0.4.30" ]; then
echo "Wrong uv version: $(uv --version)" echo "Wrong uv version: $(uv --version)"
exit 1 exit 1
fi fi
test-version-file-version: test-pyproject-file-version:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy:
matrix:
input:
- version-file: "__tests__/fixtures/uv-in-requirements-txt-project/requirements.txt"
expected-version: "0.6.17"
- version-file: "__tests__/fixtures/uv-in-requirements-hash-txt-project/requirements.txt"
expected-version: "0.8.3"
- version-file: "__tests__/fixtures/.tool-versions"
expected-version: "0.5.15"
steps: steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - uses: actions/checkout@v4
with: - name: Install version 0.5.14
persist-credentials: false id: setup-uv
- name: Install version from ${{ matrix.input.version-file }}
uses: ./ uses: ./
with: with:
version-file: ${{ matrix.input.version-file }} working-directory: "__tests__/fixtures/pyproject-toml-project"
- name: Correct version gets installed - name: Correct version gets installed
run: | run: |
if [ "$(uv --version)" != "uv ${{ matrix.input.expected-version }}" ]; then if [ "$(uv --version)" != "uv 0.5.14" ]; then
echo "Wrong uv version: $(uv --version)" echo "Wrong uv version: $(uv --version)"
exit 1 exit 1
fi fi
@@ -211,9 +131,7 @@ jobs:
test-malformed-pyproject-file-fallback: test-malformed-pyproject-file-fallback:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install using malformed pyproject.toml - name: Install using malformed pyproject.toml
id: setup-uv id: setup-uv
uses: ./ uses: ./
@@ -221,6 +139,22 @@ jobs:
working-directory: "__tests__/fixtures/malformed-pyproject-toml-project" working-directory: "__tests__/fixtures/malformed-pyproject-toml-project"
- run: uv --help - run: uv --help
test-uv-file-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install version 0.5.15
id: setup-uv
uses: ./
with:
working-directory: "__tests__/fixtures/uv-toml-project"
- name: Correct version gets installed
run: |
if [ "$(uv --version)" != "uv 0.5.15" ]; then
echo "Wrong uv version: $(uv --version)"
exit 1
fi
test-checksum: test-checksum:
runs-on: ${{ matrix.inputs.os }} runs-on: ${{ matrix.inputs.os }}
strategy: strategy:
@@ -231,9 +165,7 @@ jobs:
- os: macos-latest - os: macos-latest
checksum: "a70cbfbf3bb5c08b2f84963b4f12c94e08fbb2468ba418a3bfe1066fbe9e7218" checksum: "a70cbfbf3bb5c08b2f84963b4f12c94e08fbb2468ba418a3bfe1066fbe9e7218"
steps: steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - uses: actions/checkout@v4
with:
persist-credentials: false
- name: Checksum matches expected - name: Checksum matches expected
uses: ./ uses: ./
with: with:
@@ -245,9 +177,7 @@ jobs:
test-with-explicit-token: test-with-explicit-token:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install default version - name: Install default version
uses: ./ uses: ./
with: with:
@@ -258,9 +188,7 @@ jobs:
test-uvx: test-uvx:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install default version - name: Install default version
uses: ./ uses: ./
- run: uvx ruff --version - run: uvx ruff --version
@@ -269,11 +197,15 @@ jobs:
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
strategy: strategy:
matrix: matrix:
os: [ubuntu-latest, macos-latest, macos-14, windows-latest] os:
[
ubuntu-latest,
macos-latest,
macos-14,
windows-latest,
]
steps: steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install default version - name: Install default version
uses: ./ uses: ./
- run: uv tool install ruff - run: uv tool install ruff
@@ -282,9 +214,7 @@ jobs:
test-tilde-expansion-tool-dirs: test-tilde-expansion-tool-dirs:
runs-on: selfhosted-ubuntu-arm64 runs-on: selfhosted-ubuntu-arm64
steps: steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - uses: actions/checkout@v4
with:
persist-credentials: false
- name: Setup with cache - name: Setup with cache
uses: ./ uses: ./
with: with:
@@ -307,9 +237,7 @@ jobs:
matrix: matrix:
os: [ubuntu-latest, macos-latest, windows-latest] os: [ubuntu-latest, macos-latest, windows-latest]
steps: steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install latest version - name: Install latest version
uses: ./ uses: ./
with: with:
@@ -328,13 +256,10 @@ jobs:
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
strategy: strategy:
matrix: matrix:
os: [ubuntu-latest, macos-latest, windows-latest] os: [ ubuntu-latest, macos-latest, windows-latest ]
steps: steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install latest version - name: Install latest version
id: setup-uv
uses: ./ uses: ./
with: with:
python-version: 3.13.1t python-version: 3.13.1t
@@ -349,27 +274,12 @@ jobs:
exit 1 exit 1
fi fi
shell: bash shell: bash
- name: Verify output venv is set
run: |
if [ -z "$UV_VENV" ]; then
echo "output venv is not set"
exit 1
fi
if [ ! -d "$UV_VENV" ]; then
echo "output venv not point to a directory: $UV_VENV"
exit 1
fi
shell: bash
env:
UV_VENV: ${{ steps.setup-uv.outputs.venv }}
test-musl: test-musl:
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: alpine container: alpine
steps: steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install latest version - name: Install latest version
uses: ./ uses: ./
- run: uv sync - run: uv sync
@@ -379,12 +289,10 @@ jobs:
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
strategy: strategy:
matrix: matrix:
enable-cache: ["true", "false", "auto"] enable-cache: [ "true", "false", "auto" ]
os: ["ubuntu-latest", "selfhosted-ubuntu-arm64", "windows-latest"] os: [ "ubuntu-latest", "selfhosted-ubuntu-arm64", "windows-latest" ]
steps: steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - uses: actions/checkout@v4
with:
persist-credentials: false
- name: Setup with cache - name: Setup with cache
uses: ./ uses: ./
with: with:
@@ -397,13 +305,11 @@ jobs:
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
strategy: strategy:
matrix: matrix:
enable-cache: ["true", "false", "auto"] enable-cache: [ "true", "false", "auto" ]
os: ["ubuntu-latest", "selfhosted-ubuntu-arm64", "windows-latest"] os: [ "ubuntu-latest", "selfhosted-ubuntu-arm64", "windows-latest" ]
needs: test-setup-cache needs: test-setup-cache
steps: steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - uses: actions/checkout@v4
with:
persist-credentials: false
- name: Restore with cache - name: Restore with cache
id: restore id: restore
uses: ./ uses: ./
@@ -435,9 +341,7 @@ jobs:
test-setup-cache-requirements-txt: test-setup-cache-requirements-txt:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - uses: actions/checkout@v4
with:
persist-credentials: false
- name: Setup with cache - name: Setup with cache
uses: ./ uses: ./
with: with:
@@ -449,11 +353,9 @@ jobs:
working-directory: __tests__/fixtures/requirements-txt-project working-directory: __tests__/fixtures/requirements-txt-project
test-restore-cache-requirements-txt: test-restore-cache-requirements-txt:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: test-setup-cache-requirements-txt needs: test-setup-cache
steps: steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - uses: actions/checkout@v4
with:
persist-credentials: false
- name: Restore with cache - name: Restore with cache
id: restore id: restore
uses: ./ uses: ./
@@ -475,9 +377,7 @@ jobs:
test-setup-cache-dependency-glob: test-setup-cache-dependency-glob:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - uses: actions/checkout@v4
with:
persist-credentials: false
- name: Setup with cache - name: Setup with cache
uses: ./ uses: ./
with: with:
@@ -492,9 +392,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: test-setup-cache-dependency-glob needs: test-setup-cache-dependency-glob
steps: steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - uses: actions/checkout@v4
with:
persist-credentials: false
- name: Change pyproject.toml - name: Change pyproject.toml
run: | run: |
echo '[tool.uv]' >> __tests__/fixtures/uv-project/pyproject.toml echo '[tool.uv]' >> __tests__/fixtures/uv-project/pyproject.toml
@@ -517,78 +415,6 @@ jobs:
env: env:
CACHE_HIT: ${{ steps.restore.outputs.cache-hit }} CACHE_HIT: ${{ steps.restore.outputs.cache-hit }}
test-setup-cache-save-cache-false:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
- name: Setup with cache
uses: ./
with:
enable-cache: true
save-cache: false
cache-suffix: ${{ github.run_id }}-${{ github.run_attempt }}-test-setup-cache-save-cache-false
- run: uv sync
working-directory: __tests__/fixtures/uv-project
shell: bash
test-restore-cache-save-cache-false:
runs-on: ubuntu-latest
needs: test-setup-cache-save-cache-false
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
- name: Restore with cache
id: restore
uses: ./
with:
enable-cache: true
cache-suffix: ${{ github.run_id }}-${{ github.run_attempt }}-test-setup-cache-save-cache-false
- name: Cache was not hit
run: |
if [ "$CACHE_HIT" == "true" ]; then
exit 1
fi
env:
CACHE_HIT: ${{ steps.restore.outputs.cache-hit }}
test-setup-cache-restore-cache-false:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
- name: Setup with cache
uses: ./
with:
enable-cache: true
cache-suffix: ${{ github.run_id }}-${{ github.run_attempt }}-test-setup-cache-restore-cache-false
- run: uv sync
working-directory: __tests__/fixtures/uv-project
shell: bash
test-restore-cache-restore-cache-false:
runs-on: ubuntu-latest
needs: test-setup-cache-restore-cache-false
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
- name: Restore with cache
id: restore
uses: ./
with:
enable-cache: true
restore-cache: false
cache-suffix: ${{ github.run_id }}-${{ github.run_attempt }}-test-setup-cache-restore-cache-false
- name: Cache was not hit
run: |
if [ "$CACHE_HIT" == "true" ]; then
exit 1
fi
env:
CACHE_HIT: ${{ steps.restore.outputs.cache-hit }}
test-cache-local: test-cache-local:
strategy: strategy:
matrix: matrix:
@@ -601,13 +427,10 @@ jobs:
expected-cache-dir: "/home/ubuntu/.cache/uv" expected-cache-dir: "/home/ubuntu/.cache/uv"
runs-on: ${{ matrix.inputs.os }} runs-on: ${{ matrix.inputs.os }}
steps: steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - uses: actions/checkout@v4
with:
persist-credentials: false
- name: Setup with cache - name: Setup with cache
uses: ./ uses: ./
with: with:
enable-cache: true
cache-suffix: ${{ github.run_id }}-${{ github.run_attempt }}-test-cache-local cache-suffix: ${{ github.run_id }}-${{ github.run_attempt }}-test-cache-local
- run: | - run: |
if [ "$UV_CACHE_DIR" != "${{ matrix.inputs.expected-cache-dir }}" ]; then if [ "$UV_CACHE_DIR" != "${{ matrix.inputs.expected-cache-dir }}" ]; then
@@ -616,31 +439,10 @@ jobs:
fi fi
shell: bash shell: bash
test-cache-local-cache-disabled:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
- name: Setup without cache
uses: ./
with:
enable-cache: false
- name: Check UV_CACHE_DIR is not set
run: |
if [ -n "$UV_CACHE_DIR" ]; then
echo "UV_CACHE_DIR should not be set when cache is disabled: $UV_CACHE_DIR"
exit 1
fi
shell: bash
test-setup-cache-local: test-setup-cache-local:
runs-on: selfhosted-ubuntu-arm64 runs-on: selfhosted-ubuntu-arm64
steps: steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - uses: actions/checkout@v4
with:
persist-credentials: false
- name: Setup with cache - name: Setup with cache
uses: ./ uses: ./
with: with:
@@ -653,9 +455,7 @@ jobs:
runs-on: selfhosted-ubuntu-arm64 runs-on: selfhosted-ubuntu-arm64
needs: test-setup-cache-local needs: test-setup-cache-local
steps: steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - uses: actions/checkout@v4
with:
persist-credentials: false
- name: Restore with cache - name: Restore with cache
id: restore id: restore
uses: ./ uses: ./
@@ -676,9 +476,7 @@ jobs:
test-tilde-expansion-cache-local-path: test-tilde-expansion-cache-local-path:
runs-on: selfhosted-ubuntu-arm64 runs-on: selfhosted-ubuntu-arm64
steps: steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - uses: actions/checkout@v4
with:
persist-credentials: false
- name: Create cache directory - name: Create cache directory
run: mkdir -p ~/uv-cache run: mkdir -p ~/uv-cache
shell: bash shell: bash
@@ -692,9 +490,7 @@ jobs:
test-tilde-expansion-cache-dependency-glob: test-tilde-expansion-cache-dependency-glob:
runs-on: selfhosted-ubuntu-arm64 runs-on: selfhosted-ubuntu-arm64
steps: steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - uses: actions/checkout@v4
with:
persist-credentials: false
- name: Create cache directory - name: Create cache directory
run: mkdir -p ~/uv-cache run: mkdir -p ~/uv-cache
shell: bash shell: bash
@@ -727,9 +523,7 @@ jobs:
test-no-python-version: test-no-python-version:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - uses: actions/checkout@v4
with:
persist-credentials: false
- name: Fake pyproject.toml at root - name: Fake pyproject.toml at root
run: cp __tests__/fixtures/old-python-constraint-project/pyproject.toml pyproject.toml run: cp __tests__/fixtures/old-python-constraint-project/pyproject.toml pyproject.toml
- name: Setup with cache - name: Setup with cache
@@ -742,9 +536,7 @@ jobs:
test-custom-manifest-file: test-custom-manifest-file:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install from custom manifest file - name: Install from custom manifest file
uses: ./ uses: ./
with: with:
@@ -758,193 +550,17 @@ jobs:
exit 1 exit 1
fi fi
test-absolute-path:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
- name: Create requirements.txt
run: echo "uv==0.6.17" > /tmp/setup-uv-requirements.txt
- name: Install from requirements file
id: setup-uv
uses: ./
with:
version-file: "/tmp/setup-uv-requirements.txt"
- name: Correct version gets installed
run: |
if [ "$(uv --version)" != "uv 0.6.17" ]; then
echo "Wrong uv version: $(uv --version)"
exit 1
fi
test-relative-path:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
- name: mkdir
run: mkdir -p /tmp/setup-uv-test-relative-path
- name: Create requirements.txt
run: echo "uv==0.6.17" > /tmp/setup-uv-test-relative-path/setup-uv-requirements.txt
- name: Install from requirements file
id: setup-uv
uses: ./
with:
version-file: "./setup-uv-requirements.txt"
working-directory: "/tmp/setup-uv-test-relative-path"
cache-dependency-glob: "./setup-uv-requirements.txt"
- name: Correct version gets installed
run: |
if [ "$(uv --version)" != "uv 0.6.17" ]; then
echo "Wrong uv version: $(uv --version)"
exit 1
fi
test-cache-prune-force:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
- name: Setup uv
uses: ./
with:
cache-suffix: ${{ github.run_id }}-${{ github.run_attempt }}-test-cache-prune-force
- name: Create long running python script
run: |
echo 'import time' > __tests__/fixtures/uv-project/long-running.py
echo 'time.sleep(300)' >> __tests__/fixtures/uv-project/long-running.py
- run: uv run long-running.py &
working-directory: __tests__/fixtures/uv-project
test-cache-dir-from-file:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
- name: Verify uv cache dir is not populated
run: |
if [ -f "/tmp/pyproject-toml-defined-cache-path/CACHEDIR.TAG" ]; then
echo "Cache dir should not exist"
exit 1
fi
- name: Setup uv
uses: ./
with:
working-directory: __tests__/fixtures/cache-dir-defined-project
- run: uv sync
working-directory: __tests__/fixtures/cache-dir-defined-project
- name: Verify uv cache dir is populated
run: |
if [ ! -f "/tmp/pyproject-toml-defined-cache-path/CACHEDIR.TAG" ]; then
echo "Cache dir should exist"
exit 1
fi
test-cache-python-installs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
- name: Verify Python install dir is not populated
run: |
if [ -d /home/runner/work/_temp/uv-python-dir ]; then
echo "Python install dir should not exist"
exit 1
fi
- name: Setup uv with cache
uses: ./
with:
enable-cache: true
cache-python: true
cache-suffix: ${{ github.run_id }}-${{ github.run_attempt }}-test-cache-python-installs
- run: uv sync --managed-python
working-directory: __tests__/fixtures/uv-project
- name: Verify Python install dir exists
run: |
if [ ! -d /home/runner/work/_temp/uv-python-dir ]; then
echo "Python install dir should exist"
exit 1
fi
test-restore-python-installs:
runs-on: ubuntu-latest
needs: test-cache-python-installs
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
- name: Verify Python install dir does not exist
run: |
if [ -d /home/runner/work/_temp/uv-python-dir ]; then
echo "Python install dir should not exist"
exit 1
fi
- name: Restore with cache
id: restore
uses: ./
with:
enable-cache: true
cache-python: true
cache-suffix: ${{ github.run_id }}-${{ github.run_attempt }}-test-cache-python-installs
- name: Verify Python install dir exists
run: |
if [ ! -d /home/runner/work/_temp/uv-python-dir ]; then
echo "Python install dir should exist"
exit 1
fi
- name: Cache was hit
run: |
if [ "$CACHE_HIT" != "true" ]; then
exit 1
fi
env:
CACHE_HIT: ${{ steps.restore.outputs.cache-hit }}
- run: uv sync --managed-python
working-directory: __tests__/fixtures/uv-project
test-python-install-dir:
strategy:
matrix:
inputs:
- os: ubuntu-latest
expected-python-dir: "/home/runner/work/_temp/uv-python-dir"
- os: windows-latest
expected-python-dir: "D:\\a\\_temp\\uv-python-dir"
- os: selfhosted-ubuntu-arm64
expected-python-dir: "/home/ubuntu/.local/share/uv/python"
runs-on: ${{ matrix.inputs.os }}
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
- name: Install latest version
id: setup-uv
uses: ./
- name: Check Python dir is expected dir
run: |
if [ "$UV_PYTHON_INSTALL_DIR" != "${{ matrix.inputs.expected-python-dir }}" ]; then
echo "Wrong UV_PYTHON_INSTALL_DIR: UV_PYTHON_INSTALL_DIR"
exit 1
fi
shell: bash
- name: Install python works
run: uv python install
all-tests-passed: all-tests-passed:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: needs:
- lint - lint
- test-default-version - test-default-version
- test-uv-no-modify-path
- test-specific-version - test-specific-version
- test-latest-version - test-semver-range
- test-from-working-directory-version - test-pep440-version
- test-pyproject-file-version
- test-malformed-pyproject-file-fallback - test-malformed-pyproject-file-fallback
- test-version-file-version - test-uv-file-version
- test-checksum - test-checksum
- test-with-explicit-token - test-with-explicit-token
- test-uvx - test-uvx
@@ -954,17 +570,12 @@ jobs:
- test-activate-environment - test-activate-environment
- test-musl - test-musl
- test-cache-local - test-cache-local
- test-cache-local-cache-disabled
- test-setup-cache - test-setup-cache
- test-restore-cache - test-restore-cache
- test-setup-cache-requirements-txt - test-setup-cache-requirements-txt
- test-restore-cache-requirements-txt - test-restore-cache-requirements-txt
- test-setup-cache-dependency-glob - test-setup-cache-dependency-glob
- test-restore-cache-dependency-glob - test-restore-cache-dependency-glob
- test-setup-cache-save-cache-false
- test-restore-cache-save-cache-false
- test-setup-cache-restore-cache-false
- test-restore-cache-restore-cache-false
- test-setup-cache-local - test-setup-cache-local
- test-restore-cache-local - test-restore-cache-local
- test-tilde-expansion-cache-local-path - test-tilde-expansion-cache-local-path
@@ -972,17 +583,10 @@ jobs:
- cleanup-tilde-expansion-tests - cleanup-tilde-expansion-tests
- test-no-python-version - test-no-python-version
- test-custom-manifest-file - test-custom-manifest-file
- test-absolute-path
- test-relative-path
- test-cache-prune-force
- test-cache-dir-from-file
- test-cache-python-installs
- test-restore-python-installs
- test-python-install-dir
if: always() if: always()
steps: steps:
- name: All tests passed - name: All tests passed
run: | run: |
echo "All jobs passed: ${{ !(contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')) }}" echo "All jobs passed: ${{ !contains(needs.*.result, 'failure') }}"
# shellcheck disable=SC2242 # shellcheck disable=SC2242
exit ${{ (contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')) && 1 || 0 }} exit ${{ contains(needs.*.result, 'failure') && 1 || 0 }}

View File

@@ -3,10 +3,6 @@ on:
workflow_dispatch: workflow_dispatch:
schedule: schedule:
- cron: "0 4 * * *" # Run every day at 4am UTC - cron: "0 4 * * *" # Run every day at 4am UTC
repository_dispatch:
types: [ pypi_release ]
permissions: {}
jobs: jobs:
build: build:
@@ -15,10 +11,8 @@ jobs:
contents: write contents: write
pull-requests: write pull-requests: write
steps: steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - uses: actions/checkout@v4
with: - uses: actions/setup-node@v4
persist-credentials: true
- uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
with: with:
node-version: "20" node-version: "20"
- name: Update known versions - name: Update known versions
@@ -28,41 +22,16 @@ jobs:
src/download/checksum/known-checksums.ts src/download/checksum/known-checksums.ts
version-manifest.json version-manifest.json
${{ secrets.GITHUB_TOKEN }} ${{ secrets.GITHUB_TOKEN }}
- name: Check for changes - run: npm install && npm run all
id: changes-exist
run: |
git status --porcelain
if [ -n "$(git status --porcelain)" ]; then
echo "changes-exist=true" >> "$GITHUB_OUTPUT"
else
echo "changes-exist=false" >> "$GITHUB_OUTPUT"
fi
- name: Compile changes
if: ${{ steps.changes-exist.outputs.changes-exist == 'true' }}
run: npm ci && npm run all
- name: Commit and push changes
if: ${{ steps.changes-exist.outputs.changes-exist == 'true' }}
id: commit-and-push
continue-on-error: true
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
git add .
git commit -m "chore: update known versions for $LATEST_VERSION"
git push origin HEAD:refs/heads/main
env:
LATEST_VERSION: ${{ steps.update-known-versions.outputs.latest-version }}
- name: Create Pull Request - name: Create Pull Request
if: ${{ steps.changes-exist.outputs.changes-exist == 'true' && steps.commit-and-push.outcome != 'success' }}
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8 uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8
with: with:
commit-message: "chore: update known checksums" commit-message: "chore: update known versions"
title: title:
"chore: update known checksums for ${{ "chore: update known versions for ${{
steps.update-known-versions.outputs.latest-version }}" steps.update-known-versions.outputs.latest-version }}"
body: body:
"chore: update known checksums for ${{ "chore: update known versions for ${{
steps.update-known-versions.outputs.latest-version }}" steps.update-known-versions.outputs.latest-version }}"
base: main base: main
labels: "automated-pr,update-known-versions" labels: "automated-pr,update-known-versions"

View File

@@ -8,8 +8,6 @@ on:
tags: tags:
- "v*.*.*" - "v*.*.*"
permissions: {}
jobs: jobs:
update_major_minor_tags: update_major_minor_tags:
name: Make sure major and minor tags are up to date on a patch release name: Make sure major and minor tags are up to date on a patch release
@@ -17,9 +15,7 @@ jobs:
permissions: permissions:
contents: write contents: write
steps: steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - uses: actions/checkout@v4
with:
persist-credentials: true # needed for git push below
- name: Update Major Minor Tags - name: Update Major Minor Tags
run: | run: |
set -x set -x

View File

@@ -1,3 +0,0 @@
{
"recommendations": ["biomejs.biome"]
}

16
.vscode/settings.json vendored
View File

@@ -1,16 +0,0 @@
{
"editor.codeActionsOnSave": {
"source.action.useSortedAttributes.biome": "explicit",
"source.action.useSortedKeys.biome": "explicit",
"source.fixAll.biome": "explicit"
},
"editor.defaultFormatter": "biomejs.biome",
"editor.formatOnSave": true,
"explorer.excludeGitIgnore": false,
"search.defaultViewMode": "list",
"search.exclude": {
"**/node_modules": true
},
"typescript.enablePromptUseWorkspaceTsdk": true,
"typescript.tsdk": "node_modules/typescript/lib"
}

View File

@@ -15,25 +15,20 @@ Set up your GitHub Actions workflow with a specific version of [uv](https://docs
- [Install the latest version](#install-the-latest-version) - [Install the latest version](#install-the-latest-version)
- [Install a specific version](#install-a-specific-version) - [Install a specific version](#install-a-specific-version)
- [Install a version by supplying a semver range or pep440 specifier](#install-a-version-by-supplying-a-semver-range-or-pep440-specifier) - [Install a version by supplying a semver range or pep440 specifier](#install-a-version-by-supplying-a-semver-range-or-pep440-specifier)
- [Install a version defined in a requirements or config file](#install-a-version-defined-in-a-requirements-or-config-file)
- [Python version](#python-version) - [Python version](#python-version)
- [Activate environment](#activate-environment) - [Activate environment](#activate-environment)
- [Working directory](#working-directory) - [Working directory](#working-directory)
- [Validate checksum](#validate-checksum) - [Validate checksum](#validate-checksum)
- [Enable Caching](#enable-caching) - [Enable Caching](#enable-caching)
- [Cache dependency glob](#cache-dependency-glob) - [Cache dependency glob](#cache-dependency-glob)
- [Restore cache](#restore-cache)
- [Save cache](#save-cache)
- [Local cache path](#local-cache-path) - [Local cache path](#local-cache-path)
- [Disable cache pruning](#disable-cache-pruning) - [Disable cache pruning](#disable-cache-pruning)
- [Cache Python installs](#cache-python-installs)
- [Ignore nothing to cache](#ignore-nothing-to-cache) - [Ignore nothing to cache](#ignore-nothing-to-cache)
- [GitHub authentication token](#github-authentication-token) - [GitHub authentication token](#github-authentication-token)
- [UV_TOOL_DIR](#uv_tool_dir) - [UV_TOOL_DIR](#uv_tool_dir)
- [UV_TOOL_BIN_DIR](#uv_tool_bin_dir) - [UV_TOOL_BIN_DIR](#uv_tool_bin_dir)
- [Tilde Expansion](#tilde-expansion) - [Tilde Expansion](#tilde-expansion)
- [Manifest file](#manifest-file) - [Manifest file](#manifest-file)
- [Add problem matchers](#add-problem-matchers)
- [How it works](#how-it-works) - [How it works](#how-it-works)
- [FAQ](#faq) - [FAQ](#faq)
@@ -97,21 +92,6 @@ to install the latest version that satisfies the range.
version: ">=0.4.25,<0.5" version: ">=0.4.25,<0.5"
``` ```
### Install a version defined in a requirements or config file
You can use the `version-file` input to specify a file that contains the version of uv to install.
This can either be a `pyproject.toml` or `uv.toml` file which defines a `required-version` or
uv defined as a dependency in `pyproject.toml` or `requirements.txt`.
[asdf](https://asdf-vm.com/) `.tool-versions` is also supported, but without the `ref` syntax.
```yaml
- name: Install uv based on the version defined in pyproject.toml
uses: astral-sh/setup-uv@v6
with:
version-file: "pyproject.toml"
```
### Python version ### Python version
You can use the input `python-version` to set the environment variable `UV_PYTHON` for the rest of your workflow You can use the input `python-version` to set the environment variable `UV_PYTHON` for the rest of your workflow
@@ -126,7 +106,7 @@ This will override any python version specifications in `pyproject.toml` and `.p
- run: uv pip install --python=3.13t pip - run: uv pip install --python=3.13t pip
``` ```
You can combine this with a matrix to test multiple Python versions: You can combine this with a matrix to test multiple python versions:
```yaml ```yaml
jobs: jobs:
@@ -134,9 +114,9 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
matrix: matrix:
python-version: ["3.10", "3.11", "3.12", "3.13"] python-version: ["3.9", "3.10", "3.11", "3.12"]
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v4
- name: Install the latest version of uv and set the python version - name: Install the latest version of uv and set the python version
uses: astral-sh/setup-uv@v6 uses: astral-sh/setup-uv@v6
with: with:
@@ -199,10 +179,6 @@ are automatically verified by this action. The sha256 hashes can be found on the
### Enable caching ### Enable caching
> [!NOTE]
> The cache is pruned before it is uploaded to the GitHub Actions cache. This can lead to
> a small or empty cache. See [Disable cache pruning](#disable-cache-pruning) for more details.
If you enable caching, the [uv cache](https://docs.astral.sh/uv/concepts/cache/) will be uploaded to If you enable caching, the [uv cache](https://docs.astral.sh/uv/concepts/cache/) will be uploaded to
the GitHub Actions cache. This can speed up runs that reuse the cache by several minutes. the GitHub Actions cache. This can speed up runs that reuse the cache by several minutes.
Caching is enabled by default on GitHub-hosted runners. Caching is enabled by default on GitHub-hosted runners.
@@ -251,7 +227,6 @@ changes. If you use relative paths, they are relative to the repository root.
> **/*constraints*.in > **/*constraints*.in
> **/pyproject.toml > **/pyproject.toml
> **/uv.lock > **/uv.lock
> **/*.py.lock
> ``` > ```
```yaml ```yaml
@@ -288,47 +263,13 @@ changes. If you use relative paths, they are relative to the repository root.
cache-dependency-glob: "" cache-dependency-glob: ""
``` ```
#### Restore cache
Restoring an existing cache can be enabled or disabled with the `restore-cache` input.
By default, the cache will be restored.
```yaml
- name: Don't restore an existing cache
uses: astral-sh/setup-uv@v6
with:
enable-cache: true
restore-cache: false
```
#### Save cache
You can also disable saving the cache after the run with the `save-cache` input.
This can be useful to save cache storage when you know you will not use the cache of the run again.
By default, the cache will be saved.
```yaml
- name: Don't save the cache after the run
uses: astral-sh/setup-uv@v6
with:
enable-cache: true
save-cache: false
```
### Local cache path ### Local cache path
If caching is enabled, this action controls where uv stores its cache on the runner's filesystem This action controls where uv stores its cache on the runner's filesystem by setting `UV_CACHE_DIR`.
by setting `UV_CACHE_DIR`.
It defaults to `setup-uv-cache` in the `TMP` dir, `D:\a\_temp\uv-tool-dir` on Windows and It defaults to `setup-uv-cache` in the `TMP` dir, `D:\a\_temp\uv-tool-dir` on Windows and
`/tmp/setup-uv-cache` on Linux/macOS. You can change the default by specifying the path with the `/tmp/setup-uv-cache` on Linux/macOS. You can change the default by specifying the path with the
`cache-local-path` input. `cache-local-path` input.
> [!NOTE]
> If the environment variable `UV_CACHE_DIR` is already set this action will not override it.
> If you configured [cache-dir](https://docs.astral.sh/uv/reference/settings/#cache-dir) in your
> config file then it is also respected and this action will not set `UV_CACHE_DIR`.
```yaml ```yaml
- name: Define a custom uv cache path - name: Define a custom uv cache path
uses: astral-sh/setup-uv@v6 uses: astral-sh/setup-uv@v6
@@ -356,20 +297,6 @@ input.
prune-cache: false prune-cache: false
``` ```
### Cache Python installs
By default, the Python install dir (`uv python dir` / `UV_PYTHON_INSTALL_DIR`) is not cached,
for the same reason that the dependency cache is pruned.
If you want to cache Python installs along with your dependencies, set the `cache-python` input to `true`.
```yaml
- name: Cache Python installs
uses: astral-sh/setup-uv@v6
with:
enable-cache: true
cache-python: true
```
### Ignore nothing to cache ### Ignore nothing to cache
By default, the action will fail if caching is enabled but there is nothing to upload (the uv cache directory does not exist). By default, the action will fail if caching is enabled but there is nothing to upload (the uv cache directory does not exist).
@@ -455,7 +382,6 @@ If you want to change this behaviour (especially on self-hosted runners) you can
This action supports expanding the `~` character to the user's home directory for the following inputs: This action supports expanding the `~` character to the user's home directory for the following inputs:
- `version-file`
- `cache-local-path` - `cache-local-path`
- `tool-dir` - `tool-dir`
- `tool-bin-dir` - `tool-bin-dir`
@@ -509,21 +435,6 @@ This is useful if you maintain your own uv builds or want to override the defaul
> This means the action will install the latest version available in the custom manifest file. > This means the action will install the latest version available in the custom manifest file.
> This is different from the default behavior of installing the latest version from the official uv releases. > This is different from the default behavior of installing the latest version from the official uv releases.
### Add problem matchers
This action automatically adds
[problem matchers](https://github.com/actions/toolkit/blob/main/docs/problem-matchers.md)
for python errors.
You can disable this by setting the `add-problem-matchers` input to `false`.
```yaml
- name: Install the latest version of uv without problem matchers
uses: astral-sh/setup-uv@v6
with:
add-problem-matchers: false
```
## How it works ## How it works
This action downloads uv from the uv repo's official This action downloads uv from the uv repo's official

View File

@@ -1,4 +1,4 @@
import { expect, it, test } from "@jest/globals"; import { expect, test, it } from "@jest/globals";
import { import {
isknownVersion, isknownVersion,
validateChecksum, validateChecksum,
@@ -22,12 +22,12 @@ type KnownVersionFixture = { version: string; known: boolean };
it.each<KnownVersionFixture>([ it.each<KnownVersionFixture>([
{ {
known: true,
version: "0.3.0", version: "0.3.0",
known: true,
}, },
{ {
known: false,
version: "0.0.15", version: "0.0.15",
known: false,
}, },
])( ])(
"isknownVersion should return $known for version $version", "isknownVersion should return $known for version $version",

View File

@@ -1,9 +1,9 @@
[ [
{ {
"arch": "x86_64", "version": "0.7.12-alpha.1",
"artifactName": "uv-x86_64-unknown-linux-gnu.tar.gz", "artifactName": "uv-x86_64-unknown-linux-gnu.tar.gz",
"downloadUrl": "https://release.pyx.dev/0.7.12-alpha.1/uv-x86_64-unknown-linux-gnu.tar.gz", "arch": "x86_64",
"platform": "unknown-linux-gnu", "platform": "unknown-linux-gnu",
"version": "0.7.12-alpha.1" "downloadUrl": "https://release.pyx.dev/0.7.12-alpha.1/uv-x86_64-unknown-linux-gnu.tar.gz"
} }
] ]

View File

@@ -1 +0,0 @@
uv 0.5.15

View File

@@ -1,16 +0,0 @@
[project]
name = "uv-project"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"ruff>=0.6.2",
]
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[tool.uv]
cache-dir = "/tmp/pyproject-toml-defined-cache-path"

View File

@@ -1,2 +0,0 @@
def hello() -> str:
return "Hello from uv-project!"

View File

@@ -1,38 +0,0 @@
version = 1
requires-python = ">=3.12"
[[package]]
name = "ruff"
version = "0.6.2"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/23/f4/279d044f66b79261fd37df76bf72b64471afab5d3b7906a01499c4451910/ruff-0.6.2.tar.gz", hash = "sha256:239ee6beb9e91feb8e0ec384204a763f36cb53fb895a1a364618c6abb076b3be", size = 2460281 }
wheels = [
{ url = "https://files.pythonhosted.org/packages/72/4b/47dd7a69287afb4069fa42c198e899463605460a58120196711bfcf0446b/ruff-0.6.2-py3-none-linux_armv6l.whl", hash = "sha256:5c8cbc6252deb3ea840ad6a20b0f8583caab0c5ef4f9cca21adc5a92b8f79f3c", size = 9695871 },
{ url = "https://files.pythonhosted.org/packages/ae/c3/8aac62ac4638c14a740ee76a755a925f2d0d04580ab790a9887accb729f6/ruff-0.6.2-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:17002fe241e76544448a8e1e6118abecbe8cd10cf68fde635dad480dba594570", size = 9459354 },
{ url = "https://files.pythonhosted.org/packages/2f/cf/77fbd8d4617b9b9c503f9bffb8552c4e3ea1a58dc36975e7a9104ffb0f85/ruff-0.6.2-py3-none-macosx_11_0_arm64.whl", hash = "sha256:3dbeac76ed13456f8158b8f4fe087bf87882e645c8e8b606dd17b0b66c2c1158", size = 9163871 },
{ url = "https://files.pythonhosted.org/packages/05/1c/765192bab32b79efbb498b06f0b9dcb3629112b53b8777ae1d19b8209e09/ruff-0.6.2-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:094600ee88cda325988d3f54e3588c46de5c18dae09d683ace278b11f9d4d534", size = 10096250 },
{ url = "https://files.pythonhosted.org/packages/08/d0/86f3cb0f6934c99f759c232984a5204d67a26745cad2d9edff6248adf7d2/ruff-0.6.2-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:316d418fe258c036ba05fbf7dfc1f7d3d4096db63431546163b472285668132b", size = 9475376 },
{ url = "https://files.pythonhosted.org/packages/cd/cc/4c8d0e225b559a3fae6092ec310d7150d3b02b4669e9223f783ef64d82c0/ruff-0.6.2-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:d72b8b3abf8a2d51b7b9944a41307d2f442558ccb3859bbd87e6ae9be1694a5d", size = 10295634 },
{ url = "https://files.pythonhosted.org/packages/db/96/d2699cfb1bb5a01c68122af43454c76c31331e1c8a9bd97d653d7c82524b/ruff-0.6.2-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:2aed7e243be68487aa8982e91c6e260982d00da3f38955873aecd5a9204b1d66", size = 11024941 },
{ url = "https://files.pythonhosted.org/packages/8b/a9/6ecd66af8929e0f2a1ed308a4137f3521789f28f0eb97d32c2ca3aa7000c/ruff-0.6.2-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:d371f7fc9cec83497fe7cf5eaf5b76e22a8efce463de5f775a1826197feb9df8", size = 10606894 },
{ url = "https://files.pythonhosted.org/packages/e4/73/2ee4cd19f44992fedac1cc6db9e3d825966072f6dcbd4032f21cbd063170/ruff-0.6.2-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:a8f310d63af08f583363dfb844ba8f9417b558199c58a5999215082036d795a1", size = 11552886 },
{ url = "https://files.pythonhosted.org/packages/60/4c/c0f1cd35ce4a93c54a6bb1ee6934a3a205fa02198dd076678193853ceea1/ruff-0.6.2-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7db6880c53c56addb8638fe444818183385ec85eeada1d48fc5abe045301b2f1", size = 10264945 },
{ url = "https://files.pythonhosted.org/packages/c4/89/e45c9359b9cdd4245512ea2b9f2bb128a997feaa5f726fc9e8c7a66afadf/ruff-0.6.2-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:1175d39faadd9a50718f478d23bfc1d4da5743f1ab56af81a2b6caf0a2394f23", size = 10100007 },
{ url = "https://files.pythonhosted.org/packages/06/74/0bd4e0a7ed5f6908df87892f9bf60a2356c0fd74102d8097298bd9b4f346/ruff-0.6.2-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:5b939f9c86d51635fe486585389f54582f0d65b8238e08c327c1534844b3bb9a", size = 9559267 },
{ url = "https://files.pythonhosted.org/packages/54/03/3dc6dc9419f276f05805bf888c279e3e0b631284abd548d9e87cebb93aec/ruff-0.6.2-py3-none-musllinux_1_2_i686.whl", hash = "sha256:d0d62ca91219f906caf9b187dea50d17353f15ec9bb15aae4a606cd697b49b4c", size = 9905304 },
{ url = "https://files.pythonhosted.org/packages/5c/5b/d6a72a6a6bbf097c09de468326ef5fa1c9e7aa5e6e45979bc0d984b0dbe7/ruff-0.6.2-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:7438a7288f9d67ed3c8ce4d059e67f7ed65e9fe3aa2ab6f5b4b3610e57e3cb56", size = 10341480 },
{ url = "https://files.pythonhosted.org/packages/79/a9/0f2f21fe15ba537c46598f96aa9ae4a3d4b9ec64926664617ca6a8c772f4/ruff-0.6.2-py3-none-win32.whl", hash = "sha256:279d5f7d86696df5f9549b56b9b6a7f6c72961b619022b5b7999b15db392a4da", size = 7961901 },
{ url = "https://files.pythonhosted.org/packages/b0/80/fff12ffe11853d9f4ea3e5221e6dd2e93640a161c05c9579833e09ad40a7/ruff-0.6.2-py3-none-win_amd64.whl", hash = "sha256:d9f3469c7dd43cd22eb1c3fc16926fb8258d50cb1b216658a07be95dd117b0f2", size = 8783320 },
{ url = "https://files.pythonhosted.org/packages/56/91/577cdd64cce5e74d3f8b5ecb93f29566def569c741eb008aed4f331ef821/ruff-0.6.2-py3-none-win_arm64.whl", hash = "sha256:f28fcd2cd0e02bdf739297516d5643a945cc7caf09bd9bcb4d932540a5ea4fa9", size = 8225886 },
]
[[package]]
name = "uv-project"
version = "0.1.0"
source = { editable = "." }
dependencies = [
{ name = "ruff" },
]
[package.metadata]
requires-dist = [{ name = "ruff" }]

View File

@@ -1 +0,0 @@
print("Hello world")

View File

@@ -1,33 +0,0 @@
# This file was autogenerated by uv via the following command:
# uv pip compile --generate-hashes - -o ex-requirements.txt
click==8.2.1 \
--hash=sha256:27c491cc05d968d271d5a1db13e3b5a184636d9d930f148c50b038f0d0646202 \
--hash=sha256:61a3265b914e850b85317d0b3109c7f8cd35a670f963866005d6ef1d5175a12b
# via uvicorn
h11==0.16.0 \
--hash=sha256:4e35b956cf45792e4caa5885e69fba00bdbc6ffafbfa020300e549b208ee5ff1 \
--hash=sha256:63cf8bbe7522de3bf65932fda1d9c2772064ffb3dae62d55932da54b31cb6c86
# via uvicorn
uv==0.8.3 \
--hash=sha256:1121ad1c9389b865d029385031d3fd7d90d343c92a2149a4d4aa20bf469cb27f \
--hash=sha256:17bcdb0615e37cc5f985f7d7546f755ac6343c1dc8bbe876c892437f14f8f904 \
--hash=sha256:2ccaae4c749126c99f6404d67a0ae1eae29cbafb05603d09094a775061fdf4e5 \
--hash=sha256:2e311c029bff2ca07c6ddf877ccc5935cabb78e09b94b53a849542665b6a6fa1 \
--hash=sha256:391c97577048a40fd8c85b370055df6420f26e81df7fa906f0e0ce1aa2af3527 \
--hash=sha256:3f904f574dc2d7aa1d96ddf2483480ecd121dc9d060108cadd8bff100b754b64 \
--hash=sha256:526f2c3bd6f311ce31f6f7b6b7d818b191f41e76bed3aaab671b716220c02d8f \
--hash=sha256:5313ee776ad65731ffa8ac585246f987d3a2bf72e6153c12add1fff22ad6e500 \
--hash=sha256:5843cc43bafad05cc710d8e31bd347ee37202462a63d32c30746e9df48cfbda2 \
--hash=sha256:76de331a07e5ae9b6490e70a9439a072b91b3167a5684510af10c2752c4ece9a \
--hash=sha256:8486f7576d15cc73509f93f47b3190f44701ea36839906369301b58c8604d5db \
--hash=sha256:8b16f1bddfdf8f7470924ab34a7b55e4c372d5340c7c1e47e7fc84a743dc541f \
--hash=sha256:966ec7d7f57521fef0fee685d71e183c9cafb358ddcfe27519dfeaf40550f247 \
--hash=sha256:989898caeb6e972979543b57547d1c28ab8af81ff8fc15921fd354c17d432749 \
--hash=sha256:9ce7981f4fbeecf93dc5cf0a5a7915e84956fd99ad3ac977c048fe0cfdb1a17e \
--hash=sha256:ad13453ab0a1dfa64a221aac8f52199efdcaa52c97134fffd7bcebed794a6f4b \
--hash=sha256:ae7efe91dcfc24126fa91e0fb69a1daf6c0e494a781ba192bb0cc62d7ab623ee \
--hash=sha256:daa6e0d657a94f20e962d4a03d833ef7af5c8e51b7c8a2d92ba6cf64a4c07ac1 \
--hash=sha256:f1eb7c896fc0d80ed534748aaf46697b6ebc8ce401f1c51666ce0b9923c3db9a
uvicorn==0.35.0 \
--hash=sha256:197535216b25ff9b785e29a0b79199f55222193d47f820816e7da751e9bc8d4a \
--hash=sha256:bc662f087f7cf2ce11a1d7fd70b90c9f98ef2e2831556dd078d131b96cc94a01

View File

@@ -1 +0,0 @@
print("Hello world")

View File

@@ -1,2 +0,0 @@
uvicorn==0.35.0
uv==0.6.17

View File

@@ -1,86 +0,0 @@
jest.mock("@actions/core", () => {
return {
debug: jest.fn(),
getBooleanInput: jest.fn(
(name: string) => (mockInputs[name] ?? "") === "true",
),
getInput: jest.fn((name: string) => mockInputs[name] ?? ""),
};
});
import {
afterEach,
beforeEach,
describe,
expect,
it,
jest,
} from "@jest/globals";
// Will be mutated per test before (re-)importing the module under test
let mockInputs: Record<string, string> = {};
const ORIGINAL_HOME = process.env.HOME;
describe("cacheDependencyGlob", () => {
beforeEach(() => {
jest.resetModules();
mockInputs = {};
process.env.HOME = "/home/testuser";
});
afterEach(() => {
process.env.HOME = ORIGINAL_HOME;
});
it("returns empty string when input not provided", async () => {
mockInputs["working-directory"] = "/workspace";
const { cacheDependencyGlob } = await import("../../src/utils/inputs");
expect(cacheDependencyGlob).toBe("");
});
it("resolves a single relative path", async () => {
mockInputs["working-directory"] = "/workspace";
mockInputs["cache-dependency-glob"] = "requirements.txt";
const { cacheDependencyGlob } = await import("../../src/utils/inputs");
expect(cacheDependencyGlob).toBe("/workspace/requirements.txt");
});
it("strips leading ./ from relative path", async () => {
mockInputs["working-directory"] = "/workspace";
mockInputs["cache-dependency-glob"] = "./uv.lock";
const { cacheDependencyGlob } = await import("../../src/utils/inputs");
expect(cacheDependencyGlob).toBe("/workspace/uv.lock");
});
it("handles multiple lines, trimming whitespace, tilde expansion and absolute paths", async () => {
mockInputs["working-directory"] = "/workspace";
mockInputs["cache-dependency-glob"] =
" ~/.cache/file1\n ./rel/file2 \nfile3.txt";
const { cacheDependencyGlob } = await import("../../src/utils/inputs");
expect(cacheDependencyGlob).toBe(
[
"/home/testuser/.cache/file1", // expanded tilde, absolute path unchanged
"/workspace/rel/file2", // ./ stripped and resolved
"/workspace/file3.txt", // relative path resolved
].join("\n"),
);
});
it("keeps absolute path unchanged in multiline input", async () => {
mockInputs["working-directory"] = "/workspace";
mockInputs["cache-dependency-glob"] = "/abs/path.lock\nrelative.lock";
const { cacheDependencyGlob } = await import("../../src/utils/inputs");
expect(cacheDependencyGlob).toBe(
["/abs/path.lock", "/workspace/relative.lock"].join("\n"),
);
});
it("handles exclusions in relative paths correct", async () => {
mockInputs["working-directory"] = "/workspace";
mockInputs["cache-dependency-glob"] = "!/abs/path.lock\n!relative.lock";
const { cacheDependencyGlob } = await import("../../src/utils/inputs");
expect(cacheDependencyGlob).toBe(
["!/abs/path.lock", "!/workspace/relative.lock"].join("\n"),
);
});
});

View File

@@ -1,9 +0,0 @@
import { expect, test } from "@jest/globals";
import { getUvVersionFromFile } from "../../src/version/resolve";
test("ignores dependencies starting with uv", async () => {
const parsedVersion = getUvVersionFromFile(
"__tests__/fixtures/uv-in-requirements-txt-project/requirements.txt",
);
expect(parsedVersion).toBe("0.6.17");
});

View File

@@ -1,9 +0,0 @@
import { expect, test } from "@jest/globals";
import { getUvVersionFromFile } from "../../src/version/resolve";
test("ignores dependencies starting with uv", async () => {
const parsedVersion = getUvVersionFromFile(
"__tests__/fixtures/uv-in-requirements-hash-txt-project/requirements.txt",
);
expect(parsedVersion).toBe("0.8.3");
});

View File

@@ -1,115 +0,0 @@
jest.mock("node:fs");
jest.mock("@actions/core", () => ({
warning: jest.fn(),
}));
import fs from "node:fs";
import * as core from "@actions/core";
import { beforeEach, describe, expect, it, jest } from "@jest/globals";
import { getUvVersionFromToolVersions } from "../../src/version/tool-versions-file";
const mockedFs = fs as jest.Mocked<typeof fs>;
const mockedCore = core as jest.Mocked<typeof core>;
describe("getUvVersionFromToolVersions", () => {
beforeEach(() => {
jest.clearAllMocks();
});
it("should return undefined for non-.tool-versions files", () => {
const result = getUvVersionFromToolVersions("package.json");
expect(result).toBeUndefined();
expect(mockedFs.readFileSync).not.toHaveBeenCalled();
});
it("should return version for valid uv entry", () => {
const fileContent = "python 3.11.0\nuv 0.1.0\nnodejs 18.0.0";
mockedFs.readFileSync.mockReturnValue(fileContent);
const result = getUvVersionFromToolVersions(".tool-versions");
expect(result).toBe("0.1.0");
expect(mockedFs.readFileSync).toHaveBeenCalledWith(
".tool-versions",
"utf8",
);
});
it("should return version for uv entry with v prefix", () => {
const fileContent = "uv v0.2.0";
mockedFs.readFileSync.mockReturnValue(fileContent);
const result = getUvVersionFromToolVersions(".tool-versions");
expect(result).toBe("0.2.0");
});
it("should handle whitespace around uv entry", () => {
const fileContent = " uv 0.3.0 ";
mockedFs.readFileSync.mockReturnValue(fileContent);
const result = getUvVersionFromToolVersions(".tool-versions");
expect(result).toBe("0.3.0");
});
it("should skip commented lines", () => {
const fileContent = "# uv 0.1.0\npython 3.11.0\nuv 0.2.0";
mockedFs.readFileSync.mockReturnValue(fileContent);
const result = getUvVersionFromToolVersions(".tool-versions");
expect(result).toBe("0.2.0");
});
it("should return first matching uv version", () => {
const fileContent = "uv 0.1.0\npython 3.11.0\nuv 0.2.0";
mockedFs.readFileSync.mockReturnValue(fileContent);
const result = getUvVersionFromToolVersions(".tool-versions");
expect(result).toBe("0.1.0");
});
it("should return undefined when no uv entry found", () => {
const fileContent = "python 3.11.0\nnodejs 18.0.0";
mockedFs.readFileSync.mockReturnValue(fileContent);
const result = getUvVersionFromToolVersions(".tool-versions");
expect(result).toBeUndefined();
});
it("should return undefined for empty file", () => {
mockedFs.readFileSync.mockReturnValue("");
const result = getUvVersionFromToolVersions(".tool-versions");
expect(result).toBeUndefined();
});
it("should warn and return undefined for ref syntax", () => {
const fileContent = "uv ref:main";
mockedFs.readFileSync.mockReturnValue(fileContent);
const result = getUvVersionFromToolVersions(".tool-versions");
expect(result).toBeUndefined();
expect(mockedCore.warning).toHaveBeenCalledWith(
"The ref syntax of .tool-versions is not supported. Please use a released version instead.",
);
});
it("should handle file path with .tool-versions extension", () => {
const fileContent = "uv 0.1.0";
mockedFs.readFileSync.mockReturnValue(fileContent);
const result = getUvVersionFromToolVersions("path/to/.tool-versions");
expect(result).toBe("0.1.0");
expect(mockedFs.readFileSync).toHaveBeenCalledWith(
"path/to/.tool-versions",
"utf8",
);
});
});

View File

@@ -6,9 +6,6 @@ inputs:
version: version:
description: "The version of uv to install e.g., `0.5.0` Defaults to the version in pyproject.toml or 'latest'." description: "The version of uv to install e.g., `0.5.0` Defaults to the version in pyproject.toml or 'latest'."
default: "" default: ""
version-file:
description: "Path to a file containing the version of uv to install. Defaults to searching for uv.toml and if not found pyproject.toml."
default: ""
python-version: python-version:
description: "The version of Python to set UV_PYTHON to" description: "The version of Python to set UV_PYTHON to"
required: false required: false
@@ -21,6 +18,10 @@ inputs:
checksum: checksum:
description: "The checksum of the uv version to install" description: "The checksum of the uv version to install"
required: false required: false
server-url:
description: "(Deprecated) The server url to use when downloading uv"
required: false
default: "https://github.com"
github-token: github-token:
description: description:
"Used to increase the rate limit when retrieving versions and downloading uv." "Used to increase the rate limit when retrieving versions and downloading uv."
@@ -40,13 +41,6 @@ inputs:
**/*constraints*.in **/*constraints*.in
**/pyproject.toml **/pyproject.toml
**/uv.lock **/uv.lock
**/*.py.lock
restore-cache:
description: "Whether to restore the cache if found."
default: "true"
save-cache:
description: "Whether to save the cache after the run."
default: "true"
cache-suffix: cache-suffix:
description: "Suffix for the cache key" description: "Suffix for the cache key"
required: false required: false
@@ -56,9 +50,6 @@ inputs:
prune-cache: prune-cache:
description: "Prune cache before saving." description: "Prune cache before saving."
default: "true" default: "true"
cache-python:
description: "Upload managed Python installations to the Github Actions cache."
default: "false"
ignore-nothing-to-cache: ignore-nothing-to-cache:
description: "Ignore when nothing is found to cache." description: "Ignore when nothing is found to cache."
default: "false" default: "false"
@@ -74,9 +65,6 @@ inputs:
manifest-file: manifest-file:
description: "URL to the manifest file containing available versions and download URLs." description: "URL to the manifest file containing available versions and download URLs."
required: false required: false
add-problem-matchers:
description: "Add problem matchers."
default: "true"
outputs: outputs:
uv-version: uv-version:
description: "The installed uv version. Useful when using latest." description: "The installed uv version. Useful when using latest."
@@ -86,10 +74,8 @@ outputs:
description: "The path to the installed uvx binary." description: "The path to the installed uvx binary."
cache-hit: cache-hit:
description: "A boolean value to indicate a cache entry was found" description: "A boolean value to indicate a cache entry was found"
venv:
description: "Path to the activated venv if activate-environment is true"
runs: runs:
using: "node24" using: "node20"
main: "dist/setup/index.js" main: "dist/setup/index.js"
post: "dist/save-cache/index.js" post: "dist/save-cache/index.js"
post-if: success() post-if: success()

View File

@@ -1,34 +1,20 @@
{ {
"$schema": "https://biomejs.dev/schemas/2.2.4/schema.json", "$schema": "https://biomejs.dev/schemas/1.9.2/schema.json",
"assist": { "vcs": {
"actions": { "enabled": true,
"source": { "clientKind": "git",
"organizeImports": "on", "useIgnoreFile": false
"useSortedAttributes": "on",
"useSortedKeys": "on"
}
}
}, },
"files": { "files": {
"ignoreUnknown": false, "ignoreUnknown": false,
"includes": [ "ignore": ["dist", "lib", "node_modules"]
"**",
"!**/dist",
"!**/lib",
"!**/node_modules",
"!**/package*.json",
"!**/known-checksums.*"
]
}, },
"formatter": { "formatter": {
"enabled": true, "enabled": true,
"indentStyle": "space" "indentStyle": "space"
}, },
"javascript": { "organizeImports": {
"formatter": { "enabled": true
"quoteStyle": "double",
"trailingCommas": "all"
}
}, },
"linter": { "linter": {
"enabled": true, "enabled": true,
@@ -36,9 +22,10 @@
"recommended": true "recommended": true
} }
}, },
"vcs": { "javascript": {
"clientKind": "git", "formatter": {
"enabled": true, "quoteStyle": "double",
"useIgnoreFile": false "trailingCommas": "all"
}
} }
} }

3410
dist/save-cache/index.js generated vendored

File diff suppressed because it is too large Load Diff

8785
dist/setup/index.js generated vendored

File diff suppressed because one or more lines are too long

6690
dist/update-known-versions/index.js generated vendored

File diff suppressed because one or more lines are too long

7313
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -6,12 +6,14 @@
"main": "dist/index.js", "main": "dist/index.js",
"scripts": { "scripts": {
"build": "tsc", "build": "tsc",
"check": "biome check --write", "format": "biome format --fix",
"format-check": "biome format",
"lint": "biome lint --fix",
"package": "ncc build -o dist/setup src/setup-uv.ts && ncc build -o dist/save-cache src/save-cache.ts && ncc build -o dist/update-known-versions src/update-known-versions.ts", "package": "ncc build -o dist/setup src/setup-uv.ts && ncc build -o dist/save-cache src/save-cache.ts && ncc build -o dist/update-known-versions src/update-known-versions.ts",
"test": "jest", "test": "jest",
"act": "act pull_request -W .github/workflows/test.yml --container-architecture linux/amd64 -s GITHUB_TOKEN=\"$(gh auth token)\"", "act": "act pull_request -W .github/workflows/test.yml --container-architecture linux/amd64 -s GITHUB_TOKEN=\"$(gh auth token)\"",
"update-known-versions": "RUNNER_TEMP=known_versions node dist/update-known-versions/index.js src/download/checksum/known-versions.ts \"$(gh auth token)\"", "update-known-versions": "RUNNER_TEMP=known_versions node dist/update-known-versions/index.js src/download/checksum/known-versions.ts \"$(gh auth token)\"",
"all": "npm run build && npm run check && npm run package && npm test" "all": "npm run build && npm run format && npm run lint && npm run package && npm test"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@@ -21,28 +23,28 @@
"author": "@eifinger", "author": "@eifinger",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/cache": "^4.0.5", "@actions/cache": "^4.0.3",
"@actions/core": "^1.11.1", "@actions/core": "^1.11.1",
"@actions/exec": "^1.1.1", "@actions/exec": "^1.1.1",
"@actions/glob": "^0.5.0", "@actions/glob": "^0.5.0",
"@actions/io": "^1.1.3", "@actions/io": "^1.1.3",
"@actions/tool-cache": "^2.0.2", "@actions/tool-cache": "^2.0.2",
"@octokit/core": "^7.0.5", "@octokit/core": "^7.0.2",
"@octokit/plugin-paginate-rest": "^13.1.1", "@octokit/plugin-paginate-rest": "^12.0.0",
"@octokit/plugin-rest-endpoint-methods": "^16.1.0", "@octokit/plugin-rest-endpoint-methods": "^14.0.0",
"@renovatebot/pep440": "^4.2.1", "@renovatebot/pep440": "^4.1.0",
"smol-toml": "^1.4.2", "smol-toml": "^1.3.4",
"undici": "^7.16.0" "undici": "^7.10.0"
}, },
"devDependencies": { "devDependencies": {
"@biomejs/biome": "2.2.4", "@biomejs/biome": "1.9.4",
"@types/js-yaml": "^4.0.9", "@types/js-yaml": "^4.0.9",
"@types/node": "^24.7.0", "@types/node": "^22.15.21",
"@types/semver": "^7.7.1", "@types/semver": "^7.7.0",
"@vercel/ncc": "^0.38.4", "@vercel/ncc": "^0.38.3",
"jest": "^30.1.3", "jest": "^29.7.0",
"js-yaml": "^4.1.0", "js-yaml": "^4.1.0",
"ts-jest": "^29.4.4", "ts-jest": "^29.3.2",
"typescript": "^5.9.2" "typescript": "^5.8.3"
} }
} }

View File

@@ -1,19 +1,16 @@
import * as cache from "@actions/cache"; import * as cache from "@actions/cache";
import * as core from "@actions/core"; import * as core from "@actions/core";
import * as exec from "@actions/exec";
import { hashFiles } from "../hash/hash-files";
import { import {
cacheDependencyGlob, cacheDependencyGlob,
cacheLocalPath, cacheLocalPath,
cachePython,
cacheSuffix, cacheSuffix,
pruneCache, pruneCache,
pythonDir,
pythonVersion as pythonVersionInput, pythonVersion as pythonVersionInput,
restoreCache as shouldRestoreCache,
workingDirectory, workingDirectory,
} from "../utils/inputs"; } from "../utils/inputs";
import { getArch, getPlatform } from "../utils/platforms"; import { getArch, getPlatform } from "../utils/platforms";
import { hashFiles } from "../hash/hash-files";
import * as exec from "@actions/exec";
export const STATE_CACHE_KEY = "cache-key"; export const STATE_CACHE_KEY = "cache-key";
export const STATE_CACHE_MATCHED_KEY = "cache-matched-key"; export const STATE_CACHE_MATCHED_KEY = "cache-matched-key";
@@ -21,23 +18,13 @@ const CACHE_VERSION = "1";
export async function restoreCache(): Promise<void> { export async function restoreCache(): Promise<void> {
const cacheKey = await computeKeys(); const cacheKey = await computeKeys();
core.saveState(STATE_CACHE_KEY, cacheKey);
if (!shouldRestoreCache) {
core.info("restore-cache is false. Skipping restore cache step.");
return;
}
let matchedKey: string | undefined; let matchedKey: string | undefined;
core.info( core.info(
`Trying to restore uv cache from GitHub Actions cache with key: ${cacheKey}`, `Trying to restore uv cache from GitHub Actions cache with key: ${cacheKey}`,
); );
const cachePaths = [cacheLocalPath];
if (cachePython) {
cachePaths.push(pythonDir);
}
try { try {
matchedKey = await cache.restoreCache(cachePaths, cacheKey); matchedKey = await cache.restoreCache([cacheLocalPath], cacheKey);
} catch (err) { } catch (err) {
const message = (err as Error).message; const message = (err as Error).message;
core.warning(message); core.warning(message);
@@ -45,6 +32,8 @@ export async function restoreCache(): Promise<void> {
return; return;
} }
core.saveState(STATE_CACHE_KEY, cacheKey);
handleMatchResult(matchedKey, cacheKey); handleMatchResult(matchedKey, cacheKey);
} }
@@ -68,8 +57,7 @@ async function computeKeys(): Promise<string> {
const pythonVersion = await getPythonVersion(); const pythonVersion = await getPythonVersion();
const platform = await getPlatform(); const platform = await getPlatform();
const pruned = pruneCache ? "-pruned" : ""; const pruned = pruneCache ? "-pruned" : "";
const python = cachePython ? "-py" : ""; return `setup-uv-${CACHE_VERSION}-${getArch()}-${platform}-${pythonVersion}${pruned}${cacheDependencyPathHash}${suffix}`;
return `setup-uv-${CACHE_VERSION}-${getArch()}-${platform}-${pythonVersion}${pruned}${python}${cacheDependencyPathHash}${suffix}`;
} }
async function getPythonVersion(): Promise<string> { async function getPythonVersion(): Promise<string> {
@@ -79,12 +67,12 @@ async function getPythonVersion(): Promise<string> {
let output = ""; let output = "";
const options: exec.ExecOptions = { const options: exec.ExecOptions = {
silent: !core.isDebug(),
listeners: { listeners: {
stdout: (data: Buffer) => { stdout: (data: Buffer) => {
output += data.toString(); output += data.toString();
}, },
}, },
silent: !core.isDebug(),
}; };
try { try {

View File

@@ -1,9 +1,9 @@
import * as crypto from "node:crypto";
import * as fs from "node:fs"; import * as fs from "node:fs";
import * as crypto from "node:crypto";
import * as core from "@actions/core"; import * as core from "@actions/core";
import type { Architecture, Platform } from "../../utils/platforms";
import { KNOWN_CHECKSUMS } from "./known-checksums"; import { KNOWN_CHECKSUMS } from "./known-checksums";
import type { Architecture, Platform } from "../../utils/platforms";
export async function validateChecksum( export async function validateChecksum(
checkSum: string | undefined, checkSum: string | undefined,
@@ -12,7 +12,7 @@ export async function validateChecksum(
platform: Platform, platform: Platform,
version: string, version: string,
): Promise<void> { ): Promise<void> {
let isValid: boolean | undefined; let isValid: boolean | undefined = undefined;
if (checkSum !== undefined && checkSum !== "") { if (checkSum !== undefined && checkSum !== "") {
isValid = await validateFileCheckSum(downloadPath, checkSum); isValid = await validateFileCheckSum(downloadPath, checkSum);
} else { } else {

File diff suppressed because it is too large Load Diff

View File

@@ -1,21 +1,17 @@
import { promises as fs } from "node:fs";
import * as path from "node:path";
import * as core from "@actions/core"; import * as core from "@actions/core";
import * as tc from "@actions/tool-cache"; import * as tc from "@actions/tool-cache";
import type { Endpoints } from "@octokit/types"; import * as path from "node:path";
import * as pep440 from "@renovatebot/pep440"; import * as pep440 from "@renovatebot/pep440";
import { promises as fs } from "node:fs";
import { OWNER, REPO, TOOL_CACHE_NAME } from "../utils/constants"; import { OWNER, REPO, TOOL_CACHE_NAME } from "../utils/constants";
import { Octokit } from "../utils/octokit";
import type { Architecture, Platform } from "../utils/platforms"; import type { Architecture, Platform } from "../utils/platforms";
import { validateChecksum } from "./checksum/checksum"; import { validateChecksum } from "./checksum/checksum";
import { Octokit } from "../utils/octokit";
import { import {
getDownloadUrl, getDownloadUrl,
getLatestKnownVersion as getLatestVersionInManifest, getLatestKnownVersion as getLatestVersionInManifest,
} from "./version-manifest"; } from "./version-manifest";
type Release =
Endpoints["GET /repos/{owner}/{repo}/releases"]["response"]["data"][number];
export function tryGetFromToolCache( export function tryGetFromToolCache(
arch: Architecture, arch: Architecture,
version: string, version: string,
@@ -28,10 +24,11 @@ export function tryGetFromToolCache(
resolvedVersion = version; resolvedVersion = version;
} }
const installedPath = tc.find(TOOL_CACHE_NAME, resolvedVersion, arch); const installedPath = tc.find(TOOL_CACHE_NAME, resolvedVersion, arch);
return { installedPath, version: resolvedVersion }; return { version: resolvedVersion, installedPath };
} }
export async function downloadVersionFromGithub( export async function downloadVersionFromGithub(
serverUrl: string,
platform: Platform, platform: Platform,
arch: Architecture, arch: Architecture,
version: string, version: string,
@@ -40,7 +37,7 @@ export async function downloadVersionFromGithub(
): Promise<{ version: string; cachedToolDir: string }> { ): Promise<{ version: string; cachedToolDir: string }> {
const artifact = `uv-${arch}-${platform}`; const artifact = `uv-${arch}-${platform}`;
const extension = getExtension(platform); const extension = getExtension(platform);
const downloadUrl = `https://github.com/${OWNER}/${REPO}/releases/download/${version}/${artifact}${extension}`; const downloadUrl = `${serverUrl}/${OWNER}/${REPO}/releases/download/${version}/${artifact}${extension}`;
return await downloadVersion( return await downloadVersion(
downloadUrl, downloadUrl,
artifact, artifact,
@@ -71,6 +68,7 @@ export async function downloadVersionFromManifest(
`manifest-file does not contain version ${version}, arch ${arch}, platform ${platform}. Falling back to GitHub releases.`, `manifest-file does not contain version ${version}, arch ${arch}, platform ${platform}. Falling back to GitHub releases.`,
); );
return await downloadVersionFromGithub( return await downloadVersionFromGithub(
"https://github.com",
platform, platform,
arch, arch,
version, version,
@@ -123,7 +121,7 @@ async function downloadVersion(
version, version,
arch, arch,
); );
return { cachedToolDir, version: version }; return { version: version, cachedToolDir };
} }
function getExtension(platform: Platform): string { function getExtension(platform: Platform): string {
@@ -137,29 +135,19 @@ export async function resolveVersion(
): Promise<string> { ): Promise<string> {
core.debug(`Resolving version: ${versionInput}`); core.debug(`Resolving version: ${versionInput}`);
let version: string; let version: string;
const isSimpleMinimumVersionSpecifier =
versionInput.includes(">") && !versionInput.includes(",");
if (isSimpleMinimumVersionSpecifier) {
core.info("Found minimum version specifier, using latest version");
}
if (manifestFile) { if (manifestFile) {
version = version =
versionInput === "latest" || isSimpleMinimumVersionSpecifier versionInput === "latest"
? await getLatestVersionInManifest(manifestFile) ? await getLatestVersionInManifest(manifestFile)
: versionInput; : versionInput;
} else { } else {
version = version =
versionInput === "latest" || isSimpleMinimumVersionSpecifier versionInput === "latest"
? await getLatestVersion(githubToken) ? await getLatestVersion(githubToken)
: versionInput; : versionInput;
} }
if (tc.isExplicitVersion(version)) { if (tc.isExplicitVersion(version)) {
core.debug(`Version ${version} is an explicit version.`); core.debug(`Version ${version} is an explicit version.`);
if (isSimpleMinimumVersionSpecifier) {
if (!pep440.satisfies(version, versionInput)) {
throw new Error(`No version found for ${versionInput}`);
}
}
return version; return version;
} }
const availableVersions = await getAvailableVersions(githubToken); const availableVersions = await getAvailableVersions(githubToken);
@@ -172,7 +160,6 @@ export async function resolveVersion(
} }
async function getAvailableVersions(githubToken: string): Promise<string[]> { async function getAvailableVersions(githubToken: string): Promise<string[]> {
core.info("Getting available versions from GitHub API...");
try { try {
const octokit = new Octokit({ const octokit = new Octokit({
auth: githubToken, auth: githubToken,
@@ -190,25 +177,18 @@ async function getAvailableVersions(githubToken: string): Promise<string[]> {
} }
} }
async function getReleaseTagNames(octokit: Octokit): Promise<string[]> { async function getReleaseTagNames(
const response: Release[] = await octokit.paginate( octokit: InstanceType<typeof Octokit>,
octokit.rest.repos.listReleases, ): Promise<string[]> {
{ const response = await octokit.paginate(octokit.rest.repos.listReleases, {
owner: OWNER, owner: OWNER,
repo: REPO, repo: REPO,
}, });
); return response.map((release) => release.tag_name);
const releaseTagNames = response.map((release) => release.tag_name);
if (releaseTagNames.length === 0) {
throw Error(
"Github API request failed while getting releases. Check the GitHub status page for outages. Try again later.",
);
}
return releaseTagNames;
} }
async function getLatestVersion(githubToken: string) { async function getLatestVersion(githubToken: string) {
core.info("Getting latest version from GitHub API..."); core.debug("Getting latest version...");
const octokit = new Octokit({ const octokit = new Octokit({
auth: githubToken, auth: githubToken,
}); });
@@ -217,18 +197,14 @@ async function getLatestVersion(githubToken: string) {
try { try {
latestRelease = await getLatestRelease(octokit); latestRelease = await getLatestRelease(octokit);
} catch (err) { } catch (err) {
if ((err as Error).message.includes("Bad credentials")) { core.info(
core.info( "No (valid) GitHub token provided. Falling back to anonymous. Requests might be rate limited.",
"No (valid) GitHub token provided. Falling back to anonymous. Requests might be rate limited.", );
); if (err instanceof Error) {
const octokit = new Octokit(); core.debug(err.message);
latestRelease = await getLatestRelease(octokit);
} else {
core.error(
"Github API request failed while getting latest release. Check the GitHub status page for outages. Try again later.",
);
throw err;
} }
const octokit = new Octokit();
latestRelease = await getLatestRelease(octokit);
} }
if (!latestRelease) { if (!latestRelease) {
@@ -238,7 +214,7 @@ async function getLatestVersion(githubToken: string) {
return latestRelease.tag_name; return latestRelease.tag_name;
} }
async function getLatestRelease(octokit: Octokit) { async function getLatestRelease(octokit: InstanceType<typeof Octokit>) {
const { data: latestRelease } = await octokit.rest.repos.getLatestRelease({ const { data: latestRelease } = await octokit.rest.repos.getLatestRelease({
owner: OWNER, owner: OWNER,
repo: REPO, repo: REPO,

View File

@@ -1,8 +1,8 @@
import { promises as fs } from "node:fs"; import { promises as fs } from "node:fs";
import { join } from "node:path";
import * as core from "@actions/core"; import * as core from "@actions/core";
import * as semver from "semver"; import * as semver from "semver";
import { fetch } from "../utils/fetch"; import { fetch } from "../utils/fetch";
import { join } from "node:path";
const localManifestFile = join(__dirname, "..", "..", "version-manifest.json"); const localManifestFile = join(__dirname, "..", "..", "version-manifest.json");
@@ -79,11 +79,11 @@ export async function updateVersionManifest(
} }
const artifactParts = artifactName.split(".")[0].split("-"); const artifactParts = artifactName.split(".")[0].split("-");
manifest.push({ manifest.push({
arch: artifactParts[1],
artifactName: artifactName,
downloadUrl: downloadUrl,
platform: artifactName.split(`uv-${artifactParts[1]}-`)[1].split(".")[0],
version: version, version: version,
artifactName: artifactName,
arch: artifactParts[1],
platform: artifactName.split(`uv-${artifactParts[1]}-`)[1].split(".")[0],
downloadUrl: downloadUrl,
}); });
} }
core.debug(`Updating manifest-file: ${JSON.stringify(manifest)}`); core.debug(`Updating manifest-file: ${JSON.stringify(manifest)}`);

View File

@@ -1,8 +1,8 @@
import * as crypto from "node:crypto"; import * as crypto from "node:crypto";
import * as core from "@actions/core";
import * as fs from "node:fs"; import * as fs from "node:fs";
import * as stream from "node:stream"; import * as stream from "node:stream";
import * as util from "node:util"; import * as util from "node:util";
import * as core from "@actions/core";
import { create } from "@actions/glob"; import { create } from "@actions/glob";
/** /**

View File

@@ -1,31 +1,22 @@
import * as fs from "node:fs";
import * as cache from "@actions/cache"; import * as cache from "@actions/cache";
import * as core from "@actions/core"; import * as core from "@actions/core";
import * as exec from "@actions/exec"; import * as exec from "@actions/exec";
import * as pep440 from "@renovatebot/pep440"; import * as fs from "node:fs";
import { import {
STATE_CACHE_KEY,
STATE_CACHE_MATCHED_KEY, STATE_CACHE_MATCHED_KEY,
STATE_CACHE_KEY,
} from "./cache/restore-cache"; } from "./cache/restore-cache";
import { STATE_UV_PATH, STATE_UV_VERSION } from "./utils/constants";
import { import {
cacheLocalPath, cacheLocalPath,
cachePython,
enableCache, enableCache,
ignoreNothingToCache, ignoreNothingToCache,
pythonDir,
pruneCache as shouldPruneCache, pruneCache as shouldPruneCache,
saveCache as shouldSaveCache,
} from "./utils/inputs"; } from "./utils/inputs";
export async function run(): Promise<void> { export async function run(): Promise<void> {
try { try {
if (enableCache) { if (enableCache) {
if (shouldSaveCache) { await saveCache();
await saveCache();
} else {
core.info("save-cache is false. Skipping save cache step.");
}
// node will stay alive if any promises are not resolved, // node will stay alive if any promises are not resolved,
// which is a possibility if HTTP requests are dangling // which is a possibility if HTTP requests are dangling
// due to retries or timeouts. We know that if we got here // due to retries or timeouts. We know that if we got here
@@ -56,35 +47,14 @@ async function saveCache(): Promise<void> {
await pruneCache(); await pruneCache();
} }
let actualCachePath = cacheLocalPath; core.info(`Saving cache path: ${cacheLocalPath}`);
if (process.env.UV_CACHE_DIR && process.env.UV_CACHE_DIR !== cacheLocalPath) { if (!fs.existsSync(cacheLocalPath) && !ignoreNothingToCache) {
core.warning(
`The environment variable UV_CACHE_DIR has been changed to "${process.env.UV_CACHE_DIR}", by an action or step running after astral-sh/setup-uv. This can lead to unexpected behavior. If you expected this to happen set the cache-local-path input to "${process.env.UV_CACHE_DIR}" instead of "${cacheLocalPath}".`,
);
actualCachePath = process.env.UV_CACHE_DIR;
}
core.info(`Saving cache path: ${actualCachePath}`);
if (!fs.existsSync(actualCachePath) && !ignoreNothingToCache) {
throw new Error( throw new Error(
`Cache path ${actualCachePath} does not exist on disk. This likely indicates that there are no dependencies to cache. Consider disabling the cache input if it is not needed.`, `Cache path ${cacheLocalPath} does not exist on disk. This likely indicates that there are no dependencies to cache. Consider disabling the cache input if it is not needed.`,
); );
} }
const cachePaths = [actualCachePath];
if (cachePython) {
core.info(`Including Python cache path: ${pythonDir}`);
if (!fs.existsSync(pythonDir) && !ignoreNothingToCache) {
throw new Error(
`Python cache path ${pythonDir} does not exist on disk. This likely indicates that there are no dependencies to cache. Consider disabling the cache input if it is not needed.`,
);
}
cachePaths.push(pythonDir);
}
core.info(`Final cache paths: ${cachePaths.join(", ")}`);
try { try {
await cache.saveCache(cachePaths, cacheKey); await cache.saveCache([cacheLocalPath], cacheKey);
core.info(`cache saved with the key: ${cacheKey}`); core.info(`cache saved with the key: ${cacheKey}`);
} catch (e) { } catch (e) {
if ( if (
@@ -102,19 +72,13 @@ async function saveCache(): Promise<void> {
} }
async function pruneCache(): Promise<void> { async function pruneCache(): Promise<void> {
const forceSupported = pep440.gte(core.getState(STATE_UV_VERSION), "0.8.24");
const options: exec.ExecOptions = { const options: exec.ExecOptions = {
silent: false, silent: !core.isDebug(),
}; };
const execArgs = ["cache", "prune", "--ci"]; const execArgs = ["cache", "prune", "--ci"];
if (forceSupported) {
execArgs.push("--force");
}
core.info("Pruning cache..."); core.info("Pruning cache...");
const uvPath = core.getState(STATE_UV_PATH); await exec.exec("uv", execArgs, options);
await exec.exec(uvPath, execArgs, options);
} }
run(); run();

View File

@@ -1,39 +1,37 @@
import fs from "node:fs";
import * as path from "node:path";
import * as core from "@actions/core"; import * as core from "@actions/core";
import * as exec from "@actions/exec"; import * as path from "node:path";
import { restoreCache } from "./cache/restore-cache";
import { import {
downloadVersionFromManifest,
resolveVersion,
tryGetFromToolCache, tryGetFromToolCache,
resolveVersion,
downloadVersionFromGithub,
downloadVersionFromManifest,
} from "./download/download-version"; } from "./download/download-version";
import { getConfigValueFromTomlFile } from "./utils/config-file"; import { restoreCache } from "./cache/restore-cache";
import { STATE_UV_PATH, STATE_UV_VERSION } from "./utils/constants";
import {
activateEnvironment as activateEnvironmentInput,
addProblemMatchers,
cacheLocalPath,
checkSum,
enableCache,
githubToken,
ignoreEmptyWorkdir,
manifestFile,
pythonDir,
pythonVersion,
toolBinDir,
toolDir,
versionFile as versionFileInput,
version as versionInput,
workingDirectory,
} from "./utils/inputs";
import { import {
type Architecture, type Architecture,
getArch, getArch,
getPlatform, getPlatform,
type Platform, type Platform,
} from "./utils/platforms"; } from "./utils/platforms";
import { getUvVersionFromFile } from "./version/resolve"; import {
activateEnvironment as activateEnvironmentInput,
cacheLocalPath,
checkSum,
ignoreEmptyWorkdir,
enableCache,
githubToken,
pythonVersion,
toolBinDir,
toolDir,
version as versionInput,
workingDirectory,
serverUrl,
manifestFile,
} from "./utils/inputs";
import * as exec from "@actions/exec";
import fs from "node:fs";
import { getUvVersionFromConfigFile } from "./utils/config-file";
async function run(): Promise<void> { async function run(): Promise<void> {
detectEmptyWorkdir(); detectEmptyWorkdir();
@@ -52,14 +50,12 @@ async function run(): Promise<void> {
addToolBinToPath(); addToolBinToPath();
addUvToPathAndOutput(setupResult.uvDir); addUvToPathAndOutput(setupResult.uvDir);
setToolDir(); setToolDir();
addPythonDirToPath();
setupPython(); setupPython();
await activateEnvironment(); await activateEnvironment();
addMatchers(); addMatchers();
setCacheDir(); setCacheDir(cacheLocalPath);
core.setOutput("uv-version", setupResult.version); core.setOutput("uv-version", setupResult.version);
core.saveState(STATE_UV_VERSION, setupResult.version);
core.info(`Successfully installed uv version ${setupResult.version}`); core.info(`Successfully installed uv version ${setupResult.version}`);
if (enableCache) { if (enableCache) {
@@ -101,14 +97,29 @@ async function setupUv(
}; };
} }
const downloadVersionResult = await downloadVersionFromManifest( let downloadVersionResult: { version: string; cachedToolDir: string };
manifestFile, if (serverUrl !== "https://github.com") {
platform, core.warning(
arch, "The input server-url is deprecated. Please use manifest-file instead.",
resolvedVersion, );
checkSum, downloadVersionResult = await downloadVersionFromGithub(
githubToken, serverUrl,
); platform,
arch,
resolvedVersion,
checkSum,
githubToken,
);
} else {
downloadVersionResult = await downloadVersionFromManifest(
manifestFile,
platform,
arch,
resolvedVersion,
checkSum,
githubToken,
);
}
return { return {
uvDir: downloadVersionResult.cachedToolDir, uvDir: downloadVersionResult.cachedToolDir,
@@ -122,19 +133,10 @@ async function determineVersion(
if (versionInput !== "") { if (versionInput !== "") {
return await resolveVersion(versionInput, manifestFile, githubToken); return await resolveVersion(versionInput, manifestFile, githubToken);
} }
if (versionFileInput !== "") { const versionFromUvToml = getUvVersionFromConfigFile(
const versionFromFile = getUvVersionFromFile(versionFileInput);
if (versionFromFile === undefined) {
throw new Error(
`Could not determine uv version from file: ${versionFileInput}`,
);
}
return await resolveVersion(versionFromFile, manifestFile, githubToken);
}
const versionFromUvToml = getUvVersionFromFile(
`${workingDirectory}${path.sep}uv.toml`, `${workingDirectory}${path.sep}uv.toml`,
); );
const versionFromPyproject = getUvVersionFromFile( const versionFromPyproject = getUvVersionFromConfigFile(
`${workingDirectory}${path.sep}pyproject.toml`, `${workingDirectory}${path.sep}pyproject.toml`,
); );
if (versionFromUvToml === undefined && versionFromPyproject === undefined) { if (versionFromUvToml === undefined && versionFromPyproject === undefined) {
@@ -151,31 +153,18 @@ async function determineVersion(
function addUvToPathAndOutput(cachedPath: string): void { function addUvToPathAndOutput(cachedPath: string): void {
core.setOutput("uv-path", `${cachedPath}${path.sep}uv`); core.setOutput("uv-path", `${cachedPath}${path.sep}uv`);
core.saveState(STATE_UV_PATH, `${cachedPath}${path.sep}uv`);
core.setOutput("uvx-path", `${cachedPath}${path.sep}uvx`); core.setOutput("uvx-path", `${cachedPath}${path.sep}uvx`);
if (process.env.UV_NO_MODIFY_PATH !== undefined) { core.addPath(cachedPath);
core.info("UV_NO_MODIFY_PATH is set, not modifying PATH"); core.info(`Added ${cachedPath} to the path`);
} else {
core.addPath(cachedPath);
core.info(`Added ${cachedPath} to the path`);
}
} }
function addToolBinToPath(): void { function addToolBinToPath(): void {
if (toolBinDir !== undefined) { if (toolBinDir !== undefined) {
core.exportVariable("UV_TOOL_BIN_DIR", toolBinDir); core.exportVariable("UV_TOOL_BIN_DIR", toolBinDir);
core.info(`Set UV_TOOL_BIN_DIR to ${toolBinDir}`); core.info(`Set UV_TOOL_BIN_DIR to ${toolBinDir}`);
if (process.env.UV_NO_MODIFY_PATH !== undefined) { core.addPath(toolBinDir);
core.info(`UV_NO_MODIFY_PATH is set, not adding ${toolBinDir} to path`); core.info(`Added ${toolBinDir} to the path`);
} else {
core.addPath(toolBinDir);
core.info(`Added ${toolBinDir} to the path`);
}
} else { } else {
if (process.env.UV_NO_MODIFY_PATH !== undefined) {
core.info("UV_NO_MODIFY_PATH is set, not adding user local bin to path");
return;
}
if (process.env.XDG_BIN_HOME !== undefined) { if (process.env.XDG_BIN_HOME !== undefined) {
core.addPath(process.env.XDG_BIN_HOME); core.addPath(process.env.XDG_BIN_HOME);
core.info(`Added ${process.env.XDG_BIN_HOME} to the path`); core.info(`Added ${process.env.XDG_BIN_HOME} to the path`);
@@ -196,17 +185,6 @@ function setToolDir(): void {
} }
} }
function addPythonDirToPath(): void {
core.exportVariable("UV_PYTHON_INSTALL_DIR", pythonDir);
core.info(`Set UV_PYTHON_INSTALL_DIR to ${pythonDir}`);
if (process.env.UV_NO_MODIFY_PATH !== undefined) {
core.info("UV_NO_MODIFY_PATH is set, not adding python dir to path");
} else {
core.addPath(pythonDir);
core.info(`Added ${pythonDir} to the path`);
}
}
function setupPython(): void { function setupPython(): void {
if (pythonVersion !== "") { if (pythonVersion !== "") {
core.exportVariable("UV_PYTHON", pythonVersion); core.exportVariable("UV_PYTHON", pythonVersion);
@@ -216,46 +194,31 @@ function setupPython(): void {
async function activateEnvironment(): Promise<void> { async function activateEnvironment(): Promise<void> {
if (activateEnvironmentInput) { if (activateEnvironmentInput) {
if (process.env.UV_NO_MODIFY_PATH !== undefined) {
throw new Error(
"UV_NO_MODIFY_PATH and activate-environment cannot be used together.",
);
}
const execArgs = ["venv", ".venv", "--directory", workingDirectory]; const execArgs = ["venv", ".venv", "--directory", workingDirectory];
core.info("Activating python venv..."); core.info("Activating python venv...");
await exec.exec("uv", execArgs); await exec.exec("uv", execArgs);
const venvPath = path.resolve(`${workingDirectory}${path.sep}.venv`); let venvBinPath = `${workingDirectory}${path.sep}.venv${path.sep}bin`;
let venvBinPath = `${venvPath}${path.sep}bin`;
if (process.platform === "win32") { if (process.platform === "win32") {
venvBinPath = `${venvPath}${path.sep}Scripts`; venvBinPath = `${workingDirectory}${path.sep}.venv${path.sep}Scripts`;
} }
core.addPath(path.resolve(venvBinPath)); core.addPath(path.resolve(venvBinPath));
core.exportVariable("VIRTUAL_ENV", venvPath); core.exportVariable(
core.setOutput("venv", venvPath); "VIRTUAL_ENV",
path.resolve(`${workingDirectory}${path.sep}.venv`),
);
} }
} }
function setCacheDir(): void { function setCacheDir(cacheLocalPath: string): void {
if (enableCache) { core.exportVariable("UV_CACHE_DIR", cacheLocalPath);
const cacheDirFromConfig = getConfigValueFromTomlFile("", "cache-dir"); core.info(`Set UV_CACHE_DIR to ${cacheLocalPath}`);
if (cacheDirFromConfig !== undefined) {
core.info(
"Using cache-dir from uv config file, not modifying UV_CACHE_DIR",
);
return;
}
core.exportVariable("UV_CACHE_DIR", cacheLocalPath);
core.info(`Set UV_CACHE_DIR to ${cacheLocalPath}`);
}
} }
function addMatchers(): void { function addMatchers(): void {
if (addProblemMatchers) { const matchersPath = path.join(__dirname, `..${path.sep}..`, ".github");
const matchersPath = path.join(__dirname, `..${path.sep}..`, ".github"); core.info(`##[add-matcher]${path.join(matchersPath, "python.json")}`);
core.info(`##[add-matcher]${path.join(matchersPath, "python.json")}`);
}
} }
run(); run();

View File

@@ -1,16 +1,14 @@
import * as core from "@actions/core";
import type { Endpoints } from "@octokit/types";
import * as semver from "semver"; import * as semver from "semver";
import { updateChecksums } from "./download/checksum/update-known-checksums"; import * as core from "@actions/core";
import {
getLatestKnownVersion,
updateVersionManifest,
} from "./download/version-manifest";
import { OWNER, REPO } from "./utils/constants";
import { Octokit } from "./utils/octokit"; import { Octokit } from "./utils/octokit";
type Release = import { OWNER, REPO } from "./utils/constants";
Endpoints["GET /repos/{owner}/{repo}/releases"]["response"]["data"][number];
import { updateChecksums } from "./download/checksum/update-known-checksums";
import {
updateVersionManifest,
getLatestKnownVersion,
} from "./download/version-manifest";
async function run(): Promise<void> { async function run(): Promise<void> {
const checksumFilePath = process.argv.slice(2)[0]; const checksumFilePath = process.argv.slice(2)[0];
@@ -35,13 +33,10 @@ async function run(): Promise<void> {
return; return;
} }
const releases: Release[] = await octokit.paginate( const releases = await octokit.paginate(octokit.rest.repos.listReleases, {
octokit.rest.repos.listReleases, owner: OWNER,
{ repo: REPO,
owner: OWNER, });
repo: REPO,
},
);
const checksumDownloadUrls: string[] = releases.flatMap((release) => const checksumDownloadUrls: string[] = releases.flatMap((release) =>
release.assets release.assets
.filter((asset) => asset.name.endsWith(".sha256")) .filter((asset) => asset.name.endsWith(".sha256"))

View File

@@ -1,24 +1,46 @@
import fs from "node:fs"; import fs from "node:fs";
import * as core from "@actions/core";
import * as toml from "smol-toml"; import * as toml from "smol-toml";
export function getConfigValueFromTomlFile( export function getUvVersionFromConfigFile(
filePath: string, filePath: string,
key: string,
): string | undefined { ): string | undefined {
if (!fs.existsSync(filePath) || !filePath.endsWith(".toml")) { core.info(`Trying to find required-version for uv in: ${filePath}`);
if (!fs.existsSync(filePath)) {
core.info(`Could not find file: ${filePath}`);
return undefined; return undefined;
} }
let requiredVersion: string | undefined;
try {
requiredVersion = getRequiredVersion(filePath);
} catch (err) {
const message = (err as Error).message;
core.warning(`Error while parsing ${filePath}: ${message}`);
return undefined;
}
if (requiredVersion?.startsWith("==")) {
requiredVersion = requiredVersion.slice(2);
}
if (requiredVersion !== undefined) {
core.info(
`Found required-version for uv in ${filePath}: ${requiredVersion}`,
);
}
return requiredVersion;
}
function getRequiredVersion(filePath: string): string | undefined {
const fileContent = fs.readFileSync(filePath, "utf-8"); const fileContent = fs.readFileSync(filePath, "utf-8");
if (filePath.endsWith("pyproject.toml")) { if (filePath.endsWith("pyproject.toml")) {
const tomlContent = toml.parse(fileContent) as { const tomlContent = toml.parse(fileContent) as {
tool?: { uv?: Record<string, string | undefined> }; tool?: { uv?: { "required-version"?: string } };
}; };
return tomlContent?.tool?.uv?.[key]; return tomlContent?.tool?.uv?.["required-version"];
} }
const tomlContent = toml.parse(fileContent) as Record< const tomlContent = toml.parse(fileContent) as {
string, "required-version"?: string;
string | undefined };
>; return tomlContent["required-version"];
return tomlContent[key];
} }

View File

@@ -1,5 +1,3 @@
export const REPO = "uv"; export const REPO = "uv";
export const OWNER = "astral-sh"; export const OWNER = "astral-sh";
export const TOOL_CACHE_NAME = "uv"; export const TOOL_CACHE_NAME = "uv";
export const STATE_UV_PATH = "uv-path";
export const STATE_UV_VERSION = "uv-version";

View File

@@ -1,4 +1,4 @@
import { ProxyAgent, type RequestInit, fetch as undiciFetch } from "undici"; import { fetch as undiciFetch, ProxyAgent, type RequestInit } from "undici";
export function getProxyAgent() { export function getProxyAgent() {
const httpProxy = process.env.HTTP_PROXY || process.env.http_proxy; const httpProxy = process.env.HTTP_PROXY || process.env.http_proxy;

View File

@@ -1,41 +1,26 @@
import path from "node:path";
import * as core from "@actions/core"; import * as core from "@actions/core";
import { getConfigValueFromTomlFile } from "./config-file"; import path from "node:path";
import { getManifestFromRepo } from "@actions/tool-cache";
export const workingDirectory = core.getInput("working-directory");
export const version = core.getInput("version"); export const version = core.getInput("version");
export const versionFile = getVersionFile();
export const pythonVersion = core.getInput("python-version"); export const pythonVersion = core.getInput("python-version");
export const activateEnvironment = core.getBooleanInput("activate-environment"); export const activateEnvironment = core.getBooleanInput("activate-environment");
export const workingDirectory = core.getInput("working-directory");
export const checkSum = core.getInput("checksum"); export const checkSum = core.getInput("checksum");
export const enableCache = getEnableCache(); export const enableCache = getEnableCache();
export const restoreCache = core.getInput("restore-cache") === "true";
export const saveCache = core.getInput("save-cache") === "true";
export const cacheSuffix = core.getInput("cache-suffix") || ""; export const cacheSuffix = core.getInput("cache-suffix") || "";
export const cacheLocalPath = getCacheLocalPath(); export const cacheLocalPath = getCacheLocalPath();
export const cacheDependencyGlob = getCacheDependencyGlob(); export const cacheDependencyGlob = core.getInput("cache-dependency-glob");
export const pruneCache = core.getInput("prune-cache") === "true"; export const pruneCache = core.getInput("prune-cache") === "true";
export const cachePython = core.getInput("cache-python") === "true";
export const ignoreNothingToCache = export const ignoreNothingToCache =
core.getInput("ignore-nothing-to-cache") === "true"; core.getInput("ignore-nothing-to-cache") === "true";
export const ignoreEmptyWorkdir = export const ignoreEmptyWorkdir =
core.getInput("ignore-empty-workdir") === "true"; core.getInput("ignore-empty-workdir") === "true";
export const toolBinDir = getToolBinDir(); export const toolBinDir = getToolBinDir();
export const toolDir = getToolDir(); export const toolDir = getToolDir();
export const pythonDir = getUvPythonDir(); export const serverUrl = core.getInput("server-url");
export const githubToken = core.getInput("github-token"); export const githubToken = core.getInput("github-token");
export const manifestFile = getManifestFile(); export const manifestFile = getManifestFile();
export const addProblemMatchers =
core.getInput("add-problem-matchers") === "true";
function getVersionFile(): string {
const versionFileInput = core.getInput("version-file");
if (versionFileInput !== "") {
const tildeExpanded = expandTilde(versionFileInput);
return resolveRelativePath(tildeExpanded);
}
return versionFileInput;
}
function getEnableCache(): boolean { function getEnableCache(): boolean {
const enableCacheInput = core.getInput("enable-cache"); const enableCacheInput = core.getInput("enable-cache");
@@ -48,8 +33,7 @@ function getEnableCache(): boolean {
function getToolBinDir(): string | undefined { function getToolBinDir(): string | undefined {
const toolBinDirInput = core.getInput("tool-bin-dir"); const toolBinDirInput = core.getInput("tool-bin-dir");
if (toolBinDirInput !== "") { if (toolBinDirInput !== "") {
const tildeExpanded = expandTilde(toolBinDirInput); return expandTilde(toolBinDirInput);
return resolveRelativePath(tildeExpanded);
} }
if (process.platform === "win32") { if (process.platform === "win32") {
if (process.env.RUNNER_TEMP !== undefined) { if (process.env.RUNNER_TEMP !== undefined) {
@@ -65,8 +49,7 @@ function getToolBinDir(): string | undefined {
function getToolDir(): string | undefined { function getToolDir(): string | undefined {
const toolDirInput = core.getInput("tool-dir"); const toolDirInput = core.getInput("tool-dir");
if (toolDirInput !== "") { if (toolDirInput !== "") {
const tildeExpanded = expandTilde(toolDirInput); return expandTilde(toolDirInput);
return resolveRelativePath(tildeExpanded);
} }
if (process.platform === "win32") { if (process.platform === "win32") {
if (process.env.RUNNER_TEMP !== undefined) { if (process.env.RUNNER_TEMP !== undefined) {
@@ -82,16 +65,7 @@ function getToolDir(): string | undefined {
function getCacheLocalPath(): string { function getCacheLocalPath(): string {
const cacheLocalPathInput = core.getInput("cache-local-path"); const cacheLocalPathInput = core.getInput("cache-local-path");
if (cacheLocalPathInput !== "") { if (cacheLocalPathInput !== "") {
const tildeExpanded = expandTilde(cacheLocalPathInput); return expandTilde(cacheLocalPathInput);
return resolveRelativePath(tildeExpanded);
}
const cacheDirFromConfig = getCacheDirFromConfig();
if (cacheDirFromConfig !== undefined) {
return cacheDirFromConfig;
}
if (process.env.UV_CACHE_DIR !== undefined) {
core.info(`UV_CACHE_DIR is already set to ${process.env.UV_CACHE_DIR}`);
return process.env.UV_CACHE_DIR;
} }
if (process.env.RUNNER_ENVIRONMENT === "github-hosted") { if (process.env.RUNNER_ENVIRONMENT === "github-hosted") {
if (process.env.RUNNER_TEMP !== undefined) { if (process.env.RUNNER_TEMP !== undefined) {
@@ -107,59 +81,6 @@ function getCacheLocalPath(): string {
return `${process.env.HOME}${path.sep}.cache${path.sep}uv`; return `${process.env.HOME}${path.sep}.cache${path.sep}uv`;
} }
function getCacheDirFromConfig(): string | undefined {
for (const filePath of [versionFile, "uv.toml", "pyproject.toml"]) {
const resolvedPath = resolveRelativePath(filePath);
try {
const cacheDir = getConfigValueFromTomlFile(resolvedPath, "cache-dir");
if (cacheDir !== undefined) {
core.info(`Found cache-dir in ${resolvedPath}: ${cacheDir}`);
return cacheDir;
}
} catch (err) {
const message = (err as Error).message;
core.warning(`Error while parsing ${filePath}: ${message}`);
return undefined;
}
}
return undefined;
}
export function getUvPythonDir(): string {
if (process.env.UV_PYTHON_INSTALL_DIR !== undefined) {
core.info(
`UV_PYTHON_INSTALL_DIR is already set to ${process.env.UV_PYTHON_INSTALL_DIR}`,
);
return process.env.UV_PYTHON_INSTALL_DIR;
}
if (process.env.RUNNER_ENVIRONMENT !== "github-hosted") {
if (process.platform === "win32") {
return `${process.env.APPDATA}${path.sep}uv${path.sep}python`;
} else {
return `${process.env.HOME}${path.sep}.local${path.sep}share${path.sep}uv${path.sep}python`;
}
}
if (process.env.RUNNER_TEMP !== undefined) {
return `${process.env.RUNNER_TEMP}${path.sep}uv-python-dir`;
}
throw Error(
"Could not determine UV_PYTHON_INSTALL_DIR. Please make sure RUNNER_TEMP is set or provide the UV_PYTHON_INSTALL_DIR environment variable",
);
}
function getCacheDependencyGlob(): string {
const cacheDependencyGlobInput = core.getInput("cache-dependency-glob");
if (cacheDependencyGlobInput !== "") {
return cacheDependencyGlobInput
.split("\n")
.map((part) => part.trim())
.map((part) => expandTilde(part))
.map((part) => resolveRelativePath(part))
.join("\n");
}
return cacheDependencyGlobInput;
}
function expandTilde(input: string): string { function expandTilde(input: string): string {
if (input.startsWith("~")) { if (input.startsWith("~")) {
return `${process.env.HOME}${input.substring(1)}`; return `${process.env.HOME}${input.substring(1)}`;
@@ -167,18 +88,6 @@ function expandTilde(input: string): string {
return input; return input;
} }
function resolveRelativePath(inputPath: string): string {
const hasNegation = inputPath.startsWith("!");
const pathWithoutNegation = hasNegation ? inputPath.substring(1) : inputPath;
const resolvedPath = path.resolve(workingDirectory, pathWithoutNegation);
core.debug(
`Resolving relative path ${inputPath} to ${hasNegation ? "!" : ""}${resolvedPath}`,
);
return hasNegation ? `!${resolvedPath}` : resolvedPath;
}
function getManifestFile(): string | undefined { function getManifestFile(): string | undefined {
const manifestFileInput = core.getInput("manifest-file"); const manifestFileInput = core.getInput("manifest-file");
if (manifestFileInput !== "") { if (manifestFileInput !== "") {

View File

@@ -1,8 +1,11 @@
import type { OctokitOptions } from "@octokit/core";
import { Octokit as Core } from "@octokit/core"; import { Octokit as Core } from "@octokit/core";
import type {
Constructor,
OctokitOptions,
} from "@octokit/core/dist-types/types";
import { import {
type PaginateInterface,
paginateRest, paginateRest,
type PaginateInterface,
} from "@octokit/plugin-paginate-rest"; } from "@octokit/plugin-paginate-rest";
import { legacyRestEndpointMethods } from "@octokit/plugin-rest-endpoint-methods"; import { legacyRestEndpointMethods } from "@octokit/plugin-rest-endpoint-methods";
import { fetch as customFetch } from "./fetch"; import { fetch as customFetch } from "./fetch";
@@ -14,21 +17,22 @@ const DEFAULTS = {
userAgent: "setup-uv", userAgent: "setup-uv",
}; };
const OctokitWithPlugins = Core.plugin(paginateRest, legacyRestEndpointMethods); export const Octokit: typeof Core &
Constructor<
{
paginate: PaginateInterface;
} & ReturnType<typeof legacyRestEndpointMethods>
> = Core.plugin(paginateRest, legacyRestEndpointMethods).defaults(
function buildDefaults(options: OctokitOptions): OctokitOptions {
return {
...DEFAULTS,
...options,
request: {
fetch: customFetch,
...options.request,
},
};
},
);
export const Octokit = OctokitWithPlugins.defaults(function buildDefaults( export type Octokit = InstanceType<typeof Octokit>;
options: OctokitOptions,
): OctokitOptions {
return {
...DEFAULTS,
...options,
request: {
fetch: customFetch,
...options.request,
},
};
});
export type Octokit = InstanceType<typeof OctokitWithPlugins> & {
paginate: PaginateInterface;
};

View File

@@ -1,5 +1,5 @@
import * as core from "@actions/core";
import * as exec from "@actions/exec"; import * as exec from "@actions/exec";
import * as core from "@actions/core";
export type Platform = export type Platform =
| "unknown-linux-gnu" | "unknown-linux-gnu"
| "unknown-linux-musl" | "unknown-linux-musl"
@@ -16,11 +16,11 @@ export type Architecture =
export function getArch(): Architecture | undefined { export function getArch(): Architecture | undefined {
const arch = process.arch; const arch = process.arch;
const archMapping: { [key: string]: Architecture } = { const archMapping: { [key: string]: Architecture } = {
arm64: "aarch64",
ia32: "i686", ia32: "i686",
ppc64: "powerpc64le",
s390x: "s390x",
x64: "x86_64", x64: "x86_64",
arm64: "aarch64",
s390x: "s390x",
ppc64: "powerpc64le",
}; };
if (arch in archMapping) { if (arch in archMapping) {
@@ -31,8 +31,8 @@ export function getArch(): Architecture | undefined {
export async function getPlatform(): Promise<Platform | undefined> { export async function getPlatform(): Promise<Platform | undefined> {
const processPlatform = process.platform; const processPlatform = process.platform;
const platformMapping: { [key: string]: Platform } = { const platformMapping: { [key: string]: Platform } = {
darwin: "apple-darwin",
linux: "unknown-linux-gnu", linux: "unknown-linux-gnu",
darwin: "apple-darwin",
win32: "pc-windows-msvc", win32: "pc-windows-msvc",
}; };
@@ -50,16 +50,16 @@ async function isMuslOs(): Promise<boolean> {
let stdOutput = ""; let stdOutput = "";
let errOutput = ""; let errOutput = "";
const options: exec.ExecOptions = { const options: exec.ExecOptions = {
ignoreReturnCode: true, silent: !core.isDebug(),
listeners: { listeners: {
stderr: (data: Buffer) => {
errOutput += data.toString();
},
stdout: (data: Buffer) => { stdout: (data: Buffer) => {
stdOutput += data.toString(); stdOutput += data.toString();
}, },
stderr: (data: Buffer) => {
errOutput += data.toString();
},
}, },
silent: !core.isDebug(), ignoreReturnCode: true,
}; };
try { try {

View File

@@ -1,43 +0,0 @@
import fs from "node:fs";
import * as toml from "smol-toml";
export function getUvVersionFromRequirementsFile(
filePath: string,
): string | undefined {
const fileContent = fs.readFileSync(filePath, "utf-8");
if (filePath.endsWith(".txt")) {
return getUvVersionFromAllDependencies(fileContent.split("\n"));
}
const dependencies = parsePyprojectDependencies(fileContent);
return getUvVersionFromAllDependencies(dependencies);
}
function getUvVersionFromAllDependencies(
allDependencies: string[],
): string | undefined {
return allDependencies
.find((dep: string) => dep.match(/^uv[=<>~!]/))
?.match(/^uv([=<>~!]+\S*)/)?.[1]
.trim();
}
interface Pyproject {
project?: {
dependencies?: string[];
"optional-dependencies"?: Record<string, string[]>;
};
"dependency-groups"?: Record<string, Array<string | object>>;
}
function parsePyprojectDependencies(pyprojectContent: string): string[] {
const pyproject: Pyproject = toml.parse(pyprojectContent);
const dependencies: string[] = pyproject?.project?.dependencies || [];
const optionalDependencies: string[] = Object.values(
pyproject?.project?.["optional-dependencies"] || {},
).flat();
const devDependencies: string[] = Object.values(
pyproject?.["dependency-groups"] || {},
)
.flat()
.filter((item: string | object) => typeof item === "string");
return dependencies.concat(optionalDependencies, devDependencies);
}

View File

@@ -1,34 +0,0 @@
import fs from "node:fs";
import * as core from "@actions/core";
import { getConfigValueFromTomlFile } from "../utils/config-file";
import { getUvVersionFromRequirementsFile } from "./requirements-file";
import { getUvVersionFromToolVersions } from "./tool-versions-file";
export function getUvVersionFromFile(filePath: string): string | undefined {
core.info(`Trying to find version for uv in: ${filePath}`);
if (!fs.existsSync(filePath)) {
core.info(`Could not find file: ${filePath}`);
return undefined;
}
let uvVersion: string | undefined;
try {
uvVersion = getUvVersionFromToolVersions(filePath);
if (uvVersion === undefined) {
uvVersion = getConfigValueFromTomlFile(filePath, "required-version");
}
if (uvVersion === undefined) {
uvVersion = getUvVersionFromRequirementsFile(filePath);
}
} catch (err) {
const message = (err as Error).message;
core.warning(`Error while parsing ${filePath}: ${message}`);
return undefined;
}
if (uvVersion?.startsWith("==")) {
uvVersion = uvVersion.slice(2);
}
if (uvVersion !== undefined) {
core.info(`Found version for uv in ${filePath}: ${uvVersion}`);
}
return uvVersion;
}

View File

@@ -1,31 +0,0 @@
import fs from "node:fs";
import * as core from "@actions/core";
export function getUvVersionFromToolVersions(
filePath: string,
): string | undefined {
if (!filePath.endsWith(".tool-versions")) {
return undefined;
}
const fileContents = fs.readFileSync(filePath, "utf8");
const lines = fileContents.split("\n");
for (const line of lines) {
// Skip commented lines
if (line.trim().startsWith("#")) {
continue;
}
const match = line.match(/^\s*uv\s*v?\s*(?<version>[^\s]+)\s*$/);
if (match) {
const matchedVersion = match.groups?.version.trim();
if (matchedVersion?.startsWith("ref")) {
core.warning(
"The ref syntax of .tool-versions is not supported. Please use a released version instead.",
);
return undefined;
}
return matchedVersion;
}
}
return undefined;
}

View File

@@ -1,12 +1,12 @@
{ {
"compilerOptions": { "compilerOptions": {
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, "target": "ES2022" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
"module": "nodenext" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */, "module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
"outDir": "./lib" /* Redirect output structure to the directory. */, "outDir": "./lib" /* Redirect output structure to the directory. */,
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */, "rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
"strict": true /* Enable all strict type-checking options. */, "strict": true /* Enable all strict type-checking options. */,
"target": "ES2024" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ "noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
}, },
"exclude": ["node_modules", "**/*.test.ts"] "exclude": ["node_modules", "**/*.test.ts"]
} }

File diff suppressed because it is too large Load Diff