Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Python versions from version-file in one environment #647

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,29 @@ jobs:
}
$pythonVersion
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 changes: 11 additions & 6 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67984,6 +67984,15 @@ function cacheDependencies(cache, pythonVersion) {
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() {
const versions = core.getMultilineInput('python-version');
let versionFile = core.getInput('python-version-file');
Expand All @@ -67997,16 +68006,12 @@ function resolveVersionInput() {
if (!fs_1.default.existsSync(versionFile)) {
throw new Error(`The specified python version file at: ${versionFile} doesn't exist.`);
}
const version = fs_1.default.readFileSync(versionFile, 'utf8');
core.info(`Resolved ${versionFile} as ${version}`);
return [version];
return readVersionFile(versionFile);
}
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)) {
const version = fs_1.default.readFileSync(versionFile, 'utf8');
core.info(`Resolved ${versionFile} as ${version}`);
return [version];
return readVersionFile(versionFile);
}
utils_1.logWarning(`${versionFile} doesn't exist.`);
return versions;
Expand Down
18 changes: 12 additions & 6 deletions src/setup-python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ async function cacheDependencies(cache: string, pythonVersion: string) {
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() {
const versions = core.getMultilineInput('python-version');
let versionFile = core.getInput('python-version-file');
Expand All @@ -42,19 +52,15 @@ function resolveVersionInput() {
`The specified python version file at: ${versionFile} doesn't exist.`
);
}
const version = fs.readFileSync(versionFile, 'utf8');
core.info(`Resolved ${versionFile} as ${version}`);
return [version];
return readVersionFile(versionFile);
}

logWarning(
"Neither 'python-version' nor 'python-version-file' inputs were supplied. Attempting to find '.python-version' file."
);
versionFile = '.python-version';
if (fs.existsSync(versionFile)) {
const version = fs.readFileSync(versionFile, 'utf8');
core.info(`Resolved ${versionFile} as ${version}`);
return [version];
return readVersionFile(versionFile);
}

logWarning(`${versionFile} doesn't exist.`);
Expand Down