From 70f6f2a532013d250c9c0c7cb594dc60b060774c Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Wed, 4 May 2022 12:33:57 +0200 Subject: [PATCH 1/4] fix poetry python version --- __tests__/cache-restore.test.ts | 7 +++++++ dist/setup/index.js | 13 +++++++++++++ src/cache-distributions/poetry-cache.ts | 18 +++++++++++++++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/__tests__/cache-restore.test.ts b/__tests__/cache-restore.test.ts index 99b674ef8..c8769e440 100644 --- a/__tests__/cache-restore.test.ts +++ b/__tests__/cache-restore.test.ts @@ -1,6 +1,7 @@ import * as core from '@actions/core'; import * as cache from '@actions/cache'; import * as exec from '@actions/exec'; +import * as io from '@actions/io'; import {getCacheDistributor} from '../src/cache-distributions/cache-factory'; describe('restore-cache', () => { @@ -35,6 +36,9 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py // exec spy let getExecOutputSpy: jest.SpyInstance; + // io spy + let whichSpy: jest.SpyInstance; + beforeEach(() => { process.env['RUNNER_OS'] = process.env['RUNNER_OS'] ?? 'linux'; @@ -74,6 +78,9 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py return primaryKey; } ); + + whichSpy = jest.spyOn(io, 'which'); + whichSpy.mockImplementation(() => '/path/to/python'); }); describe('Validate provided package manager', () => { diff --git a/dist/setup/index.js b/dist/setup/index.js index 4afa92b0f..fcea6fa1f 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -38355,8 +38355,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); const glob = __importStar(__webpack_require__(281)); +const io = __importStar(__webpack_require__(1)); const path = __importStar(__webpack_require__(622)); const exec = __importStar(__webpack_require__(986)); +const core = __importStar(__webpack_require__(470)); const cache_distributor_1 = __importDefault(__webpack_require__(596)); class PoetryCache extends cache_distributor_1.default { constructor(pythonVersion, patterns = '**/poetry.lock') { @@ -38373,6 +38375,17 @@ class PoetryCache extends cache_distributor_1.default { if (poetryConfig['virtualenvs.in-project'] === true) { paths.push(path.join(process.cwd(), '.venv')); } + const pythonLocation = yield io.which('python'); + if (pythonLocation) { + core.debug(`pythonLocation is ${pythonLocation}`); + const { exitCode, stderr } = yield exec.getExecOutput(`poetry env use ${pythonLocation}`); + if (exitCode) { + throw new Error(stderr); + } + } + else { + core.warning('python binaries were not found in PATH.'); + } return paths; }); } diff --git a/src/cache-distributions/poetry-cache.ts b/src/cache-distributions/poetry-cache.ts index 58aa5fd97..6263c4949 100644 --- a/src/cache-distributions/poetry-cache.ts +++ b/src/cache-distributions/poetry-cache.ts @@ -1,7 +1,8 @@ import * as glob from '@actions/glob'; -import * as os from 'os'; +import * as io from '@actions/io'; import * as path from 'path'; import * as exec from '@actions/exec'; +import * as core from '@actions/core'; import CacheDistributor from './cache-distributor'; @@ -28,6 +29,21 @@ class PoetryCache extends CacheDistributor { paths.push(path.join(process.cwd(), '.venv')); } + const pythonLocation = await io.which('python'); + + if (pythonLocation) { + core.debug(`pythonLocation is ${pythonLocation}`); + const {exitCode, stderr} = await exec.getExecOutput( + `poetry env use ${pythonLocation}` + ); + + if (exitCode) { + throw new Error(stderr); + } + } else { + core.warning('python binaries were not found in PATH.'); + } + return paths; } From cb8feb63f7b3a19df733f132d60dbc17388bbb20 Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Mon, 27 Jun 2022 14:00:48 +0200 Subject: [PATCH 2/4] add fixes --- .github/workflows/e2e-cache.yml | 6 +++--- __tests__/data/pyproject.toml | 15 +++++++++++++++ dist/setup/index.js | 13 +++++++++++++ src/cache-distributions/poetry-cache.ts | 13 +++++++++---- 4 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 __tests__/data/pyproject.toml diff --git a/.github/workflows/e2e-cache.yml b/.github/workflows/e2e-cache.yml index ce3366a1f..c94b2f49f 100644 --- a/.github/workflows/e2e-cache.yml +++ b/.github/workflows/e2e-cache.yml @@ -66,15 +66,15 @@ jobs: - uses: actions/checkout@v3 - name: Install poetry run: pipx install poetry + - name: Init pyproject.toml + run: mv ./__tests__/data/pyproject.toml . - name: Setup Python uses: ./ with: python-version: ${{ matrix.python-version }} cache: 'poetry' - - name: Init pyproject.toml - run: poetry init -n - name: Install dependencies - run: poetry add flake8 + run: poetry install python-pip-dependencies-caching-path: name: Test pip (Python ${{ matrix.python-version}}, ${{ matrix.os }}) diff --git a/__tests__/data/pyproject.toml b/__tests__/data/pyproject.toml new file mode 100644 index 000000000..ff4d8bd0b --- /dev/null +++ b/__tests__/data/pyproject.toml @@ -0,0 +1,15 @@ +[tool.poetry] +name = "testactiontasks" +version = "0.1.0" +description = "" +authors = ["Your Name "] + +[tool.poetry.dependencies] +python = "^3.8" +flake8 = "^4.0.1" + +[tool.poetry.dev-dependencies] + +[build-system] +requires = ["poetry-core>=1.0.0"] +build-backend = "poetry.core.masonry.api" diff --git a/dist/setup/index.js b/dist/setup/index.js index 3c417588f..7f067dcd7 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -63876,8 +63876,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", ({ value: true })); const glob = __importStar(__nccwpck_require__(8090)); +const io = __importStar(__nccwpck_require__(7436)); const path = __importStar(__nccwpck_require__(1017)); const exec = __importStar(__nccwpck_require__(1514)); +const core = __importStar(__nccwpck_require__(2186)); const cache_distributor_1 = __importDefault(__nccwpck_require__(8953)); class PoetryCache extends cache_distributor_1.default { constructor(pythonVersion, patterns = '**/poetry.lock') { @@ -63894,6 +63896,17 @@ class PoetryCache extends cache_distributor_1.default { if (poetryConfig['virtualenvs.in-project'] === true) { paths.push(path.join(process.cwd(), '.venv')); } + const pythonLocation = yield io.which('python'); + if (pythonLocation) { + core.debug(`pythonLocation is ${pythonLocation}`); + const { exitCode, stderr } = yield exec.getExecOutput(`poetry env use ${pythonLocation}`, undefined, { ignoreReturnCode: true }); + if (exitCode) { + core.info(`[warning]${stderr}`); + } + } + else { + core.info('[warning]python binaries were not found in PATH.'); + } return paths; }); } diff --git a/src/cache-distributions/poetry-cache.ts b/src/cache-distributions/poetry-cache.ts index 464a58bee..3c22011f9 100644 --- a/src/cache-distributions/poetry-cache.ts +++ b/src/cache-distributions/poetry-cache.ts @@ -33,15 +33,20 @@ class PoetryCache extends CacheDistributor { if (pythonLocation) { core.debug(`pythonLocation is ${pythonLocation}`); - const {exitCode, stderr} = await exec.getExecOutput( - `poetry env use ${pythonLocation}` + const { + exitCode, + stderr + } = await exec.getExecOutput( + `poetry env use ${pythonLocation}`, + undefined, + {ignoreReturnCode: true} ); if (exitCode) { - throw new Error(stderr); + core.info(`[warning]${stderr}`); } } else { - core.warning('python binaries were not found in PATH.'); + core.info('[warning]python binaries were not found in PATH.'); } return paths; From 0572342a8a0b0a7530b9337ee279a37efdaebce3 Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Mon, 25 Jul 2022 12:42:35 +0200 Subject: [PATCH 3/4] fix comments --- dist/setup/index.js | 22 +++++++++++----------- src/cache-distributions/poetry-cache.ts | 5 +++-- src/setup-python.ts | 7 +------ src/utils.ts | 5 +++++ 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 9d5d16a7b..3d373467b 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -64578,6 +64578,7 @@ const path = __importStar(__nccwpck_require__(1017)); const exec = __importStar(__nccwpck_require__(1514)); const core = __importStar(__nccwpck_require__(2186)); const cache_distributor_1 = __importDefault(__nccwpck_require__(8953)); +const utils_1 = __nccwpck_require__(1314); class PoetryCache extends cache_distributor_1.default { constructor(pythonVersion, patterns = '**/poetry.lock') { super('poetry', patterns); @@ -64598,11 +64599,11 @@ class PoetryCache extends cache_distributor_1.default { core.debug(`pythonLocation is ${pythonLocation}`); const { exitCode, stderr } = yield exec.getExecOutput(`poetry env use ${pythonLocation}`, undefined, { ignoreReturnCode: true }); if (exitCode) { - core.info(`[warning]${stderr}`); + utils_1.logWarning(stderr); } } else { - core.info('[warning]python binaries were not found in PATH.'); + utils_1.logWarning('python binaries were not found in PATH'); } return paths; }); @@ -65254,7 +65255,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.logWarning = void 0; const core = __importStar(__nccwpck_require__(2186)); const finder = __importStar(__nccwpck_require__(9996)); const finderPyPy = __importStar(__nccwpck_require__(4003)); @@ -65290,14 +65290,14 @@ function resolveVersionInput() { core.info(`Resolved ${versionFile} as ${version}`); return version; } - logWarning("Neither 'python-version' nor 'python-version-file' inputs were supplied. Attempting to find '.python-version' file."); + utils_1.logWarning("Neither 'python-version' nor 'python-version-file' inputs were supplied. Attempting to find '.python-version' file."); versionFile = '.python-version'; if (fs_1.default.existsSync(versionFile)) { version = fs_1.default.readFileSync(versionFile, 'utf8'); core.info(`Resolved ${versionFile} as ${version}`); return version; } - logWarning(`${versionFile} doesn't exist.`); + utils_1.logWarning(`${versionFile} doesn't exist.`); return version; } function run() { @@ -65345,11 +65345,6 @@ function run() { } }); } -function logWarning(message) { - const warningPrefix = '[warning]'; - core.info(`${warningPrefix}${message}`); -} -exports.logWarning = logWarning; run(); @@ -65392,7 +65387,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.getLinuxOSReleaseInfo = exports.isCacheFeatureAvailable = exports.isGhes = exports.validatePythonVersionFormatForPyPy = exports.writeExactPyPyVersionFile = exports.readExactPyPyVersionFile = exports.getPyPyVersionFromPath = exports.isNightlyKeyword = exports.validateVersion = exports.createSymlinkInFolder = exports.WINDOWS_PLATFORMS = exports.WINDOWS_ARCHS = exports.IS_LINUX = exports.IS_WINDOWS = void 0; +exports.logWarning = exports.getLinuxOSReleaseInfo = exports.isCacheFeatureAvailable = exports.isGhes = exports.validatePythonVersionFormatForPyPy = exports.writeExactPyPyVersionFile = exports.readExactPyPyVersionFile = exports.getPyPyVersionFromPath = exports.isNightlyKeyword = exports.validateVersion = exports.createSymlinkInFolder = exports.WINDOWS_PLATFORMS = exports.WINDOWS_ARCHS = exports.IS_LINUX = exports.IS_WINDOWS = void 0; const cache = __importStar(__nccwpck_require__(7799)); const core = __importStar(__nccwpck_require__(2186)); const fs_1 = __importDefault(__nccwpck_require__(7147)); @@ -65493,6 +65488,11 @@ function getLinuxOSReleaseInfo() { }); } exports.getLinuxOSReleaseInfo = getLinuxOSReleaseInfo; +function logWarning(message) { + const warningPrefix = '[warning]'; + core.info(`${warningPrefix}${message}`); +} +exports.logWarning = logWarning; /***/ }), diff --git a/src/cache-distributions/poetry-cache.ts b/src/cache-distributions/poetry-cache.ts index 3c22011f9..7f84fef92 100644 --- a/src/cache-distributions/poetry-cache.ts +++ b/src/cache-distributions/poetry-cache.ts @@ -5,6 +5,7 @@ import * as exec from '@actions/exec'; import * as core from '@actions/core'; import CacheDistributor from './cache-distributor'; +import { logWarning } from '../utils'; class PoetryCache extends CacheDistributor { constructor( @@ -43,10 +44,10 @@ class PoetryCache extends CacheDistributor { ); if (exitCode) { - core.info(`[warning]${stderr}`); + logWarning(stderr); } } else { - core.info('[warning]python binaries were not found in PATH.'); + logWarning('python binaries were not found in PATH'); } return paths; diff --git a/src/setup-python.ts b/src/setup-python.ts index 233568899..d27e9717c 100644 --- a/src/setup-python.ts +++ b/src/setup-python.ts @@ -5,7 +5,7 @@ import * as path from 'path'; import * as os from 'os'; import fs from 'fs'; import {getCacheDistributor} from './cache-distributions/cache-factory'; -import {isCacheFeatureAvailable, IS_LINUX, IS_WINDOWS} from './utils'; +import {isCacheFeatureAvailable, logWarning, IS_LINUX, IS_WINDOWS} from './utils'; function isPyPyVersion(versionSpec: string) { return versionSpec.startsWith('pypy'); @@ -115,9 +115,4 @@ async function run() { } } -export function logWarning(message: string): void { - const warningPrefix = '[warning]'; - core.info(`${warningPrefix}${message}`); -} - run(); diff --git a/src/utils.ts b/src/utils.ts index 6eb1388fe..5440d1ffd 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -136,3 +136,8 @@ export async function getLinuxOSReleaseInfo() { return `${osVersion}-${osRelease}`; } + +export function logWarning(message: string): void { + const warningPrefix = '[warning]'; + core.info(`${warningPrefix}${message}`); +} \ No newline at end of file From 0e54e8df71034333dd5075b47c8d0a3f5e519e7e Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Mon, 25 Jul 2022 12:48:47 +0200 Subject: [PATCH 4/4] format code --- src/cache-distributions/poetry-cache.ts | 2 +- src/setup-python.ts | 7 ++++++- src/utils.ts | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/cache-distributions/poetry-cache.ts b/src/cache-distributions/poetry-cache.ts index 7f84fef92..60ecea2b1 100644 --- a/src/cache-distributions/poetry-cache.ts +++ b/src/cache-distributions/poetry-cache.ts @@ -5,7 +5,7 @@ import * as exec from '@actions/exec'; import * as core from '@actions/core'; import CacheDistributor from './cache-distributor'; -import { logWarning } from '../utils'; +import {logWarning} from '../utils'; class PoetryCache extends CacheDistributor { constructor( diff --git a/src/setup-python.ts b/src/setup-python.ts index d27e9717c..1ebcbac3e 100644 --- a/src/setup-python.ts +++ b/src/setup-python.ts @@ -5,7 +5,12 @@ import * as path from 'path'; import * as os from 'os'; import fs from 'fs'; import {getCacheDistributor} from './cache-distributions/cache-factory'; -import {isCacheFeatureAvailable, logWarning, IS_LINUX, IS_WINDOWS} from './utils'; +import { + isCacheFeatureAvailable, + logWarning, + IS_LINUX, + IS_WINDOWS +} from './utils'; function isPyPyVersion(versionSpec: string) { return versionSpec.startsWith('pypy'); diff --git a/src/utils.ts b/src/utils.ts index 5440d1ffd..7d4fa02ec 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -140,4 +140,4 @@ export async function getLinuxOSReleaseInfo() { export function logWarning(message: string): void { const warningPrefix = '[warning]'; core.info(`${warningPrefix}${message}`); -} \ No newline at end of file +}