Skip to content

Commit 49a521f

Browse files
Fix poetry version (#445)
1 parent 592a7a7 commit 49a521f

File tree

7 files changed

+80
-19
lines changed

7 files changed

+80
-19
lines changed

.github/workflows/e2e-cache.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ jobs:
7272
- uses: actions/checkout@v3
7373
- name: Install poetry
7474
run: pipx install poetry
75+
- name: Init pyproject.toml
76+
run: mv ./__tests__/data/pyproject.toml .
7577
- name: Setup Python
7678
uses: ./
7779
with:
7880
python-version: ${{ matrix.python-version }}
7981
cache: 'poetry'
80-
- name: Init pyproject.toml
81-
run: poetry init -n
8282
- name: Install dependencies
83-
run: poetry add flake8
83+
run: poetry install
8484

8585
python-pip-dependencies-caching-path:
8686
name: Test pip (Python ${{ matrix.python-version}}, ${{ matrix.os }})

__tests__/cache-restore.test.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as core from '@actions/core';
22
import * as cache from '@actions/cache';
33
import * as exec from '@actions/exec';
4+
import * as io from '@actions/io';
45
import {getCacheDistributor} from '../src/cache-distributions/cache-factory';
56
import * as utils from './../src/utils';
67

@@ -37,6 +38,9 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py
3738
// exec spy
3839
let getExecOutputSpy: jest.SpyInstance;
3940

41+
// io spy
42+
let whichSpy: jest.SpyInstance;
43+
4044
beforeEach(() => {
4145
process.env['RUNNER_OS'] = process.env['RUNNER_OS'] ?? 'linux';
4246

@@ -77,6 +81,8 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py
7781
}
7882
);
7983

84+
whichSpy = jest.spyOn(io, 'which');
85+
whichSpy.mockImplementation(() => '/path/to/python');
8086
getLinuxOSReleaseInfoSpy = jest.spyOn(utils, 'getLinuxOSReleaseInfo');
8187
});
8288

__tests__/data/pyproject.toml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[tool.poetry]
2+
name = "testactiontasks"
3+
version = "0.1.0"
4+
description = ""
5+
authors = ["Your Name <[email protected]>"]
6+
7+
[tool.poetry.dependencies]
8+
python = "^3.8"
9+
flake8 = "^4.0.1"
10+
11+
[tool.poetry.dev-dependencies]
12+
13+
[build-system]
14+
requires = ["poetry-core>=1.0.0"]
15+
build-backend = "poetry.core.masonry.api"

dist/setup/index.js

+22-9
Original file line numberDiff line numberDiff line change
@@ -64573,9 +64573,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
6457364573
};
6457464574
Object.defineProperty(exports, "__esModule", ({ value: true }));
6457564575
const glob = __importStar(__nccwpck_require__(8090));
64576+
const io = __importStar(__nccwpck_require__(7436));
6457664577
const path = __importStar(__nccwpck_require__(1017));
6457764578
const exec = __importStar(__nccwpck_require__(1514));
64579+
const core = __importStar(__nccwpck_require__(2186));
6457864580
const cache_distributor_1 = __importDefault(__nccwpck_require__(8953));
64581+
const utils_1 = __nccwpck_require__(1314);
6457964582
class PoetryCache extends cache_distributor_1.default {
6458064583
constructor(pythonVersion, patterns = '**/poetry.lock') {
6458164584
super('poetry', patterns);
@@ -64591,6 +64594,17 @@ class PoetryCache extends cache_distributor_1.default {
6459164594
if (poetryConfig['virtualenvs.in-project'] === true) {
6459264595
paths.push(path.join(process.cwd(), '.venv'));
6459364596
}
64597+
const pythonLocation = yield io.which('python');
64598+
if (pythonLocation) {
64599+
core.debug(`pythonLocation is ${pythonLocation}`);
64600+
const { exitCode, stderr } = yield exec.getExecOutput(`poetry env use ${pythonLocation}`, undefined, { ignoreReturnCode: true });
64601+
if (exitCode) {
64602+
utils_1.logWarning(stderr);
64603+
}
64604+
}
64605+
else {
64606+
utils_1.logWarning('python binaries were not found in PATH');
64607+
}
6459464608
return paths;
6459564609
});
6459664610
}
@@ -65241,7 +65255,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
6524165255
return (mod && mod.__esModule) ? mod : { "default": mod };
6524265256
};
6524365257
Object.defineProperty(exports, "__esModule", ({ value: true }));
65244-
exports.logWarning = void 0;
6524565258
const core = __importStar(__nccwpck_require__(2186));
6524665259
const finder = __importStar(__nccwpck_require__(9996));
6524765260
const finderPyPy = __importStar(__nccwpck_require__(4003));
@@ -65277,14 +65290,14 @@ function resolveVersionInput() {
6527765290
core.info(`Resolved ${versionFile} as ${version}`);
6527865291
return version;
6527965292
}
65280-
logWarning("Neither 'python-version' nor 'python-version-file' inputs were supplied. Attempting to find '.python-version' file.");
65293+
utils_1.logWarning("Neither 'python-version' nor 'python-version-file' inputs were supplied. Attempting to find '.python-version' file.");
6528165294
versionFile = '.python-version';
6528265295
if (fs_1.default.existsSync(versionFile)) {
6528365296
version = fs_1.default.readFileSync(versionFile, 'utf8');
6528465297
core.info(`Resolved ${versionFile} as ${version}`);
6528565298
return version;
6528665299
}
65287-
logWarning(`${versionFile} doesn't exist.`);
65300+
utils_1.logWarning(`${versionFile} doesn't exist.`);
6528865301
return version;
6528965302
}
6529065303
function run() {
@@ -65332,11 +65345,6 @@ function run() {
6533265345
}
6533365346
});
6533465347
}
65335-
function logWarning(message) {
65336-
const warningPrefix = '[warning]';
65337-
core.info(`${warningPrefix}${message}`);
65338-
}
65339-
exports.logWarning = logWarning;
6534065348
run();
6534165349

6534265350

@@ -65379,7 +65387,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
6537965387
return (mod && mod.__esModule) ? mod : { "default": mod };
6538065388
};
6538165389
Object.defineProperty(exports, "__esModule", ({ value: true }));
65382-
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;
65390+
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;
6538365391
const cache = __importStar(__nccwpck_require__(7799));
6538465392
const core = __importStar(__nccwpck_require__(2186));
6538565393
const fs_1 = __importDefault(__nccwpck_require__(7147));
@@ -65480,6 +65488,11 @@ function getLinuxOSReleaseInfo() {
6548065488
});
6548165489
}
6548265490
exports.getLinuxOSReleaseInfo = getLinuxOSReleaseInfo;
65491+
function logWarning(message) {
65492+
const warningPrefix = '[warning]';
65493+
core.info(`${warningPrefix}${message}`);
65494+
}
65495+
exports.logWarning = logWarning;
6548365496

6548465497

6548565498
/***/ }),

src/cache-distributions/poetry-cache.ts

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import * as glob from '@actions/glob';
2-
import * as os from 'os';
2+
import * as io from '@actions/io';
33
import * as path from 'path';
44
import * as exec from '@actions/exec';
5+
import * as core from '@actions/core';
56

67
import CacheDistributor from './cache-distributor';
8+
import {logWarning} from '../utils';
79

810
class PoetryCache extends CacheDistributor {
911
constructor(
@@ -28,6 +30,26 @@ class PoetryCache extends CacheDistributor {
2830
paths.push(path.join(process.cwd(), '.venv'));
2931
}
3032

33+
const pythonLocation = await io.which('python');
34+
35+
if (pythonLocation) {
36+
core.debug(`pythonLocation is ${pythonLocation}`);
37+
const {
38+
exitCode,
39+
stderr
40+
} = await exec.getExecOutput(
41+
`poetry env use ${pythonLocation}`,
42+
undefined,
43+
{ignoreReturnCode: true}
44+
);
45+
46+
if (exitCode) {
47+
logWarning(stderr);
48+
}
49+
} else {
50+
logWarning('python binaries were not found in PATH');
51+
}
52+
3153
return paths;
3254
}
3355

src/setup-python.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ import * as path from 'path';
55
import * as os from 'os';
66
import fs from 'fs';
77
import {getCacheDistributor} from './cache-distributions/cache-factory';
8-
import {isCacheFeatureAvailable, IS_LINUX, IS_WINDOWS} from './utils';
8+
import {
9+
isCacheFeatureAvailable,
10+
logWarning,
11+
IS_LINUX,
12+
IS_WINDOWS
13+
} from './utils';
914

1015
function isPyPyVersion(versionSpec: string) {
1116
return versionSpec.startsWith('pypy');
@@ -115,9 +120,4 @@ async function run() {
115120
}
116121
}
117122

118-
export function logWarning(message: string): void {
119-
const warningPrefix = '[warning]';
120-
core.info(`${warningPrefix}${message}`);
121-
}
122-
123123
run();

src/utils.ts

+5
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,8 @@ export async function getLinuxOSReleaseInfo() {
136136

137137
return `${osVersion}-${osRelease}`;
138138
}
139+
140+
export function logWarning(message: string): void {
141+
const warningPrefix = '[warning]';
142+
core.info(`${warningPrefix}${message}`);
143+
}

0 commit comments

Comments
 (0)