mirror of
https://github.com/actions/setup-python
synced 2025-04-07 07:49:45 +00: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:
@ -3,6 +3,7 @@ import * as finder from './find-python';
|
||||
import * as finderPyPy from './find-pypy';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import fs from 'fs';
|
||||
import {getCacheDistributor} from './cache-distributions/cache-factory';
|
||||
import {isCacheFeatureAvailable} from './utils';
|
||||
|
||||
@ -21,6 +22,35 @@ async function cacheDependencies(cache: string, pythonVersion: string) {
|
||||
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() {
|
||||
if (process.env.AGENT_TOOLSDIRECTORY?.trim()) {
|
||||
core.debug(
|
||||
@ -33,7 +63,7 @@ async function run() {
|
||||
);
|
||||
}
|
||||
try {
|
||||
const version = core.getInput('python-version');
|
||||
const version = resolveVersionInput();
|
||||
if (version) {
|
||||
let pythonVersion: string;
|
||||
const arch: string = core.getInput('architecture') || os.arch();
|
||||
|
Reference in New Issue
Block a user