mirror of
https://github.com/actions/setup-python.git
synced 2024-12-27 01:50:35 +01:00
add support for python-version-file (#336)
* add support for python-version-file * Update action.yml * update to v4, remove python-version default * python-version overrides python-version-file, like setup-node * checks '.python-version' by default if nothing else specified * update tests, update to checkout@v3 * update build * appease the linter * remove old test for default python version * revert readme changes * update build
This commit is contained in:
parent
3f82819745
commit
53e15292cd
5 changed files with 98 additions and 32 deletions
68
.github/workflows/test-python.yml
vendored
68
.github/workflows/test-python.yml
vendored
|
@ -10,33 +10,9 @@ on:
|
||||||
- '**.md'
|
- '**.md'
|
||||||
schedule:
|
schedule:
|
||||||
- cron: 30 3 * * *
|
- cron: 30 3 * * *
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
default-version:
|
|
||||||
name: Setup default version
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os: [macos-latest, windows-latest, ubuntu-18.04, ubuntu-20.04]
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- name: setup default python
|
|
||||||
id: setup-python
|
|
||||||
uses: ./
|
|
||||||
|
|
||||||
- name: Check python-path
|
|
||||||
run: ./__tests__/check-python-path.sh '${{ steps.setup-python.outputs.python-path }}'
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
- name: Validate version
|
|
||||||
run: python --version
|
|
||||||
|
|
||||||
- name: Run simple python code
|
|
||||||
run: python -c 'import math; print(math.factorial(5))'
|
|
||||||
|
|
||||||
setup-versions-from-manifest:
|
setup-versions-from-manifest:
|
||||||
name: Setup ${{ matrix.python }} ${{ matrix.os }}
|
name: Setup ${{ matrix.python }} ${{ matrix.os }}
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
@ -47,7 +23,7 @@ jobs:
|
||||||
python: [3.5.4, 3.6.7, 3.7.5, 3.8.1]
|
python: [3.5.4, 3.6.7, 3.7.5, 3.8.1]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: setup-python ${{ matrix.python }}
|
- name: setup-python ${{ matrix.python }}
|
||||||
id: setup-python
|
id: setup-python
|
||||||
|
@ -72,6 +48,44 @@ jobs:
|
||||||
- name: Run simple code
|
- name: Run simple code
|
||||||
run: python -c 'import math; print(math.factorial(5))'
|
run: python -c 'import math; print(math.factorial(5))'
|
||||||
|
|
||||||
|
setup-versions-from-file:
|
||||||
|
name: Setup ${{ matrix.python }} ${{ matrix.os }} version file
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [macos-latest, windows-latest, ubuntu-18.04, ubuntu-20.04]
|
||||||
|
python: [3.5.4, 3.6.7, 3.7.5, 3.8.1]
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: build-version-file ${{ matrix.python }}
|
||||||
|
run: echo ${{ matrix.python }} > .python-version
|
||||||
|
|
||||||
|
- name: setup-python ${{ matrix.python }}
|
||||||
|
id: setup-python
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
python-version-file: '.python-version'
|
||||||
|
|
||||||
|
- name: Check python-path
|
||||||
|
run: ./__tests__/check-python-path.sh '${{ steps.setup-python.outputs.python-path }}'
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
- name: Validate version
|
||||||
|
run: |
|
||||||
|
$pythonVersion = (python --version)
|
||||||
|
if ("Python ${{ matrix.python }}" -ne "$pythonVersion"){
|
||||||
|
Write-Host "The current version is $pythonVersion; expected version is ${{ matrix.python }}"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
$pythonVersion
|
||||||
|
shell: pwsh
|
||||||
|
|
||||||
|
- name: Run simple code
|
||||||
|
run: python -c 'import math; print(math.factorial(5))'
|
||||||
|
|
||||||
setup-pre-release-version-from-manifest:
|
setup-pre-release-version-from-manifest:
|
||||||
name: Setup 3.9.0-beta.4 ${{ matrix.os }}
|
name: Setup 3.9.0-beta.4 ${{ matrix.os }}
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
@ -81,7 +95,7 @@ jobs:
|
||||||
os: [macos-latest, windows-latest, ubuntu-18.04, ubuntu-20.04]
|
os: [macos-latest, windows-latest, ubuntu-18.04, ubuntu-20.04]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: setup-python 3.9.0-beta.4
|
- name: setup-python 3.9.0-beta.4
|
||||||
id: setup-python
|
id: setup-python
|
||||||
|
|
|
@ -4,8 +4,9 @@ description: 'Set up a specific version of Python and add the command-line tools
|
||||||
author: 'GitHub'
|
author: 'GitHub'
|
||||||
inputs:
|
inputs:
|
||||||
python-version:
|
python-version:
|
||||||
description: "Version range or exact version of a Python version to use, using SemVer's version range syntax."
|
description: "Version range or exact version of Python to use, using SemVer's version range syntax. Reads from .python-version if unset."
|
||||||
default: '3.x'
|
python-version-file:
|
||||||
|
description: "File containing the Python version to use. Example: .python-version"
|
||||||
cache:
|
cache:
|
||||||
description: 'Used to specify a package manager for caching in the default directory. Supported values: pip, pipenv, poetry.'
|
description: 'Used to specify a package manager for caching in the default directory. Supported values: pip, pipenv, poetry.'
|
||||||
required: false
|
required: false
|
||||||
|
|
23
dist/setup/index.js
vendored
23
dist/setup/index.js
vendored
|
@ -64527,12 +64527,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
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));
|
||||||
const path = __importStar(__nccwpck_require__(1017));
|
const path = __importStar(__nccwpck_require__(1017));
|
||||||
const os = __importStar(__nccwpck_require__(2037));
|
const os = __importStar(__nccwpck_require__(2037));
|
||||||
|
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
||||||
const cache_factory_1 = __nccwpck_require__(7549);
|
const cache_factory_1 = __nccwpck_require__(7549);
|
||||||
const utils_1 = __nccwpck_require__(1314);
|
const utils_1 = __nccwpck_require__(1314);
|
||||||
function isPyPyVersion(versionSpec) {
|
function isPyPyVersion(versionSpec) {
|
||||||
|
@ -64545,6 +64549,23 @@ function cacheDependencies(cache, pythonVersion) {
|
||||||
yield cacheDistributor.restoreCache();
|
yield cacheDistributor.restoreCache();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
function resolveVersionInput() {
|
||||||
|
let version = core.getInput('python-version');
|
||||||
|
const versionFile = core.getInput('python-version-file');
|
||||||
|
if (version && versionFile) {
|
||||||
|
core.warning('Both python-version and python-version-file inputs are specified, only python-version will be used');
|
||||||
|
}
|
||||||
|
if (version) {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
const versionFilePath = path.join(process.env.GITHUB_WORKSPACE, versionFile || '.python-version');
|
||||||
|
if (!fs_1.default.existsSync(versionFilePath)) {
|
||||||
|
throw new Error(`The specified python version file at: ${versionFilePath} does not exist`);
|
||||||
|
}
|
||||||
|
version = fs_1.default.readFileSync(versionFilePath, 'utf8');
|
||||||
|
core.info(`Resolved ${versionFile} as ${version}`);
|
||||||
|
return version;
|
||||||
|
}
|
||||||
function run() {
|
function run() {
|
||||||
var _a;
|
var _a;
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
@ -64556,7 +64577,7 @@ function run() {
|
||||||
core.debug(`Python is expected to be installed into RUNNER_TOOL_CACHE==${process.env['RUNNER_TOOL_CACHE']}`);
|
core.debug(`Python is expected to be installed into RUNNER_TOOL_CACHE==${process.env['RUNNER_TOOL_CACHE']}`);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const version = core.getInput('python-version');
|
const version = resolveVersionInput();
|
||||||
if (version) {
|
if (version) {
|
||||||
let pythonVersion;
|
let pythonVersion;
|
||||||
const arch = core.getInput('architecture') || os.arch();
|
const arch = core.getInput('architecture') || os.arch();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "setup-python",
|
"name": "setup-python",
|
||||||
"version": "3.1.1",
|
"version": "4.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "Setup python action",
|
"description": "Setup python action",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
|
|
@ -3,6 +3,7 @@ import * as finder from './find-python';
|
||||||
import * as finderPyPy from './find-pypy';
|
import * as finderPyPy from './find-pypy';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
|
import fs from 'fs';
|
||||||
import {getCacheDistributor} from './cache-distributions/cache-factory';
|
import {getCacheDistributor} from './cache-distributions/cache-factory';
|
||||||
import {isCacheFeatureAvailable} from './utils';
|
import {isCacheFeatureAvailable} from './utils';
|
||||||
|
|
||||||
|
@ -21,6 +22,35 @@ async function cacheDependencies(cache: string, pythonVersion: string) {
|
||||||
await cacheDistributor.restoreCache();
|
await cacheDistributor.restoreCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resolveVersionInput(): string {
|
||||||
|
let version = core.getInput('python-version');
|
||||||
|
const versionFile = core.getInput('python-version-file');
|
||||||
|
|
||||||
|
if (version && versionFile) {
|
||||||
|
core.warning(
|
||||||
|
'Both python-version and python-version-file inputs are specified, only python-version will be used'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (version) {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
const versionFilePath = path.join(
|
||||||
|
process.env.GITHUB_WORKSPACE!,
|
||||||
|
versionFile || '.python-version'
|
||||||
|
);
|
||||||
|
if (!fs.existsSync(versionFilePath)) {
|
||||||
|
throw new Error(
|
||||||
|
`The specified python version file at: ${versionFilePath} does not exist`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
version = fs.readFileSync(versionFilePath, 'utf8');
|
||||||
|
core.info(`Resolved ${versionFile} as ${version}`);
|
||||||
|
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
if (process.env.AGENT_TOOLSDIRECTORY?.trim()) {
|
if (process.env.AGENT_TOOLSDIRECTORY?.trim()) {
|
||||||
core.debug(
|
core.debug(
|
||||||
|
@ -33,7 +63,7 @@ async function run() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const version = core.getInput('python-version');
|
const version = resolveVersionInput();
|
||||||
if (version) {
|
if (version) {
|
||||||
let pythonVersion: string;
|
let pythonVersion: string;
|
||||||
const arch: string = core.getInput('architecture') || os.arch();
|
const arch: string = core.getInput('architecture') || os.arch();
|
||||||
|
|
Loading…
Reference in a new issue