mirror of
https://github.com/actions/setup-python.git
synced 2025-04-24 07:22:14 +00:00
Merge branch 'main' into v-dmshib/add-check-latest
This commit is contained in:
commit
1c2a569ab1
14 changed files with 191 additions and 52 deletions
4
.github/workflows/check-dist.yml
vendored
4
.github/workflows/check-dist.yml
vendored
|
@ -21,7 +21,7 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Set Node.js 16.x
|
- name: Set Node.js 16.x
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v3
|
||||||
|
@ -45,7 +45,7 @@ jobs:
|
||||||
id: diff
|
id: diff
|
||||||
|
|
||||||
# If index.js was different than expected, upload the expected version as an artifact
|
# If index.js was different than expected, upload the expected version as an artifact
|
||||||
- uses: actions/upload-artifact@v2
|
- uses: actions/upload-artifact@v3
|
||||||
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
|
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
|
||||||
with:
|
with:
|
||||||
name: dist
|
name: dist
|
||||||
|
|
8
.github/workflows/codeql-analysis.yml
vendored
8
.github/workflows/codeql-analysis.yml
vendored
|
@ -18,11 +18,11 @@ jobs:
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
# Initializes the CodeQL tools for scanning.
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@v1
|
uses: github/codeql-action/init@v2
|
||||||
# Override language selection by uncommenting this and choosing your languages
|
# Override language selection by uncommenting this and choosing your languages
|
||||||
# with:
|
# with:
|
||||||
# languages: go, javascript, csharp, python, cpp, java
|
# languages: go, javascript, csharp, python, cpp, java
|
||||||
|
@ -30,7 +30,7 @@ jobs:
|
||||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
# If this step fails, then you should remove it and run the build manually (see below)
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
- name: Autobuild
|
- name: Autobuild
|
||||||
uses: github/codeql-action/autobuild@v1
|
uses: github/codeql-action/autobuild@v2
|
||||||
|
|
||||||
# ℹ️ Command-line programs to run using the OS shell.
|
# ℹ️ Command-line programs to run using the OS shell.
|
||||||
# 📚 https://git.io/JvXDl
|
# 📚 https://git.io/JvXDl
|
||||||
|
@ -44,4 +44,4 @@ jobs:
|
||||||
# make release
|
# make release
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
- name: Perform CodeQL Analysis
|
||||||
uses: github/codeql-action/analyze@v1
|
uses: github/codeql-action/analyze@v2
|
||||||
|
|
6
.github/workflows/e2e-cache.yml
vendored
6
.github/workflows/e2e-cache.yml
vendored
|
@ -72,15 +72,15 @@ jobs:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Install poetry
|
- name: Install poetry
|
||||||
run: pipx install poetry
|
run: pipx install poetry
|
||||||
|
- name: Init pyproject.toml
|
||||||
|
run: mv ./__tests__/data/pyproject.toml .
|
||||||
- name: Setup Python
|
- name: Setup Python
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
python-version: ${{ matrix.python-version }}
|
python-version: ${{ matrix.python-version }}
|
||||||
cache: 'poetry'
|
cache: 'poetry'
|
||||||
- name: Init pyproject.toml
|
|
||||||
run: poetry init -n
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: poetry add flake8
|
run: poetry install
|
||||||
|
|
||||||
python-pip-dependencies-caching-path:
|
python-pip-dependencies-caching-path:
|
||||||
name: Test pip (Python ${{ matrix.python-version}}, ${{ matrix.os }})
|
name: Test pip (Python ${{ matrix.python-version}}, ${{ matrix.os }})
|
||||||
|
|
2
.github/workflows/licensed.yml
vendored
2
.github/workflows/licensed.yml
vendored
|
@ -13,7 +13,7 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
name: Check licenses
|
name: Check licenses
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: Set Node.js 16.x
|
- name: Set Node.js 16.x
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
|
|
|
@ -21,7 +21,7 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Update the ${{ env.TAG_NAME }} tag
|
- name: Update the ${{ env.TAG_NAME }} tag
|
||||||
uses: actions/publish-action@v0.1.0
|
uses: actions/publish-action@v0.2.0
|
||||||
with:
|
with:
|
||||||
source-tag: ${{ env.TAG_NAME }}
|
source-tag: ${{ env.TAG_NAME }}
|
||||||
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
|
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
|
2
.github/workflows/test-pypy.yml
vendored
2
.github/workflows/test-pypy.yml
vendored
|
@ -34,7 +34,7 @@ jobs:
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: setup-python ${{ matrix.pypy }}
|
- name: setup-python ${{ matrix.pypy }}
|
||||||
id: setup-python
|
id: setup-python
|
||||||
|
|
2
.github/workflows/workflow.yml
vendored
2
.github/workflows/workflow.yml
vendored
|
@ -17,7 +17,7 @@ jobs:
|
||||||
operating-system: [ubuntu-latest, windows-latest]
|
operating-system: [ubuntu-latest, windows-latest]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Set Node.js 16.x
|
- name: Set Node.js 16.x
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v3
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as cache from '@actions/cache';
|
import * as cache from '@actions/cache';
|
||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
|
import * as io from '@actions/io';
|
||||||
import {getCacheDistributor} from '../src/cache-distributions/cache-factory';
|
import {getCacheDistributor} from '../src/cache-distributions/cache-factory';
|
||||||
|
import * as utils from './../src/utils';
|
||||||
|
|
||||||
describe('restore-cache', () => {
|
describe('restore-cache', () => {
|
||||||
const pipFileLockHash =
|
const pipFileLockHash =
|
||||||
|
@ -28,6 +30,7 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py
|
||||||
let saveSatetSpy: jest.SpyInstance;
|
let saveSatetSpy: jest.SpyInstance;
|
||||||
let getStateSpy: jest.SpyInstance;
|
let getStateSpy: jest.SpyInstance;
|
||||||
let setOutputSpy: jest.SpyInstance;
|
let setOutputSpy: jest.SpyInstance;
|
||||||
|
let getLinuxOSReleaseInfoSpy: jest.SpyInstance;
|
||||||
|
|
||||||
// cache spy
|
// cache spy
|
||||||
let restoreCacheSpy: jest.SpyInstance;
|
let restoreCacheSpy: jest.SpyInstance;
|
||||||
|
@ -35,6 +38,9 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py
|
||||||
// exec spy
|
// exec spy
|
||||||
let getExecOutputSpy: jest.SpyInstance;
|
let getExecOutputSpy: jest.SpyInstance;
|
||||||
|
|
||||||
|
// io spy
|
||||||
|
let whichSpy: jest.SpyInstance;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
process.env['RUNNER_OS'] = process.env['RUNNER_OS'] ?? 'linux';
|
process.env['RUNNER_OS'] = process.env['RUNNER_OS'] ?? 'linux';
|
||||||
|
|
||||||
|
@ -74,6 +80,10 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py
|
||||||
return primaryKey;
|
return primaryKey;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
whichSpy = jest.spyOn(io, 'which');
|
||||||
|
whichSpy.mockImplementation(() => '/path/to/python');
|
||||||
|
getLinuxOSReleaseInfoSpy = jest.spyOn(utils, 'getLinuxOSReleaseInfo');
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Validate provided package manager', () => {
|
describe('Validate provided package manager', () => {
|
||||||
|
@ -109,11 +119,24 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py
|
||||||
pythonVersion,
|
pythonVersion,
|
||||||
dependencyFile
|
dependencyFile
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (process.platform === 'linux') {
|
||||||
|
getLinuxOSReleaseInfoSpy.mockImplementation(() =>
|
||||||
|
Promise.resolve('Ubuntu-20.4')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
await cacheDistributor.restoreCache();
|
await cacheDistributor.restoreCache();
|
||||||
|
|
||||||
expect(infoSpy).toHaveBeenCalledWith(
|
if (process.platform === 'linux' && packageManager === 'pip') {
|
||||||
`Cache restored from key: setup-python-${process.env['RUNNER_OS']}-python-${pythonVersion}-${packageManager}-${fileHash}`
|
expect(infoSpy).toHaveBeenCalledWith(
|
||||||
);
|
`Cache restored from key: setup-python-${process.env['RUNNER_OS']}-Ubuntu-20.4-python-${pythonVersion}-${packageManager}-${fileHash}`
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
expect(infoSpy).toHaveBeenCalledWith(
|
||||||
|
`Cache restored from key: setup-python-${process.env['RUNNER_OS']}-python-${pythonVersion}-${packageManager}-${fileHash}`
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
30000
|
30000
|
||||||
);
|
);
|
||||||
|
|
15
__tests__/data/pyproject.toml
Normal file
15
__tests__/data/pyproject.toml
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
[tool.poetry]
|
||||||
|
name = "testactiontasks"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = ""
|
||||||
|
authors = ["Your Name <you@example.com>"]
|
||||||
|
|
||||||
|
[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"
|
76
dist/setup/index.js
vendored
76
dist/setup/index.js
vendored
|
@ -64430,8 +64430,17 @@ class PipCache extends cache_distributor_1.default {
|
||||||
computeKeys() {
|
computeKeys() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const hash = yield glob.hashFiles(this.cacheDependencyPath);
|
const hash = yield glob.hashFiles(this.cacheDependencyPath);
|
||||||
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
|
let primaryKey = '';
|
||||||
const restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}`;
|
let restoreKey = '';
|
||||||
|
if (utils_1.IS_LINUX) {
|
||||||
|
const osRelease = yield utils_1.getLinuxOSReleaseInfo();
|
||||||
|
primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${osRelease}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
|
||||||
|
restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${osRelease}-python-${this.pythonVersion}-${this.packageManager}`;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
|
||||||
|
restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}`;
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
primaryKey,
|
primaryKey,
|
||||||
restoreKey: [restoreKey]
|
restoreKey: [restoreKey]
|
||||||
|
@ -64564,9 +64573,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
const glob = __importStar(__nccwpck_require__(8090));
|
const glob = __importStar(__nccwpck_require__(8090));
|
||||||
|
const io = __importStar(__nccwpck_require__(7436));
|
||||||
const path = __importStar(__nccwpck_require__(1017));
|
const path = __importStar(__nccwpck_require__(1017));
|
||||||
const exec = __importStar(__nccwpck_require__(1514));
|
const exec = __importStar(__nccwpck_require__(1514));
|
||||||
|
const core = __importStar(__nccwpck_require__(2186));
|
||||||
const cache_distributor_1 = __importDefault(__nccwpck_require__(8953));
|
const cache_distributor_1 = __importDefault(__nccwpck_require__(8953));
|
||||||
|
const utils_1 = __nccwpck_require__(1314);
|
||||||
class PoetryCache extends cache_distributor_1.default {
|
class PoetryCache extends cache_distributor_1.default {
|
||||||
constructor(pythonVersion, patterns = '**/poetry.lock') {
|
constructor(pythonVersion, patterns = '**/poetry.lock') {
|
||||||
super('poetry', patterns);
|
super('poetry', patterns);
|
||||||
|
@ -64582,6 +64594,17 @@ class PoetryCache extends cache_distributor_1.default {
|
||||||
if (poetryConfig['virtualenvs.in-project'] === true) {
|
if (poetryConfig['virtualenvs.in-project'] === true) {
|
||||||
paths.push(path.join(process.cwd(), '.venv'));
|
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) {
|
||||||
|
utils_1.logWarning(stderr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
utils_1.logWarning('python binaries were not found in PATH');
|
||||||
|
}
|
||||||
return paths;
|
return paths;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -65269,7 +65292,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.logWarning = void 0;
|
|
||||||
const core = __importStar(__nccwpck_require__(2186));
|
const core = __importStar(__nccwpck_require__(2186));
|
||||||
const finder = __importStar(__nccwpck_require__(9996));
|
const finder = __importStar(__nccwpck_require__(9996));
|
||||||
const finderPyPy = __importStar(__nccwpck_require__(4003));
|
const finderPyPy = __importStar(__nccwpck_require__(4003));
|
||||||
|
@ -65299,17 +65321,20 @@ function resolveVersionInput() {
|
||||||
}
|
}
|
||||||
if (versionFile) {
|
if (versionFile) {
|
||||||
if (!fs_1.default.existsSync(versionFile)) {
|
if (!fs_1.default.existsSync(versionFile)) {
|
||||||
logWarning(`The specified python version file at: ${versionFile} doesn't exist. Attempting to find .python-version file.`);
|
throw new Error(`The specified python version file at: ${versionFile} doesn't exist.`);
|
||||||
versionFile = '.python-version';
|
|
||||||
if (!fs_1.default.existsSync(versionFile)) {
|
|
||||||
throw new Error(`The ${versionFile} doesn't exist.`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
version = fs_1.default.readFileSync(versionFile, 'utf8');
|
version = fs_1.default.readFileSync(versionFile, 'utf8');
|
||||||
core.info(`Resolved ${versionFile} as ${version}`);
|
core.info(`Resolved ${versionFile} as ${version}`);
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
core.warning("Neither 'python-version' nor 'python-version-file' inputs were supplied.");
|
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;
|
||||||
|
}
|
||||||
|
utils_1.logWarning(`${versionFile} doesn't exist.`);
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
function run() {
|
function run() {
|
||||||
|
@ -65358,11 +65383,6 @@ function run() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function logWarning(message) {
|
|
||||||
const warningPrefix = '[warning]';
|
|
||||||
core.info(`${warningPrefix}${message}`);
|
|
||||||
}
|
|
||||||
exports.logWarning = logWarning;
|
|
||||||
run();
|
run();
|
||||||
|
|
||||||
|
|
||||||
|
@ -65392,16 +65412,26 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
__setModuleDefault(result, mod);
|
__setModuleDefault(result, mod);
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
|
});
|
||||||
|
};
|
||||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
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 cache = __importStar(__nccwpck_require__(7799));
|
||||||
const core = __importStar(__nccwpck_require__(2186));
|
const core = __importStar(__nccwpck_require__(2186));
|
||||||
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
||||||
const path = __importStar(__nccwpck_require__(1017));
|
const path = __importStar(__nccwpck_require__(1017));
|
||||||
const semver = __importStar(__nccwpck_require__(1383));
|
const semver = __importStar(__nccwpck_require__(1383));
|
||||||
|
const exec = __importStar(__nccwpck_require__(1514));
|
||||||
exports.IS_WINDOWS = process.platform === 'win32';
|
exports.IS_WINDOWS = process.platform === 'win32';
|
||||||
exports.IS_LINUX = process.platform === 'linux';
|
exports.IS_LINUX = process.platform === 'linux';
|
||||||
exports.WINDOWS_ARCHS = ['x86', 'x64'];
|
exports.WINDOWS_ARCHS = ['x86', 'x64'];
|
||||||
|
@ -65485,6 +65515,22 @@ function isCacheFeatureAvailable() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
|
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
|
||||||
|
function getLinuxOSReleaseInfo() {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const { stdout, stderr, exitCode } = yield exec.getExecOutput('lsb_release', ['-i', '-r', '-s'], {
|
||||||
|
silent: true
|
||||||
|
});
|
||||||
|
const [osRelease, osVersion] = stdout.trim().split('\n');
|
||||||
|
core.debug(`OS Release: ${osRelease}, Version: ${osVersion}`);
|
||||||
|
return `${osVersion}-${osRelease}`;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.getLinuxOSReleaseInfo = getLinuxOSReleaseInfo;
|
||||||
|
function logWarning(message) {
|
||||||
|
const warningPrefix = '[warning]';
|
||||||
|
core.info(`${warningPrefix}${message}`);
|
||||||
|
}
|
||||||
|
exports.logWarning = logWarning;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
|
@ -7,7 +7,7 @@ import * as path from 'path';
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
|
|
||||||
import CacheDistributor from './cache-distributor';
|
import CacheDistributor from './cache-distributor';
|
||||||
import {IS_WINDOWS} from '../utils';
|
import {getLinuxOSReleaseInfo, IS_LINUX, IS_WINDOWS} from '../utils';
|
||||||
|
|
||||||
class PipCache extends CacheDistributor {
|
class PipCache extends CacheDistributor {
|
||||||
constructor(
|
constructor(
|
||||||
|
@ -57,8 +57,17 @@ class PipCache extends CacheDistributor {
|
||||||
|
|
||||||
protected async computeKeys() {
|
protected async computeKeys() {
|
||||||
const hash = await glob.hashFiles(this.cacheDependencyPath);
|
const hash = await glob.hashFiles(this.cacheDependencyPath);
|
||||||
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
|
let primaryKey = '';
|
||||||
const restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}`;
|
let restoreKey = '';
|
||||||
|
|
||||||
|
if (IS_LINUX) {
|
||||||
|
const osRelease = await getLinuxOSReleaseInfo();
|
||||||
|
primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${osRelease}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
|
||||||
|
restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${osRelease}-python-${this.pythonVersion}-${this.packageManager}`;
|
||||||
|
} else {
|
||||||
|
primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
|
||||||
|
restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}`;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
primaryKey,
|
primaryKey,
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
import * as glob from '@actions/glob';
|
import * as glob from '@actions/glob';
|
||||||
import * as os from 'os';
|
import * as io from '@actions/io';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
|
import * as core from '@actions/core';
|
||||||
|
|
||||||
import CacheDistributor from './cache-distributor';
|
import CacheDistributor from './cache-distributor';
|
||||||
|
import {logWarning} from '../utils';
|
||||||
|
|
||||||
class PoetryCache extends CacheDistributor {
|
class PoetryCache extends CacheDistributor {
|
||||||
constructor(
|
constructor(
|
||||||
|
@ -28,6 +30,26 @@ class PoetryCache extends CacheDistributor {
|
||||||
paths.push(path.join(process.cwd(), '.venv'));
|
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}`,
|
||||||
|
undefined,
|
||||||
|
{ignoreReturnCode: true}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (exitCode) {
|
||||||
|
logWarning(stderr);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logWarning('python binaries were not found in PATH');
|
||||||
|
}
|
||||||
|
|
||||||
return paths;
|
return paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,12 @@ import * as path from 'path';
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import {getCacheDistributor} from './cache-distributions/cache-factory';
|
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) {
|
function isPyPyVersion(versionSpec: string) {
|
||||||
return versionSpec.startsWith('pypy');
|
return versionSpec.startsWith('pypy');
|
||||||
|
@ -38,24 +43,26 @@ function resolveVersionInput(): string {
|
||||||
|
|
||||||
if (versionFile) {
|
if (versionFile) {
|
||||||
if (!fs.existsSync(versionFile)) {
|
if (!fs.existsSync(versionFile)) {
|
||||||
logWarning(
|
throw new Error(
|
||||||
`The specified python version file at: ${versionFile} doesn't exist. Attempting to find .python-version file.`
|
`The specified python version file at: ${versionFile} doesn't exist.`
|
||||||
);
|
);
|
||||||
versionFile = '.python-version';
|
|
||||||
if (!fs.existsSync(versionFile)) {
|
|
||||||
throw new Error(`The ${versionFile} doesn't exist.`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
version = fs.readFileSync(versionFile, 'utf8');
|
version = fs.readFileSync(versionFile, 'utf8');
|
||||||
core.info(`Resolved ${versionFile} as ${version}`);
|
core.info(`Resolved ${versionFile} as ${version}`);
|
||||||
|
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
core.warning(
|
logWarning(
|
||||||
"Neither 'python-version' nor 'python-version-file' inputs were supplied."
|
"Neither 'python-version' nor 'python-version-file' inputs were supplied. Attempting to find '.python-version' file."
|
||||||
);
|
);
|
||||||
|
versionFile = '.python-version';
|
||||||
|
if (fs.existsSync(versionFile)) {
|
||||||
|
version = fs.readFileSync(versionFile, 'utf8');
|
||||||
|
core.info(`Resolved ${versionFile} as ${version}`);
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
logWarning(`${versionFile} doesn't exist.`);
|
||||||
|
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
@ -117,9 +124,4 @@ async function run() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function logWarning(message: string): void {
|
|
||||||
const warningPrefix = '[warning]';
|
|
||||||
core.info(`${warningPrefix}${message}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
|
22
src/utils.ts
22
src/utils.ts
|
@ -3,6 +3,7 @@ import * as core from '@actions/core';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as semver from 'semver';
|
import * as semver from 'semver';
|
||||||
|
import * as exec from '@actions/exec';
|
||||||
|
|
||||||
export const IS_WINDOWS = process.platform === 'win32';
|
export const IS_WINDOWS = process.platform === 'win32';
|
||||||
export const IS_LINUX = process.platform === 'linux';
|
export const IS_LINUX = process.platform === 'linux';
|
||||||
|
@ -119,3 +120,24 @@ export function isCacheFeatureAvailable(): boolean {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getLinuxOSReleaseInfo() {
|
||||||
|
const {stdout, stderr, exitCode} = await exec.getExecOutput(
|
||||||
|
'lsb_release',
|
||||||
|
['-i', '-r', '-s'],
|
||||||
|
{
|
||||||
|
silent: true
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const [osRelease, osVersion] = stdout.trim().split('\n');
|
||||||
|
|
||||||
|
core.debug(`OS Release: ${osRelease}, Version: ${osVersion}`);
|
||||||
|
|
||||||
|
return `${osVersion}-${osRelease}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function logWarning(message: string): void {
|
||||||
|
const warningPrefix = '[warning]';
|
||||||
|
core.info(`${warningPrefix}${message}`);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue