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; exports.parseExtensionSource = parseExtensionSource;
async function resolveVersion() { async function resolveVersion() {
let version = await getInput('php-version', false); const version = await getInput('php-version', false);
let versionFile = await getInput('php-version-file', false);
if (version) { if (version) {
return 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.`); throw new Error(`Could not find '${versionFile}' file.`);
} }
versionFile ??= '.php-version'; return 'latest';
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;
} }
exports.resolveVersion = resolveVersion; exports.resolveVersion = resolveVersion;
async function setVariable(variable, command, os) { async function setVariable(variable, command, os) {

View File

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