Allow python-version-file to be a relative path

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.
This commit is contained in:
Kurt von Laven 2022-06-11 17:45:39 -07:00 committed by Kurt von Laven
parent 632a5f6f70
commit c3247d24b5
No known key found for this signature in database
GPG key ID: 1CDDDF4A62B85F39
2 changed files with 10 additions and 13 deletions

10
dist/setup/index.js vendored
View file

@ -64546,18 +64546,18 @@ function cacheDependencies(cache, pythonVersion) {
} }
function resolveVersionInput() { function resolveVersionInput() {
let version = core.getInput('python-version'); let version = core.getInput('python-version');
const versionFile = core.getInput('python-version-file'); let versionFile = core.getInput('python-version-file');
if (version && versionFile) { if (version && versionFile) {
core.warning('Both python-version and python-version-file inputs are specified, only python-version will be used'); core.warning('Both python-version and python-version-file inputs are specified, only python-version will be used');
} }
if (version) { if (version) {
return version; return version;
} }
const versionFilePath = path.join(process.env.GITHUB_WORKSPACE, versionFile || '.python-version'); versionFile = versionFile || '.python-version';
if (!fs_1.default.existsSync(versionFilePath)) { if (!fs_1.default.existsSync(versionFile)) {
throw new Error(`The specified python version file at: ${versionFilePath} does not exist`); 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}`); core.info(`Resolved ${versionFile} as ${version}`);
return version; return version;
} }

View file

@ -24,7 +24,7 @@ async function cacheDependencies(cache: string, pythonVersion: string) {
function resolveVersionInput(): string { function resolveVersionInput(): string {
let version = core.getInput('python-version'); let version = core.getInput('python-version');
const versionFile = core.getInput('python-version-file'); let versionFile = core.getInput('python-version-file');
if (version && versionFile) { if (version && versionFile) {
core.warning( core.warning(
@ -36,16 +36,13 @@ function resolveVersionInput(): string {
return version; return version;
} }
const versionFilePath = path.join( versionFile = versionFile || '.python-version';
process.env.GITHUB_WORKSPACE!, if (!fs.existsSync(versionFile)) {
versionFile || '.python-version'
);
if (!fs.existsSync(versionFilePath)) {
throw new Error( 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}`); core.info(`Resolved ${versionFile} as ${version}`);
return version; return version;