Respect UV_NO_MODIFY_PATH (#603)
Some checks failed
CodeQL / Analyze (TypeScript) (push) Failing after 2s
Release Drafter / ✏️ Draft release (push) Has been cancelled

Fixes: #519
This commit is contained in:
Kevin Stillhammer
2025-10-02 17:54:15 +02:00
committed by GitHub
parent f9c6974d8b
commit f2859da213
7 changed files with 96 additions and 12 deletions

View File

@@ -72,6 +72,29 @@ jobs:
env: env:
UVX_PATH: ${{ steps.setup-uv.outputs.uvx-path }} 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: test-specific-version:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
@@ -755,6 +778,7 @@ jobs:
needs: needs:
- lint - lint
- test-default-version - test-default-version
- test-uv-no-modify-path
- test-specific-version - test-specific-version
- test-latest-version - test-latest-version
- test-from-working-directory-version - test-from-working-directory-version

19
dist/save-cache/index.js generated vendored
View File

@@ -90019,6 +90019,7 @@ const cache = __importStar(__nccwpck_require__(5116));
const core = __importStar(__nccwpck_require__(7484)); const core = __importStar(__nccwpck_require__(7484));
const exec = __importStar(__nccwpck_require__(5236)); const exec = __importStar(__nccwpck_require__(5236));
const restore_cache_1 = __nccwpck_require__(5391); const restore_cache_1 = __nccwpck_require__(5391);
const constants_1 = __nccwpck_require__(6156);
const inputs_1 = __nccwpck_require__(9612); const inputs_1 = __nccwpck_require__(9612);
async function run() { async function run() {
try { try {
@@ -90086,11 +90087,27 @@ async function pruneCache() {
}; };
const execArgs = ["cache", "prune", "--ci"]; const execArgs = ["cache", "prune", "--ci"];
core.info("Pruning cache..."); 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(); 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: /***/ 9612:

30
dist/setup/index.js generated vendored
View File

@@ -129387,6 +129387,7 @@ const core = __importStar(__nccwpck_require__(37484));
const exec = __importStar(__nccwpck_require__(95236)); const exec = __importStar(__nccwpck_require__(95236));
const restore_cache_1 = __nccwpck_require__(95391); const restore_cache_1 = __nccwpck_require__(95391);
const download_version_1 = __nccwpck_require__(28255); const download_version_1 = __nccwpck_require__(28255);
const constants_1 = __nccwpck_require__(56156);
const inputs_1 = __nccwpck_require__(9612); const inputs_1 = __nccwpck_require__(9612);
const platforms_1 = __nccwpck_require__(98361); const platforms_1 = __nccwpck_require__(98361);
const resolve_1 = __nccwpck_require__(36772); const resolve_1 = __nccwpck_require__(36772);
@@ -129473,18 +129474,33 @@ async function determineVersion(manifestFile) {
} }
function addUvToPathAndOutput(cachedPath) { function addUvToPathAndOutput(cachedPath) {
core.setOutput("uv-path", `${cachedPath}${path.sep}uv`); 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.setOutput("uvx-path", `${cachedPath}${path.sep}uvx`);
core.addPath(cachedPath); if (process.env.UV_NO_MODIFY_PATH !== undefined) {
core.info(`Added ${cachedPath} to the path`); core.info("UV_NO_MODIFY_PATH is set, not modifying PATH");
}
else {
core.addPath(cachedPath);
core.info(`Added ${cachedPath} to the path`);
}
} }
function addToolBinToPath() { function addToolBinToPath() {
if (inputs_1.toolBinDir !== undefined) { if (inputs_1.toolBinDir !== undefined) {
core.exportVariable("UV_TOOL_BIN_DIR", inputs_1.toolBinDir); core.exportVariable("UV_TOOL_BIN_DIR", inputs_1.toolBinDir);
core.info(`Set UV_TOOL_BIN_DIR to ${inputs_1.toolBinDir}`); core.info(`Set UV_TOOL_BIN_DIR to ${inputs_1.toolBinDir}`);
core.addPath(inputs_1.toolBinDir); if (process.env.UV_NO_MODIFY_PATH !== undefined) {
core.info(`Added ${inputs_1.toolBinDir} to the path`); 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 { 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) { if (process.env.XDG_BIN_HOME !== undefined) {
core.addPath(process.env.XDG_BIN_HOME); core.addPath(process.env.XDG_BIN_HOME);
core.info(`Added ${process.env.XDG_BIN_HOME} to the path`); core.info(`Added ${process.env.XDG_BIN_HOME} to the path`);
@@ -129513,6 +129529,9 @@ function setupPython() {
} }
async function activateEnvironment() { async function activateEnvironment() {
if (inputs_1.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]; const execArgs = ["venv", ".venv", "--directory", inputs_1.workingDirectory];
core.info("Activating python venv..."); core.info("Activating python venv...");
await exec.exec("uv", execArgs); await exec.exec("uv", execArgs);
@@ -129545,10 +129564,11 @@ run();
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", ({ value: true })); 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.REPO = "uv";
exports.OWNER = "astral-sh"; exports.OWNER = "astral-sh";
exports.TOOL_CACHE_NAME = "uv"; exports.TOOL_CACHE_NAME = "uv";
exports.STATE_UV_PATH = "uv-path";
/***/ }), /***/ }),

View File

@@ -65748,10 +65748,11 @@ run();
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", ({ value: true })); 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.REPO = "uv";
exports.OWNER = "astral-sh"; exports.OWNER = "astral-sh";
exports.TOOL_CACHE_NAME = "uv"; exports.TOOL_CACHE_NAME = "uv";
exports.STATE_UV_PATH = "uv-path";
/***/ }), /***/ }),

View File

@@ -6,6 +6,7 @@ import {
STATE_CACHE_KEY, STATE_CACHE_KEY,
STATE_CACHE_MATCHED_KEY, STATE_CACHE_MATCHED_KEY,
} from "./cache/restore-cache"; } from "./cache/restore-cache";
import { STATE_UV_PATH } from "./utils/constants";
import { import {
cacheLocalPath, cacheLocalPath,
enableCache, enableCache,
@@ -91,7 +92,8 @@ async function pruneCache(): Promise<void> {
const execArgs = ["cache", "prune", "--ci"]; const execArgs = ["cache", "prune", "--ci"];
core.info("Pruning cache..."); core.info("Pruning cache...");
await exec.exec("uv", execArgs, options); const uvPath = core.getState(STATE_UV_PATH);
await exec.exec(uvPath, execArgs, options);
} }
run(); run();

View File

@@ -9,6 +9,7 @@ import {
resolveVersion, resolveVersion,
tryGetFromToolCache, tryGetFromToolCache,
} from "./download/download-version"; } from "./download/download-version";
import { STATE_UV_PATH } from "./utils/constants";
import { import {
activateEnvironment as activateEnvironmentInput, activateEnvironment as activateEnvironmentInput,
addProblemMatchers, addProblemMatchers,
@@ -163,18 +164,31 @@ async function determineVersion(
function addUvToPathAndOutput(cachedPath: string): void { function addUvToPathAndOutput(cachedPath: string): void {
core.setOutput("uv-path", `${cachedPath}${path.sep}uv`); 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.setOutput("uvx-path", `${cachedPath}${path.sep}uvx`);
core.addPath(cachedPath); if (process.env.UV_NO_MODIFY_PATH !== undefined) {
core.info(`Added ${cachedPath} to the path`); 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 { function addToolBinToPath(): void {
if (toolBinDir !== undefined) { if (toolBinDir !== undefined) {
core.exportVariable("UV_TOOL_BIN_DIR", toolBinDir); core.exportVariable("UV_TOOL_BIN_DIR", toolBinDir);
core.info(`Set UV_TOOL_BIN_DIR to ${toolBinDir}`); core.info(`Set UV_TOOL_BIN_DIR to ${toolBinDir}`);
core.addPath(toolBinDir); if (process.env.UV_NO_MODIFY_PATH !== undefined) {
core.info(`Added ${toolBinDir} to the path`); 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 { } 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) { if (process.env.XDG_BIN_HOME !== undefined) {
core.addPath(process.env.XDG_BIN_HOME); core.addPath(process.env.XDG_BIN_HOME);
core.info(`Added ${process.env.XDG_BIN_HOME} to the path`); core.info(`Added ${process.env.XDG_BIN_HOME} to the path`);
@@ -204,6 +218,11 @@ function setupPython(): void {
async function activateEnvironment(): Promise<void> { async function activateEnvironment(): Promise<void> {
if (activateEnvironmentInput) { 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]; const execArgs = ["venv", ".venv", "--directory", workingDirectory];
core.info("Activating python venv..."); core.info("Activating python venv...");

View File

@@ -1,3 +1,4 @@
export const REPO = "uv"; export const REPO = "uv";
export const OWNER = "astral-sh"; export const OWNER = "astral-sh";
export const TOOL_CACHE_NAME = "uv"; export const TOOL_CACHE_NAME = "uv";
export const STATE_UV_PATH = "uv-path";