mirror of
https://gitea.com/actions/setup-python.git
synced 2024-11-22 18:19:35 +01:00
Multiple Python versions from version-file in one environment
This makes the change from #567 also available for users of .python-version.
This commit is contained in:
parent
7a4f344e33
commit
d59aa9efa4
3 changed files with 49 additions and 12 deletions
26
.github/workflows/test-python.yml
vendored
26
.github/workflows/test-python.yml
vendored
|
@ -271,3 +271,29 @@ jobs:
|
||||||
}
|
}
|
||||||
$pythonVersion
|
$pythonVersion
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
|
|
||||||
|
setup-python-multiple-python-versions-from-file:
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Build multi-version file
|
||||||
|
run: printf '%s\n' 3.7 3.8 3.9 3.10 > .python-version
|
||||||
|
shell: bash
|
||||||
|
- name: Setup Python and check latest
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
python-version-file: '.python-version'
|
||||||
|
check-latest: true
|
||||||
|
- name: Validate version
|
||||||
|
run: |
|
||||||
|
$pythonVersion = (python --version)
|
||||||
|
if ("$pythonVersion" -NotMatch "3.10"){
|
||||||
|
Write-Host "The current version is $pythonVersion; expected version is 3.10"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
$pythonVersion
|
||||||
|
shell: pwsh
|
||||||
|
|
17
dist/setup/index.js
vendored
17
dist/setup/index.js
vendored
|
@ -67984,6 +67984,15 @@ function cacheDependencies(cache, pythonVersion) {
|
||||||
yield cacheDistributor.restoreCache();
|
yield cacheDistributor.restoreCache();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
function readVersionFile(versionFile) {
|
||||||
|
const data = fs_1.default.readFileSync(versionFile, 'utf8');
|
||||||
|
const versions = data
|
||||||
|
.split('\n')
|
||||||
|
.map(input => input.trim())
|
||||||
|
.filter(x => x !== '');
|
||||||
|
core.info(`Resolved ${versionFile} as ${versions.join(', ')}`);
|
||||||
|
return versions;
|
||||||
|
}
|
||||||
function resolveVersionInput() {
|
function resolveVersionInput() {
|
||||||
const versions = core.getMultilineInput('python-version');
|
const versions = core.getMultilineInput('python-version');
|
||||||
let versionFile = core.getInput('python-version-file');
|
let versionFile = core.getInput('python-version-file');
|
||||||
|
@ -67997,16 +68006,12 @@ function resolveVersionInput() {
|
||||||
if (!fs_1.default.existsSync(versionFile)) {
|
if (!fs_1.default.existsSync(versionFile)) {
|
||||||
throw new Error(`The specified python version file at: ${versionFile} doesn't exist.`);
|
throw new Error(`The specified python version file at: ${versionFile} doesn't exist.`);
|
||||||
}
|
}
|
||||||
const version = fs_1.default.readFileSync(versionFile, 'utf8');
|
return readVersionFile(versionFile);
|
||||||
core.info(`Resolved ${versionFile} as ${version}`);
|
|
||||||
return [version];
|
|
||||||
}
|
}
|
||||||
utils_1.logWarning("Neither 'python-version' nor 'python-version-file' inputs were supplied. Attempting to find '.python-version' file.");
|
utils_1.logWarning("Neither 'python-version' nor 'python-version-file' inputs were supplied. Attempting to find '.python-version' file.");
|
||||||
versionFile = '.python-version';
|
versionFile = '.python-version';
|
||||||
if (fs_1.default.existsSync(versionFile)) {
|
if (fs_1.default.existsSync(versionFile)) {
|
||||||
const version = fs_1.default.readFileSync(versionFile, 'utf8');
|
return readVersionFile(versionFile);
|
||||||
core.info(`Resolved ${versionFile} as ${version}`);
|
|
||||||
return [version];
|
|
||||||
}
|
}
|
||||||
utils_1.logWarning(`${versionFile} doesn't exist.`);
|
utils_1.logWarning(`${versionFile} doesn't exist.`);
|
||||||
return versions;
|
return versions;
|
||||||
|
|
|
@ -22,6 +22,16 @@ async function cacheDependencies(cache: string, pythonVersion: string) {
|
||||||
await cacheDistributor.restoreCache();
|
await cacheDistributor.restoreCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function readVersionFile(versionFile: string) {
|
||||||
|
const data = fs.readFileSync(versionFile, 'utf8');
|
||||||
|
const versions = data
|
||||||
|
.split('\n')
|
||||||
|
.map(input => input.trim())
|
||||||
|
.filter(x => x !== '');
|
||||||
|
core.info(`Resolved ${versionFile} as ${versions.join(', ')}`);
|
||||||
|
return versions;
|
||||||
|
}
|
||||||
|
|
||||||
function resolveVersionInput() {
|
function resolveVersionInput() {
|
||||||
const versions = core.getMultilineInput('python-version');
|
const versions = core.getMultilineInput('python-version');
|
||||||
let versionFile = core.getInput('python-version-file');
|
let versionFile = core.getInput('python-version-file');
|
||||||
|
@ -42,9 +52,7 @@ function resolveVersionInput() {
|
||||||
`The specified python version file at: ${versionFile} doesn't exist.`
|
`The specified python version file at: ${versionFile} doesn't exist.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const version = fs.readFileSync(versionFile, 'utf8');
|
return readVersionFile(versionFile);
|
||||||
core.info(`Resolved ${versionFile} as ${version}`);
|
|
||||||
return [version];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logWarning(
|
logWarning(
|
||||||
|
@ -52,9 +60,7 @@ function resolveVersionInput() {
|
||||||
);
|
);
|
||||||
versionFile = '.python-version';
|
versionFile = '.python-version';
|
||||||
if (fs.existsSync(versionFile)) {
|
if (fs.existsSync(versionFile)) {
|
||||||
const version = fs.readFileSync(versionFile, 'utf8');
|
return readVersionFile(versionFile);
|
||||||
core.info(`Resolved ${versionFile} as ${version}`);
|
|
||||||
return [version];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logWarning(`${versionFile} doesn't exist.`);
|
logWarning(`${versionFile} doesn't exist.`);
|
||||||
|
|
Loading…
Reference in a new issue