mirror of
https://github.com/astral-sh/setup-uv.git
synced 2026-11-19 23:45:59 +00:00
Compare commits
No files matched your search
@@ -1,2 +1,3 @@
|
||||
* text=auto eol=lf
|
||||
dist/** -diff linguist-generated=true
|
||||
src/download/checksum/known-checksums.json linguist-generated=true
|
||||
@@ -8,6 +8,10 @@ self-hosted-runner:
|
||||
# Empty array means no configuration variable is allowed.
|
||||
config-variables: null
|
||||
paths:
|
||||
.github/workflows/**/*.{yml,yaml}:
|
||||
ignore:
|
||||
- 'specifying action "\$/" in invalid format because ref is missing'
|
||||
- 'reusable workflow call "\$/.+" at "uses" is not following the format'
|
||||
.github/workflows/test.yml:
|
||||
ignore:
|
||||
- 'invalid runner name.+'
|
||||
@@ -5,11 +5,11 @@ updates:
|
||||
schedule:
|
||||
interval: daily
|
||||
cooldown:
|
||||
default-days: 7
|
||||
default-days: 30
|
||||
|
||||
- package-ecosystem: npm
|
||||
directory: /
|
||||
schedule:
|
||||
interval: daily
|
||||
cooldown:
|
||||
default-days: 7
|
||||
default-days: 30
|
||||
@@ -47,7 +47,7 @@ jobs:
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
|
||||
uses: github/codeql-action/init@2892aa5e19bbd11bc0cff5427e3b750a04d9e3c2 # v4.38.2
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
source-root: src
|
||||
@@ -59,7 +59,7 @@ jobs:
|
||||
# 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)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
|
||||
uses: github/codeql-action/autobuild@2892aa5e19bbd11bc0cff5427e3b750a04d9e3c2 # v4.38.2
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
@@ -73,4 +73,4 @@ jobs:
|
||||
# make release
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
|
||||
uses: github/codeql-action/analyze@2892aa5e19bbd11bc0cff5427e3b750a04d9e3c2 # v4.38.2
|
||||
@@ -19,7 +19,7 @@ jobs:
|
||||
pull-requests: read
|
||||
steps:
|
||||
- name: 🚀 Run Release Drafter
|
||||
uses: release-drafter/release-drafter@34d80673e067bdc0c24568d3af899c216adcfaa9 # v7.7.0
|
||||
uses: release-drafter/release-drafter@978bb0b30c5ee8cdd332ced253758157150d43f0 # v7.10.0
|
||||
with:
|
||||
commitish: ${{ github.sha }}
|
||||
env:
|
||||
|
||||
@@ -116,7 +116,7 @@ jobs:
|
||||
name: Update docs
|
||||
needs:
|
||||
- release
|
||||
uses: ./.github/workflows/update-docs.yml
|
||||
uses: $/.github/workflows/update-docs.yml
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
|
||||
+110
-126
@@ -27,18 +27,20 @@ jobs:
|
||||
- name: Actionlint
|
||||
uses: eifinger/actionlint-action@1fc89649be682d16ec5cf65ea16e269eb88d3982 # v1.10.2
|
||||
- name: Run zizmor
|
||||
uses: zizmorcore/zizmor-action@3dc1ecc9bcb9e94e9b2c709687979e1298497054 # v0.6.2
|
||||
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
|
||||
uses: zizmorcore/zizmor-action@85b2b9fb8e3325e7a23d7d0a9d7ba5ae0f999e3e # v0.7.1
|
||||
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
|
||||
with:
|
||||
node-version-file: .nvmrc
|
||||
cache: npm
|
||||
- run: |
|
||||
npm ci --ignore-scripts
|
||||
- name: Verify npm package signatures
|
||||
run: npm audit signatures
|
||||
- run: |
|
||||
npm run all
|
||||
- name: Check all jobs are in all-tests-passed.needs
|
||||
run: |
|
||||
tsc -p tsconfig.json
|
||||
npx --no-install tsc -p tsconfig.json
|
||||
node check-all-tests-passed-needs.js
|
||||
working-directory: .github/scripts
|
||||
- name: Make sure no changes from linters are detected
|
||||
@@ -49,14 +51,16 @@ jobs:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, macos-14, windows-latest]
|
||||
os: [ubuntu-latest, macos-latest, macos-15, windows-latest]
|
||||
steps:
|
||||
- if: runner.os == 'macOS'
|
||||
uses: astral-sh/github-actions/demudhra@67dc9ee1ddc113eccd8116e7b949fb6cdcd89889 # 2026.11.16.0
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Install latest version
|
||||
id: setup-uv
|
||||
uses: ./
|
||||
uses: $/
|
||||
- run: uv sync
|
||||
working-directory: __tests__/fixtures/uv-project
|
||||
shell: bash
|
||||
@@ -81,7 +85,7 @@ jobs:
|
||||
persist-credentials: false
|
||||
- name: Install with UV_NO_MODIFY_PATH set
|
||||
id: setup-uv
|
||||
uses: ./
|
||||
uses: $/
|
||||
env:
|
||||
UV_NO_MODIFY_PATH: 1
|
||||
- run: |
|
||||
@@ -130,8 +134,9 @@ jobs:
|
||||
persist-credentials: false
|
||||
- name: Install version ${{ matrix.input.version-input }} with strategy ${{ matrix.input.resolution-strategy || 'highest' }}
|
||||
id: setup-uv
|
||||
uses: ./
|
||||
uses: $/
|
||||
with:
|
||||
enable-cache: false
|
||||
version: ${{ matrix.input.version-input }}
|
||||
resolution-strategy: ${{ matrix.input.resolution-strategy || 'highest' }}
|
||||
- name: Correct version gets installed
|
||||
@@ -154,11 +159,8 @@ jobs:
|
||||
matrix:
|
||||
version-input: ["latest", ">=0.8"]
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Install version ${{ matrix.version-input }}
|
||||
uses: ./
|
||||
uses: $/
|
||||
with:
|
||||
version: ${{ matrix.version-input }}
|
||||
- name: Latest version gets installed
|
||||
@@ -198,7 +200,7 @@ jobs:
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Install version from ${{ matrix.input.working-directory }}
|
||||
uses: ./
|
||||
uses: $/
|
||||
with:
|
||||
working-directory: ${{ matrix.input.working-directory }}
|
||||
- name: Correct version gets installed
|
||||
@@ -224,8 +226,9 @@ jobs:
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Install version from ${{ matrix.input.version-file }}
|
||||
uses: ./
|
||||
uses: $/
|
||||
with:
|
||||
enable-cache: false
|
||||
version-file: ${{ matrix.input.version-file }}
|
||||
- name: Correct version gets installed
|
||||
run: |
|
||||
@@ -242,8 +245,9 @@ jobs:
|
||||
persist-credentials: false
|
||||
- name: Install versions from .tool-versions
|
||||
id: setup-uv
|
||||
uses: ./
|
||||
uses: $/
|
||||
with:
|
||||
enable-cache: false
|
||||
version-file: "__tests__/fixtures/.tool-versions"
|
||||
- name: Verify Python version from .tool-versions
|
||||
run: |
|
||||
@@ -267,7 +271,7 @@ jobs:
|
||||
persist-credentials: false
|
||||
- name: Install using malformed pyproject.toml
|
||||
id: setup-uv
|
||||
uses: ./
|
||||
uses: $/
|
||||
with:
|
||||
working-directory: "__tests__/fixtures/malformed-pyproject-toml-project"
|
||||
- run: uv --help
|
||||
@@ -282,11 +286,13 @@ jobs:
|
||||
- os: macos-latest
|
||||
checksum: "a70cbfbf3bb5c08b2f84963b4f12c94e08fbb2468ba418a3bfe1066fbe9e7218"
|
||||
steps:
|
||||
- if: runner.os == 'macOS'
|
||||
uses: astral-sh/github-actions/demudhra@67dc9ee1ddc113eccd8116e7b949fb6cdcd89889 # 2026.11.16.0
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Checksum matches expected
|
||||
uses: ./
|
||||
uses: $/
|
||||
with:
|
||||
version: "0.3.2"
|
||||
checksum: ${{ matrix.inputs.checksum }}
|
||||
@@ -300,7 +306,7 @@ jobs:
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Install default version
|
||||
uses: ./
|
||||
uses: $/
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
- run: uv sync
|
||||
@@ -309,25 +315,21 @@ jobs:
|
||||
test-uvx:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Install default version
|
||||
uses: ./
|
||||
- run: uvx ruff --version
|
||||
uses: $/
|
||||
- run: uvx ruff@0.14.10 --version
|
||||
|
||||
test-tool-install:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, macos-14, windows-latest]
|
||||
os: [ubuntu-latest, macos-latest, macos-15, windows-latest]
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
- if: runner.os == 'macOS'
|
||||
uses: astral-sh/github-actions/demudhra@67dc9ee1ddc113eccd8116e7b949fb6cdcd89889 # 2026.11.16.0
|
||||
- name: Install default version
|
||||
uses: ./
|
||||
- run: uv tool install ruff
|
||||
uses: $/
|
||||
- run: uv tool install ruff==0.14.10
|
||||
- run: ruff --version
|
||||
|
||||
test-python-version:
|
||||
@@ -336,12 +338,14 @@ jobs:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
steps:
|
||||
- if: runner.os == 'macOS'
|
||||
uses: astral-sh/github-actions/demudhra@67dc9ee1ddc113eccd8116e7b949fb6cdcd89889 # 2026.11.16.0
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Install latest version
|
||||
id: setup-uv
|
||||
uses: ./
|
||||
uses: $/
|
||||
with:
|
||||
python-version: 3.13.1t
|
||||
- name: Verify UV_PYTHON is set to correct version
|
||||
@@ -356,9 +360,14 @@ jobs:
|
||||
if [ "$PYTHON_VERSION" != "3.13.1t" ]; then
|
||||
exit 1
|
||||
fi
|
||||
if [ -n "$PYTHON_RUNTIME_ID" ]; then
|
||||
echo "python-runtime-id should be empty without environment activation"
|
||||
exit 1
|
||||
fi
|
||||
shell: bash
|
||||
env:
|
||||
PYTHON_VERSION: ${{ steps.setup-uv.outputs.python-version }}
|
||||
PYTHON_RUNTIME_ID: ${{ steps.setup-uv.outputs.python-runtime-id }}
|
||||
- run: uv sync
|
||||
working-directory: __tests__/fixtures/uv-project
|
||||
|
||||
@@ -368,12 +377,11 @@ jobs:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
- if: runner.os == 'macOS'
|
||||
uses: astral-sh/github-actions/demudhra@67dc9ee1ddc113eccd8116e7b949fb6cdcd89889 # 2026.11.16.0
|
||||
- name: Install latest version
|
||||
id: setup-uv
|
||||
uses: ./
|
||||
uses: $/
|
||||
with:
|
||||
python-version: 3.13.1t
|
||||
activate-environment: true
|
||||
@@ -407,12 +415,11 @@ jobs:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
- if: runner.os == 'macOS'
|
||||
uses: astral-sh/github-actions/demudhra@67dc9ee1ddc113eccd8116e7b949fb6cdcd89889 # 2026.11.16.0
|
||||
- name: Install latest version
|
||||
id: setup-uv
|
||||
uses: ./
|
||||
uses: $/
|
||||
with:
|
||||
python-version: 3.13.1t
|
||||
activate-environment: true
|
||||
@@ -454,13 +461,19 @@ jobs:
|
||||
raise SystemExit(f"Python is not running from custom venv: {sys.executable}")
|
||||
PY
|
||||
shell: bash
|
||||
- name: Verify Python runtime ID from custom venv
|
||||
run: |
|
||||
case "$PYTHON_RUNTIME_ID" in
|
||||
cpython-3.13.1+freethreaded-*) ;;
|
||||
*) echo "Wrong Python runtime ID: $PYTHON_RUNTIME_ID"; exit 1 ;;
|
||||
esac
|
||||
shell: bash
|
||||
env:
|
||||
PYTHON_RUNTIME_ID: ${{ steps.setup-uv.outputs.python-runtime-id }}
|
||||
|
||||
test-activate-environment-no-project:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Create incompatible pyproject.toml
|
||||
run: |
|
||||
cat > pyproject.toml <<'EOF'
|
||||
@@ -476,7 +489,7 @@ jobs:
|
||||
shell: bash
|
||||
- name: Install latest version with no-project
|
||||
id: setup-uv
|
||||
uses: ./
|
||||
uses: $/
|
||||
with:
|
||||
python-version: 3.13.1t
|
||||
activate-environment: true
|
||||
@@ -506,7 +519,7 @@ jobs:
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Install latest version
|
||||
uses: ./
|
||||
uses: $/
|
||||
with:
|
||||
enable-cache: true
|
||||
- run: uv sync
|
||||
@@ -521,7 +534,7 @@ jobs:
|
||||
persist-credentials: false
|
||||
- name: Install latest version
|
||||
id: setup-uv
|
||||
uses: ./
|
||||
uses: $/
|
||||
with:
|
||||
enable-cache: true
|
||||
- name: Verify cache key contains alpine
|
||||
@@ -546,8 +559,6 @@ jobs:
|
||||
expected-os: "ubuntu-22.04"
|
||||
- os: ubuntu-24.04
|
||||
expected-os: "ubuntu-24.04"
|
||||
- os: macos-14
|
||||
expected-os: "macos-14"
|
||||
- os: macos-15
|
||||
expected-os: "macos-15"
|
||||
- os: windows-2022
|
||||
@@ -555,12 +566,11 @@ jobs:
|
||||
- os: windows-2025
|
||||
expected-os: "windows-2025"
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
- if: runner.os == 'macOS'
|
||||
uses: astral-sh/github-actions/demudhra@67dc9ee1ddc113eccd8116e7b949fb6cdcd89889 # 2026.11.16.0
|
||||
- name: Setup uv
|
||||
id: setup-uv
|
||||
uses: ./
|
||||
uses: $/
|
||||
with:
|
||||
enable-cache: true
|
||||
- name: Verify cache key contains OS version
|
||||
@@ -585,7 +595,7 @@ jobs:
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Setup with cache
|
||||
uses: ./
|
||||
uses: $/
|
||||
with:
|
||||
enable-cache: ${{ matrix.enable-cache }}
|
||||
cache-suffix: ${{ github.run_id }}-${{ github.run_attempt }}-test-setup-cache-${{ matrix.os }}-${{ matrix.enable-cache }}
|
||||
@@ -605,7 +615,7 @@ jobs:
|
||||
persist-credentials: false
|
||||
- name: Restore with cache
|
||||
id: restore
|
||||
uses: ./
|
||||
uses: $/
|
||||
with:
|
||||
enable-cache: ${{ matrix.enable-cache }}
|
||||
cache-suffix: ${{ github.run_id }}-${{ github.run_attempt }}-test-setup-cache-${{ matrix.os }}-${{ matrix.enable-cache }}
|
||||
@@ -638,7 +648,7 @@ jobs:
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Setup with cache
|
||||
uses: ./
|
||||
uses: $/
|
||||
with:
|
||||
enable-cache: true
|
||||
cache-suffix: ${{ github.run_id }}-${{ github.run_attempt }}-test-setup-cache-requirements-txt
|
||||
@@ -655,7 +665,7 @@ jobs:
|
||||
persist-credentials: false
|
||||
- name: Restore with cache
|
||||
id: restore
|
||||
uses: ./
|
||||
uses: $/
|
||||
with:
|
||||
enable-cache: true
|
||||
cache-suffix: ${{ github.run_id }}-${{ github.run_attempt }}-test-setup-cache-requirements-txt
|
||||
@@ -678,7 +688,7 @@ jobs:
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Setup with cache
|
||||
uses: ./
|
||||
uses: $/
|
||||
with:
|
||||
enable-cache: true
|
||||
cache-dependency-glob: |
|
||||
@@ -700,7 +710,7 @@ jobs:
|
||||
echo 'dev-dependencies = []' >> __tests__/fixtures/uv-project/pyproject.toml
|
||||
- name: Restore with cache
|
||||
id: restore
|
||||
uses: ./
|
||||
uses: $/
|
||||
with:
|
||||
enable-cache: true
|
||||
cache-dependency-glob: |
|
||||
@@ -723,7 +733,7 @@ jobs:
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Setup with cache
|
||||
uses: ./
|
||||
uses: $/
|
||||
with:
|
||||
enable-cache: true
|
||||
save-cache: false
|
||||
@@ -740,7 +750,7 @@ jobs:
|
||||
persist-credentials: false
|
||||
- name: Restore with cache
|
||||
id: restore
|
||||
uses: ./
|
||||
uses: $/
|
||||
with:
|
||||
enable-cache: true
|
||||
cache-suffix: ${{ github.run_id }}-${{ github.run_attempt }}-test-setup-cache-save-cache-false
|
||||
@@ -759,7 +769,7 @@ jobs:
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Setup with cache
|
||||
uses: ./
|
||||
uses: $/
|
||||
with:
|
||||
enable-cache: true
|
||||
cache-suffix: ${{ github.run_id }}-${{ github.run_attempt }}-test-setup-cache-restore-cache-false
|
||||
@@ -775,7 +785,7 @@ jobs:
|
||||
persist-credentials: false
|
||||
- name: Restore with cache
|
||||
id: restore
|
||||
uses: ./
|
||||
uses: $/
|
||||
with:
|
||||
enable-cache: true
|
||||
restore-cache: false
|
||||
@@ -798,11 +808,8 @@ jobs:
|
||||
expected-cache-dir: "D:\\a\\_temp\\setup-uv-cache"
|
||||
runs-on: ${{ matrix.inputs.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Setup with cache
|
||||
uses: ./
|
||||
uses: $/
|
||||
with:
|
||||
enable-cache: true
|
||||
cache-suffix: ${{ github.run_id }}-${{ github.run_attempt }}-test-cache-local
|
||||
@@ -816,11 +823,8 @@ jobs:
|
||||
test-cache-local-cache-disabled:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Setup without cache
|
||||
uses: ./
|
||||
uses: $/
|
||||
with:
|
||||
enable-cache: false
|
||||
|
||||
@@ -835,11 +839,8 @@ jobs:
|
||||
test-cache-local-cache-disabled-but-explicit-path:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Setup without cache
|
||||
uses: ./
|
||||
uses: $/
|
||||
with:
|
||||
enable-cache: false
|
||||
cache-local-path: /tmp/uv-cache-disabled
|
||||
@@ -861,7 +862,7 @@ jobs:
|
||||
- name: Fake pyproject.toml at root
|
||||
run: cp __tests__/fixtures/old-python-constraint-project/pyproject.toml pyproject.toml
|
||||
- name: Setup with cache
|
||||
uses: ./
|
||||
uses: $/
|
||||
with:
|
||||
enable-cache: true
|
||||
- run: uv sync
|
||||
@@ -874,7 +875,7 @@ jobs:
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Install from custom manifest file
|
||||
uses: ./
|
||||
uses: $/
|
||||
with:
|
||||
manifest-file: "https://raw.githubusercontent.com/astral-sh/setup-uv/${{ github.ref }}/__tests__/download/custom-manifest.ndjson"
|
||||
- run: uv sync
|
||||
@@ -889,12 +890,9 @@ jobs:
|
||||
test-download-from-astral-mirror-false:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Install with download-from-astral-mirror disabled
|
||||
id: setup-uv
|
||||
uses: ./
|
||||
uses: $/
|
||||
with:
|
||||
download-from-astral-mirror: false
|
||||
- name: Verify uv is installed
|
||||
@@ -903,14 +901,11 @@ jobs:
|
||||
test-absolute-path:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
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: ./
|
||||
uses: $/
|
||||
with:
|
||||
version-file: "/tmp/setup-uv-requirements.txt"
|
||||
- name: Correct version gets installed
|
||||
@@ -923,16 +918,13 @@ jobs:
|
||||
test-relative-path:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
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: ./
|
||||
uses: $/
|
||||
with:
|
||||
version-file: "./setup-uv-requirements.txt"
|
||||
working-directory: "/tmp/setup-uv-test-relative-path"
|
||||
@@ -951,7 +943,7 @@ jobs:
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Setup uv
|
||||
uses: ./
|
||||
uses: $/
|
||||
with:
|
||||
cache-suffix: ${{ github.run_id }}-${{ github.run_attempt }}-test-cache-prune-force
|
||||
- name: Create long running python script
|
||||
@@ -974,7 +966,7 @@ jobs:
|
||||
exit 1
|
||||
fi
|
||||
- name: Setup uv
|
||||
uses: ./
|
||||
uses: $/
|
||||
with:
|
||||
working-directory: __tests__/fixtures/cache-dir-defined-project
|
||||
- run: uv sync
|
||||
@@ -995,7 +987,7 @@ jobs:
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Setup uv with cache and python cache enabled
|
||||
uses: ./
|
||||
uses: $/
|
||||
with:
|
||||
enable-cache: true
|
||||
cache-python: true
|
||||
@@ -1010,19 +1002,23 @@ jobs:
|
||||
run: rm -rf "$UV_PYTHON_INSTALL_DIR"
|
||||
|
||||
test-cache-python-installs:
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-2022]
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Verify Python install dir is not populated
|
||||
shell: bash
|
||||
run: |
|
||||
if [ -d /home/runner/work/_temp/uv-python-dir ]; then
|
||||
if [ -e "$RUNNER_TEMP/uv-python-dir" ]; then
|
||||
echo "Python install dir should not exist"
|
||||
exit 1
|
||||
fi
|
||||
- name: Setup uv with cache
|
||||
uses: ./
|
||||
uses: $/
|
||||
with:
|
||||
enable-cache: true
|
||||
cache-python: true
|
||||
@@ -1030,44 +1026,51 @@ jobs:
|
||||
- run: uv sync --managed-python
|
||||
working-directory: __tests__/fixtures/uv-project
|
||||
- name: Verify Python install dir exists
|
||||
shell: bash
|
||||
run: |
|
||||
if [ ! -d /home/runner/work/_temp/uv-python-dir ]; then
|
||||
if [ ! -d "$UV_PYTHON_INSTALL_DIR" ]; then
|
||||
echo "Python install dir should exist"
|
||||
exit 1
|
||||
fi
|
||||
test-restore-python-installs:
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ${{ matrix.os }}
|
||||
needs: test-cache-python-installs
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-2022]
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Verify Python install dir does not exist
|
||||
shell: bash
|
||||
run: |
|
||||
if [ -d /home/runner/work/_temp/uv-python-dir ]; then
|
||||
if [ -e "$RUNNER_TEMP/uv-python-dir" ]; then
|
||||
echo "Python install dir should not exist"
|
||||
exit 1
|
||||
fi
|
||||
- name: Restore with cache
|
||||
id: restore
|
||||
uses: ./
|
||||
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
|
||||
- name: Verify the restored Python minor-version link resolves to the patch directory
|
||||
shell: python
|
||||
env:
|
||||
CACHE_HIT: ${{ steps.restore.outputs.python-cache-hit }}
|
||||
run: |
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
assert os.environ["CACHE_HIT"] == "true", "expected a Python cache hit"
|
||||
installs = Path(os.environ["UV_PYTHON_INSTALL_DIR"]).resolve()
|
||||
assert installs.is_dir(), "Python install dir should exist"
|
||||
patch_dir, = installs.glob("cpython-*.*.*-*")
|
||||
minor_prefix = patch_dir.name.rsplit(".", 1)[0]
|
||||
alias, = installs.glob(f"{minor_prefix}-*")
|
||||
assert alias.resolve(strict=True) == patch_dir, alias
|
||||
- run: uv sync --managed-python
|
||||
working-directory: __tests__/fixtures/uv-project
|
||||
|
||||
@@ -1081,12 +1084,9 @@ jobs:
|
||||
expected-python-dir: "D:\\a\\_temp\\uv-python-dir"
|
||||
runs-on: ${{ matrix.inputs.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Install latest version
|
||||
id: setup-uv
|
||||
uses: ./
|
||||
uses: $/
|
||||
- name: Check Python dir is expected dir
|
||||
run: |
|
||||
if [ "$UV_PYTHON_INSTALL_DIR" != "${{ matrix.inputs.expected-python-dir }}" ]; then
|
||||
@@ -1097,21 +1097,6 @@ jobs:
|
||||
- name: Install python works
|
||||
run: uv python install
|
||||
|
||||
test-act:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Install act
|
||||
run: gh extension install https://github.com/nektos/gh-act
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
- name: Run test-uvx with act
|
||||
run: gh act -j test-uvx -P ubuntu-latest=catthehacker/ubuntu:act-latest
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
|
||||
test-workflow-run:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
@@ -1187,7 +1172,6 @@ jobs:
|
||||
- test-cache-python-installs
|
||||
- test-restore-python-installs
|
||||
- test-python-install-dir
|
||||
- test-act
|
||||
- test-workflow-run
|
||||
- validate-typings
|
||||
if: always()
|
||||
|
||||
@@ -60,20 +60,8 @@ jobs:
|
||||
else
|
||||
echo "changes-exist=false" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
- 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 "docs: update version references to $NEW_VERSION"
|
||||
git push origin HEAD:refs/heads/main
|
||||
env:
|
||||
NEW_VERSION: ${{ steps.tag-info.outputs.tag }}
|
||||
- name: Create Pull Request
|
||||
if: ${{ steps.changes-exist.outputs.changes-exist == 'true' && steps.commit-and-push.outcome != 'success' }}
|
||||
if: ${{ steps.changes-exist.outputs.changes-exist == 'true' }}
|
||||
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
|
||||
with:
|
||||
commit-message: "docs: update version references to ${{ steps.tag-info.outputs.tag }}"
|
||||
|
||||
@@ -18,7 +18,7 @@ jobs:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: true
|
||||
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
|
||||
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
|
||||
with:
|
||||
node-version-file: .nvmrc
|
||||
cache: npm
|
||||
@@ -26,7 +26,7 @@ jobs:
|
||||
id: update-known-checksums
|
||||
run:
|
||||
node dist/update-known-checksums/index.cjs
|
||||
src/download/checksum/known-checksums.ts
|
||||
src/download/checksum/known-checksums.json
|
||||
- name: Check for changes
|
||||
id: changes-exist
|
||||
run: |
|
||||
@@ -38,22 +38,12 @@ jobs:
|
||||
fi
|
||||
- name: Compile changes
|
||||
if: ${{ steps.changes-exist.outputs.changes-exist == 'true' }}
|
||||
run: npm ci --ignore-scripts && 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 checksums for $LATEST_VERSION"
|
||||
git push origin HEAD:refs/heads/main
|
||||
env:
|
||||
LATEST_VERSION: ${{ steps.update-known-checksums.outputs.latest-version }}
|
||||
|
||||
npm ci --ignore-scripts
|
||||
npm audit signatures
|
||||
npm run all
|
||||
- name: Create Pull Request
|
||||
if: ${{ steps.changes-exist.outputs.changes-exist == 'true' && steps.commit-and-push.outcome != 'success' }}
|
||||
if: ${{ steps.changes-exist.outputs.changes-exist == 'true' }}
|
||||
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
|
||||
with:
|
||||
commit-message: "chore: update known checksums"
|
||||
|
||||
@@ -6,7 +6,7 @@ Set up your GitHub Actions workflow with a specific version of [uv](https://docs
|
||||
- Cache the installed version of uv to speed up consecutive runs on self-hosted runners
|
||||
- Register problem matchers for error output
|
||||
- (Optional) Persist the uv's cache in the GitHub Actions Cache
|
||||
- (Optional) Verify the checksum of the downloaded uv executable
|
||||
- Verify the SHA-256 checksum of the downloaded uv archive
|
||||
|
||||
## Contents
|
||||
|
||||
@@ -15,6 +15,7 @@ Set up your GitHub Actions workflow with a specific version of [uv](https://docs
|
||||
- [Inputs](#inputs)
|
||||
- [Outputs](#outputs)
|
||||
- [Python version](#python-version)
|
||||
- [Python architecture](#python-architecture)
|
||||
- [Working directory](#working-directory)
|
||||
- [Advanced Configuration](#advanced-configuration)
|
||||
- [How it works](#how-it-works)
|
||||
@@ -26,7 +27,7 @@ Set up your GitHub Actions workflow with a specific version of [uv](https://docs
|
||||
|
||||
```yaml
|
||||
- name: Install the latest version of uv
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
```
|
||||
|
||||
If you do not specify a version, this action will look for a [required-version](https://docs.astral.sh/uv/reference/settings/#required-version)
|
||||
@@ -42,7 +43,7 @@ Have a look under [Advanced Configuration](#advanced-configuration) for detailed
|
||||
|
||||
```yaml
|
||||
- name: Install uv with all available options
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
# The version of uv to install, e.g., "0.5.0", "latest", or "latest-known" (default: searches for version in config files, then latest)
|
||||
version: ""
|
||||
@@ -56,6 +57,9 @@ Have a look under [Advanced Configuration](#advanced-configuration) for detailed
|
||||
# The version of Python to set UV_PYTHON to (overrides the Python version from .tool-versions)
|
||||
python-version: ""
|
||||
|
||||
# The Python architecture to set UV_PYTHON_ARCH to, e.g., x86_64 or aarch64
|
||||
python-arch: ""
|
||||
|
||||
# Use uv venv to activate a venv ready to be used by later steps
|
||||
activate-environment: "false"
|
||||
|
||||
@@ -71,13 +75,16 @@ Have a look under [Advanced Configuration](#advanced-configuration) for detailed
|
||||
# The checksum of the uv version to install
|
||||
checksum: ""
|
||||
|
||||
# Require a checksum bundled with setup-uv or supplied through the checksum input
|
||||
require-checksums: "false"
|
||||
|
||||
# Used when downloading uv from GitHub releases
|
||||
github-token: ${{ github.token }}
|
||||
|
||||
# Enable the GitHub Actions cache for uv: true, false, or auto (enabled on GitHub-hosted runners except for release, tag push, pull_request_target, and workflow_run events; disabled on self-hosted runners)
|
||||
enable-cache: "auto"
|
||||
|
||||
# Glob pattern to match files relative to the repository root to control the cache
|
||||
# Glob pattern to match files relative to the working directory to control the cache
|
||||
cache-dependency-glob: |
|
||||
**/*requirements*.txt
|
||||
**/*requirements*.in
|
||||
@@ -90,8 +97,8 @@ Have a look under [Advanced Configuration](#advanced-configuration) for detailed
|
||||
# Whether to restore the cache if found
|
||||
restore-cache: "true"
|
||||
|
||||
# Whether to save the cache after the run
|
||||
save-cache: "true"
|
||||
# Whether to save the cache after the run: true, false, or auto (disabled for merge_group events)
|
||||
save-cache: "auto"
|
||||
|
||||
# Suffix for the cache key
|
||||
cache-suffix: ""
|
||||
@@ -138,7 +145,8 @@ Have a look under [Advanced Configuration](#advanced-configuration) for detailed
|
||||
- `cache-hit`: A boolean value to indicate a cache entry was found.
|
||||
- `venv`: Path to the activated venv if activate-environment is true.
|
||||
- `python-version`: The Python version that was set.
|
||||
- `python-cache-hit`: A boolean value to indicate the Python cache entry was found.
|
||||
- `python-runtime-id`: An opaque identifier reported by uv for the activated venv's Python runtime. Empty when `activate-environment` is false.
|
||||
- `python-cache-hit`: A boolean indicating whether the Python cache was restored successfully.
|
||||
|
||||
### Python version
|
||||
|
||||
@@ -156,7 +164,7 @@ python 3.13
|
||||
```
|
||||
|
||||
```yaml
|
||||
- uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
- uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
version-file: ".tool-versions"
|
||||
```
|
||||
@@ -167,7 +175,7 @@ a warning.
|
||||
|
||||
```yaml
|
||||
- name: Install the latest version of uv and set the python version to 3.13t
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
python-version: 3.13t
|
||||
- run: uv pip install --python=3.13t pip
|
||||
@@ -185,13 +193,32 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- name: Install the latest version of uv and set the python version
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
- name: Test with python ${{ matrix.python-version }}
|
||||
run: uv run --frozen pytest
|
||||
```
|
||||
|
||||
### Python architecture
|
||||
|
||||
Use `python-arch` to set `UV_PYTHON_ARCH` for the rest of the job. This selects the Python
|
||||
architecture independently of the version, including versions requested by `.python-version`.
|
||||
An explicit architecture or interpreter path in a Python request takes precedence.
|
||||
|
||||
```yaml
|
||||
- uses: astral-sh/setup-uv@main
|
||||
with:
|
||||
python-version: "3.14"
|
||||
python-arch: x86_64
|
||||
- run: uv run --frozen pytest
|
||||
```
|
||||
|
||||
The input overrides an existing `UV_PYTHON_ARCH` value. When it is omitted, the action respects
|
||||
`UV_PYTHON_ARCH` from the environment. Both forms require a uv version that supports the variable;
|
||||
the action reports an error if the installed version does not support it. The selected architecture
|
||||
is included in the [cache key](docs/caching.md#cache-key).
|
||||
|
||||
### Working directory
|
||||
|
||||
You can set the working directory with the `working-directory` input.
|
||||
@@ -202,7 +229,7 @@ It also controls where [the venv gets created](#activate-environment), unless `v
|
||||
|
||||
```yaml
|
||||
- name: Install uv based on the config files in the working-directory
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
working-directory: my/subproject/dir
|
||||
```
|
||||
@@ -244,7 +271,7 @@ For example:
|
||||
- name: Checkout the repository
|
||||
uses: actions/checkout@main
|
||||
- name: Install the latest version of uv
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
enable-cache: true
|
||||
- name: Test
|
||||
@@ -256,7 +283,7 @@ To install a specific version of Python, use
|
||||
|
||||
```yaml
|
||||
- name: Install the latest version of uv
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
enable-cache: true
|
||||
- name: Install Python 3.12
|
||||
@@ -275,7 +302,7 @@ output:
|
||||
uses: actions/checkout@main
|
||||
- name: Install the default version of uv
|
||||
id: setup-uv
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
- name: Print the installed version
|
||||
run: echo "Installed uv version is ${{ steps.setup-uv.outputs.uv-version }}"
|
||||
```
|
||||
|
||||
+81
-3
@@ -1,9 +1,13 @@
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { beforeEach, describe, expect, it, jest } from "@jest/globals";
|
||||
import { createSetupInputs } from "../helpers/setup-inputs";
|
||||
|
||||
const mockRestoreCache = jest.fn();
|
||||
const mockSaveState = jest.fn();
|
||||
const mockSetOutput = jest.fn();
|
||||
const mockGetArch = jest.fn(() => "x86_64");
|
||||
const mockGetOSNameVersion = jest.fn(() => "ubuntu-24.04");
|
||||
const mockGetPlatform = jest.fn(async () => "unknown-linux-gnu");
|
||||
|
||||
jest.unstable_mockModule("@actions/cache", () => ({
|
||||
restoreCache: mockRestoreCache,
|
||||
@@ -24,9 +28,9 @@ jest.unstable_mockModule("../../src/utils/logging", () => ({
|
||||
}));
|
||||
|
||||
jest.unstable_mockModule("../../src/utils/platforms", () => ({
|
||||
getArch: jest.fn(() => "x86_64"),
|
||||
getOSNameVersion: jest.fn(() => "ubuntu-24.04"),
|
||||
getPlatform: jest.fn(async () => "unknown-linux-gnu"),
|
||||
getArch: mockGetArch,
|
||||
getOSNameVersion: mockGetOSNameVersion,
|
||||
getPlatform: mockGetPlatform,
|
||||
}));
|
||||
|
||||
const { restoreCache } = await import("../../src/cache/restore-cache");
|
||||
@@ -39,9 +43,48 @@ function cacheKeyOutput(): string {
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockGetArch.mockReturnValue("x86_64");
|
||||
mockGetOSNameVersion.mockReturnValue("ubuntu-24.04");
|
||||
mockGetPlatform.mockResolvedValue("unknown-linux-gnu");
|
||||
});
|
||||
|
||||
describe("restoreCache", () => {
|
||||
it.each([
|
||||
["win32", false],
|
||||
["linux", true],
|
||||
] as const)(
|
||||
"keeps the matched Python cache key on %s when the install directory cannot be read",
|
||||
async (platform, pythonCacheHit) => {
|
||||
const inputs = createSetupInputs({
|
||||
cachePython: true,
|
||||
// A file at the install directory path makes readdir fail.
|
||||
pythonDir: fileURLToPath(import.meta.url),
|
||||
restoreCache: true,
|
||||
});
|
||||
mockRestoreCache
|
||||
.mockReturnValueOnce("uv-key")
|
||||
.mockReturnValueOnce("python-key");
|
||||
|
||||
const originalPlatform = process.platform;
|
||||
Object.defineProperty(process, "platform", { value: platform });
|
||||
try {
|
||||
await restoreCache(inputs);
|
||||
} finally {
|
||||
Object.defineProperty(process, "platform", { value: originalPlatform });
|
||||
}
|
||||
|
||||
expect(mockSetOutput).toHaveBeenCalledWith("cache-hit", true);
|
||||
expect(mockSetOutput).toHaveBeenCalledWith(
|
||||
"python-cache-hit",
|
||||
pythonCacheHit,
|
||||
);
|
||||
expect(mockSaveState).toHaveBeenCalledWith(
|
||||
"python-cache-matched-key",
|
||||
"python-key",
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
it("encodes Python version ranges before adding them to the cache key", async () => {
|
||||
await restoreCache(createSetupInputs(), ">3.10.11,<3.11");
|
||||
|
||||
@@ -71,4 +114,39 @@ describe("restoreCache", () => {
|
||||
"setup-uv-2-x86_64-unknown-linux-gnu-ubuntu-24.04-3.11-dependencyhash-tests-3.11",
|
||||
);
|
||||
});
|
||||
|
||||
it("includes the resolved Python architecture in the cache key", async () => {
|
||||
const inputs = createSetupInputs({ pythonArch: "aarch64" });
|
||||
|
||||
await restoreCache(inputs, "3.14");
|
||||
|
||||
expect(cacheKeyOutput()).toContain("-3.14-python-aarch64-");
|
||||
});
|
||||
|
||||
it.each(["aarch64", "x86_64"])(
|
||||
"separates %s Python caches on a Windows ARM64 runner",
|
||||
async (pythonArch) => {
|
||||
mockGetArch.mockReturnValue("aarch64");
|
||||
mockGetOSNameVersion.mockReturnValue("windows-11");
|
||||
mockGetPlatform.mockResolvedValue("pc-windows-msvc");
|
||||
const inputs = createSetupInputs({
|
||||
cachePython: true,
|
||||
pythonArch,
|
||||
restoreCache: true,
|
||||
});
|
||||
|
||||
await restoreCache(inputs, "3.14");
|
||||
|
||||
const cacheKey = `setup-uv-2-aarch64-pc-windows-msvc-windows-11-3.14-python-${pythonArch}-py-dependencyhash`;
|
||||
expect(cacheKeyOutput()).toBe(cacheKey);
|
||||
expect(mockRestoreCache).toHaveBeenCalledWith(
|
||||
[inputs.cacheLocalPath?.path],
|
||||
cacheKey,
|
||||
);
|
||||
expect(mockRestoreCache).toHaveBeenCalledWith(
|
||||
[inputs.pythonDir],
|
||||
`${cacheKey}-python`,
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { runInNewContext } from "node:vm";
|
||||
import { expect, it } from "@jest/globals";
|
||||
|
||||
const saveCacheBundle = readFileSync(
|
||||
new URL("../../dist/save-cache/index.cjs", import.meta.url),
|
||||
"utf8",
|
||||
);
|
||||
|
||||
function bundledErrorClass(name: string): new (message: string) => Error {
|
||||
const start = saveCacheBundle.indexOf(`var ${name} = class`);
|
||||
expect(start).toBeGreaterThanOrEqual(0);
|
||||
|
||||
const end = saveCacheBundle.indexOf("\n};", start);
|
||||
expect(end).toBeGreaterThan(start);
|
||||
|
||||
const declaration = saveCacheBundle.slice(start, end + 3);
|
||||
return runInNewContext(`${declaration}; ${name}`, {
|
||||
__name: (target: object, value: string) =>
|
||||
Object.defineProperty(target, "name", { configurable: true, value }),
|
||||
}) as new (
|
||||
message: string,
|
||||
) => Error;
|
||||
}
|
||||
|
||||
it.each(["ValidationError", "ReserveCacheError", "FinalizeCacheError"])(
|
||||
"preserves the %s name in the save-cache bundle",
|
||||
(name) => {
|
||||
const ErrorClass = bundledErrorClass(name);
|
||||
|
||||
expect(new ErrorClass("test").name).toBe(ErrorClass.name);
|
||||
},
|
||||
);
|
||||
Vendored
+87
@@ -0,0 +1,87 @@
|
||||
import { mkdtempSync, rmSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import {
|
||||
afterAll,
|
||||
beforeEach,
|
||||
describe,
|
||||
expect,
|
||||
it,
|
||||
jest,
|
||||
} from "@jest/globals";
|
||||
import { CacheLocalSource, type SetupInputs } from "../../src/utils/inputs";
|
||||
import { createSetupInputs } from "../helpers/setup-inputs";
|
||||
|
||||
const mockSaveCache = jest.fn<() => Promise<number>>();
|
||||
const mockInfo = jest.fn();
|
||||
const mockLoadInputs = jest.fn<() => SetupInputs>(() =>
|
||||
createSetupInputs({ enableCache: false }),
|
||||
);
|
||||
const state: Record<string, string> = {};
|
||||
|
||||
jest.unstable_mockModule("@actions/cache", () => ({
|
||||
saveCache: mockSaveCache,
|
||||
}));
|
||||
|
||||
jest.unstable_mockModule("@actions/core", () => ({
|
||||
getState: jest.fn((name: string) => state[name] ?? ""),
|
||||
setFailed: jest.fn(),
|
||||
}));
|
||||
|
||||
jest.unstable_mockModule("../../src/utils/inputs", () => ({
|
||||
loadInputs: mockLoadInputs,
|
||||
}));
|
||||
|
||||
jest.unstable_mockModule("../../src/utils/logging", () => ({
|
||||
info: mockInfo,
|
||||
warning: jest.fn(),
|
||||
}));
|
||||
|
||||
jest.spyOn(process, "exit").mockImplementation((() => undefined) as never);
|
||||
|
||||
const { run } = await import("../../src/save-cache");
|
||||
|
||||
const cacheDir = mkdtempSync(join(tmpdir(), "setup-uv-save-cache-"));
|
||||
const cacheKey = "setup-uv-2-x86_64-unknown-linux-gnu-ubuntu-24.04-3.12-hash";
|
||||
|
||||
function infoMessages(): string[] {
|
||||
return mockInfo.mock.calls.map(([msg]) => msg as string);
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
delete process.env.UV_CACHE_DIR;
|
||||
state["cache-key"] = cacheKey;
|
||||
state["cache-matched-key"] = "";
|
||||
mockLoadInputs.mockReturnValue(
|
||||
createSetupInputs({
|
||||
cacheLocalPath: { path: cacheDir, source: CacheLocalSource.Input },
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
rmSync(cacheDir, { force: true, recursive: true });
|
||||
});
|
||||
|
||||
describe("saveCache", () => {
|
||||
it("reports the saved key when the cache is saved", async () => {
|
||||
mockSaveCache.mockResolvedValue(42);
|
||||
|
||||
await run();
|
||||
|
||||
expect(mockSaveCache).toHaveBeenCalledWith([cacheDir], cacheKey);
|
||||
expect(infoMessages()).toContain(`uv cache saved with key: ${cacheKey}`);
|
||||
});
|
||||
|
||||
it("does not report the cache as saved when saving fails", async () => {
|
||||
// @actions/cache logs the failure itself and returns -1
|
||||
mockSaveCache.mockResolvedValue(-1);
|
||||
|
||||
await run();
|
||||
|
||||
expect(mockSaveCache).toHaveBeenCalledWith([cacheDir], cacheKey);
|
||||
expect(infoMessages()).not.toContain(
|
||||
`uv cache saved with key: ${cacheKey}`,
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -26,9 +26,49 @@ test("provided checksum beats known checksums", async () => {
|
||||
"x86_64",
|
||||
"unknown-linux-gnu",
|
||||
"0.3.0",
|
||||
"incorrect-manifest-checksum",
|
||||
);
|
||||
});
|
||||
|
||||
test("known checksums beat manifest checksums", async () => {
|
||||
await expect(
|
||||
validateChecksum(
|
||||
undefined,
|
||||
filePath,
|
||||
"x86_64",
|
||||
"unknown-linux-gnu",
|
||||
"0.3.0",
|
||||
validChecksum,
|
||||
),
|
||||
).rejects.toThrow("did not match");
|
||||
});
|
||||
|
||||
test("manifest checksums are used when no known checksum exists", async () => {
|
||||
await expect(
|
||||
validateChecksum(
|
||||
undefined,
|
||||
filePath,
|
||||
"aarch64",
|
||||
"pc-windows-msvc",
|
||||
"1.2.3",
|
||||
"incorrect-manifest-checksum",
|
||||
),
|
||||
).rejects.toThrow("did not match");
|
||||
});
|
||||
|
||||
test.each(["", undefined])("rejects missing checksums (%s)", async (hash) => {
|
||||
await expect(
|
||||
validateChecksum(
|
||||
undefined,
|
||||
filePath,
|
||||
"aarch64",
|
||||
"pc-windows-msvc",
|
||||
"1.2.3",
|
||||
hash,
|
||||
),
|
||||
).rejects.toThrow("No checksum found");
|
||||
});
|
||||
|
||||
type KnownVersionFixture = { version: string; known: boolean };
|
||||
|
||||
it.each<KnownVersionFixture>([
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import { promises as fs } from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { expect, test } from "@jest/globals";
|
||||
import { updateChecksums } from "../../../src/download/checksum/update-known-checksums";
|
||||
|
||||
test("serializes checksum entries as JSON data", async () => {
|
||||
const tempDirectory = await fs.mkdtemp(
|
||||
path.join(os.tmpdir(), "setup-uv-checksums-test-"),
|
||||
);
|
||||
const outputPath = path.join(tempDirectory, "known-checksums.json");
|
||||
const key = 'platform-1.0.0"\n};\nglobalThis.compromised = true;';
|
||||
const checksum = 'checksum"\\\nvalue';
|
||||
|
||||
try {
|
||||
await updateChecksums(outputPath, [
|
||||
{ checksum, key },
|
||||
{ checksum: "duplicate", key },
|
||||
]);
|
||||
|
||||
const content = await fs.readFile(outputPath, "utf8");
|
||||
expect(JSON.parse(content)).toEqual({ [key]: checksum });
|
||||
expect(content.endsWith("\n")).toBe(true);
|
||||
} finally {
|
||||
await fs.rm(tempDirectory, { force: true, recursive: true });
|
||||
}
|
||||
});
|
||||
@@ -146,6 +146,55 @@ describe("download-version", () => {
|
||||
expect(mockGetAllVersions).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("resolves ~= with PEP 440 compatible release semantics", async () => {
|
||||
mockGetFirstMatchingVersion.mockImplementation(
|
||||
(predicate: (version: string) => boolean) =>
|
||||
["1.0.0", "0.10.2", "0.9.26"].find(predicate),
|
||||
);
|
||||
|
||||
const version = await resolveVersion("~=0.9", undefined);
|
||||
|
||||
expect(version).toBe("0.10.2");
|
||||
});
|
||||
|
||||
it("resolves ~= with PEP 440 compatible release semantics from manifest-file", async () => {
|
||||
mockGetAllVersions.mockResolvedValue(["1.0.0", "0.10.2", "0.9.26"]);
|
||||
|
||||
const version = await resolveVersion(
|
||||
"~=0.9",
|
||||
"https://example.com/custom.ndjson",
|
||||
);
|
||||
|
||||
expect(version).toBe("0.10.2");
|
||||
});
|
||||
|
||||
it.each([
|
||||
["<=0.9", "0.9.0"],
|
||||
["==0.9", "0.9.0"],
|
||||
])("resolves %s with PEP 440 semantics", async (specifier, expected) => {
|
||||
mockGetFirstMatchingVersion.mockImplementation(
|
||||
(predicate: (version: string) => boolean) =>
|
||||
["0.10.2", "0.9.26", "0.9.0", "0.8.24"].find(predicate),
|
||||
);
|
||||
|
||||
const version = await resolveVersion(specifier, undefined);
|
||||
|
||||
expect(version).toBe(expected);
|
||||
});
|
||||
|
||||
it("resolves >0.9 with PEP 440 semantics for the lowest strategy", async () => {
|
||||
mockGetAllVersions.mockResolvedValue([
|
||||
"0.10.0",
|
||||
"0.9.26",
|
||||
"0.9.1",
|
||||
"0.9.0",
|
||||
]);
|
||||
|
||||
const version = await resolveVersion(">0.9", undefined, "lowest");
|
||||
|
||||
expect(version).toBe("0.9.1");
|
||||
});
|
||||
|
||||
it("treats == exact pins as explicit versions", async () => {
|
||||
const version = await resolveVersion("==0.9.26", undefined);
|
||||
|
||||
@@ -220,17 +269,17 @@ describe("download-version", () => {
|
||||
"token",
|
||||
),
|
||||
).rejects.toThrow(
|
||||
"Could not find artifact for version 0.9.26, arch x86_64, platform unknown-linux-gnu in https://raw.githubusercontent.com/astral-sh/versions/main/v1/uv.ndjson .",
|
||||
"Could not find artifact for version 0.9.26, arch x86_64, platform unknown-linux-gnu in https://releases.astral.sh/github/versions/main/v1/uv.ndjson .",
|
||||
);
|
||||
|
||||
expect(mockDownloadTool).not.toHaveBeenCalled();
|
||||
expect(mockValidateChecksum).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("uses built-in checksums for default manifest downloads", async () => {
|
||||
it("uses the default manifest checksum as a fallback", async () => {
|
||||
mockGetArtifact.mockResolvedValue({
|
||||
archiveFormat: "tar.gz",
|
||||
checksum: "manifest-checksum-that-should-be-ignored",
|
||||
checksum: "manifest-checksum",
|
||||
downloadUrl: "https://example.com/uv.tar.gz",
|
||||
});
|
||||
|
||||
@@ -248,6 +297,7 @@ describe("download-version", () => {
|
||||
"x86_64",
|
||||
"unknown-linux-gnu",
|
||||
"0.9.26",
|
||||
"manifest-checksum",
|
||||
);
|
||||
});
|
||||
|
||||
@@ -400,6 +450,7 @@ describe("download-version", () => {
|
||||
"x86_64",
|
||||
"unknown-linux-gnu",
|
||||
"0.9.26",
|
||||
"manifest-checksum",
|
||||
);
|
||||
});
|
||||
|
||||
@@ -425,6 +476,7 @@ describe("download-version", () => {
|
||||
"x86_64",
|
||||
"unknown-linux-gnu",
|
||||
"0.9.26",
|
||||
"manifest-checksum",
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
import { execFile, execFileSync } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
import fs from "node:fs";
|
||||
import { createServer } from "node:http";
|
||||
import type { AddressInfo } from "node:net";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
import { expect, test } from "@jest/globals";
|
||||
import { getArch, getPlatform } from "../../src/utils/platforms";
|
||||
|
||||
test("enforces intrinsic checksums on downloads and tool-cache hits", async () => {
|
||||
const platform = await getPlatform();
|
||||
const target = `${getArch()}-${platform}`;
|
||||
const windows = platform === "pc-windows-msvc";
|
||||
const dir = fs.mkdtempSync(path.join(tmpdir(), "setup-uv-checksums-"));
|
||||
const server = createServer();
|
||||
try {
|
||||
const member = windows ? "uv.exe" : `uv-${target}/uv`;
|
||||
const archiveName = windows ? "uv.zip" : "uv.tar.gz";
|
||||
fs.mkdirSync(path.dirname(path.join(dir, member)), { recursive: true });
|
||||
fs.writeFileSync(path.join(dir, member), "test build");
|
||||
execFileSync("tar", ["-acf", archiveName, member], { cwd: dir });
|
||||
const archive = fs.readFileSync(path.join(dir, archiveName));
|
||||
const digest = createHash("sha256").update(archive).digest("hex");
|
||||
let downloads = 0;
|
||||
server.on("request", (_req, res) => {
|
||||
downloads++;
|
||||
res.end(archive);
|
||||
});
|
||||
await new Promise<void>((resolve) =>
|
||||
server.listen(0, "127.0.0.1", resolve),
|
||||
);
|
||||
const address = server.address() as AddressInfo;
|
||||
|
||||
function install(version: string, strict: boolean, checksum = "") {
|
||||
const manifest = JSON.stringify({
|
||||
artifacts: [
|
||||
{
|
||||
archive_format: windows ? "zip" : "tar.gz",
|
||||
platform: target,
|
||||
sha256: digest,
|
||||
url: `http://127.0.0.1:${address.port}/${archiveName}`,
|
||||
},
|
||||
],
|
||||
version,
|
||||
});
|
||||
return promisify(execFile)(process.execPath, ["dist/setup/index.cjs"], {
|
||||
env: {
|
||||
"INPUT_ACTIVATE-ENVIRONMENT": "false",
|
||||
INPUT_CHECKSUM: checksum,
|
||||
"INPUT_MANIFEST-FILE": `data:application/json,${encodeURIComponent(manifest)}`,
|
||||
"INPUT_NO-PROJECT": "false",
|
||||
"INPUT_PYTHON-VERSION": "3.13",
|
||||
"INPUT_REQUIRE-CHECKSUMS": String(strict),
|
||||
INPUT_VERSION: version,
|
||||
"INPUT_WORKING-DIRECTORY": dir,
|
||||
PATH: process.env.PATH,
|
||||
RUNNER_TEMP: dir,
|
||||
RUNNER_TOOL_CACHE: path.join(dir, "cache"),
|
||||
SystemRoot: process.env.SystemRoot,
|
||||
},
|
||||
timeout: 10_000,
|
||||
});
|
||||
}
|
||||
|
||||
const version = "99.0.0";
|
||||
await install(version, false);
|
||||
await expect(install(version, true)).rejects.toMatchObject({
|
||||
stdout: expect.stringContaining(
|
||||
`No bundled checksum for ${target}-${version}`,
|
||||
),
|
||||
});
|
||||
expect(downloads).toBe(1);
|
||||
await install(version, true, digest);
|
||||
expect(downloads).toBe(2);
|
||||
await install(version, true, digest);
|
||||
expect(downloads).toBe(2);
|
||||
await expect(install(version, true, "0".repeat(64))).rejects.toMatchObject({
|
||||
stdout: expect.stringContaining("did not match"),
|
||||
});
|
||||
// The custom manifest also offers these bytes under a known release version.
|
||||
await expect(install("0.9.26", true)).rejects.toMatchObject({
|
||||
stdout: expect.stringContaining("did not match"),
|
||||
});
|
||||
await expect(install(version, true, "../uv")).rejects.toMatchObject({
|
||||
stdout: expect.stringContaining("Expected a SHA-256 checksum"),
|
||||
});
|
||||
} finally {
|
||||
server.close();
|
||||
fs.rmSync(dir, { force: true, recursive: true });
|
||||
}
|
||||
}, 30_000);
|
||||
@@ -1,4 +1,11 @@
|
||||
import { beforeEach, describe, expect, it, jest } from "@jest/globals";
|
||||
import {
|
||||
afterEach,
|
||||
beforeEach,
|
||||
describe,
|
||||
expect,
|
||||
it,
|
||||
jest,
|
||||
} from "@jest/globals";
|
||||
|
||||
// biome-ignore lint/suspicious/noExplicitAny: Mock requires flexible typing in tests.
|
||||
const mockFetch = jest.fn<any>();
|
||||
@@ -13,6 +20,7 @@ jest.unstable_mockModule("../../src/utils/fetch", () => ({
|
||||
}));
|
||||
|
||||
const {
|
||||
MANIFEST_FETCH_ATTEMPTS,
|
||||
clearManifestCache,
|
||||
fetchManifest,
|
||||
getAllVersions,
|
||||
@@ -73,6 +81,10 @@ describe("manifest", () => {
|
||||
mockFetch.mockReset();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.useRealTimers();
|
||||
});
|
||||
|
||||
describe("fetchManifest", () => {
|
||||
it("fetches and parses manifest data", async () => {
|
||||
mockFetch.mockResolvedValue(
|
||||
@@ -84,6 +96,106 @@ describe("manifest", () => {
|
||||
expect(versions).toHaveLength(2);
|
||||
expect(versions[0]?.version).toBe("0.9.26");
|
||||
expect(versions[1]?.version).toBe("0.9.25");
|
||||
expect(mockFetch.mock.calls.map(([url]) => url)).toEqual([
|
||||
"https://releases.astral.sh/github/versions/main/v1/uv.ndjson",
|
||||
]);
|
||||
});
|
||||
|
||||
it("falls back to GitHub after mirror network retries are exhausted", async () => {
|
||||
jest.useFakeTimers();
|
||||
mockFetch
|
||||
.mockRejectedValueOnce(new Error("mirror unavailable"))
|
||||
.mockRejectedValueOnce(new Error("mirror unavailable"))
|
||||
.mockRejectedValueOnce(new Error("mirror unavailable"))
|
||||
.mockResolvedValueOnce(
|
||||
createMockResponse(true, 200, "OK", sampleManifestResponse),
|
||||
);
|
||||
|
||||
const result = fetchManifest();
|
||||
await jest.runAllTimersAsync();
|
||||
|
||||
await expect(result).resolves.toEqual([
|
||||
expect.objectContaining({ version: "0.9.26" }),
|
||||
expect.objectContaining({ version: "0.9.25" }),
|
||||
]);
|
||||
expect(mockFetch.mock.calls.map(([url]) => url)).toEqual([
|
||||
"https://releases.astral.sh/github/versions/main/v1/uv.ndjson",
|
||||
"https://releases.astral.sh/github/versions/main/v1/uv.ndjson",
|
||||
"https://releases.astral.sh/github/versions/main/v1/uv.ndjson",
|
||||
"https://raw.githubusercontent.com/astral-sh/versions/main/v1/uv.ndjson",
|
||||
]);
|
||||
|
||||
await expect(getLatestVersion()).resolves.toBe("0.9.26");
|
||||
expect(mockFetch).toHaveBeenCalledTimes(4);
|
||||
});
|
||||
|
||||
it.each([404, 429, 503])(
|
||||
"falls back to a streaming GitHub manifest on mirror HTTP %s",
|
||||
async (status) => {
|
||||
mockFetch
|
||||
.mockResolvedValueOnce(createMockResponse(false, status, "Error", ""))
|
||||
.mockResolvedValueOnce(
|
||||
createStreamingMockResponse([`${sampleManifestResponse}\n`]),
|
||||
);
|
||||
|
||||
await expect(getLatestVersion()).resolves.toBe("0.9.26");
|
||||
await expect(
|
||||
getArtifact("0.9.26", "aarch64", "apple-darwin"),
|
||||
).resolves.toEqual({
|
||||
archiveFormat: "tar.gz",
|
||||
checksum:
|
||||
"fcf0a9ea6599c6ae28a4c854ac6da76f2c889354d7c36ce136ef071f7ab9721f",
|
||||
downloadUrl:
|
||||
"https://github.com/astral-sh/uv/releases/download/0.9.26/uv-aarch64-apple-darwin.tar.gz",
|
||||
});
|
||||
expect(mockFetch.mock.calls.map(([url]) => url)).toEqual([
|
||||
"https://releases.astral.sh/github/versions/main/v1/uv.ndjson",
|
||||
"https://raw.githubusercontent.com/astral-sh/versions/main/v1/uv.ndjson",
|
||||
]);
|
||||
},
|
||||
);
|
||||
|
||||
it("does not fall back from a custom manifest", async () => {
|
||||
mockFetch.mockResolvedValue(
|
||||
createMockResponse(false, 503, "Service Unavailable", ""),
|
||||
);
|
||||
|
||||
await expect(
|
||||
fetchManifest("https://example.com/custom.ndjson"),
|
||||
).rejects.toThrow(
|
||||
"Failed to fetch manifest data: 503 Service Unavailable",
|
||||
);
|
||||
expect(mockFetch.mock.calls.map(([url]) => url)).toEqual([
|
||||
"https://example.com/custom.ndjson",
|
||||
]);
|
||||
});
|
||||
|
||||
it("retries network failures", async () => {
|
||||
jest.useFakeTimers();
|
||||
mockFetch
|
||||
.mockRejectedValueOnce(new Error("request timed out"))
|
||||
.mockResolvedValueOnce(
|
||||
createMockResponse(true, 200, "OK", sampleManifestResponse),
|
||||
);
|
||||
|
||||
const result = fetchManifest();
|
||||
await jest.runAllTimersAsync();
|
||||
|
||||
await expect(result).resolves.toHaveLength(2);
|
||||
expect(mockFetch).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it("stops after the configured number of network failures", async () => {
|
||||
jest.useFakeTimers();
|
||||
mockFetch.mockRejectedValue(new Error("request timed out"));
|
||||
|
||||
const result = expect(fetchManifest()).rejects.toThrow(
|
||||
"request timed out",
|
||||
);
|
||||
await jest.runAllTimersAsync();
|
||||
|
||||
await result;
|
||||
expect(mockFetch).toHaveBeenCalledTimes(MANIFEST_FETCH_ATTEMPTS * 2);
|
||||
});
|
||||
|
||||
it("throws on a failed fetch", async () => {
|
||||
|
||||
@@ -16,14 +16,17 @@ export function createSetupInputs(
|
||||
checksum: "",
|
||||
downloadFromAstralMirror: false,
|
||||
enableCache: true,
|
||||
exportPythonArch: false,
|
||||
githubToken: "",
|
||||
ignoreEmptyWorkdir: false,
|
||||
ignoreNothingToCache: false,
|
||||
noProject: false,
|
||||
pruneCache: false,
|
||||
pythonArch: "",
|
||||
pythonDir: "/tmp/uv-python-dir",
|
||||
pythonVersion: "",
|
||||
quiet: false,
|
||||
requireChecksums: false,
|
||||
resolutionStrategy: "highest",
|
||||
restoreCache: false,
|
||||
saveCache: true,
|
||||
|
||||
@@ -19,6 +19,7 @@ const ORIGINAL_RUNNER_ENVIRONMENT = process.env.RUNNER_ENVIRONMENT;
|
||||
const ORIGINAL_RUNNER_TEMP = process.env.RUNNER_TEMP;
|
||||
const ORIGINAL_UV_CACHE_DIR = process.env.UV_CACHE_DIR;
|
||||
const ORIGINAL_UV_PYTHON = process.env.UV_PYTHON;
|
||||
const ORIGINAL_UV_PYTHON_ARCH = process.env.UV_PYTHON_ARCH;
|
||||
const ORIGINAL_UV_PYTHON_INSTALL_DIR = process.env.UV_PYTHON_INSTALL_DIR;
|
||||
|
||||
const mockDebug = jest.fn();
|
||||
@@ -62,6 +63,7 @@ function resetEnvironment(): void {
|
||||
delete process.env.RUNNER_TEMP;
|
||||
delete process.env.UV_CACHE_DIR;
|
||||
delete process.env.UV_PYTHON;
|
||||
delete process.env.UV_PYTHON_ARCH;
|
||||
delete process.env.UV_PYTHON_INSTALL_DIR;
|
||||
}
|
||||
|
||||
@@ -77,6 +79,11 @@ function restoreEnvironment(): void {
|
||||
process.env.RUNNER_TEMP = ORIGINAL_RUNNER_TEMP;
|
||||
process.env.UV_CACHE_DIR = ORIGINAL_UV_CACHE_DIR;
|
||||
process.env.UV_PYTHON = ORIGINAL_UV_PYTHON;
|
||||
if (ORIGINAL_UV_PYTHON_ARCH === undefined) {
|
||||
delete process.env.UV_PYTHON_ARCH;
|
||||
} else {
|
||||
process.env.UV_PYTHON_ARCH = ORIGINAL_UV_PYTHON_ARCH;
|
||||
}
|
||||
process.env.UV_PYTHON_INSTALL_DIR = ORIGINAL_UV_PYTHON_INSTALL_DIR;
|
||||
}
|
||||
|
||||
@@ -98,11 +105,19 @@ describe("loadInputs", () => {
|
||||
source: CacheLocalSource.Default,
|
||||
});
|
||||
expect(inputs.pythonDir).toBe("/runner-temp/uv-python-dir");
|
||||
expect(inputs.pythonArch).toBe("");
|
||||
expect(inputs.exportPythonArch).toBe(false);
|
||||
expect(inputs.venvPath).toBe("/workspace/.venv");
|
||||
expect(inputs.manifestFile).toBeUndefined();
|
||||
expect(inputs.requireChecksums).toBe(false);
|
||||
expect(inputs.resolutionStrategy).toBe("highest");
|
||||
});
|
||||
|
||||
it("loads require-checksums", () => {
|
||||
mockInputs["require-checksums"] = "true";
|
||||
expect(loadInputs().requireChecksums).toBe(true);
|
||||
});
|
||||
|
||||
it("uses the Python version from an explicitly selected .tool-versions file", () => {
|
||||
mockInputs["working-directory"] = createTempProject({
|
||||
".tool-versions": "uv 0.12.3\npython 3.13.1t\n",
|
||||
@@ -149,6 +164,28 @@ describe("loadInputs", () => {
|
||||
expect(inputs.pythonVersion).toBe("");
|
||||
});
|
||||
|
||||
it("prefers the python-arch input over UV_PYTHON_ARCH", () => {
|
||||
mockInputs["working-directory"] = "/workspace";
|
||||
mockInputs["python-arch"] = "x86_64";
|
||||
process.env.UV_PYTHON_ARCH = "aarch64";
|
||||
|
||||
const inputs = loadInputs();
|
||||
expect(inputs.pythonArch).toBe("x86_64");
|
||||
expect(inputs.exportPythonArch).toBe(true);
|
||||
});
|
||||
|
||||
it.each(["aarch64", "x86_64_v3", ""])(
|
||||
"uses UV_PYTHON_ARCH when python-arch is omitted: %s",
|
||||
(pythonArch) => {
|
||||
mockInputs["working-directory"] = "/workspace";
|
||||
process.env.UV_PYTHON_ARCH = pythonArch;
|
||||
|
||||
const inputs = loadInputs();
|
||||
expect(inputs.pythonArch).toBe(pythonArch);
|
||||
expect(inputs.exportPythonArch).toBe(false);
|
||||
},
|
||||
);
|
||||
|
||||
it.each(["pull_request_target", "workflow_run", "release"])(
|
||||
"disables automatic caching for the %s event",
|
||||
(eventName) => {
|
||||
@@ -206,6 +243,51 @@ describe("loadInputs", () => {
|
||||
expect(inputs.enableCache).toBe(true);
|
||||
});
|
||||
|
||||
it("restores but does not save cache automatically for merge groups", () => {
|
||||
mockInputs["working-directory"] = "/workspace";
|
||||
mockInputs["enable-cache"] = "auto";
|
||||
mockInputs["restore-cache"] = "true";
|
||||
mockInputs["save-cache"] = "auto";
|
||||
process.env.RUNNER_ENVIRONMENT = "github-hosted";
|
||||
process.env.RUNNER_TEMP = "/runner-temp";
|
||||
process.env.GITHUB_EVENT_NAME = "merge_group";
|
||||
|
||||
const inputs = loadInputs();
|
||||
|
||||
expect(inputs.enableCache).toBe(true);
|
||||
expect(inputs.restoreCache).toBe(true);
|
||||
expect(inputs.saveCache).toBe(false);
|
||||
expect(mockInfo).toHaveBeenCalledWith(
|
||||
"Cache saving is disabled for the merge_group event",
|
||||
);
|
||||
});
|
||||
|
||||
it.each([
|
||||
["true", true],
|
||||
["false", false],
|
||||
])("honors save-cache %s for merge groups", (saveCacheInput, expected) => {
|
||||
mockInputs["working-directory"] = "/workspace";
|
||||
mockInputs["save-cache"] = saveCacheInput;
|
||||
process.env.GITHUB_EVENT_NAME = "merge_group";
|
||||
|
||||
const inputs = loadInputs();
|
||||
|
||||
expect(inputs.saveCache).toBe(expected);
|
||||
expect(mockInfo).not.toHaveBeenCalledWith(
|
||||
"Cache saving is disabled for the merge_group event",
|
||||
);
|
||||
});
|
||||
|
||||
it("automatically saves cache for other events", () => {
|
||||
mockInputs["working-directory"] = "/workspace";
|
||||
mockInputs["save-cache"] = "auto";
|
||||
process.env.GITHUB_EVENT_NAME = "push";
|
||||
|
||||
const inputs = loadInputs();
|
||||
|
||||
expect(inputs.saveCache).toBe(true);
|
||||
});
|
||||
|
||||
it("uses cache-dir from pyproject.toml when present", () => {
|
||||
mockInputs["working-directory"] = createTempProject({
|
||||
"pyproject.toml": `[project]
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
import { promisify } from "node:util";
|
||||
import {
|
||||
afterEach,
|
||||
beforeEach,
|
||||
describe,
|
||||
expect,
|
||||
it,
|
||||
jest,
|
||||
} from "@jest/globals";
|
||||
|
||||
const ORIGINAL_UV_PYTHON_ARCH = process.env.UV_PYTHON_ARCH;
|
||||
|
||||
const mockExecFile =
|
||||
jest.fn<
|
||||
(...args: unknown[]) => Promise<{
|
||||
stdout: string;
|
||||
stderr: string;
|
||||
}>
|
||||
>();
|
||||
const mockExportVariable = jest.fn();
|
||||
|
||||
jest.unstable_mockModule("node:child_process", () => ({
|
||||
execFile: Object.assign(mockExecFile, { [promisify.custom]: mockExecFile }),
|
||||
}));
|
||||
jest.unstable_mockModule("@actions/core", () => ({
|
||||
exportVariable: mockExportVariable,
|
||||
}));
|
||||
jest.unstable_mockModule("../../src/utils/logging", () => ({
|
||||
info: jest.fn(),
|
||||
}));
|
||||
|
||||
const { setupPythonArch } = await import("../../src/utils/python-arch");
|
||||
|
||||
const supportedProbe = Object.assign(new Error("uv exited with code 2"), {
|
||||
code: 2,
|
||||
stderr:
|
||||
"error: Failed to parse environment variable `UV_PYTHON_ARCH` with invalid value `setup-uv-probe`: Unknown architecture: setup-uv-probe\n",
|
||||
});
|
||||
const success = { stderr: "", stdout: "/cache\n" };
|
||||
|
||||
beforeEach(() => {
|
||||
delete process.env.UV_PYTHON_ARCH;
|
||||
jest.clearAllMocks();
|
||||
mockExecFile
|
||||
.mockReset()
|
||||
.mockRejectedValueOnce(supportedProbe)
|
||||
.mockResolvedValueOnce(success);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
if (ORIGINAL_UV_PYTHON_ARCH === undefined) {
|
||||
delete process.env.UV_PYTHON_ARCH;
|
||||
} else {
|
||||
process.env.UV_PYTHON_ARCH = ORIGINAL_UV_PYTHON_ARCH;
|
||||
}
|
||||
});
|
||||
|
||||
describe("setupPythonArch", () => {
|
||||
it("leaves Python selection alone without an architecture", async () => {
|
||||
await setupPythonArch("/tools/uv", "", false);
|
||||
|
||||
expect(mockExecFile).not.toHaveBeenCalled();
|
||||
expect(mockExportVariable).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("validates a resolved environment architecture without exporting it", async () => {
|
||||
process.env.UV_PYTHON_ARCH = "aarch64";
|
||||
|
||||
await setupPythonArch("/tools/uv", "aarch64", false);
|
||||
|
||||
expect(mockExecFile).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
"/tools/uv",
|
||||
["--no-config", "cache", "dir"],
|
||||
expect.objectContaining({
|
||||
env: expect.objectContaining({ UV_PYTHON_ARCH: "aarch64" }),
|
||||
}),
|
||||
);
|
||||
expect(mockExportVariable).not.toHaveBeenCalled();
|
||||
expect(process.env.UV_PYTHON_ARCH).toBe("aarch64");
|
||||
});
|
||||
|
||||
it.each(["/runner temp/uv", "C:\\runner temp\\uv.exe"])(
|
||||
"validates and exports the architecture using the installed uv: %s",
|
||||
async (uvPath) => {
|
||||
await setupPythonArch(uvPath, "x86_64", true);
|
||||
|
||||
expect(mockExecFile).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
uvPath,
|
||||
["--no-config", "cache", "dir"],
|
||||
expect.objectContaining({
|
||||
encoding: "utf8",
|
||||
env: expect.objectContaining({ UV_PYTHON_ARCH: "setup-uv-probe" }),
|
||||
}),
|
||||
);
|
||||
expect(mockExecFile).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
uvPath,
|
||||
["--no-config", "cache", "dir"],
|
||||
expect.objectContaining({
|
||||
env: expect.objectContaining({ UV_PYTHON_ARCH: "x86_64" }),
|
||||
}),
|
||||
);
|
||||
expect(mockExportVariable).toHaveBeenCalledWith(
|
||||
"UV_PYTHON_ARCH",
|
||||
"x86_64",
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
it("rejects uv versions that ignore UV_PYTHON_ARCH", async () => {
|
||||
mockExecFile.mockReset().mockResolvedValue(success);
|
||||
|
||||
await expect(setupPythonArch("/tools/uv", "x86_64", true)).rejects.toThrow(
|
||||
"The installed version of uv does not support UV_PYTHON_ARCH",
|
||||
);
|
||||
expect(mockExecFile).toHaveBeenCalledTimes(1);
|
||||
expect(mockExportVariable).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("reports unexpected probe failures", async () => {
|
||||
mockExecFile.mockReset().mockRejectedValue(
|
||||
Object.assign(new Error("uv exited with code 2"), {
|
||||
code: 2,
|
||||
stderr: "error: unrelated configuration error\n",
|
||||
}),
|
||||
);
|
||||
|
||||
await expect(setupPythonArch("/tools/uv", "x86_64", true)).rejects.toThrow(
|
||||
"Failed to check uv's support for UV_PYTHON_ARCH: error: unrelated configuration error",
|
||||
);
|
||||
expect(mockExportVariable).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("reports invalid architectures before exporting them", async () => {
|
||||
mockExecFile
|
||||
.mockReset()
|
||||
.mockRejectedValueOnce(supportedProbe)
|
||||
.mockRejectedValueOnce(
|
||||
Object.assign(new Error("uv exited with code 2"), {
|
||||
code: 2,
|
||||
stderr: "error: Unknown architecture: invalid\n",
|
||||
}),
|
||||
);
|
||||
|
||||
await expect(setupPythonArch("/tools/uv", "invalid", true)).rejects.toThrow(
|
||||
"Failed to set Python architecture to invalid: error: Unknown architecture: invalid",
|
||||
);
|
||||
expect(mockExportVariable).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,86 @@
|
||||
import { promisify } from "node:util";
|
||||
import { beforeEach, expect, it, jest } from "@jest/globals";
|
||||
import { createSetupInputs } from "../helpers/setup-inputs";
|
||||
|
||||
const mockExecFile =
|
||||
jest.fn<
|
||||
(...args: unknown[]) => Promise<{ stdout: string; stderr: string }>
|
||||
>();
|
||||
const inputs = createSetupInputs({
|
||||
activateEnvironment: true,
|
||||
pythonVersion: "3.15t",
|
||||
});
|
||||
|
||||
jest.unstable_mockModule("node:child_process", () => ({
|
||||
// execFile's custom promisifier returns both stdout and stderr.
|
||||
execFile: Object.assign(mockExecFile, { [promisify.custom]: mockExecFile }),
|
||||
}));
|
||||
|
||||
const { getPythonRuntimeId } = await import("../../src/utils/python-runtime");
|
||||
|
||||
beforeEach(() => {
|
||||
mockExecFile.mockReset();
|
||||
mockExecFile.mockResolvedValue({
|
||||
stderr: "",
|
||||
stdout: '[{"key":"cpython-3.13.1-linux-x86_64-gnu"}]\r\n',
|
||||
});
|
||||
});
|
||||
|
||||
it("does not query uv without environment activation", async () => {
|
||||
expect(
|
||||
await getPythonRuntimeId({ ...inputs, activateEnvironment: false }),
|
||||
).toBe("");
|
||||
expect(mockExecFile).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it.each([
|
||||
"cpython-3.13.1-linux-x86_64-gnu",
|
||||
"cpython-3.15.0rc1+freethreaded-macos-aarch64-none",
|
||||
"cpython-3.15.0rc2+freethreaded-windows-x86_64-none",
|
||||
"pypy-3.11.15-linux-x86_64-gnu",
|
||||
])("returns uv's opaque runtime key unchanged: %s", async (key) => {
|
||||
mockExecFile.mockResolvedValue({
|
||||
stderr: "",
|
||||
stdout: `${JSON.stringify([{ key }])}\r\n`,
|
||||
});
|
||||
expect(await getPythonRuntimeId(inputs)).toBe(key);
|
||||
});
|
||||
|
||||
it.each(['/runner temp/a "quoted" venv', "C:\\runner temp\\custom venv"])(
|
||||
"queries the exact venv directory: %s",
|
||||
async (venvPath) => {
|
||||
await getPythonRuntimeId({ ...inputs, venvPath });
|
||||
expect(mockExecFile).toHaveBeenCalledWith(
|
||||
"uv",
|
||||
[
|
||||
"python",
|
||||
"list",
|
||||
venvPath,
|
||||
"--only-installed",
|
||||
"--output-format",
|
||||
"json",
|
||||
],
|
||||
{ encoding: "utf8" },
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
new Error("uv failed"),
|
||||
"not JSON",
|
||||
"null",
|
||||
"{}",
|
||||
"[]",
|
||||
'[{"key":""}]',
|
||||
'[{"key":123}]',
|
||||
'[{"key":"first"},{"key":"second"}]',
|
||||
])("rejects uv failure or invalid results: %s", async (result) => {
|
||||
if (result instanceof Error) {
|
||||
mockExecFile.mockRejectedValue(result);
|
||||
} else {
|
||||
mockExecFile.mockResolvedValue({ stderr: "", stdout: result });
|
||||
}
|
||||
await expect(getPythonRuntimeId(inputs)).rejects.toThrow(
|
||||
"Failed to identify the activated environment's Python runtime:",
|
||||
);
|
||||
});
|
||||
@@ -35,3 +35,14 @@ test("strips PEP 508 markers from requirements dependencies", () => {
|
||||
|
||||
expect(parsedVersion).toBe("==0.11.20");
|
||||
});
|
||||
|
||||
test.each([
|
||||
["uv >= 0.5.0", ">=0.5.0"],
|
||||
["uv == 0.11.20", "==0.11.20"],
|
||||
["uv>=0.5.0, <0.6.0", ">=0.5.0,<0.6.0"],
|
||||
["uv >= 0.5.0 , < 0.6.0", ">=0.5.0,<0.6.0"],
|
||||
["uv==0.11.20 --hash=sha256:abc", "==0.11.20"],
|
||||
["uv==0.11.20 # pinned for CI", "==0.11.20"],
|
||||
])("allows whitespace in the uv specifier %s", (dependency, expected) => {
|
||||
expect(getUvVersionFromRequirementsText(dependency)).toBe(expected);
|
||||
});
|
||||
+11
-1
@@ -7,6 +7,8 @@ inputs:
|
||||
type: string
|
||||
python-version:
|
||||
type: string
|
||||
python-arch:
|
||||
type: string
|
||||
activate-environment:
|
||||
type: boolean
|
||||
venv-path:
|
||||
@@ -17,6 +19,8 @@ inputs:
|
||||
type: string
|
||||
checksum:
|
||||
type: string
|
||||
require-checksums:
|
||||
type: boolean
|
||||
github-token:
|
||||
type: string
|
||||
enable-cache:
|
||||
@@ -33,7 +37,11 @@ inputs:
|
||||
restore-cache:
|
||||
type: boolean
|
||||
save-cache:
|
||||
type: boolean
|
||||
type: enum
|
||||
allowed-values:
|
||||
- "true"
|
||||
- "false"
|
||||
- auto
|
||||
cache-suffix:
|
||||
type: string
|
||||
cache-local-path:
|
||||
@@ -79,5 +87,7 @@ outputs:
|
||||
type: string
|
||||
python-version:
|
||||
type: string
|
||||
python-runtime-id:
|
||||
type: string
|
||||
python-cache-hit:
|
||||
type: boolean
|
||||
+11
-3
@@ -12,6 +12,9 @@ inputs:
|
||||
python-version:
|
||||
description: "The version of Python to set UV_PYTHON to. Overrides the Python version from .tool-versions."
|
||||
required: false
|
||||
python-arch:
|
||||
description: "The Python architecture to set UV_PYTHON_ARCH to, e.g., x86_64 or aarch64. Overrides UV_PYTHON_ARCH."
|
||||
required: false
|
||||
activate-environment:
|
||||
description: "Use uv venv to activate a venv ready to be used by later steps. "
|
||||
default: "false"
|
||||
@@ -27,6 +30,9 @@ inputs:
|
||||
checksum:
|
||||
description: "The checksum of the uv version to install"
|
||||
required: false
|
||||
require-checksums:
|
||||
description: "Require a SHA-256 checksum bundled with setup-uv or supplied through the checksum input."
|
||||
default: "false"
|
||||
github-token:
|
||||
description:
|
||||
"Used when downloading uv from GitHub releases."
|
||||
@@ -51,8 +57,8 @@ inputs:
|
||||
description: "Whether to restore the cache if found."
|
||||
default: "true"
|
||||
save-cache:
|
||||
description: "Whether to save the cache after the run."
|
||||
default: "true"
|
||||
description: "Whether to save the cache after the run. 'auto' disables saving for merge_group events."
|
||||
default: "auto"
|
||||
cache-suffix:
|
||||
description: "Suffix for the cache key"
|
||||
required: false
|
||||
@@ -107,8 +113,10 @@ outputs:
|
||||
description: "Path to the activated venv if activate-environment is true"
|
||||
python-version:
|
||||
description: "The Python version that was set."
|
||||
python-runtime-id:
|
||||
description: "An opaque identifier reported by uv for the activated venv's Python runtime. Empty when activate-environment is false."
|
||||
python-cache-hit:
|
||||
description: "A boolean value to indicate the Python cache entry was found"
|
||||
description: "A boolean indicating whether the Python cache was restored successfully."
|
||||
runs:
|
||||
using: "node24"
|
||||
main: "dist/setup/index.cjs"
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"$schema": "https://biomejs.dev/schemas/2.5.7/schema.json",
|
||||
"$schema": "https://biomejs.dev/schemas/2.5.14/schema.json",
|
||||
"assist": {
|
||||
"actions": {
|
||||
"source": {
|
||||
|
||||
+2822
-1027
File diff suppressed because it is too large.
Load diff
+2615
-1097
File diff suppressed because it is too large.
Load diff
+2085
-733
File diff suppressed because it is too large.
Load diff
@@ -6,7 +6,7 @@ This document covers advanced options for configuring which version of uv to ins
|
||||
|
||||
```yaml
|
||||
- name: Install the latest version of uv
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
version: "latest"
|
||||
```
|
||||
@@ -15,11 +15,13 @@ This document covers advanced options for configuring which version of uv to ins
|
||||
|
||||
Use `latest-known` to install the newest uv version whose checksums were bundled with the version of setup-uv used by your workflow. Version resolution is performed locally without fetching the latest release, so updating setup-uv also updates the version selected by `latest-known`.
|
||||
|
||||
When `manifest-file` is set, `latest-known` still selects a version from setup-uv's bundled checksum table, but the artifact and checksum come from the custom manifest.
|
||||
When `manifest-file` is set, `latest-known` still selects a version from setup-uv's bundled checksum table.
|
||||
By default the custom manifest supplies the artifact and checksum. To require a bundled or explicitly
|
||||
supplied checksum, enable `require-checksums`. [Checksum validation](customization.md#validate-checksum)
|
||||
|
||||
```yaml
|
||||
- name: Install the latest version of uv known to setup-uv
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
version: "latest-known"
|
||||
```
|
||||
@@ -28,7 +30,7 @@ When `manifest-file` is set, `latest-known` still selects a version from setup-u
|
||||
|
||||
```yaml
|
||||
- name: Install a specific version of uv
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
version: "0.4.4"
|
||||
```
|
||||
@@ -41,21 +43,21 @@ to install the latest version that satisfies the range.
|
||||
|
||||
```yaml
|
||||
- name: Install a semver range of uv
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
version: ">=0.4.0"
|
||||
```
|
||||
|
||||
```yaml
|
||||
- name: Pinning a minor version of uv
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
version: "0.4.x"
|
||||
```
|
||||
|
||||
```yaml
|
||||
- name: Install a pep440-specifier-satisfying version of uv
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
version: ">=0.4.25,<0.5"
|
||||
```
|
||||
@@ -67,7 +69,7 @@ You can change this behavior using the `resolution-strategy` input:
|
||||
|
||||
```yaml
|
||||
- name: Install the lowest compatible version of uv
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
version: ">=0.4.0"
|
||||
resolution-strategy: "lowest"
|
||||
@@ -92,7 +94,7 @@ as `UV_PYTHON`. Only a single Python version is supported; multiple fallback ver
|
||||
|
||||
```yaml
|
||||
- name: Install uv based on the version defined in pyproject.toml
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
version-file: "pyproject.toml"
|
||||
```
|
||||
@@ -103,7 +105,7 @@ silently picking up a newer uv until the lockfile is updated.
|
||||
|
||||
```yaml
|
||||
- name: Install uv based on the version locked in uv.lock
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
version-file: "uv.lock"
|
||||
```
|
||||
+17
-14
@@ -11,6 +11,7 @@ The cache key is automatically generated based on:
|
||||
`pc-windows-msvc`)
|
||||
- **OS version**: OS name and version (e.g., `ubuntu-22.04`, `macos-14`, `windows-2022`)
|
||||
- **Python version**: The Python version in use
|
||||
- **Python architecture**: The architecture selected by `python-arch` or `UV_PYTHON_ARCH`, when set
|
||||
- **Cache options**: Whether pruning and Python caching are enabled
|
||||
- **Dependency hash**: Hash of files matching `cache-dependency-glob`
|
||||
- **Suffix**: Optional `cache-suffix` if provided
|
||||
@@ -23,7 +24,7 @@ The computed cache key is available as the `cache-key` output:
|
||||
```yaml
|
||||
- name: Setup uv
|
||||
id: setup-uv
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
enable-cache: true
|
||||
- name: Print cache key
|
||||
@@ -53,7 +54,7 @@ You can optionally define a custom cache key suffix.
|
||||
```yaml
|
||||
- name: Enable caching and define a custom cache key suffix
|
||||
id: setup-uv
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
enable-cache: true
|
||||
cache-suffix: "optional-suffix"
|
||||
@@ -92,7 +93,7 @@ changes. If you use relative paths, they are relative to the working directory.
|
||||
|
||||
```yaml
|
||||
- name: Define a cache dependency glob
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
enable-cache: true
|
||||
cache-dependency-glob: "**/pyproject.toml"
|
||||
@@ -100,7 +101,7 @@ changes. If you use relative paths, they are relative to the working directory.
|
||||
|
||||
```yaml
|
||||
- name: Define a list of cache dependency globs
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
enable-cache: true
|
||||
cache-dependency-glob: |
|
||||
@@ -110,7 +111,7 @@ changes. If you use relative paths, they are relative to the working directory.
|
||||
|
||||
```yaml
|
||||
- name: Define an absolute cache dependency glob
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
enable-cache: true
|
||||
cache-dependency-glob: "/tmp/my-folder/requirements*.txt"
|
||||
@@ -118,7 +119,7 @@ changes. If you use relative paths, they are relative to the working directory.
|
||||
|
||||
```yaml
|
||||
- name: Never invalidate the cache
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
enable-cache: true
|
||||
cache-dependency-glob: ""
|
||||
@@ -131,7 +132,7 @@ By default, the cache will be restored.
|
||||
|
||||
```yaml
|
||||
- name: Don't restore an existing cache
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
enable-cache: true
|
||||
restore-cache: false
|
||||
@@ -139,13 +140,15 @@ By default, the cache will be restored.
|
||||
|
||||
## Save cache
|
||||
|
||||
You can also disable saving the cache after the run with the `save-cache` input.
|
||||
You can control 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.
|
||||
By default, `save-cache: auto` saves the cache except for `merge_group` events, where caches created
|
||||
for temporary merge queue refs are unlikely to be reused. Cache restoration remains enabled for
|
||||
these events. Set `save-cache: true` to save the cache for all events.
|
||||
|
||||
```yaml
|
||||
- name: Don't save the cache after the run
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
enable-cache: true
|
||||
save-cache: false
|
||||
@@ -171,7 +174,7 @@ It defaults to `setup-uv-cache` in the `TMP` dir, `D:\a\_temp\setup-uv-cache` on
|
||||
|
||||
```yaml
|
||||
- name: Define a custom uv cache path
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
cache-local-path: "/path/to/cache"
|
||||
```
|
||||
@@ -188,7 +191,7 @@ If you want to prune the cache before saving it, enable cache pruning with the `
|
||||
|
||||
```yaml
|
||||
- name: Prune the cache before saving it
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
enable-cache: true
|
||||
prune-cache: true
|
||||
@@ -207,7 +210,7 @@ To force managed Python installs, set `UV_PYTHON_PREFERENCE=only-managed`.
|
||||
|
||||
```yaml
|
||||
- name: Cache Python installs
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
enable-cache: true
|
||||
cache-python: true
|
||||
@@ -225,7 +228,7 @@ If you want to ignore this, set the `ignore-nothing-to-cache` input to `true`.
|
||||
|
||||
```yaml
|
||||
- name: Ignore nothing to cache
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
enable-cache: true
|
||||
ignore-nothing-to-cache: true
|
||||
|
||||
+33
-7
@@ -4,25 +4,51 @@ This document covers advanced customization options including checksum validatio
|
||||
|
||||
## Validate checksum
|
||||
|
||||
You can specify a checksum to validate the downloaded executable. Checksums up to the default version
|
||||
are automatically verified by this action. The sha256 hashes can be found on the
|
||||
Downloaded archives are automatically verified using checksums bundled with this action or,
|
||||
for newer, not yet bundled versions, the checksum from [`astral-sh/versions`](https://github.com/astral-sh/versions).
|
||||
You can specify a checksum to override those values. The sha256 hashes can also be found on the
|
||||
[releases page](https://github.com/astral-sh/uv/releases) of the uv repo.
|
||||
|
||||
```yaml
|
||||
- name: Install a specific version and validate the checksum
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
version: "0.3.1"
|
||||
checksum: "e11b01402ab645392c7ad6044db63d37e4fd1e745e015306993b07695ea5f9f8"
|
||||
```
|
||||
|
||||
For an additional layer of protection, you can set `require-checksums: true`.
|
||||
This prevents setup-uv from trusting an unknown version's checksum from
|
||||
[`astral-sh/versions`](https://github.com/astral-sh/versions) *unless* it is also
|
||||
present in the action's own bundled data *or* explicitly provided with `checksum`.
|
||||
|
||||
This can be combined with `version: latest-known` to select the newest bundled release,
|
||||
meaning that this newer requires an external checksum source:
|
||||
|
||||
```yaml
|
||||
- name: Install the latest known version of uv
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
version: latest-known
|
||||
require-checksums: true
|
||||
```
|
||||
|
||||
With this mode, you'll need to update setup-uv itself to get newer uv versions
|
||||
*unless* you explicitly pass in a `checksum` with a version that post-dates the setup-uv
|
||||
release.
|
||||
|
||||
On runners with a persistent tool cache, this mode reuses only installations previously verified
|
||||
against the same digest. The first run may download uv again.
|
||||
|
||||
## Manifest file
|
||||
|
||||
By default, setup-uv reads version metadata from
|
||||
[`astral-sh/versions`](https://github.com/astral-sh/versions).
|
||||
the [Astral mirror](https://releases.astral.sh/github/versions/main/v1/uv.ndjson).
|
||||
If the mirror request fails, it falls back to [`astral-sh/versions`](https://github.com/astral-sh/versions).
|
||||
|
||||
The `manifest-file` input lets you override that source with your own URL, for example to test
|
||||
custom uv builds or alternate download locations.
|
||||
custom uv builds or alternate download locations. Custom manifest URLs do not fall back to the
|
||||
default sources.
|
||||
|
||||
### Format
|
||||
|
||||
@@ -39,7 +65,7 @@ The `archive_format` field is currently ignored.
|
||||
|
||||
```yaml
|
||||
- name: Use a custom manifest file
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
manifest-file: "https://example.com/my-custom-manifest.ndjson"
|
||||
```
|
||||
@@ -58,7 +84,7 @@ 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@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
add-problem-matchers: false
|
||||
```
|
||||
@@ -9,7 +9,7 @@ This allows directly using it in later steps:
|
||||
|
||||
```yaml
|
||||
- name: Install the latest version of uv and activate the environment
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
activate-environment: true
|
||||
- run: uv pip install pip
|
||||
@@ -17,10 +17,22 @@ This allows directly using it in later steps:
|
||||
|
||||
By default, the venv is created at `.venv` inside the `working-directory`.
|
||||
|
||||
With `activate-environment: true`, the `python-runtime-id` output identifies the
|
||||
venv's Python runtime as reported by uv. This is an opaque identifier that users of the action
|
||||
can use as a cache key if necessary; users should not assume anything about
|
||||
the stability or structure of the identifier itself.
|
||||
|
||||
For example, you can combine it with the platform and dependency information relevant to
|
||||
your cache with `id: setup-uv` on the setup step:
|
||||
|
||||
```yaml
|
||||
key: build-${{ runner.os }}-${{ runner.arch }}-${{ steps.setup-uv.outputs.python-runtime-id }}-${{ hashFiles('uv.lock') }}
|
||||
```
|
||||
|
||||
You can customize the venv location with `venv-path`, for example to place it in the runner temp directory:
|
||||
|
||||
```yaml
|
||||
- uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
- uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
activate-environment: true
|
||||
venv-path: ${{ runner.temp }}/custom-venv
|
||||
@@ -38,12 +50,13 @@ You can customize the venv location with `venv-path`, for example to place it in
|
||||
|
||||
## GitHub authentication token
|
||||
|
||||
By default, this action resolves available uv versions from
|
||||
[`astral-sh/versions`](https://github.com/astral-sh/versions), then downloads uv artifacts from
|
||||
GitHub Releases.
|
||||
By default, this action fetches version metadata and uv archives from the Astral mirror.
|
||||
If a manifest request fails, it falls back to `raw.githubusercontent.com`. If an archive download
|
||||
fails, it falls back to GitHub Releases.
|
||||
|
||||
You can provide a token via `github-token` to authenticate those downloads. By default, the
|
||||
`GITHUB_TOKEN` secret is used, which is automatically provided by GitHub Actions.
|
||||
You can provide a token via `github-token` to authenticate GitHub Releases downloads. The token
|
||||
is not sent to the Astral mirror or used for manifest requests. By default, the `GITHUB_TOKEN`
|
||||
secret is used, which is automatically provided by GitHub Actions.
|
||||
|
||||
If the default
|
||||
[permissions for the GitHub token](https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication#permissions-for-the-github_token)
|
||||
@@ -51,7 +64,7 @@ are not sufficient, you can provide a custom GitHub token with the necessary per
|
||||
|
||||
```yaml
|
||||
- name: Install the latest version of uv with a custom GitHub token
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
github-token: ${{ secrets.CUSTOM_GITHUB_TOKEN }}
|
||||
```
|
||||
@@ -69,7 +82,7 @@ input:
|
||||
|
||||
```yaml
|
||||
- name: Install the latest version of uv with a custom tool dir
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
tool-dir: "/path/to/tool/dir"
|
||||
```
|
||||
@@ -88,7 +101,7 @@ If you want to change this behaviour (especially on self-hosted runners) you can
|
||||
|
||||
```yaml
|
||||
- name: Install the latest version of uv with a custom tool bin dir
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
tool-bin-dir: "/path/to/tool-bin/dir"
|
||||
```
|
||||
@@ -105,7 +118,7 @@ This action supports expanding the `~` character to the user's home directory fo
|
||||
|
||||
```yaml
|
||||
- name: Expand the tilde character
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
cache-local-path: "~/path/to/cache"
|
||||
tool-dir: "~/path/to/tool/dir"
|
||||
@@ -122,7 +135,7 @@ If you want to ignore this, set the `ignore-empty-workdir` input to `true`.
|
||||
|
||||
```yaml
|
||||
- name: Ignore empty workdir
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
ignore-empty-workdir: true
|
||||
```
|
||||
@@ -132,6 +145,7 @@ If you want to ignore this, set the `ignore-empty-workdir` input to `true`.
|
||||
This action sets several environment variables that influence uv's behavior and can be used by subsequent steps:
|
||||
|
||||
- `UV_PYTHON`: Set when `python-version` is specified or the selected `.tool-versions` file contains a supported `python` entry. Controls which Python version uv uses.
|
||||
- `UV_PYTHON_ARCH`: Set when `python-arch` is specified. Controls the architecture of Python requests that do not specify one.
|
||||
- `UV_CACHE_DIR`: Set when caching is enabled (unless already configured in uv config files). Controls where uv stores its cache.
|
||||
- `UV_TOOL_DIR`: Set when `tool-dir` input is specified. Controls where uv installs tool environments.
|
||||
- `UV_TOOL_BIN_DIR`: Set when `tool-bin-dir` input is specified. Controls where uv installs tool binaries.
|
||||
@@ -143,10 +157,11 @@ This action sets several environment variables that influence uv's behavior and
|
||||
- `UV_NO_MODIFY_PATH`: If set, prevents the action from modifying PATH. Cannot be used with `activate-environment`.
|
||||
- `UV_CACHE_DIR`: If already set, the action will respect it instead of setting its own cache directory.
|
||||
- `UV_PYTHON`: If already set and `python-version` is not specified, the action will respect it instead of using the `python` entry from `.tool-versions`.
|
||||
- `UV_PYTHON_ARCH`: If already set and `python-arch` is not specified, the action will use it and include it in the cache key. Requires a uv version that supports `UV_PYTHON_ARCH`.
|
||||
|
||||
```yaml
|
||||
- name: Example using environment variables
|
||||
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
|
||||
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
||||
with:
|
||||
python-version: "3.12"
|
||||
tool-dir: "/custom/tool/dir"
|
||||
|
||||
@@ -38,7 +38,7 @@ Material failures are unauthorized executable selection, credential disclosure,
|
||||
### Security invariants
|
||||
|
||||
1. **Published runtime:** review `action.yml`, committed `dist/*.cjs`, and runner-interpreted shipped files; source-only fixes do not protect consumers.
|
||||
2. **Executable identity:** precedence is workflow version, version file, project configuration, then `latest`. Manifest authority, platform, variant, URL, checksum, mirror fallback, extraction, and cache placement must bind the intended artifact. A tool-cache hit bypasses download validation and depends on cache provenance.
|
||||
2. **Executable identity:** precedence is workflow version, version file, project configuration, then `latest`. Manifest authority, platform, variant, URL, checksum, mirror fallback, extraction, and cache placement must bind the intended artifact. A tool-cache hit bypasses download validation and depends on cache provenance. With `require-checksums`, only entries keyed by the explicit or bundled archive digest are eligible.
|
||||
3. **Credential recipients:** tokens and URL credentials may reach only workflow-authorized origins, redirects, paths, and logs. Metadata authority does not imply token-recipient authority.
|
||||
4. **Executable boundaries:** checkout-selected interpreters are authorized by default. Explicit workflow selections must win, and independent cache, runner, or remote state must not substitute executables or gain additional authority.
|
||||
5. **Paths and action channels:** path/environment changes, virtual-environment clearing, outputs, state, and problem matchers must affect only authorized targets and keep untrusted values as data.
|
||||
|
||||
Generated
+2287
-2183
File diff suppressed because it is too large.
Load diff
+19
-9
@@ -5,6 +5,16 @@
|
||||
"type": "module",
|
||||
"description": "Set up your GitHub Actions workflow with a specific version of uv",
|
||||
"main": "dist/setup/index.cjs",
|
||||
"engines": {
|
||||
"npm": ">=11.10.0"
|
||||
},
|
||||
"devEngines": {
|
||||
"packageManager": {
|
||||
"name": "npm",
|
||||
"version": ">=11.10.0",
|
||||
"onFail": "error"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc --noEmit",
|
||||
"check": "biome check --write",
|
||||
@@ -12,7 +22,7 @@
|
||||
"test:unit": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js",
|
||||
"test": "npm run build && npm run test:unit",
|
||||
"act": "act pull_request -W .github/workflows/test.yml --container-architecture linux/amd64 -s GITHUB_TOKEN=\"$(gh auth token)\"",
|
||||
"update-known-checksums": "RUNNER_TEMP=known_versions node dist/update-known-checksums/index.cjs src/download/checksum/known-checksums.ts",
|
||||
"update-known-checksums": "RUNNER_TEMP=known_versions node dist/update-known-checksums/index.cjs src/download/checksum/known-checksums.json",
|
||||
"all": "npm run build && npm run check && npm run package && npm run test:unit"
|
||||
},
|
||||
"repository": {
|
||||
@@ -35,18 +45,18 @@
|
||||
"@actions/io": "^3.0.2",
|
||||
"@actions/tool-cache": "^4.0.0",
|
||||
"@renovatebot/pep440": "^5.0.0",
|
||||
"smol-toml": "^1.7.1",
|
||||
"undici": "^8.10.0"
|
||||
"smol-toml": "^1.8.0",
|
||||
"undici": "^8.11.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "^2.5.7",
|
||||
"@biomejs/biome": "^2.5.14",
|
||||
"@types/js-yaml": "^4.0.9",
|
||||
"@types/node": "^26.1.2",
|
||||
"@types/node": "^26.6.2",
|
||||
"@types/semver": "^7.8.0",
|
||||
"@vercel/ncc": "^0.44.1",
|
||||
"esbuild": "^0.28.1",
|
||||
"jest": "^30.4.2",
|
||||
"js-yaml": "^5.2.3",
|
||||
"@vercel/ncc": "^0.45.0",
|
||||
"esbuild": "^0.28.2",
|
||||
"jest": "^30.5.2",
|
||||
"js-yaml": "^5.4.1",
|
||||
"ts-jest": "^29.4.11",
|
||||
"typescript": "^6.0.3"
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ const builds = [
|
||||
},
|
||||
{
|
||||
entryPoints: ["src/save-cache.ts"],
|
||||
// @actions/cache compares error.name to the error constructor's name.
|
||||
keepNames: true,
|
||||
outfile: "dist/save-cache/index.cjs",
|
||||
staleOutfiles: ["dist/save-cache/index.mjs"],
|
||||
},
|
||||
|
||||
Vendored
+60
@@ -0,0 +1,60 @@
|
||||
import { readdir, readlink, realpath, symlink, unlink } from "node:fs/promises";
|
||||
import nodePath from "node:path";
|
||||
|
||||
export async function repairPythonJunctions(pythonDir: string): Promise<void> {
|
||||
const entries = await readdir(pythonDir, { withFileTypes: true });
|
||||
const directories = new Set(
|
||||
entries
|
||||
.filter((entry) => entry.isDirectory())
|
||||
.map((entry) => entry.name.toLowerCase()),
|
||||
);
|
||||
|
||||
for (const entry of entries) {
|
||||
const name = entry.name.toLowerCase();
|
||||
if (!entry.isSymbolicLink() || !/^cpython-\d+\.\d+[+-].+$/.test(name)) {
|
||||
continue;
|
||||
}
|
||||
const link = nodePath.join(pythonDir, entry.name);
|
||||
let target: string;
|
||||
try {
|
||||
target = nodePath.resolve(pythonDir, await readlink(link));
|
||||
} catch (err) {
|
||||
// Fail only if the link still has the access error that requires repair.
|
||||
if (await resolvesWithAccessDenied(link)) {
|
||||
throw err;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// uv omits only the patch and prerelease from its minor-version links.
|
||||
const sibling = nodePath.relative(pythonDir, target).toLowerCase();
|
||||
const version = /^(cpython-\d+\.\d+)\.\d+(?:(?:a|b|rc)\d+)?([+-].+)$/.exec(
|
||||
sibling,
|
||||
);
|
||||
if (
|
||||
!version ||
|
||||
version[1] + version[2] !== name ||
|
||||
!directories.has(sibling)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
// Git for Windows tar can restore a junction as a file symlink when it
|
||||
// extracts the link before its target. Opening it as a directory fails.
|
||||
if (!(await resolvesWithAccessDenied(link))) {
|
||||
continue;
|
||||
}
|
||||
// An inaccessible installation can also cause EPERM through a valid link.
|
||||
await realpath(target);
|
||||
await unlink(link);
|
||||
await symlink(target, link, "junction");
|
||||
}
|
||||
}
|
||||
|
||||
async function resolvesWithAccessDenied(link: string): Promise<boolean> {
|
||||
try {
|
||||
await realpath(link);
|
||||
return false;
|
||||
} catch (err) {
|
||||
return (err as NodeJS.ErrnoException).code === "EPERM";
|
||||
}
|
||||
}
|
||||
Vendored
+25
-23
@@ -4,6 +4,7 @@ import { hashFiles } from "../hash/hash-files";
|
||||
import type { SetupInputs } from "../utils/inputs";
|
||||
import * as log from "../utils/logging";
|
||||
import { getArch, getOSNameVersion, getPlatform } from "../utils/platforms";
|
||||
import { repairPythonJunctions } from "./repair-python-junctions";
|
||||
|
||||
export const STATE_CACHE_KEY = "cache-key";
|
||||
export const STATE_CACHE_MATCHED_KEY = "cache-matched-key";
|
||||
@@ -44,6 +45,9 @@ export async function restoreCache(
|
||||
inputs.pythonDir,
|
||||
STATE_PYTHON_CACHE_MATCHED_KEY,
|
||||
"python-cache-hit",
|
||||
// TODO: Remove this repair once @actions/cache preserves Windows junctions.
|
||||
// https://github.com/actions/toolkit/issues/2562
|
||||
process.platform === "win32" ? repairPythonJunctions : undefined,
|
||||
);
|
||||
} else {
|
||||
core.setOutput("python-cache-hit", false);
|
||||
@@ -55,21 +59,33 @@ async function restoreCacheFromKey(
|
||||
cachePath: string,
|
||||
stateKey: string,
|
||||
outputKey: string,
|
||||
afterRestore?: (cachePath: string) => Promise<void>,
|
||||
): Promise<void> {
|
||||
log.info(
|
||||
`Trying to restore cache from GitHub Actions cache with key: ${cacheKey}`,
|
||||
);
|
||||
let matchedKey: string | undefined;
|
||||
try {
|
||||
matchedKey = await cache.restoreCache([cachePath], cacheKey);
|
||||
const matchedKey = await cache.restoreCache([cachePath], cacheKey);
|
||||
if (!matchedKey) {
|
||||
log.info(`No GitHub Actions cache found for key: ${cacheKey}`);
|
||||
core.setOutput(outputKey, false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Record the match before the post-restore hook so the post step can skip
|
||||
// archiving the directory again even if the hook fails. A PR that restored
|
||||
// from its base branch could otherwise save the broken copy in its own cache.
|
||||
core.saveState(stateKey, matchedKey);
|
||||
await afterRestore?.(cachePath);
|
||||
log.info(
|
||||
`cache restored from GitHub Actions cache with key: ${matchedKey}`,
|
||||
);
|
||||
core.setOutput(outputKey, true);
|
||||
} catch (err) {
|
||||
const message = (err as Error).message;
|
||||
log.warning(message);
|
||||
core.setOutput(outputKey, false);
|
||||
return;
|
||||
}
|
||||
|
||||
handleMatchResult(matchedKey, cacheKey, stateKey, outputKey);
|
||||
}
|
||||
|
||||
async function computeKeys(
|
||||
@@ -98,26 +114,12 @@ async function computeKeys(
|
||||
? `-${encodeURIComponent(inputs.cacheSuffix)}`
|
||||
: "";
|
||||
const version = encodeURIComponent(pythonVersion ?? "unknown");
|
||||
const pythonArchKey = inputs.pythonArch
|
||||
? `-python-${encodeURIComponent(inputs.pythonArch)}`
|
||||
: "";
|
||||
const platform = await getPlatform();
|
||||
const osNameVersion = getOSNameVersion();
|
||||
const pruned = inputs.pruneCache ? "-pruned" : "";
|
||||
const python = inputs.cachePython ? "-py" : "";
|
||||
return `setup-uv-${CACHE_VERSION}-${getArch()}-${platform}-${osNameVersion}-${version}${pruned}${python}${cacheDependencyPathHash}${suffix}`;
|
||||
}
|
||||
|
||||
function handleMatchResult(
|
||||
matchedKey: string | undefined,
|
||||
primaryKey: string,
|
||||
stateKey: string,
|
||||
outputKey: string,
|
||||
): void {
|
||||
if (!matchedKey) {
|
||||
log.info(`No GitHub Actions cache found for key: ${primaryKey}`);
|
||||
core.setOutput(outputKey, false);
|
||||
return;
|
||||
}
|
||||
|
||||
core.saveState(stateKey, matchedKey);
|
||||
log.info(`cache restored from GitHub Actions cache with key: ${matchedKey}`);
|
||||
core.setOutput(outputKey, true);
|
||||
return `setup-uv-${CACHE_VERSION}-${getArch()}-${platform}-${osNameVersion}-${version}${pythonArchKey}${pruned}${python}${cacheDependencyPathHash}${suffix}`;
|
||||
}
|
||||
@@ -11,19 +11,26 @@ export async function validateChecksum(
|
||||
arch: Architecture,
|
||||
platform: Platform,
|
||||
version: string,
|
||||
manifestChecksum?: string,
|
||||
): Promise<void> {
|
||||
const key = `${arch}-${platform}-${version}`;
|
||||
const hasProvidedChecksum = checksum !== undefined && checksum !== "";
|
||||
const checksumToUse = hasProvidedChecksum ? checksum : KNOWN_CHECKSUMS[key];
|
||||
const knownChecksum = KNOWN_CHECKSUMS[key];
|
||||
const hasManifestChecksum =
|
||||
manifestChecksum !== undefined && manifestChecksum !== "";
|
||||
const checksumToUse = hasProvidedChecksum
|
||||
? checksum
|
||||
: (knownChecksum ?? (hasManifestChecksum ? manifestChecksum : undefined));
|
||||
|
||||
if (checksumToUse === undefined) {
|
||||
core.debug(`No checksum found for ${key}.`);
|
||||
return;
|
||||
throw new Error(`No checksum found for ${key} in manifest.`);
|
||||
}
|
||||
|
||||
const checksumSource = hasProvidedChecksum
|
||||
? "provided checksum"
|
||||
: `KNOWN_CHECKSUMS entry for ${key}`;
|
||||
: knownChecksum !== undefined
|
||||
? `KNOWN_CHECKSUMS entry for ${key}`
|
||||
: "manifest checksum";
|
||||
|
||||
core.debug(`Validating checksum using ${checksumSource}.`);
|
||||
const isValid = await validateFileCheckSum(downloadPath, checksumToUse);
|
||||
|
||||
+5686
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -19,16 +19,7 @@ export async function updateChecksums(
|
||||
deduplicatedEntries.set(entry.key, entry.checksum);
|
||||
}
|
||||
|
||||
const body = [...deduplicatedEntries.entries()]
|
||||
.map(([key, checksum]) => ` "${key}":\n "${checksum}"`)
|
||||
.join(",\n");
|
||||
|
||||
const content =
|
||||
"// AUTOGENERATED_DO_NOT_EDIT\n" +
|
||||
"export const KNOWN_CHECKSUMS: { [key: string]: string } = {\n" +
|
||||
body +
|
||||
(body === "" ? "" : ",\n") +
|
||||
"};\n";
|
||||
const content = `${JSON.stringify(Object.fromEntries(deduplicatedEntries), null, 2)}\n`;
|
||||
|
||||
await fs.writeFile(filePath, content);
|
||||
}
|
||||
@@ -11,22 +11,40 @@ import {
|
||||
import * as log from "../utils/logging";
|
||||
import type { Architecture, Platform } from "../utils/platforms";
|
||||
import { validateChecksum } from "./checksum/checksum";
|
||||
import { KNOWN_CHECKSUMS } from "./checksum/known-checksums";
|
||||
import { getArtifact } from "./manifest";
|
||||
|
||||
export { resolveVersion } from "../version/resolve";
|
||||
|
||||
export function getIntrinsicChecksum(
|
||||
key: string,
|
||||
providedChecksum: string,
|
||||
): string {
|
||||
const checksum = providedChecksum || KNOWN_CHECKSUMS[key];
|
||||
if (!checksum) {
|
||||
throw new Error(
|
||||
`No bundled checksum for ${key}. With require-checksums enabled, update setup-uv or provide the checksum input for this archive.`,
|
||||
);
|
||||
}
|
||||
if (!/^[a-f0-9]{64}$/.test(checksum)) {
|
||||
throw new Error(`Expected a SHA-256 checksum for ${key}.`);
|
||||
}
|
||||
return checksum;
|
||||
}
|
||||
|
||||
export function tryGetFromToolCache(
|
||||
arch: Architecture,
|
||||
version: string,
|
||||
toolCacheName = TOOL_CACHE_NAME,
|
||||
): { version: string; installedPath: string | undefined } {
|
||||
core.debug(`Trying to get uv from tool cache for ${version}...`);
|
||||
const cachedVersions = tc.findAllVersions(TOOL_CACHE_NAME, arch);
|
||||
const cachedVersions = tc.findAllVersions(toolCacheName, arch);
|
||||
core.debug(`Cached versions: ${cachedVersions}`);
|
||||
let resolvedVersion = tc.evaluateVersions(cachedVersions, version);
|
||||
if (resolvedVersion === "") {
|
||||
resolvedVersion = version;
|
||||
}
|
||||
const installedPath = tc.find(TOOL_CACHE_NAME, resolvedVersion, arch);
|
||||
const installedPath = tc.find(toolCacheName, resolvedVersion, arch);
|
||||
return { installedPath, version: resolvedVersion };
|
||||
}
|
||||
|
||||
@@ -38,6 +56,7 @@ export async function downloadVersion(
|
||||
githubToken: string,
|
||||
manifestUrl?: string,
|
||||
downloadFromAstralMirror = true,
|
||||
toolCacheName = TOOL_CACHE_NAME,
|
||||
): Promise<{ version: string; cachedToolDir: string }> {
|
||||
const artifact = await getArtifact(version, arch, platform, manifestUrl);
|
||||
|
||||
@@ -47,12 +66,14 @@ export async function downloadVersion(
|
||||
);
|
||||
}
|
||||
|
||||
// For the default astral-sh/versions source, checksum validation relies on
|
||||
// user input or the built-in KNOWN_CHECKSUMS table, not manifest sha256 values.
|
||||
// Custom manifests are explicitly selected by the user, so their checksum
|
||||
// takes precedence over the built-in table. For the default manifest, pass
|
||||
// its checksum as a fallback after user input and KNOWN_CHECKSUMS.
|
||||
const resolvedChecksum =
|
||||
manifestUrl === undefined
|
||||
? checksum
|
||||
: resolveChecksum(checksum, artifact.checksum);
|
||||
const manifestChecksum = artifact.checksum;
|
||||
|
||||
const mirrorUrl = downloadFromAstralMirror
|
||||
? rewriteToMirror(artifact.downloadUrl)
|
||||
@@ -67,7 +88,9 @@ export async function downloadVersion(
|
||||
arch,
|
||||
version,
|
||||
resolvedChecksum,
|
||||
manifestChecksum,
|
||||
githubTokenForUrl(downloadUrl, githubToken),
|
||||
toolCacheName,
|
||||
);
|
||||
} catch (err) {
|
||||
if (mirrorUrl === undefined) {
|
||||
@@ -85,7 +108,9 @@ export async function downloadVersion(
|
||||
arch,
|
||||
version,
|
||||
resolvedChecksum,
|
||||
manifestChecksum,
|
||||
githubTokenForUrl(artifact.downloadUrl, githubToken),
|
||||
toolCacheName,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -122,7 +147,9 @@ async function downloadArtifact(
|
||||
arch: Architecture,
|
||||
version: string,
|
||||
checksum: string | undefined,
|
||||
manifestChecksum: string | undefined,
|
||||
githubToken: string | undefined,
|
||||
toolCacheName: string,
|
||||
): Promise<{ version: string; cachedToolDir: string }> {
|
||||
log.info(`Downloading uv from "${downloadUrl}" ...`);
|
||||
const downloadPath = await tc.downloadTool(
|
||||
@@ -130,7 +157,14 @@ async function downloadArtifact(
|
||||
undefined,
|
||||
githubToken,
|
||||
);
|
||||
await validateChecksum(checksum, downloadPath, arch, platform, version);
|
||||
await validateChecksum(
|
||||
checksum,
|
||||
downloadPath,
|
||||
arch,
|
||||
platform,
|
||||
version,
|
||||
manifestChecksum,
|
||||
);
|
||||
|
||||
let uvDir: string;
|
||||
if (platform === "pc-windows-msvc") {
|
||||
@@ -153,12 +187,7 @@ async function downloadArtifact(
|
||||
uvDir = path.join(extractedDir, artifactName);
|
||||
}
|
||||
|
||||
const cachedToolDir = await tc.cacheDir(
|
||||
uvDir,
|
||||
TOOL_CACHE_NAME,
|
||||
version,
|
||||
arch,
|
||||
);
|
||||
const cachedToolDir = await tc.cacheDir(uvDir, toolCacheName, version, arch);
|
||||
return { cachedToolDir, version };
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { createInterface } from "node:readline";
|
||||
import { Readable } from "node:stream";
|
||||
import * as core from "@actions/core";
|
||||
import { VERSIONS_MANIFEST_URL } from "../utils/constants";
|
||||
import {
|
||||
GITHUB_VERSIONS_MANIFEST_URL,
|
||||
VERSIONS_MANIFEST_URL,
|
||||
} from "../utils/constants";
|
||||
import { fetch } from "../utils/fetch";
|
||||
import * as log from "../utils/logging";
|
||||
import { selectDefaultVariant } from "./variant-selection";
|
||||
@@ -31,6 +34,7 @@ interface CachedManifest {
|
||||
}
|
||||
|
||||
const cachedManifestData = new Map<string, CachedManifest>();
|
||||
export const MANIFEST_FETCH_ATTEMPTS = 3;
|
||||
|
||||
export async function fetchManifest(
|
||||
manifestUrl: string = VERSIONS_MANIFEST_URL,
|
||||
@@ -166,8 +170,40 @@ export function clearManifestCache(manifestUrl?: string): void {
|
||||
}
|
||||
|
||||
async function fetchManifestResponse(manifestUrl: string) {
|
||||
log.info(`Fetching manifest data from ${manifestUrl} ...`);
|
||||
const response = await fetch(manifestUrl, {});
|
||||
try {
|
||||
return await fetchManifestResponseFromUrl(manifestUrl);
|
||||
} catch (error) {
|
||||
if (manifestUrl !== VERSIONS_MANIFEST_URL) {
|
||||
throw error;
|
||||
}
|
||||
log.info(
|
||||
`Failed to fetch manifest from Astral mirror, falling back to GitHub: ${(error as Error).message}`,
|
||||
);
|
||||
return await fetchManifestResponseFromUrl(GITHUB_VERSIONS_MANIFEST_URL);
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchManifestResponseFromUrl(manifestUrl: string) {
|
||||
let response: Awaited<ReturnType<typeof fetch>> | undefined;
|
||||
for (let attempt = 1; attempt <= MANIFEST_FETCH_ATTEMPTS; attempt++) {
|
||||
log.info(`Fetching manifest data from ${manifestUrl} ...`);
|
||||
try {
|
||||
response = await fetch(manifestUrl, {});
|
||||
break;
|
||||
} catch (error) {
|
||||
if (attempt >= MANIFEST_FETCH_ATTEMPTS) {
|
||||
throw error;
|
||||
}
|
||||
const delayMs = 1_000 * 2 ** (attempt - 1);
|
||||
log.info(`Manifest fetch failed; retrying in ${delayMs}ms ...`);
|
||||
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
||||
}
|
||||
}
|
||||
|
||||
if (response === undefined) {
|
||||
throw new Error("Manifest fetch attempts exhausted.");
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`Failed to fetch manifest data: ${response.status} ${response.statusText}`,
|
||||
|
||||
+4
-2
@@ -159,8 +159,10 @@ async function saveCacheToKey(
|
||||
}
|
||||
|
||||
log.info(`Including ${cacheName} path: ${cachePath}`);
|
||||
await cache.saveCache([cachePath], cacheKey);
|
||||
log.info(`${cacheName} saved with key: ${cacheKey}`);
|
||||
const cacheId = await cache.saveCache([cachePath], cacheKey);
|
||||
if (cacheId !== -1) {
|
||||
log.info(`${cacheName} saved with key: ${cacheKey}`);
|
||||
}
|
||||
}
|
||||
|
||||
run();
|
||||
+31
-3
@@ -5,9 +5,14 @@ import * as exec from "@actions/exec";
|
||||
import { restoreCache } from "./cache/restore-cache";
|
||||
import {
|
||||
downloadVersion,
|
||||
getIntrinsicChecksum,
|
||||
tryGetFromToolCache,
|
||||
} from "./download/download-version";
|
||||
import { STATE_UV_PATH, STATE_UV_VERSION } from "./utils/constants";
|
||||
import {
|
||||
STATE_UV_PATH,
|
||||
STATE_UV_VERSION,
|
||||
TOOL_CACHE_NAME,
|
||||
} from "./utils/constants";
|
||||
import { CacheLocalSource, loadInputs, type SetupInputs } from "./utils/inputs";
|
||||
import * as log from "./utils/logging";
|
||||
import {
|
||||
@@ -16,6 +21,8 @@ import {
|
||||
getPlatform,
|
||||
type Platform,
|
||||
} from "./utils/platforms";
|
||||
import { setupPythonArch } from "./utils/python-arch";
|
||||
import { getPythonRuntimeId } from "./utils/python-runtime";
|
||||
import { resolveUvVersion } from "./version/resolve";
|
||||
|
||||
const sourceDir = __dirname;
|
||||
@@ -85,6 +92,11 @@ async function run(): Promise<void> {
|
||||
throw new Error(`Unsupported architecture: ${process.arch}`);
|
||||
}
|
||||
const setupResult = await setupUv(inputs, platform, arch);
|
||||
const uvPath = path.join(
|
||||
setupResult.uvDir,
|
||||
process.platform === "win32" ? "uv.exe" : "uv",
|
||||
);
|
||||
await setupPythonArch(uvPath, inputs.pythonArch, inputs.exportPythonArch);
|
||||
|
||||
addToolBinToPath(inputs);
|
||||
addUvToPathAndOutput(setupResult.uvDir);
|
||||
@@ -101,6 +113,7 @@ async function run(): Promise<void> {
|
||||
|
||||
const detectedPythonVersion = await getPythonVersion(inputs);
|
||||
core.setOutput("python-version", detectedPythonVersion);
|
||||
core.setOutput("python-runtime-id", await getPythonRuntimeId(inputs));
|
||||
|
||||
if (inputs.enableCache) {
|
||||
await restoreCache(inputs, detectedPythonVersion);
|
||||
@@ -139,7 +152,21 @@ async function setupUv(
|
||||
versionFile: inputs.versionFile,
|
||||
workingDirectory: inputs.workingDirectory,
|
||||
});
|
||||
const toolCacheResult = tryGetFromToolCache(arch, resolvedVersion);
|
||||
let checksum = inputs.checksum;
|
||||
let toolCacheName = TOOL_CACHE_NAME;
|
||||
if (inputs.requireChecksums) {
|
||||
checksum = getIntrinsicChecksum(
|
||||
`${arch}-${platform}-${resolvedVersion}`,
|
||||
inputs.checksum,
|
||||
);
|
||||
// A regular tool-cache entry may have been verified using a manifest checksum.
|
||||
toolCacheName = `${TOOL_CACHE_NAME}-${checksum}`;
|
||||
}
|
||||
const toolCacheResult = tryGetFromToolCache(
|
||||
arch,
|
||||
resolvedVersion,
|
||||
toolCacheName,
|
||||
);
|
||||
if (toolCacheResult.installedPath) {
|
||||
log.info(`Found uv in tool-cache for ${toolCacheResult.version}`);
|
||||
return {
|
||||
@@ -152,10 +179,11 @@ async function setupUv(
|
||||
platform,
|
||||
arch,
|
||||
resolvedVersion,
|
||||
inputs.checksum,
|
||||
checksum,
|
||||
inputs.githubToken,
|
||||
inputs.manifestFile,
|
||||
inputs.downloadFromAstralMirror,
|
||||
toolCacheName,
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
@@ -2,6 +2,8 @@ export const TOOL_CACHE_NAME = "uv";
|
||||
export const STATE_UV_PATH = "uv-path";
|
||||
export const STATE_UV_VERSION = "uv-version";
|
||||
export const VERSIONS_MANIFEST_URL =
|
||||
"https://releases.astral.sh/github/versions/main/v1/uv.ndjson";
|
||||
export const GITHUB_VERSIONS_MANIFEST_URL =
|
||||
"https://raw.githubusercontent.com/astral-sh/versions/main/v1/uv.ndjson";
|
||||
|
||||
/** GitHub Releases URL prefix for uv artifacts. */
|
||||
|
||||
+6
-16
@@ -1,18 +1,8 @@
|
||||
import { ProxyAgent, type RequestInit, fetch as undiciFetch } from "undici";
|
||||
|
||||
export function getProxyAgent() {
|
||||
const httpProxy = process.env.HTTP_PROXY || process.env.http_proxy;
|
||||
if (httpProxy) {
|
||||
return new ProxyAgent(httpProxy);
|
||||
}
|
||||
|
||||
const httpsProxy = process.env.HTTPS_PROXY || process.env.https_proxy;
|
||||
if (httpsProxy) {
|
||||
return new ProxyAgent(httpsProxy);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
import {
|
||||
EnvHttpProxyAgent,
|
||||
type RequestInit,
|
||||
fetch as undiciFetch,
|
||||
} from "undici";
|
||||
|
||||
export const fetch = async (url: string, opts: RequestInit) => {
|
||||
// Merge timeout signal with any existing signal from opts
|
||||
@@ -23,7 +13,7 @@ export const fetch = async (url: string, opts: RequestInit) => {
|
||||
: timeoutSignal;
|
||||
|
||||
return await undiciFetch(url, {
|
||||
dispatcher: getProxyAgent(),
|
||||
dispatcher: new EnvHttpProxyAgent(),
|
||||
...opts,
|
||||
signal: mergedSignal,
|
||||
});
|
||||
|
||||
+23
-1
@@ -24,10 +24,13 @@ export interface SetupInputs {
|
||||
version: string;
|
||||
versionFile: string;
|
||||
pythonVersion: string;
|
||||
pythonArch: string;
|
||||
exportPythonArch: boolean;
|
||||
activateEnvironment: boolean;
|
||||
noProject: boolean;
|
||||
venvPath: string;
|
||||
checksum: string;
|
||||
requireChecksums: boolean;
|
||||
enableCache: boolean;
|
||||
restoreCache: boolean;
|
||||
saveCache: boolean;
|
||||
@@ -54,13 +57,17 @@ export function loadInputs(): SetupInputs {
|
||||
const version = core.getInput("version");
|
||||
const versionFile = getVersionFile(workingDirectory);
|
||||
const pythonVersion = getPythonVersion(versionFile);
|
||||
const pythonArchInput = core.getInput("python-arch");
|
||||
const pythonArch = pythonArchInput || process.env.UV_PYTHON_ARCH || "";
|
||||
const exportPythonArch = pythonArchInput !== "";
|
||||
const activateEnvironment = core.getBooleanInput("activate-environment");
|
||||
const noProject = core.getBooleanInput("no-project");
|
||||
const venvPath = getVenvPath(workingDirectory, activateEnvironment);
|
||||
const checksum = core.getInput("checksum");
|
||||
const requireChecksums = core.getBooleanInput("require-checksums");
|
||||
const enableCache = getEnableCache();
|
||||
const restoreCache = core.getInput("restore-cache") === "true";
|
||||
const saveCache = core.getInput("save-cache") === "true";
|
||||
const saveCache = getSaveCache();
|
||||
const cacheSuffix = core.getInput("cache-suffix") || "";
|
||||
const cacheLocalPath = getCacheLocalPath(
|
||||
workingDirectory,
|
||||
@@ -94,15 +101,18 @@ export function loadInputs(): SetupInputs {
|
||||
checksum,
|
||||
downloadFromAstralMirror,
|
||||
enableCache,
|
||||
exportPythonArch,
|
||||
githubToken,
|
||||
ignoreEmptyWorkdir,
|
||||
ignoreNothingToCache,
|
||||
manifestFile,
|
||||
noProject,
|
||||
pruneCache,
|
||||
pythonArch,
|
||||
pythonDir,
|
||||
pythonVersion,
|
||||
quiet,
|
||||
requireChecksums,
|
||||
resolutionStrategy,
|
||||
restoreCache,
|
||||
saveCache,
|
||||
@@ -189,6 +199,18 @@ function getEnableCache(): boolean {
|
||||
return enableCacheInput === "true";
|
||||
}
|
||||
|
||||
function getSaveCache(): boolean {
|
||||
const saveCacheInput = core.getInput("save-cache");
|
||||
if (saveCacheInput === "auto") {
|
||||
if (process.env.GITHUB_EVENT_NAME === "merge_group") {
|
||||
log.info("Cache saving is disabled for the merge_group event");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return saveCacheInput === "true";
|
||||
}
|
||||
|
||||
function getToolBinDir(workingDirectory: string): string | undefined {
|
||||
const toolBinDirInput = core.getInput("tool-bin-dir");
|
||||
if (toolBinDirInput !== "") {
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { promisify } from "node:util";
|
||||
import * as core from "@actions/core";
|
||||
import * as log from "./logging";
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
const PROBE_ARCH = "setup-uv-probe";
|
||||
|
||||
export async function setupPythonArch(
|
||||
uvPath: string,
|
||||
pythonArch: string,
|
||||
exportPythonArch: boolean,
|
||||
): Promise<void> {
|
||||
if (pythonArch === "") {
|
||||
return;
|
||||
}
|
||||
|
||||
// Older uv releases ignore unknown environment variables. An invalid architecture
|
||||
// confirms that uv recognizes UV_PYTHON_ARCH without finding or downloading Python.
|
||||
const probe = await queryPythonArch(uvPath, PROBE_ARCH);
|
||||
if (probe.exitCode === 0) {
|
||||
throw new Error(
|
||||
"The installed version of uv does not support UV_PYTHON_ARCH. Select a newer uv version or use an architecture-qualified python-version.",
|
||||
);
|
||||
}
|
||||
if (
|
||||
!probe.stderr.includes(
|
||||
`environment variable \`UV_PYTHON_ARCH\` with invalid value \`${PROBE_ARCH}\``,
|
||||
)
|
||||
) {
|
||||
throw new Error(
|
||||
`Failed to check uv's support for UV_PYTHON_ARCH: ${probe.stderr.trim() || `uv exited with code ${probe.exitCode}`}`,
|
||||
);
|
||||
}
|
||||
|
||||
const selected = await queryPythonArch(uvPath, pythonArch);
|
||||
if (selected.exitCode !== 0) {
|
||||
throw new Error(
|
||||
`Failed to set Python architecture to ${pythonArch}: ${selected.stderr.trim() || `uv exited with code ${selected.exitCode}`}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (exportPythonArch) {
|
||||
core.exportVariable("UV_PYTHON_ARCH", pythonArch);
|
||||
log.info(`Set UV_PYTHON_ARCH to ${pythonArch}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function queryPythonArch(
|
||||
uvPath: string,
|
||||
pythonArch: string,
|
||||
): Promise<{ exitCode: number; stderr: string }> {
|
||||
try {
|
||||
const { stderr } = await execFileAsync(
|
||||
uvPath,
|
||||
["--no-config", "cache", "dir"],
|
||||
{
|
||||
encoding: "utf8",
|
||||
env: { ...process.env, NO_COLOR: "1", UV_PYTHON_ARCH: pythonArch },
|
||||
},
|
||||
);
|
||||
return { exitCode: 0, stderr };
|
||||
} catch (error) {
|
||||
if (
|
||||
error instanceof Error &&
|
||||
"code" in error &&
|
||||
typeof error.code === "number" &&
|
||||
"stderr" in error &&
|
||||
typeof error.stderr === "string"
|
||||
) {
|
||||
return { exitCode: error.code, stderr: error.stderr };
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { promisify } from "node:util";
|
||||
import type { SetupInputs } from "./inputs";
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
|
||||
export async function getPythonRuntimeId(inputs: SetupInputs): Promise<string> {
|
||||
if (!inputs.activateEnvironment) {
|
||||
return "";
|
||||
}
|
||||
|
||||
try {
|
||||
// The venv path restricts results to this invocation's runtime, even if
|
||||
// earlier setup-uv calls installed other Python versions in the same job.
|
||||
const { stdout } = await execFileAsync(
|
||||
"uv",
|
||||
[
|
||||
"python",
|
||||
"list",
|
||||
inputs.venvPath,
|
||||
"--only-installed",
|
||||
"--output-format",
|
||||
"json",
|
||||
],
|
||||
{ encoding: "utf8" },
|
||||
);
|
||||
const pythons = JSON.parse(stdout);
|
||||
if (
|
||||
!Array.isArray(pythons) ||
|
||||
pythons.length !== 1 ||
|
||||
typeof pythons[0]?.key !== "string" ||
|
||||
pythons[0].key === ""
|
||||
) {
|
||||
throw new Error("Expected one installed Python with a runtime key");
|
||||
}
|
||||
return pythons[0].key;
|
||||
} catch (error) {
|
||||
throw new Error(
|
||||
`Failed to identify the activated environment's Python runtime: ${error instanceof Error ? error.message : String(error)}`,
|
||||
{ cause: error },
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -69,5 +69,7 @@ function getUvVersionFromAllDependencies(
|
||||
|
||||
function getUvVersionFromDependency(dependency: string): string | undefined {
|
||||
const dependencyWithoutMarker = dependency.split(";", 1)[0]?.trim();
|
||||
return dependencyWithoutMarker?.match(/^uv([=<>~!]+\S*)/)?.[1].trim();
|
||||
return dependencyWithoutMarker
|
||||
?.match(/^uv\s*((?:[=<>~!]+\s*[^\s,]+\s*,?\s*)+)/)?.[1]
|
||||
.replace(/\s/g, "");
|
||||
}
|
||||
+19
-3
@@ -169,7 +169,9 @@ async function findHighestSatisfyingVersion(
|
||||
): Promise<string | undefined> {
|
||||
// This fast path assumes uv releases are semver-monotonic: newer manifest
|
||||
// entries always have higher versions, with no lower-version backports.
|
||||
const semverRange = semver.validRange(versionSpecifier);
|
||||
const semverRange = isPep440Specifier(versionSpecifier)
|
||||
? null
|
||||
: semver.validRange(versionSpecifier);
|
||||
if (semverRange !== null) {
|
||||
const semverMatch = await getFirstMatchingVersion((version) =>
|
||||
semver.satisfies(version, semverRange),
|
||||
@@ -193,11 +195,23 @@ async function findHighestSatisfyingVersion(
|
||||
return pep440Match;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifiers that are valid PEP 440 must be evaluated as PEP 440. semver
|
||||
* accepts several of them with different semantics, e.g. `~=0.5` as `<0.6.0`
|
||||
* instead of `<1.0`, `<=0.5` as `<0.6.0` instead of `<=0.5.0` and `>0.5` as
|
||||
* `>=0.6.0` instead of `>0.5.0`.
|
||||
*/
|
||||
function isPep440Specifier(versionSpecifier: string): boolean {
|
||||
return pep440.validRange(versionSpecifier);
|
||||
}
|
||||
|
||||
function maxSatisfying(
|
||||
versions: string[],
|
||||
version: string,
|
||||
): string | undefined {
|
||||
const maxSemver = tc.evaluateVersions(versions, version);
|
||||
const maxSemver = isPep440Specifier(version)
|
||||
? ""
|
||||
: tc.evaluateVersions(versions, version);
|
||||
if (maxSemver !== "") {
|
||||
core.debug(`Found a version that satisfies the semver range: ${maxSemver}`);
|
||||
return maxSemver;
|
||||
@@ -218,7 +232,9 @@ function minSatisfying(
|
||||
versions: string[],
|
||||
version: string,
|
||||
): string | undefined {
|
||||
const minSemver = semver.minSatisfying(versions, version);
|
||||
const minSemver = isPep440Specifier(version)
|
||||
? null
|
||||
: semver.minSatisfying(versions, version);
|
||||
if (minSemver !== null) {
|
||||
core.debug(`Found a version that satisfies the semver range: ${minSemver}`);
|
||||
return minSemver;
|
||||
|
||||
@@ -21,8 +21,13 @@ export type ParsedVersionSpecifier =
|
||||
export function normalizeVersionSpecifier(specifier: string): string {
|
||||
const trimmedSpecifier = specifier.trim();
|
||||
|
||||
// Only strip `==` from full versions. A partial pin like `==0.5` means
|
||||
// `==0.5.0` in PEP 440, but `0.5` alone is read as the semver range `0.5.x`.
|
||||
if (trimmedSpecifier.startsWith("==")) {
|
||||
return trimmedSpecifier.slice(2);
|
||||
const pinnedVersion = trimmedSpecifier.slice(2).trim();
|
||||
if (tc.isExplicitVersion(pinnedVersion)) {
|
||||
return pinnedVersion;
|
||||
}
|
||||
}
|
||||
|
||||
return trimmedSpecifier;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"module": "esnext",
|
||||
"moduleResolution": "bundler",
|
||||
"noImplicitAny": true,
|
||||
"resolveJsonModule": true,
|
||||
"strict": true,
|
||||
"target": "ES2022"
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user