Minor refactor in utils.resolveVersion

This commit is contained in:
Shivam Mathur 2023-01-29 20:17:23 +05:30
parent e8d8aa3403
commit 9c411b6e2b
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
2 changed files with 14 additions and 30 deletions

19
dist/index.js vendored
View File

@ -1284,23 +1284,18 @@ async function parseExtensionSource(extension, prefix) {
}
exports.parseExtensionSource = parseExtensionSource;
async function resolveVersion() {
let version = await getInput('php-version', false);
let versionFile = await getInput('php-version-file', false);
const version = await getInput('php-version', false);
if (version) {
return version;
}
if (versionFile && !fs_1.default.existsSync(versionFile)) {
const versionFile = (await getInput('php-version-file', false)) || '.php-version';
if (fs_1.default.existsSync(versionFile)) {
return fs_1.default.readFileSync(versionFile, 'utf8');
}
else if (versionFile !== '.php-version') {
throw new Error(`Could not find '${versionFile}' file.`);
}
versionFile ??= '.php-version';
if (fs_1.default.existsSync(versionFile)) {
version = fs_1.default.readFileSync(versionFile, 'utf8');
core.info(`Resolved ${versionFile} as ${version}`);
}
if (!version) {
version = 'latest';
}
return version;
return 'latest';
}
exports.resolveVersion = resolveVersion;
async function setVariable(variable, command, os) {

View File

@ -427,29 +427,18 @@ export async function parseExtensionSource(
* Resolve php version from input or file
*/
export async function resolveVersion(): Promise<string> {
let version = await getInput('php-version', false);
let versionFile = await getInput('php-version-file', false);
const version = await getInput('php-version', false);
if (version) {
return version;
}
if (versionFile && !fs.existsSync(versionFile)) {
const versionFile =
(await getInput('php-version-file', false)) || '.php-version';
if (fs.existsSync(versionFile)) {
return fs.readFileSync(versionFile, 'utf8');
} else if (versionFile !== '.php-version') {
throw new Error(`Could not find '${versionFile}' file.`);
}
versionFile ??= '.php-version';
if (fs.existsSync(versionFile)) {
version = fs.readFileSync(versionFile, 'utf8');
core.info(`Resolved ${versionFile} as ${version}`);
}
if (!version) {
version = 'latest';
}
return version;
return 'latest';
}
/**