Skip to content

Commit

Permalink
Add input python-version
Browse files Browse the repository at this point in the history
  • Loading branch information
eifinger committed Nov 28, 2024
1 parent 9839fa9 commit cf466e8
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ concurrency:
cancel-in-progress: true

jobs:
test-default-version:
test-latest-version:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Set up your GitHub Actions workflow with a specific version of [uv](https://docs
- [Install the latest version (default)](#install-the-latest-version-default)
- [Install a specific version](#install-a-specific-version)
- [Install a version by supplying a semver range](#install-a-version-by-supplying-a-semver-range)
- [Python version](#python-version)
- [Validate checksum](#validate-checksum)
- [Enable Caching](#enable-caching)
- [Cache dependency glob](#cache-dependency-glob)
Expand Down Expand Up @@ -75,6 +76,19 @@ to install the latest version that satisfies the range.
version: "0.4.x"
```

### Python version

You can use the input `python-version` to set the environment variable `UV_PYTHON` for the rest
of your workflow.
This will override any python version specifications in `pyproject.toml` and `.python-version`

```yaml
- name: Install the latest version of uv and set the python version to 3.12
uses: astral-sh/setup-uv@v3
with:
python-version: "3.12"
```

### Validate checksum

You can specify a checksum to validate the downloaded executable. Checksums up to the default version
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ inputs:
version:
description: "The version of uv to install"
default: "latest"
python-version:
description: "The version of Python to set UV_PYTHON to"
required: false
checksum:
description: "The checksum of the uv version to install"
required: false
Expand Down
3 changes: 2 additions & 1 deletion dist/save-cache/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions dist/setup/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions src/setup-uv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
checkSum,
enableCache,
githubToken,
pythonVersion,
toolBinDir,
toolDir,
version,
Expand Down Expand Up @@ -45,12 +46,13 @@ async function run(): Promise<void> {
addUvToPath(setupResult.uvDir);
addToolBinToPath();
setToolDir();
core.setOutput("uv-version", setupResult.version);
core.info(`Successfully installed uv version ${setupResult.version}`);

setupPython();
addMatchers();
setCacheDir(cacheLocalPath);

core.setOutput("uv-version", setupResult.version);
core.info(`Successfully installed uv version ${setupResult.version}`);

if (enableCache) {
await restoreCache(setupResult.version);
}
Expand Down Expand Up @@ -133,6 +135,13 @@ function setToolDir(): void {
}
}

function setupPython(): void {
if (pythonVersion !== "") {
core.exportVariable("UV_PYTHON", pythonVersion);
core.info(`Set UV_PYTHON to ${pythonVersion}`);
}
}

function setCacheDir(cacheLocalPath: string): void {
core.exportVariable("UV_CACHE_DIR", cacheLocalPath);
core.info(`Set UV_CACHE_DIR to ${cacheLocalPath}`);
Expand Down
1 change: 1 addition & 0 deletions src/utils/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as core from "@actions/core";
import path from "node:path";

export const version = core.getInput("version");
export const pythonVersion = core.getInput("python-version");
export const checkSum = core.getInput("checksum");
export const enableCache = core.getInput("enable-cache") === "true";
export const cacheSuffix = core.getInput("cache-suffix") || "";
Expand Down

0 comments on commit cf466e8

Please sign in to comment.