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

Rearranged logic of the ResolveVersionInput() #450

Merged
merged 11 commits into from Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 19 additions & 6 deletions dist/setup/index.js
Expand Up @@ -65241,6 +65241,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.logWarning = void 0;
const core = __importStar(__nccwpck_require__(2186));
const finder = __importStar(__nccwpck_require__(9996));
const finderPyPy = __importStar(__nccwpck_require__(4003));
Expand All @@ -65263,17 +65264,24 @@ function resolveVersionInput() {
let version = core.getInput('python-version');
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');
core.warning('Both python-version and python-version-file inputs are specified, only python-version will be used.');
}
if (version) {
return version;
}
versionFile = versionFile || '.python-version';
if (!fs_1.default.existsSync(versionFile)) {
throw new Error(`The specified python version file at: ${versionFile} does not exist`);
if (versionFile) {
if (!fs_1.default.existsSync(versionFile)) {
logWarning(`The specified python version file at: ${versionFile} doesn't exist. Attempting to find .python-version file.`);
versionFile = '.python-version';
if (!fs_1.default.existsSync(versionFile)) {
throw new Error(`The ${versionFile} doesn't exist.`);
}
}
version = fs_1.default.readFileSync(versionFile, 'utf8');
core.info(`Resolved ${versionFile} as ${version}`);
return version;
}
version = fs_1.default.readFileSync(versionFile, 'utf8');
core.info(`Resolved ${versionFile} as ${version}`);
core.warning("Neither 'python-version' nor 'python-version-file' inputs were supplied.");
return version;
}
function run() {
Expand Down Expand Up @@ -65318,6 +65326,11 @@ function run() {
}
});
}
function logWarning(message) {
const warningPrefix = '[warning]';
core.info(`${warningPrefix}${message}`);
}
exports.logWarning = logWarning;
run();


Expand Down
33 changes: 25 additions & 8 deletions src/setup-python.ts
Expand Up @@ -28,22 +28,34 @@ function resolveVersionInput(): string {

if (version && versionFile) {
core.warning(
'Both python-version and python-version-file inputs are specified, only python-version will be used'
'Both python-version and python-version-file inputs are specified, only python-version will be used.'
);
}

if (version) {
return version;
}

versionFile = versionFile || '.python-version';
if (!fs.existsSync(versionFile)) {
throw new Error(
`The specified python version file at: ${versionFile} does not exist`
);
if (versionFile) {
if (!fs.existsSync(versionFile)) {
logWarning(
`The specified python version file at: ${versionFile} doesn't exist. Attempting to find .python-version file.`
);
versionFile = '.python-version';
if (!fs.existsSync(versionFile)) {
throw new Error(`The ${versionFile} doesn't exist.`);
}
}

version = fs.readFileSync(versionFile, 'utf8');
core.info(`Resolved ${versionFile} as ${version}`);

return version;
}
version = fs.readFileSync(versionFile, 'utf8');
core.info(`Resolved ${versionFile} as ${version}`);

core.warning(
"Neither 'python-version' nor 'python-version-file' inputs were supplied."
);

return version;
}
Expand Down Expand Up @@ -101,4 +113,9 @@ async function run() {
}
}

export function logWarning(message: string): void {
const warningPrefix = '[warning]';
core.info(`${warningPrefix}${message}`);
}

run();