From 5e5f66be2b90e40094c08b36a88d5826c78198f8 Mon Sep 17 00:00:00 2001 From: Priyagupta108 Date: Fri, 21 Feb 2025 14:56:34 +0530 Subject: [PATCH 1/2] Add error handling for Windows 'pip cache dir' execution --- dist/setup/index.js | 19 ++++++++++--------- src/cache-distributions/pip-cache.ts | 18 +++++++++--------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 53196f67..c2158733 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -98893,24 +98893,25 @@ class PipCache extends cache_distributor_1.default { } getCacheGlobalDirectories() { return __awaiter(this, void 0, void 0, function* () { - 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 } = yield execPromisify('pip cache dir')); + try { + ({ stdout, stderr } = yield execPromisify('pip cache dir')); + } + catch (err) { + exitCode = 1; + } } else { - ({ - stdout: stdout, - stderr: stderr, - exitCode: exitCode - } = yield exec.getExecOutput('pip cache dir')); + ({ stdout, stderr, exitCode } = yield exec.getExecOutput('pip cache dir')); } if (exitCode && stderr) { throw new Error(`Could not get cache folder path for pip package manager`); diff --git a/src/cache-distributions/pip-cache.ts b/src/cache-distributions/pip-cache.ts index d64ae931..1833c5f2 100644 --- a/src/cache-distributions/pip-cache.ts +++ b/src/cache-distributions/pip-cache.ts @@ -21,24 +21,24 @@ 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) { + 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) { From 91b95c4e89d506c5229e30f1a626609613558c50 Mon Sep 17 00:00:00 2001 From: Priyagupta108 Date: Tue, 25 Feb 2025 14:40:22 +0530 Subject: [PATCH 2/2] Add comments --- dist/setup/index.js | 3 +++ src/cache-distributions/pip-cache.ts | 3 +++ 2 files changed, 6 insertions(+) diff --git a/dist/setup/index.js b/dist/setup/index.js index c2158733..7f7400d6 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -98907,6 +98907,9 @@ class PipCache extends cache_distributor_1.default { ({ stdout, stderr } = yield 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, set exitCode to 1 to indicate failure exitCode = 1; } } diff --git a/src/cache-distributions/pip-cache.ts b/src/cache-distributions/pip-cache.ts index 1833c5f2..4af492c0 100644 --- a/src/cache-distributions/pip-cache.ts +++ b/src/cache-distributions/pip-cache.ts @@ -35,6 +35,9 @@ class PipCache extends CacheDistributor { 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, set exitCode to 1 to indicate failure exitCode = 1; } } else {