mirror of
https://github.com/shivammathur/setup-php.git
synced 2026-09-20 10:51:29 +00:00
Support all valid PHP version file values (#1121)
* Support all valid PHP version file values Allow version files to use partial versions and aliases accepted by the php-version input while preserving support for both plain .php-version files and asdf-style php entries. * Regenerate bundled action --------- Co-authored-by: Shivam Mathur <shivam_jpr@hotmail.com>
This commit is contained in:
co-authored by
Shivam Mathur
parent
e3f88f3ca7
commit
0bbee91078
@@ -334,6 +334,12 @@ describe('Utils tests', () => {
|
|||||||
readFileSync.mockReturnValue('ruby 1.2.3\nphp 8.4.2\nnode 20.1.2');
|
readFileSync.mockReturnValue('ruby 1.2.3\nphp 8.4.2\nnode 20.1.2');
|
||||||
expect(await utils.readPHPVersion()).toBe('8.4.2');
|
expect(await utils.readPHPVersion()).toBe('8.4.2');
|
||||||
|
|
||||||
|
readFileSync.mockReturnValue('ruby 1.2.3\nphp 8.4\nnode 20.1.2');
|
||||||
|
expect(await utils.readPHPVersion()).toBe('8.4');
|
||||||
|
|
||||||
|
readFileSync.mockReturnValue('ruby 1.2.3\nphp latest\nnode 20.1.2');
|
||||||
|
expect(await utils.readPHPVersion()).toBe('latest');
|
||||||
|
|
||||||
existsSync.mockReturnValue(true);
|
existsSync.mockReturnValue(true);
|
||||||
readFileSync.mockReturnValue('setup-php');
|
readFileSync.mockReturnValue('setup-php');
|
||||||
await expect(utils.readPHPVersion()).rejects.toThrow('Invalid PHP version');
|
await expect(utils.readPHPVersion()).rejects.toThrow('Invalid PHP version');
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+1
-1
@@ -535,7 +535,7 @@ export async function readPHPVersion(): Promise<string> {
|
|||||||
(await getInput('php-version-file', false)) || '.php-version';
|
(await getInput('php-version-file', false)) || '.php-version';
|
||||||
if (fs.existsSync(versionFile)) {
|
if (fs.existsSync(versionFile)) {
|
||||||
const contents: string = fs.readFileSync(versionFile, 'utf8');
|
const contents: string = fs.readFileSync(versionFile, 'utf8');
|
||||||
const match = contents.match(/^(?:php\s)?(\d+\.\d+\.\d+)$/m);
|
const match = contents.match(/^(?:php\s)?(\S+)$/m);
|
||||||
return validatePHPVersionInput(
|
return validatePHPVersionInput(
|
||||||
match ? match[1] : contents.trim(),
|
match ? match[1] : contents.trim(),
|
||||||
versionFile
|
versionFile
|
||||||
|
|||||||
Reference in New Issue
Block a user