Compare commits

...

2 Commits

Author SHA1 Message Date
Priya Gupta ece7cb06ca Fix pip cache error handling on Windows. (#1040)
* Add error handling for Windows 'pip cache dir' execution

* Add comments
2026-06-23 13:01:57 -05:00
Nic 1d18d7af5f Update advanced-usage.md (#811)
Fix invalid Url
2026-06-23 12:44:45 -05:00
3 changed files with 29 additions and 20 deletions
+14 -9
View File
@@ -54331,24 +54331,29 @@ class PipCache extends cache_distributor_1.default {
this.pythonVersion = pythonVersion;
}
async getCacheGlobalDirectories() {
let exitCode = 1;
let exitCode = 0;
let stdout = '';
let stderr = '';
// Add temporary fix for Windows
// On windows it is necessary to execute through an exec
// because the getExecOutput gives a non zero code or writes to stderr for pip 22.0.2,
// On Windows, it is necessary to execute through an exec
// because the getExecOutput gives a non-zero code or writes to stderr for pip 22.0.2,
// or spawn must be started with the shell option enabled for getExecOutput
// Related issue: https://github.com/actions/setup-python/issues/328
if (utils_1.IS_WINDOWS) {
const execPromisify = util_1.default.promisify(child_process.exec);
({ stdout: stdout, stderr: stderr } = await execPromisify('pip cache dir'));
try {
({ stdout, stderr } = await execPromisify('pip cache dir'));
}
catch (err) {
// Pip outputs warnings to stderr (e.g., --no-python-version-warning flag deprecation warning), causing false failure detection
// Related issue: https://github.com/actions/setup-python/issues/1034
// If an error occurs, capture stderr and set exitCode to 1 to indicate failure
stderr = err.stderr ?? err.message;
exitCode = 1;
}
}
else {
({
stdout: stdout,
stderr: stderr,
exitCode: exitCode
} = await exec.getExecOutput('pip cache dir'));
({ stdout, stderr, exitCode } = await exec.getExecOutput('pip cache dir'));
}
if (exitCode && stderr) {
throw new Error(`Could not get cache folder path for pip package manager`);
+2 -2
View File
@@ -555,8 +555,8 @@ GitHub hosted runners have a tool cache that comes with a few versions of Python
|**PyPy tool cache**|`RUNNER_TOOL_CACHE/PyPy/*`|
GitHub runner images are set up in [actions/runner-images](https://github.com/actions/runner-images). During the setup, the available versions of Python and PyPy are automatically downloaded, set up and documented.
- Tool cache setup for Ubuntu: [Install-Toolset.ps1](https://github.com/actions/runner-images/blob/main/images/linux/scripts/installers/Install-Toolset.ps1) [Configure-Toolset.ps1](https://github.com/actions/runner-images/blob/main/images/linux/scripts/installers/Configure-Toolset.ps1)
- Tool cache setup for Windows: [Install-Toolset.ps1](https://github.com/actions/runner-images/blob/main/images/win/scripts/Installers/Install-Toolset.ps1) [Configure-Toolset.ps1](https://github.com/actions/runner-images/blob/main/images/win/scripts/Installers/Configure-Toolset.ps1)
- Tool cache setup for Ubuntu: [Install-Toolset.ps1](https://github.com/actions/runner-images/blob/main/images/ubuntu/scripts/build/Install-Toolset.ps1) [Configure-Toolset.ps1](https://github.com/actions/runner-images/blob/main/images/ubuntu/scripts/build/Configure-Toolset.ps1)
- Tool cache setup for Windows: [Install-Toolset.ps1](https://github.com/actions/runner-images/blob/main/images/windows/scripts/build/Install-Toolset.ps1) [Configure-Toolset.ps1](https://github.com/actions/runner-images/blob/main/images/windows/scripts/build/Configure-Toolset.ps1)
## Using `setup-python` with a self-hosted runner
+13 -9
View File
@@ -21,24 +21,28 @@ class PipCache extends CacheDistributor {
}
protected async getCacheGlobalDirectories() {
let exitCode = 1;
let exitCode = 0;
let stdout = '';
let stderr = '';
// Add temporary fix for Windows
// On windows it is necessary to execute through an exec
// because the getExecOutput gives a non zero code or writes to stderr for pip 22.0.2,
// On Windows, it is necessary to execute through an exec
// because the getExecOutput gives a non-zero code or writes to stderr for pip 22.0.2,
// or spawn must be started with the shell option enabled for getExecOutput
// Related issue: https://github.com/actions/setup-python/issues/328
if (IS_WINDOWS) {
const execPromisify = utils.promisify(child_process.exec);
({stdout: stdout, stderr: stderr} = await execPromisify('pip cache dir'));
try {
({stdout, stderr} = await execPromisify('pip cache dir'));
} catch (err) {
// Pip outputs warnings to stderr (e.g., --no-python-version-warning flag deprecation warning), causing false failure detection
// Related issue: https://github.com/actions/setup-python/issues/1034
// If an error occurs, capture stderr and set exitCode to 1 to indicate failure
stderr = (err as any).stderr ?? (err as Error).message;
exitCode = 1;
}
} else {
({
stdout: stdout,
stderr: stderr,
exitCode: exitCode
} = await exec.getExecOutput('pip cache dir'));
({stdout, stderr, exitCode} = await exec.getExecOutput('pip cache dir'));
}
if (exitCode && stderr) {