From ee4fa33003f3367d2ce38897d73042bd77c51a3c Mon Sep 17 00:00:00 2001 From: Kevin Stillhammer Date: Thu, 28 Nov 2024 21:41:37 +0100 Subject: [PATCH] Add input python-version (#174) --- .github/workflows/test.yml | 2 +- README.md | 14 ++++++++++++++ action.yml | 3 +++ dist/save-cache/index.js | 3 ++- dist/setup/index.js | 14 +++++++++++--- src/setup-uv.ts | 15 ++++++++++++--- src/utils/inputs.ts | 1 + 7 files changed, 44 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a5ae1dc..bd342a8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,7 +24,7 @@ jobs: - name: Make sure no changes from linters are detected run: | git diff --exit-code - test-latest-version: + test-default-version: runs-on: ${{ matrix.os }} strategy: matrix: diff --git a/README.md b/README.md index 6668c89..2fb7bc8 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 diff --git a/action.yml b/action.yml index 3356c2f..fbe7e34 100644 --- a/action.yml +++ b/action.yml @@ -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 diff --git a/dist/save-cache/index.js b/dist/save-cache/index.js index 5d58cbf..9a7bf37 100644 --- a/dist/save-cache/index.js +++ b/dist/save-cache/index.js @@ -82614,10 +82614,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.githubToken = exports.toolDir = exports.toolBinDir = exports.ignoreNothingToCache = exports.pruneCache = exports.cacheDependencyGlob = exports.cacheLocalPath = exports.cacheSuffix = exports.enableCache = exports.checkSum = exports.version = void 0; +exports.githubToken = exports.toolDir = exports.toolBinDir = exports.ignoreNothingToCache = exports.pruneCache = exports.cacheDependencyGlob = exports.cacheLocalPath = exports.cacheSuffix = exports.enableCache = exports.checkSum = exports.pythonVersion = exports.version = void 0; const core = __importStar(__nccwpck_require__(7484)); const node_path_1 = __importDefault(__nccwpck_require__(6760)); exports.version = core.getInput("version"); +exports.pythonVersion = core.getInput("python-version"); exports.checkSum = core.getInput("checksum"); exports.enableCache = core.getInput("enable-cache") === "true"; exports.cacheSuffix = core.getInput("cache-suffix") || ""; diff --git a/dist/setup/index.js b/dist/setup/index.js index 46d1e56..e038284 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -90028,10 +90028,11 @@ function run() { addUvToPath(setupResult.uvDir); addToolBinToPath(); setToolDir(); - core.setOutput("uv-version", setupResult.version); - core.info(`Successfully installed uv version ${setupResult.version}`); + setupPython(); addMatchers(); setCacheDir(inputs_1.cacheLocalPath); + core.setOutput("uv-version", setupResult.version); + core.info(`Successfully installed uv version ${setupResult.version}`); if (inputs_1.enableCache) { yield (0, restore_cache_1.restoreCache)(setupResult.version); } @@ -90099,6 +90100,12 @@ function setToolDir() { core.info(`Set UV_TOOL_DIR to ${inputs_1.toolDir}`); } } +function setupPython() { + if (inputs_1.pythonVersion !== "") { + core.exportVariable("UV_PYTHON", inputs_1.pythonVersion); + core.info(`Set UV_PYTHON to ${inputs_1.pythonVersion}`); + } +} function setCacheDir(cacheLocalPath) { core.exportVariable("UV_CACHE_DIR", cacheLocalPath); core.info(`Set UV_CACHE_DIR to ${cacheLocalPath}`); @@ -90158,10 +90165,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.githubToken = exports.toolDir = exports.toolBinDir = exports.ignoreNothingToCache = exports.pruneCache = exports.cacheDependencyGlob = exports.cacheLocalPath = exports.cacheSuffix = exports.enableCache = exports.checkSum = exports.version = void 0; +exports.githubToken = exports.toolDir = exports.toolBinDir = exports.ignoreNothingToCache = exports.pruneCache = exports.cacheDependencyGlob = exports.cacheLocalPath = exports.cacheSuffix = exports.enableCache = exports.checkSum = exports.pythonVersion = exports.version = void 0; const core = __importStar(__nccwpck_require__(7484)); const node_path_1 = __importDefault(__nccwpck_require__(6760)); exports.version = core.getInput("version"); +exports.pythonVersion = core.getInput("python-version"); exports.checkSum = core.getInput("checksum"); exports.enableCache = core.getInput("enable-cache") === "true"; exports.cacheSuffix = core.getInput("cache-suffix") || ""; diff --git a/src/setup-uv.ts b/src/setup-uv.ts index cbead32..43a469a 100644 --- a/src/setup-uv.ts +++ b/src/setup-uv.ts @@ -18,6 +18,7 @@ import { checkSum, enableCache, githubToken, + pythonVersion, toolBinDir, toolDir, version, @@ -45,12 +46,13 @@ async function run(): Promise { 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); } @@ -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}`); diff --git a/src/utils/inputs.ts b/src/utils/inputs.ts index d817815..8d33ecf 100644 --- a/src/utils/inputs.ts +++ b/src/utils/inputs.ts @@ -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") || "";