mirror of
https://github.com/actions/setup-python.git
synced 2025-04-24 15:32:13 +00:00
add support for python-version-file
This commit is contained in:
parent
7f80679172
commit
5d2a3532c1
5 changed files with 89 additions and 2 deletions
34
.github/workflows/test-python.yml
vendored
34
.github/workflows/test-python.yml
vendored
|
@ -10,6 +10,7 @@ on:
|
||||||
- '**.md'
|
- '**.md'
|
||||||
schedule:
|
schedule:
|
||||||
- cron: 30 3 * * *
|
- cron: 30 3 * * *
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
default-version:
|
default-version:
|
||||||
|
@ -62,6 +63,39 @@ 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@v2
|
||||||
|
|
||||||
|
- name: build-version-file ${{ matrix.python }}
|
||||||
|
run: echo ${{ matrix.python }} > .python-version
|
||||||
|
|
||||||
|
- name: setup-python ${{ matrix.python }}
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
python-version-file: '.python-version'
|
||||||
|
|
||||||
|
- 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 }}
|
||||||
|
|
12
README.md
12
README.md
|
@ -20,6 +20,7 @@ This action sets up a Python environment for use in actions by:
|
||||||
- Support for pre-release versions of Python.
|
- Support for pre-release versions of Python.
|
||||||
- Support for installing any version of PyPy on-flight
|
- Support for installing any version of PyPy on-flight
|
||||||
- Support for built-in caching of pip and pipenv dependencies
|
- Support for built-in caching of pip and pipenv dependencies
|
||||||
|
- Support for `.python-version` file
|
||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
|
|
||||||
|
@ -36,6 +37,17 @@ steps:
|
||||||
- run: python my_script.py
|
- run: python my_script.py
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Read Python version from file:
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version-file: '.python-version' # Read python version from a file
|
||||||
|
architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified
|
||||||
|
- run: python my_script.py
|
||||||
|
```
|
||||||
|
|
||||||
Matrix Testing:
|
Matrix Testing:
|
||||||
```yaml
|
```yaml
|
||||||
jobs:
|
jobs:
|
||||||
|
|
|
@ -6,6 +6,8 @@ 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 a Python version to use, using SemVer's version range syntax."
|
||||||
default: '3.x'
|
default: '3.x'
|
||||||
|
python-version-file:
|
||||||
|
description: "File containing the Python version to use. Examples: .python-version"
|
||||||
cache:
|
cache:
|
||||||
description: 'Used to specify a package manager for caching in the default directory. Supported values: pip, pipenv.'
|
description: 'Used to specify a package manager for caching in the default directory. Supported values: pip, pipenv.'
|
||||||
required: false
|
required: false
|
||||||
|
|
19
dist/setup/index.js
vendored
19
dist/setup/index.js
vendored
|
@ -6622,12 +6622,16 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
result["default"] = mod;
|
result["default"] = mod;
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
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(__webpack_require__(470));
|
const core = __importStar(__webpack_require__(470));
|
||||||
const finder = __importStar(__webpack_require__(927));
|
const finder = __importStar(__webpack_require__(927));
|
||||||
const finderPyPy = __importStar(__webpack_require__(50));
|
const finderPyPy = __importStar(__webpack_require__(50));
|
||||||
const path = __importStar(__webpack_require__(622));
|
const path = __importStar(__webpack_require__(622));
|
||||||
const os = __importStar(__webpack_require__(87));
|
const os = __importStar(__webpack_require__(87));
|
||||||
|
const fs_1 = __importDefault(__webpack_require__(747));
|
||||||
const cache_factory_1 = __webpack_require__(633);
|
const cache_factory_1 = __webpack_require__(633);
|
||||||
const utils_1 = __webpack_require__(163);
|
const utils_1 = __webpack_require__(163);
|
||||||
function isPyPyVersion(versionSpec) {
|
function isPyPyVersion(versionSpec) {
|
||||||
|
@ -6643,10 +6647,23 @@ function cacheDependencies(cache, pythonVersion) {
|
||||||
yield cacheDistributor.restoreCache();
|
yield cacheDistributor.restoreCache();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
function resolveVersionInput() {
|
||||||
|
let version = core.getInput('python-version');
|
||||||
|
const versionFileInput = core.getInput('python-version-file');
|
||||||
|
if (versionFileInput) {
|
||||||
|
const versionFilePath = path.join(process.env.GITHUB_WORKSPACE, versionFileInput);
|
||||||
|
if (!fs_1.default.existsSync(versionFilePath)) {
|
||||||
|
throw new Error(`The specified node version file at: ${versionFilePath} does not exist`);
|
||||||
|
}
|
||||||
|
version = fs_1.default.readFileSync(versionFilePath, 'utf8');
|
||||||
|
core.info(`Resolved ${versionFileInput} as ${version}`);
|
||||||
|
}
|
||||||
|
return version;
|
||||||
|
}
|
||||||
function run() {
|
function run() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
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();
|
||||||
|
|
|
@ -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 {isGhes} from './utils';
|
import {isGhes} from './utils';
|
||||||
|
|
||||||
|
@ -24,9 +25,30 @@ async function cacheDependencies(cache: string, pythonVersion: string) {
|
||||||
await cacheDistributor.restoreCache();
|
await cacheDistributor.restoreCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resolveVersionInput(): string {
|
||||||
|
let version = core.getInput('python-version');
|
||||||
|
const versionFileInput = core.getInput('python-version-file');
|
||||||
|
|
||||||
|
if (versionFileInput) {
|
||||||
|
const versionFilePath = path.join(
|
||||||
|
process.env.GITHUB_WORKSPACE!,
|
||||||
|
versionFileInput
|
||||||
|
);
|
||||||
|
if (!fs.existsSync(versionFilePath)) {
|
||||||
|
throw new Error(
|
||||||
|
`The specified node version file at: ${versionFilePath} does not exist`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
version = fs.readFileSync(versionFilePath, 'utf8');
|
||||||
|
core.info(`Resolved ${versionFileInput} as ${version}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
async function run() {
|
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…
Add table
Reference in a new issue