Skip to content

Commit 782f81b

Browse files
Merge pull request #450 from IvanZosimov/ResolveVersionFix
Rearranged logic of the ResolveVersionInput()
2 parents 78a2330 + 099ed89 commit 782f81b

File tree

2 files changed

+44
-14
lines changed

2 files changed

+44
-14
lines changed

dist/setup/index.js

+19-6
Original file line numberDiff line numberDiff line change
@@ -65241,6 +65241,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
6524165241
return (mod && mod.__esModule) ? mod : { "default": mod };
6524265242
};
6524365243
Object.defineProperty(exports, "__esModule", ({ value: true }));
65244+
exports.logWarning = void 0;
6524465245
const core = __importStar(__nccwpck_require__(2186));
6524565246
const finder = __importStar(__nccwpck_require__(9996));
6524665247
const finderPyPy = __importStar(__nccwpck_require__(4003));
@@ -65263,17 +65264,24 @@ function resolveVersionInput() {
6526365264
let version = core.getInput('python-version');
6526465265
let versionFile = core.getInput('python-version-file');
6526565266
if (version && versionFile) {
65266-
core.warning('Both python-version and python-version-file inputs are specified, only python-version will be used');
65267+
core.warning('Both python-version and python-version-file inputs are specified, only python-version will be used.');
6526765268
}
6526865269
if (version) {
6526965270
return version;
6527065271
}
65271-
versionFile = versionFile || '.python-version';
65272-
if (!fs_1.default.existsSync(versionFile)) {
65273-
throw new Error(`The specified python version file at: ${versionFile} does not exist`);
65272+
if (versionFile) {
65273+
if (!fs_1.default.existsSync(versionFile)) {
65274+
logWarning(`The specified python version file at: ${versionFile} doesn't exist. Attempting to find .python-version file.`);
65275+
versionFile = '.python-version';
65276+
if (!fs_1.default.existsSync(versionFile)) {
65277+
throw new Error(`The ${versionFile} doesn't exist.`);
65278+
}
65279+
}
65280+
version = fs_1.default.readFileSync(versionFile, 'utf8');
65281+
core.info(`Resolved ${versionFile} as ${version}`);
65282+
return version;
6527465283
}
65275-
version = fs_1.default.readFileSync(versionFile, 'utf8');
65276-
core.info(`Resolved ${versionFile} as ${version}`);
65284+
core.warning("Neither 'python-version' nor 'python-version-file' inputs were supplied.");
6527765285
return version;
6527865286
}
6527965287
function run() {
@@ -65318,6 +65326,11 @@ function run() {
6531865326
}
6531965327
});
6532065328
}
65329+
function logWarning(message) {
65330+
const warningPrefix = '[warning]';
65331+
core.info(`${warningPrefix}${message}`);
65332+
}
65333+
exports.logWarning = logWarning;
6532165334
run();
6532265335

6532365336

src/setup-python.ts

+25-8
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,34 @@ function resolveVersionInput(): string {
2828

2929
if (version && versionFile) {
3030
core.warning(
31-
'Both python-version and python-version-file inputs are specified, only python-version will be used'
31+
'Both python-version and python-version-file inputs are specified, only python-version will be used.'
3232
);
3333
}
3434

3535
if (version) {
3636
return version;
3737
}
3838

39-
versionFile = versionFile || '.python-version';
40-
if (!fs.existsSync(versionFile)) {
41-
throw new Error(
42-
`The specified python version file at: ${versionFile} does not exist`
43-
);
39+
if (versionFile) {
40+
if (!fs.existsSync(versionFile)) {
41+
logWarning(
42+
`The specified python version file at: ${versionFile} doesn't exist. Attempting to find .python-version file.`
43+
);
44+
versionFile = '.python-version';
45+
if (!fs.existsSync(versionFile)) {
46+
throw new Error(`The ${versionFile} doesn't exist.`);
47+
}
48+
}
49+
50+
version = fs.readFileSync(versionFile, 'utf8');
51+
core.info(`Resolved ${versionFile} as ${version}`);
52+
53+
return version;
4454
}
45-
version = fs.readFileSync(versionFile, 'utf8');
46-
core.info(`Resolved ${versionFile} as ${version}`);
55+
56+
core.warning(
57+
"Neither 'python-version' nor 'python-version-file' inputs were supplied."
58+
);
4759

4860
return version;
4961
}
@@ -101,4 +113,9 @@ async function run() {
101113
}
102114
}
103115

116+
export function logWarning(message: string): void {
117+
const warningPrefix = '[warning]';
118+
core.info(`${warningPrefix}${message}`);
119+
}
120+
104121
run();

0 commit comments

Comments
 (0)