From f2859da2136ea665156125d1df40f08c628ddf99 Mon Sep 17 00:00:00 2001 From: Kevin Stillhammer Date: Thu, 2 Oct 2025 17:54:15 +0200 Subject: [PATCH] Respect UV_NO_MODIFY_PATH (#603) Fixes: #519 --- .github/workflows/test.yml | 24 +++++++++++++++++++++++ dist/save-cache/index.js | 19 +++++++++++++++++- dist/setup/index.js | 30 ++++++++++++++++++++++++----- dist/update-known-versions/index.js | 3 ++- src/save-cache.ts | 4 +++- src/setup-uv.ts | 27 ++++++++++++++++++++++---- src/utils/constants.ts | 1 + 7 files changed, 96 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index afe9c90..77d5987 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -72,6 +72,29 @@ jobs: env: UVX_PATH: ${{ steps.setup-uv.outputs.uvx-path }} + test-uv-no-modify-path: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + with: + persist-credentials: false + - name: Install with UV_NO_MODIFY_PATH set + id: setup-uv + uses: ./ + env: + UV_NO_MODIFY_PATH: true + - run: "${UV_PATH}" sync + working-directory: __tests__/fixtures/uv-project + shell: bash + env: + UV_PATH: ${{ steps.setup-uv.outputs.uv-path }} + - name: uv is not on PATH + run: | + if command -v uv; then + echo "uv should not be on PATH" + exit 1 + fi + test-specific-version: runs-on: ubuntu-latest strategy: @@ -755,6 +778,7 @@ jobs: needs: - lint - test-default-version + - test-uv-no-modify-path - test-specific-version - test-latest-version - test-from-working-directory-version diff --git a/dist/save-cache/index.js b/dist/save-cache/index.js index 767e9a1..61b69ee 100644 --- a/dist/save-cache/index.js +++ b/dist/save-cache/index.js @@ -90019,6 +90019,7 @@ const cache = __importStar(__nccwpck_require__(5116)); const core = __importStar(__nccwpck_require__(7484)); const exec = __importStar(__nccwpck_require__(5236)); const restore_cache_1 = __nccwpck_require__(5391); +const constants_1 = __nccwpck_require__(6156); const inputs_1 = __nccwpck_require__(9612); async function run() { try { @@ -90086,11 +90087,27 @@ async function pruneCache() { }; const execArgs = ["cache", "prune", "--ci"]; core.info("Pruning cache..."); - await exec.exec("uv", execArgs, options); + const uvPath = core.getState(constants_1.STATE_UV_PATH); + await exec.exec(uvPath, execArgs, options); } run(); +/***/ }), + +/***/ 6156: +/***/ ((__unused_webpack_module, exports) => { + +"use strict"; + +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.STATE_UV_PATH = exports.TOOL_CACHE_NAME = exports.OWNER = exports.REPO = void 0; +exports.REPO = "uv"; +exports.OWNER = "astral-sh"; +exports.TOOL_CACHE_NAME = "uv"; +exports.STATE_UV_PATH = "uv-path"; + + /***/ }), /***/ 9612: diff --git a/dist/setup/index.js b/dist/setup/index.js index 8c8c987..bfd6bf1 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -129387,6 +129387,7 @@ const core = __importStar(__nccwpck_require__(37484)); const exec = __importStar(__nccwpck_require__(95236)); const restore_cache_1 = __nccwpck_require__(95391); const download_version_1 = __nccwpck_require__(28255); +const constants_1 = __nccwpck_require__(56156); const inputs_1 = __nccwpck_require__(9612); const platforms_1 = __nccwpck_require__(98361); const resolve_1 = __nccwpck_require__(36772); @@ -129473,18 +129474,33 @@ async function determineVersion(manifestFile) { } function addUvToPathAndOutput(cachedPath) { core.setOutput("uv-path", `${cachedPath}${path.sep}uv`); + core.saveState(constants_1.STATE_UV_PATH, `${cachedPath}${path.sep}uv`); core.setOutput("uvx-path", `${cachedPath}${path.sep}uvx`); - core.addPath(cachedPath); - core.info(`Added ${cachedPath} to the path`); + if (process.env.UV_NO_MODIFY_PATH !== undefined) { + core.info("UV_NO_MODIFY_PATH is set, not modifying PATH"); + } + else { + core.addPath(cachedPath); + core.info(`Added ${cachedPath} to the path`); + } } function addToolBinToPath() { if (inputs_1.toolBinDir !== undefined) { core.exportVariable("UV_TOOL_BIN_DIR", inputs_1.toolBinDir); core.info(`Set UV_TOOL_BIN_DIR to ${inputs_1.toolBinDir}`); - core.addPath(inputs_1.toolBinDir); - core.info(`Added ${inputs_1.toolBinDir} to the path`); + if (process.env.UV_NO_MODIFY_PATH !== undefined) { + core.info(`UV_NO_MODIFY_PATH is set, not adding ${inputs_1.toolBinDir} to path`); + } + else { + core.addPath(inputs_1.toolBinDir); + core.info(`Added ${inputs_1.toolBinDir} to the path`); + } } else { + if (process.env.UV_NO_MODIFY_PATH !== undefined) { + core.info("UV_NO_MODIFY_PATH is set, not adding user local bin to path"); + return; + } if (process.env.XDG_BIN_HOME !== undefined) { core.addPath(process.env.XDG_BIN_HOME); core.info(`Added ${process.env.XDG_BIN_HOME} to the path`); @@ -129513,6 +129529,9 @@ function setupPython() { } async function activateEnvironment() { if (inputs_1.activateEnvironment) { + if (process.env.UV_NO_MODIFY_PATH !== undefined) { + throw new Error("UV_NO_MODIFY_PATH and activate-environment cannot be used together."); + } const execArgs = ["venv", ".venv", "--directory", inputs_1.workingDirectory]; core.info("Activating python venv..."); await exec.exec("uv", execArgs); @@ -129545,10 +129564,11 @@ run(); "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.TOOL_CACHE_NAME = exports.OWNER = exports.REPO = void 0; +exports.STATE_UV_PATH = exports.TOOL_CACHE_NAME = exports.OWNER = exports.REPO = void 0; exports.REPO = "uv"; exports.OWNER = "astral-sh"; exports.TOOL_CACHE_NAME = "uv"; +exports.STATE_UV_PATH = "uv-path"; /***/ }), diff --git a/dist/update-known-versions/index.js b/dist/update-known-versions/index.js index 551d06d..7a1f49c 100644 --- a/dist/update-known-versions/index.js +++ b/dist/update-known-versions/index.js @@ -65748,10 +65748,11 @@ run(); "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.TOOL_CACHE_NAME = exports.OWNER = exports.REPO = void 0; +exports.STATE_UV_PATH = exports.TOOL_CACHE_NAME = exports.OWNER = exports.REPO = void 0; exports.REPO = "uv"; exports.OWNER = "astral-sh"; exports.TOOL_CACHE_NAME = "uv"; +exports.STATE_UV_PATH = "uv-path"; /***/ }), diff --git a/src/save-cache.ts b/src/save-cache.ts index e79d657..dfe96a0 100644 --- a/src/save-cache.ts +++ b/src/save-cache.ts @@ -6,6 +6,7 @@ import { STATE_CACHE_KEY, STATE_CACHE_MATCHED_KEY, } from "./cache/restore-cache"; +import { STATE_UV_PATH } from "./utils/constants"; import { cacheLocalPath, enableCache, @@ -91,7 +92,8 @@ async function pruneCache(): Promise { const execArgs = ["cache", "prune", "--ci"]; core.info("Pruning cache..."); - await exec.exec("uv", execArgs, options); + const uvPath = core.getState(STATE_UV_PATH); + await exec.exec(uvPath, execArgs, options); } run(); diff --git a/src/setup-uv.ts b/src/setup-uv.ts index 4ba1b6e..7b4fe56 100644 --- a/src/setup-uv.ts +++ b/src/setup-uv.ts @@ -9,6 +9,7 @@ import { resolveVersion, tryGetFromToolCache, } from "./download/download-version"; +import { STATE_UV_PATH } from "./utils/constants"; import { activateEnvironment as activateEnvironmentInput, addProblemMatchers, @@ -163,18 +164,31 @@ async function determineVersion( function addUvToPathAndOutput(cachedPath: string): void { core.setOutput("uv-path", `${cachedPath}${path.sep}uv`); + core.saveState(STATE_UV_PATH, `${cachedPath}${path.sep}uv`); core.setOutput("uvx-path", `${cachedPath}${path.sep}uvx`); - core.addPath(cachedPath); - core.info(`Added ${cachedPath} to the path`); + if (process.env.UV_NO_MODIFY_PATH !== undefined) { + core.info("UV_NO_MODIFY_PATH is set, not modifying PATH"); + } else { + core.addPath(cachedPath); + core.info(`Added ${cachedPath} to the path`); + } } function addToolBinToPath(): void { if (toolBinDir !== undefined) { core.exportVariable("UV_TOOL_BIN_DIR", toolBinDir); core.info(`Set UV_TOOL_BIN_DIR to ${toolBinDir}`); - core.addPath(toolBinDir); - core.info(`Added ${toolBinDir} to the path`); + if (process.env.UV_NO_MODIFY_PATH !== undefined) { + core.info(`UV_NO_MODIFY_PATH is set, not adding ${toolBinDir} to path`); + } else { + core.addPath(toolBinDir); + core.info(`Added ${toolBinDir} to the path`); + } } else { + if (process.env.UV_NO_MODIFY_PATH !== undefined) { + core.info("UV_NO_MODIFY_PATH is set, not adding user local bin to path"); + return; + } if (process.env.XDG_BIN_HOME !== undefined) { core.addPath(process.env.XDG_BIN_HOME); core.info(`Added ${process.env.XDG_BIN_HOME} to the path`); @@ -204,6 +218,11 @@ function setupPython(): void { async function activateEnvironment(): Promise { if (activateEnvironmentInput) { + if (process.env.UV_NO_MODIFY_PATH !== undefined) { + throw new Error( + "UV_NO_MODIFY_PATH and activate-environment cannot be used together.", + ); + } const execArgs = ["venv", ".venv", "--directory", workingDirectory]; core.info("Activating python venv..."); diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 987ae8a..9cf1542 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -1,3 +1,4 @@ export const REPO = "uv"; export const OWNER = "astral-sh"; export const TOOL_CACHE_NAME = "uv"; +export const STATE_UV_PATH = "uv-path";