Skip to content

Commit

Permalink
Allow python-version-file to be a relative path (actions#431)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kurt-von-Laven authored Jun 20, 2022
1 parent cf86e08 commit ffcd000
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
10 changes: 5 additions & 5 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64546,18 +64546,18 @@ function cacheDependencies(cache, pythonVersion) {
}
function resolveVersionInput() {
let version = core.getInput('python-version');
const versionFile = core.getInput('python-version-file');
let 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`);
versionFile = versionFile || '.python-version';
if (!fs_1.default.existsSync(versionFile)) {
throw new Error(`The specified python version file at: ${versionFile} does not exist`);
}
version = fs_1.default.readFileSync(versionFilePath, 'utf8');
version = fs_1.default.readFileSync(versionFile, 'utf8');
core.info(`Resolved ${versionFile} as ${version}`);
return version;
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 5 additions & 8 deletions src/setup-python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async function cacheDependencies(cache: string, pythonVersion: string) {

function resolveVersionInput(): string {
let version = core.getInput('python-version');
const versionFile = core.getInput('python-version-file');
let versionFile = core.getInput('python-version-file');

if (version && versionFile) {
core.warning(
Expand All @@ -36,16 +36,13 @@ function resolveVersionInput(): string {
return version;
}

const versionFilePath = path.join(
process.env.GITHUB_WORKSPACE!,
versionFile || '.python-version'
);
if (!fs.existsSync(versionFilePath)) {
versionFile = versionFile || '.python-version';
if (!fs.existsSync(versionFile)) {
throw new Error(
`The specified python version file at: ${versionFilePath} does not exist`
`The specified python version file at: ${versionFile} does not exist`
);
}
version = fs.readFileSync(versionFilePath, 'utf8');
version = fs.readFileSync(versionFile, 'utf8');
core.info(`Resolved ${versionFile} as ${version}`);

return version;
Expand Down

0 comments on commit ffcd000

Please sign in to comment.