diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2a2c254..ad1df46 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -386,6 +386,50 @@ jobs: env: UV_VENV: ${{ steps.setup-uv.outputs.venv }} + test-activate-environment-custom-path: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + steps: + - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 + with: + persist-credentials: false + - name: Install latest version + id: setup-uv + uses: ./ + with: + python-version: 3.13.1t + activate-environment: true + venv-path: ${{ runner.temp }}/custom-venv + - name: Verify VIRTUAL_ENV points to custom path + run: | + if [[ "$VIRTUAL_ENV" != "${{ runner.temp }}/custom-venv" ]]; then + echo "VIRTUAL_ENV is not set to custom path: $VIRTUAL_ENV" + exit 1 + fi + shell: bash + - name: Verify packages can be installed + run: uv pip install pip + shell: bash + - name: Verify python runs from custom venv + run: | + PYTHON_PATH=$(which python) + if [[ "$PYTHON_PATH" != *"custom-venv"* ]]; then + echo "Python is not running from custom venv: $PYTHON_PATH" + exit 1 + fi + shell: bash + - name: Verify output venv matches custom path + run: | + if [ "$UV_VENV" != "${{ runner.temp }}/custom-venv" ]; then + echo "output venv does not match custom path: $UV_VENV" + exit 1 + fi + shell: bash + env: + UV_VENV: ${{ steps.setup-uv.outputs.venv }} + test-musl: runs-on: ubuntu-latest container: alpine @@ -1069,6 +1113,7 @@ jobs: - test-tilde-expansion-tool-dirs - test-python-version - test-activate-environment + - test-activate-environment-custom-path - test-musl - test-cache-key-os-version - test-cache-local diff --git a/action.yml b/action.yml index ebeba73..f222155 100644 --- a/action.yml +++ b/action.yml @@ -15,6 +15,9 @@ inputs: activate-environment: description: "Use uv venv to activate a venv ready to be used by later steps. " default: "false" + venv-path: + description: "Custom path for the virtual environment when using activate-environment. Defaults to '.venv' in the working directory." + default: "" working-directory: description: "The directory to execute all commands in and look for files such as pyproject.toml" default: ${{ github.workspace }} diff --git a/dist/save-cache/index.js b/dist/save-cache/index.js index 7c28736..ab8ccc4 100644 --- a/dist/save-cache/index.js +++ b/dist/save-cache/index.js @@ -91032,7 +91032,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.resolutionStrategy = exports.addProblemMatchers = exports.manifestFile = exports.githubToken = exports.pythonDir = exports.toolDir = exports.toolBinDir = exports.ignoreEmptyWorkdir = exports.ignoreNothingToCache = exports.cachePython = exports.pruneCache = exports.cacheDependencyGlob = exports.cacheLocalPath = exports.cacheSuffix = exports.saveCache = exports.restoreCache = exports.enableCache = exports.checkSum = exports.activateEnvironment = exports.pythonVersion = exports.versionFile = exports.version = exports.workingDirectory = exports.CacheLocalSource = void 0; +exports.resolutionStrategy = exports.addProblemMatchers = exports.manifestFile = exports.githubToken = exports.pythonDir = exports.toolDir = exports.toolBinDir = exports.ignoreEmptyWorkdir = exports.ignoreNothingToCache = exports.cachePython = exports.pruneCache = exports.cacheDependencyGlob = exports.cacheLocalPath = exports.cacheSuffix = exports.saveCache = exports.restoreCache = exports.enableCache = exports.checkSum = exports.venvPath = exports.activateEnvironment = exports.pythonVersion = exports.versionFile = exports.version = exports.workingDirectory = exports.CacheLocalSource = void 0; exports.getUvPythonDir = getUvPythonDir; const node_path_1 = __importDefault(__nccwpck_require__(6760)); const core = __importStar(__nccwpck_require__(7484)); @@ -91049,6 +91049,7 @@ exports.version = core.getInput("version"); exports.versionFile = getVersionFile(); exports.pythonVersion = core.getInput("python-version"); exports.activateEnvironment = core.getBooleanInput("activate-environment"); +exports.venvPath = getVenvPath(); exports.checkSum = core.getInput("checksum"); exports.enableCache = getEnableCache(); exports.restoreCache = core.getInput("restore-cache") === "true"; @@ -91075,6 +91076,14 @@ function getVersionFile() { } return versionFileInput; } +function getVenvPath() { + const venvPathInput = core.getInput("venv-path"); + if (venvPathInput !== "") { + const tildeExpanded = expandTilde(venvPathInput); + return resolveRelativePath(tildeExpanded); + } + return undefined; +} function getEnableCache() { const enableCacheInput = core.getInput("enable-cache"); if (enableCacheInput === "auto") { diff --git a/dist/setup/index.js b/dist/setup/index.js index b7a1c19..fa25c0a 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -96496,10 +96496,10 @@ async function 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); - const venvPath = path.resolve(`${inputs_1.workingDirectory}${path.sep}.venv`); + // Use custom venv path if provided, otherwise default to .venv in working directory + const venvPath = inputs_1.venvPath ?? path.resolve(`${inputs_1.workingDirectory}${path.sep}.venv`); + core.info(`Activating python venv at ${venvPath}...`); + await exec.exec("uv", ["venv", venvPath]); let venvBinPath = `${venvPath}${path.sep}bin`; if (process.platform === "win32") { venvBinPath = `${venvPath}${path.sep}Scripts`; @@ -96678,7 +96678,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.resolutionStrategy = exports.addProblemMatchers = exports.manifestFile = exports.githubToken = exports.pythonDir = exports.toolDir = exports.toolBinDir = exports.ignoreEmptyWorkdir = exports.ignoreNothingToCache = exports.cachePython = exports.pruneCache = exports.cacheDependencyGlob = exports.cacheLocalPath = exports.cacheSuffix = exports.saveCache = exports.restoreCache = exports.enableCache = exports.checkSum = exports.activateEnvironment = exports.pythonVersion = exports.versionFile = exports.version = exports.workingDirectory = exports.CacheLocalSource = void 0; +exports.resolutionStrategy = exports.addProblemMatchers = exports.manifestFile = exports.githubToken = exports.pythonDir = exports.toolDir = exports.toolBinDir = exports.ignoreEmptyWorkdir = exports.ignoreNothingToCache = exports.cachePython = exports.pruneCache = exports.cacheDependencyGlob = exports.cacheLocalPath = exports.cacheSuffix = exports.saveCache = exports.restoreCache = exports.enableCache = exports.checkSum = exports.venvPath = exports.activateEnvironment = exports.pythonVersion = exports.versionFile = exports.version = exports.workingDirectory = exports.CacheLocalSource = void 0; exports.getUvPythonDir = getUvPythonDir; const node_path_1 = __importDefault(__nccwpck_require__(6760)); const core = __importStar(__nccwpck_require__(7484)); @@ -96695,6 +96695,7 @@ exports.version = core.getInput("version"); exports.versionFile = getVersionFile(); exports.pythonVersion = core.getInput("python-version"); exports.activateEnvironment = core.getBooleanInput("activate-environment"); +exports.venvPath = getVenvPath(); exports.checkSum = core.getInput("checksum"); exports.enableCache = getEnableCache(); exports.restoreCache = core.getInput("restore-cache") === "true"; @@ -96721,6 +96722,14 @@ function getVersionFile() { } return versionFileInput; } +function getVenvPath() { + const venvPathInput = core.getInput("venv-path"); + if (venvPathInput !== "") { + const tildeExpanded = expandTilde(venvPathInput); + return resolveRelativePath(tildeExpanded); + } + return undefined; +} function getEnableCache() { const enableCacheInput = core.getInput("enable-cache"); if (enableCacheInput === "auto") { diff --git a/src/setup-uv.ts b/src/setup-uv.ts index 22d8ca8..d55c16b 100644 --- a/src/setup-uv.ts +++ b/src/setup-uv.ts @@ -24,6 +24,7 @@ import { resolutionStrategy, toolBinDir, toolDir, + venvPath as venvPathInput, versionFile as versionFileInput, version as versionInput, workingDirectory, @@ -269,12 +270,14 @@ async function activateEnvironment(): Promise { "UV_NO_MODIFY_PATH and activate-environment cannot be used together.", ); } - const execArgs = ["venv", ".venv", "--directory", workingDirectory]; - core.info("Activating python venv..."); - await exec.exec("uv", execArgs); + // Use custom venv path if provided, otherwise default to .venv in working directory + const venvPath = + venvPathInput ?? path.resolve(`${workingDirectory}${path.sep}.venv`); + + core.info(`Activating python venv at ${venvPath}...`); + await exec.exec("uv", ["venv", venvPath]); - const venvPath = path.resolve(`${workingDirectory}${path.sep}.venv`); let venvBinPath = `${venvPath}${path.sep}bin`; if (process.platform === "win32") { venvBinPath = `${venvPath}${path.sep}Scripts`; diff --git a/src/utils/inputs.ts b/src/utils/inputs.ts index 5490104..3091afe 100644 --- a/src/utils/inputs.ts +++ b/src/utils/inputs.ts @@ -14,6 +14,7 @@ export const version = core.getInput("version"); export const versionFile = getVersionFile(); export const pythonVersion = core.getInput("python-version"); export const activateEnvironment = core.getBooleanInput("activate-environment"); +export const venvPath = getVenvPath(); export const checkSum = core.getInput("checksum"); export const enableCache = getEnableCache(); export const restoreCache = core.getInput("restore-cache") === "true"; @@ -45,6 +46,15 @@ function getVersionFile(): string { return versionFileInput; } +function getVenvPath(): string | undefined { + const venvPathInput = core.getInput("venv-path"); + if (venvPathInput !== "") { + const tildeExpanded = expandTilde(venvPathInput); + return resolveRelativePath(tildeExpanded); + } + return undefined; +} + function getEnableCache(): boolean { const enableCacheInput = core.getInput("enable-cache"); if (enableCacheInput === "auto") {