Skip to content

Commit

Permalink
Allow python-version-file to be a relative path
Browse files Browse the repository at this point in the history
Don't assume that it is safe to prepend the GITHUB_WORKSPACE
environment variable to the given path since the path may already be
absolute.
  • Loading branch information
Kurt-von-Laven committed Jun 12, 2022
1 parent 813f9b1 commit 2f379a6
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/setup-python.ts
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 ||= '.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 2f379a6

Please sign in to comment.