Skip to content

Commit b6d8115

Browse files
committed
Add support for .tool-versions format in php-version-file
1 parent 84f76b1 commit b6d8115

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

__tests__/utils.test.ts

+8
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,14 @@ describe('Utils tests', () => {
285285
delete process.env['php-version-file'];
286286
delete process.env['php-version'];
287287

288+
existsSync.mockReturnValue(true);
289+
readFileSync.mockReturnValue('ruby 1.2.3\nphp 8.4.2\nnode 20.1.2');
290+
expect(await utils.readPHPVersion()).toBe('8.4.2');
291+
292+
existsSync.mockReturnValue(true);
293+
readFileSync.mockReturnValue('setup-php');
294+
expect(await utils.readPHPVersion()).toBe('setup-php');
295+
288296
existsSync.mockReturnValueOnce(false).mockReturnValueOnce(true);
289297
readFileSync.mockReturnValue(
290298
'{ "platform-overrides": { "php": "7.3.25" } }'

dist/index.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/utils.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,11 @@ export async function readPHPVersion(): Promise<string> {
436436
const versionFile =
437437
(await getInput('php-version-file', false)) || '.php-version';
438438
if (fs.existsSync(versionFile)) {
439-
return fs.readFileSync(versionFile, 'utf8').replace(/[\r\n]/g, '');
439+
const contents: string = fs.readFileSync(versionFile, 'utf8');
440+
const match: RegExpMatchArray | null = contents.match(
441+
/^(?:php\s)?(\d+\.\d+\.\d+)$/m
442+
);
443+
return match ? match[1] : contents.trim();
440444
} else if (versionFile !== '.php-version') {
441445
throw new Error(`Could not find '${versionFile}' file.`);
442446
}

0 commit comments

Comments
 (0)