From c49ecc13612df379e711d4b0bfd36c3eaf5f5192 Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Fri, 4 Feb 2022 11:20:27 +0300 Subject: [PATCH 1/4] add temporary fix for Windows pip cache dir --- dist/setup/index.js | 16 +++++++++++++++- src/cache-distributions/pip-cache.ts | 19 +++++++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index c12968514..e0cb9e7b2 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -34463,9 +34463,12 @@ Object.defineProperty(exports, "__esModule", { value: true }); const glob = __importStar(__webpack_require__(281)); const core = __importStar(__webpack_require__(470)); const exec = __importStar(__webpack_require__(986)); +const child_process = __importStar(__webpack_require__(129)); +const util_1 = __importDefault(__webpack_require__(669)); const path = __importStar(__webpack_require__(622)); const os_1 = __importDefault(__webpack_require__(87)); const cache_distributor_1 = __importDefault(__webpack_require__(435)); +const utils_1 = __webpack_require__(163); class PipCache extends cache_distributor_1.default { constructor(pythonVersion, cacheDependencyPath = '**/requirements.txt') { super('pip', cacheDependencyPath); @@ -34473,7 +34476,18 @@ class PipCache extends cache_distributor_1.default { } getCacheGlobalDirectories() { return __awaiter(this, void 0, void 0, function* () { - const { stdout, stderr, exitCode } = yield exec.getExecOutput('pip cache dir'); + let exitCode = 1; + let stdout = ''; + let stderr = ''; + // Add temporary fix for Windows + // 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')); + } + else { + ({ stdout: stdout, stderr: stderr, exitCode: 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 f4d7c2424..44cfeeecd 100644 --- a/src/cache-distributions/pip-cache.ts +++ b/src/cache-distributions/pip-cache.ts @@ -1,11 +1,13 @@ import * as glob from '@actions/glob'; import * as core from '@actions/core'; import * as exec from '@actions/exec'; - +import * as child_process from 'child_process'; +import utils from 'util'; import * as path from 'path'; import os from 'os'; import CacheDistributor from './cache-distributor'; +import {IS_WINDOWS} from '../utils'; class PipCache extends CacheDistributor { constructor( @@ -16,9 +18,18 @@ class PipCache extends CacheDistributor { } protected async getCacheGlobalDirectories() { - const {stdout, stderr, exitCode} = await exec.getExecOutput( - 'pip cache dir' - ); + let exitCode = 1; + let stdout = ''; + let stderr = ''; + + // Add temporary fix for Windows + // 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')); + } else { + ({stdout: stdout, stderr: stderr, exitCode: exitCode} = await exec.getExecOutput('pip cache dir')); + } if (exitCode && stderr) { throw new Error( From 2934810f3d9efda4e4160f9466db257d4d8e8ff5 Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Fri, 4 Feb 2022 11:33:49 +0300 Subject: [PATCH 2/4] format and rebuild --- dist/setup/index.js | 6 +++++- src/cache-distributions/pip-cache.ts | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index e0cb9e7b2..240851640 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -34486,7 +34486,11 @@ class PipCache extends cache_distributor_1.default { ({ stdout: stdout, stderr: stderr } = yield execPromisify('pip cache dir')); } else { - ({ stdout: stdout, stderr: stderr, exitCode: exitCode } = yield exec.getExecOutput('pip cache dir')); + ({ + stdout: stdout, + stderr: stderr, + exitCode: 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 44cfeeecd..78ab1ebea 100644 --- a/src/cache-distributions/pip-cache.ts +++ b/src/cache-distributions/pip-cache.ts @@ -28,7 +28,11 @@ class PipCache extends CacheDistributor { const execPromisify = utils.promisify(child_process.exec); ({stdout: stdout, stderr: stderr} = await execPromisify('pip cache dir')); } else { - ({stdout: stdout, stderr: stderr, exitCode: exitCode} = await exec.getExecOutput('pip cache dir')); + ({ + stdout: stdout, + stderr: stderr, + exitCode: exitCode + } = await exec.getExecOutput('pip cache dir')); } if (exitCode && stderr) { From 218a9edead34f9c67fc3b30bfc2bba47e737660a Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Fri, 4 Feb 2022 12:06:12 +0300 Subject: [PATCH 3/4] increase timeout --- __tests__/cache-restore.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/__tests__/cache-restore.test.ts b/__tests__/cache-restore.test.ts index d982fd060..6c3b16c5d 100644 --- a/__tests__/cache-restore.test.ts +++ b/__tests__/cache-restore.test.ts @@ -96,7 +96,8 @@ describe('restore-cache', () => { expect(infoSpy).toHaveBeenCalledWith( `Cache restored from key: setup-python-${process.env['RUNNER_OS']}-python-${pythonVersion}-${packageManager}-${fileHash}` ); - } + }, + 30000 ); it.each([ From 098f0d7c5c28a1beef812273c704945b55395183 Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Fri, 4 Feb 2022 12:20:33 +0300 Subject: [PATCH 4/4] 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 240851640..a742d5880 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -34480,6 +34480,9 @@ class PipCache extends cache_distributor_1.default { 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, + // 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); diff --git a/src/cache-distributions/pip-cache.ts b/src/cache-distributions/pip-cache.ts index 78ab1ebea..17055ea5a 100644 --- a/src/cache-distributions/pip-cache.ts +++ b/src/cache-distributions/pip-cache.ts @@ -23,6 +23,9 @@ class PipCache extends CacheDistributor { 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, + // 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);