Skip to content

Commit ee4fa33

Browse files
authored
Add input python-version (#174)
1 parent 4209155 commit ee4fa33

File tree

7 files changed

+44
-8
lines changed

7 files changed

+44
-8
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- name: Make sure no changes from linters are detected
2525
run: |
2626
git diff --exit-code
27-
test-latest-version:
27+
test-default-version:
2828
runs-on: ${{ matrix.os }}
2929
strategy:
3030
matrix:

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Set up your GitHub Actions workflow with a specific version of [uv](https://docs
1414
- [Install the latest version (default)](#install-the-latest-version-default)
1515
- [Install a specific version](#install-a-specific-version)
1616
- [Install a version by supplying a semver range](#install-a-version-by-supplying-a-semver-range)
17+
- [Python version](#python-version)
1718
- [Validate checksum](#validate-checksum)
1819
- [Enable Caching](#enable-caching)
1920
- [Cache dependency glob](#cache-dependency-glob)
@@ -75,6 +76,19 @@ to install the latest version that satisfies the range.
7576
version: "0.4.x"
7677
```
7778

79+
### Python version
80+
81+
You can use the input `python-version` to set the environment variable `UV_PYTHON` for the rest
82+
of your workflow.
83+
This will override any python version specifications in `pyproject.toml` and `.python-version`
84+
85+
```yaml
86+
- name: Install the latest version of uv and set the python version to 3.12
87+
uses: astral-sh/setup-uv@v3
88+
with:
89+
python-version: "3.12"
90+
```
91+
7892
### Validate checksum
7993

8094
You can specify a checksum to validate the downloaded executable. Checksums up to the default version

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ inputs:
66
version:
77
description: "The version of uv to install"
88
default: "latest"
9+
python-version:
10+
description: "The version of Python to set UV_PYTHON to"
11+
required: false
912
checksum:
1013
description: "The checksum of the uv version to install"
1114
required: false

dist/save-cache/index.js

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/setup/index.js

Lines changed: 11 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/setup-uv.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
checkSum,
1919
enableCache,
2020
githubToken,
21+
pythonVersion,
2122
toolBinDir,
2223
toolDir,
2324
version,
@@ -45,12 +46,13 @@ async function run(): Promise<void> {
4546
addUvToPath(setupResult.uvDir);
4647
addToolBinToPath();
4748
setToolDir();
48-
core.setOutput("uv-version", setupResult.version);
49-
core.info(`Successfully installed uv version ${setupResult.version}`);
50-
49+
setupPython();
5150
addMatchers();
5251
setCacheDir(cacheLocalPath);
5352

53+
core.setOutput("uv-version", setupResult.version);
54+
core.info(`Successfully installed uv version ${setupResult.version}`);
55+
5456
if (enableCache) {
5557
await restoreCache(setupResult.version);
5658
}
@@ -133,6 +135,13 @@ function setToolDir(): void {
133135
}
134136
}
135137

138+
function setupPython(): void {
139+
if (pythonVersion !== "") {
140+
core.exportVariable("UV_PYTHON", pythonVersion);
141+
core.info(`Set UV_PYTHON to ${pythonVersion}`);
142+
}
143+
}
144+
136145
function setCacheDir(cacheLocalPath: string): void {
137146
core.exportVariable("UV_CACHE_DIR", cacheLocalPath);
138147
core.info(`Set UV_CACHE_DIR to ${cacheLocalPath}`);

src/utils/inputs.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as core from "@actions/core";
22
import path from "node:path";
33

44
export const version = core.getInput("version");
5+
export const pythonVersion = core.getInput("python-version");
56
export const checkSum = core.getInput("checksum");
67
export const enableCache = core.getInput("enable-cache") === "true";
78
export const cacheSuffix = core.getInput("cache-suffix") || "";

0 commit comments

Comments
 (0)