setup-php 2.31.1 → 2.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/utils.ts CHANGED
@@ -436,12 +436,17 @@ export async function readPHPVersion(): Promise<string> {
436
436
  const versionFile =
437
437
  (await getInput('php-version-file', false)) || '.php-version';
438
438
  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();
440
444
  } else if (versionFile !== '.php-version') {
441
445
  throw new Error(`Could not find '${versionFile}' file.`);
442
446
  }
443
447
 
444
- const composerLock = 'composer.lock';
448
+ const composerProjectDir = await readEnv('COMPOSER_PROJECT_DIR');
449
+ const composerLock = path.join(composerProjectDir, 'composer.lock');
445
450
  if (fs.existsSync(composerLock)) {
446
451
  const lockFileContents = JSON.parse(fs.readFileSync(composerLock, 'utf8'));
447
452
  if (
@@ -452,7 +457,7 @@ export async function readPHPVersion(): Promise<string> {
452
457
  }
453
458
  }
454
459
 
455
- const composerJson = 'composer.json';
460
+ const composerJson = path.join(composerProjectDir, 'composer.json');
456
461
  if (fs.existsSync(composerJson)) {
457
462
  const composerFileContents = JSON.parse(
458
463
  fs.readFileSync(composerJson, 'utf8')