mirror of
				https://github.com/shivammathur/setup-php.git
				synced 2025-11-04 00:46:36 +07:00 
			
		
		
		
	Improve tools support
This commit is contained in:
		@ -72,7 +72,7 @@ Setup PHP with required extensions, php.ini configuration, code-coverage support
 | 
			
		||||
 | 
			
		||||
The latest version of the following tools can be setup globally using the `tools` input
 | 
			
		||||
 | 
			
		||||
`composer`, `codeception`, `deployer`, `pecl`, `phpcbf`, `phpcpd`, `php-cs-fixer`, `phpcs`, `phpmd`, `phpstan`, `phpunit`, `prestissimo`
 | 
			
		||||
`composer`, `codeception`, `deployer`, `pecl`, `phinx`, `phpcbf`, `phpcpd`, `php-cs-fixer`, `phpcs`, `phpmd`, `phpstan`, `phpunit`, `prestissimo`, `psalm`
 | 
			
		||||
 | 
			
		||||
```yml
 | 
			
		||||
uses: shivammathur/setup-php@v1
 | 
			
		||||
 | 
			
		||||
@ -21,40 +21,57 @@ describe('Tools tests', () => {
 | 
			
		||||
 | 
			
		||||
  it('checking addTools', async () => {
 | 
			
		||||
    let script: string = await tools.addTools(
 | 
			
		||||
      'php-cs-fixer, phpstan, phpunit, pecl',
 | 
			
		||||
      'php-cs-fixer, phpstan, phpunit, pecl, phinx',
 | 
			
		||||
      'linux'
 | 
			
		||||
    );
 | 
			
		||||
    expect(script).toContain('add_tool https://getcomposer.org/composer.phar');
 | 
			
		||||
    expect(script).toContain(
 | 
			
		||||
      'add_tool https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/latest/download/php-cs-fixer.phar'
 | 
			
		||||
      'add_tool https://github.com/composer/composer/releases/latest/download/composer.phar composer'
 | 
			
		||||
    );
 | 
			
		||||
    expect(script).toContain(
 | 
			
		||||
      'add_tool https://github.com/phpstan/phpstan/releases/latest/download/phpstan.phar'
 | 
			
		||||
      'add_tool https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/latest/download/php-cs-fixer.phar php-cs-fixer'
 | 
			
		||||
    );
 | 
			
		||||
    expect(script).toContain(
 | 
			
		||||
      'add_tool https://github.com/phpstan/phpstan/releases/latest/download/phpstan.phar phpstan'
 | 
			
		||||
    );
 | 
			
		||||
    expect(script).toContain(
 | 
			
		||||
      'add_tool https://phar.phpunit.de/phpunit.phar phpunit'
 | 
			
		||||
    );
 | 
			
		||||
    expect(script).toContain('add_tool https://phar.phpunit.de/phpunit.phar');
 | 
			
		||||
    expect(script).toContain('add_pecl');
 | 
			
		||||
    expect(script).toContain('composer global require robmorgan/phinx');
 | 
			
		||||
 | 
			
		||||
    script = await tools.addTools('phpcs, phpcbf, phpcpd, phpmd', 'darwin');
 | 
			
		||||
    expect(script).toContain('add_tool https://getcomposer.org/composer.phar');
 | 
			
		||||
    expect(script).toContain(
 | 
			
		||||
      'add_tool https://github.com/squizlabs/PHP_CodeSniffer/releases/latest/download/phpcs.phar'
 | 
			
		||||
    script = await tools.addTools(
 | 
			
		||||
      'phpcs, phpcbf, phpcpd, phpmd, psalm',
 | 
			
		||||
      'darwin'
 | 
			
		||||
    );
 | 
			
		||||
    expect(script).toContain(
 | 
			
		||||
      'add_tool https://github.com/squizlabs/PHP_CodeSniffer/releases/latest/download/phpcbf.phar'
 | 
			
		||||
      'add_tool https://github.com/composer/composer/releases/latest/download/composer.phar composer'
 | 
			
		||||
    );
 | 
			
		||||
    expect(script).toContain(
 | 
			
		||||
      'add_tool https://github.com/sebastianbergmann/phpcpd/releases/latest/download/phpcpd.phar'
 | 
			
		||||
      'add_tool https://github.com/squizlabs/PHP_CodeSniffer/releases/latest/download/phpcs.phar phpcs'
 | 
			
		||||
    );
 | 
			
		||||
    expect(script).toContain(
 | 
			
		||||
      'add_tool https://github.com/phpmd/phpmd/releases/latest/download/phpmd.phar'
 | 
			
		||||
      'add_tool https://github.com/squizlabs/PHP_CodeSniffer/releases/latest/download/phpcbf.phar phpcbf'
 | 
			
		||||
    );
 | 
			
		||||
    expect(script).toContain(
 | 
			
		||||
      'add_tool https://github.com/sebastianbergmann/phpcpd/releases/latest/download/phpcpd.phar phpcpd'
 | 
			
		||||
    );
 | 
			
		||||
    expect(script).toContain(
 | 
			
		||||
      'add_tool https://github.com/phpmd/phpmd/releases/latest/download/phpmd.phar phpmd'
 | 
			
		||||
    );
 | 
			
		||||
    expect(script).toContain(
 | 
			
		||||
      'https://github.com/vimeo/psalm/releases/latest/download/psalm.phar psalm'
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    script = await tools.addTools(
 | 
			
		||||
      'codeception, deployer, prestissimo, phpmd, does_not_exit',
 | 
			
		||||
      'win32'
 | 
			
		||||
    );
 | 
			
		||||
    expect(script).toContain('Add-Tool https://getcomposer.org/composer.phar');
 | 
			
		||||
    expect(script).toContain('Add-Tool https://deployer.org/deployer.phar');
 | 
			
		||||
    expect(script).toContain(
 | 
			
		||||
      'Add-Tool https://github.com/composer/composer/releases/latest/download/composer.phar composer'
 | 
			
		||||
    );
 | 
			
		||||
    expect(script).toContain(
 | 
			
		||||
      'Add-Tool https://deployer.org/deployer.phar deployer'
 | 
			
		||||
    );
 | 
			
		||||
    expect(script).toContain('composer global require hirak/prestissimo');
 | 
			
		||||
    expect(script).toContain('Tool does_not_exit is not supported');
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										16
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										16
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							@ -1591,7 +1591,7 @@ exports.getPECLCommand = getPECLCommand;
 | 
			
		||||
 */
 | 
			
		||||
function addTools(tools_csv, os_version) {
 | 
			
		||||
    return __awaiter(this, void 0, void 0, function* () {
 | 
			
		||||
        let script = yield utils.stepLog('Setup Tools', os_version);
 | 
			
		||||
        let script = '\n' + (yield utils.stepLog('Setup Tools', os_version));
 | 
			
		||||
        let tools = yield utils.CSVArray(tools_csv);
 | 
			
		||||
        tools = tools.filter(tool => tool !== 'composer');
 | 
			
		||||
        tools.unshift('composer');
 | 
			
		||||
@ -1641,10 +1641,22 @@ function addTools(tools_csv, os_version) {
 | 
			
		||||
                                ' ' +
 | 
			
		||||
                                'phpmd';
 | 
			
		||||
                        break;
 | 
			
		||||
                    case 'psalm':
 | 
			
		||||
                        script +=
 | 
			
		||||
                            (yield getToolCommand(os_version)) +
 | 
			
		||||
                                'https://github.com/vimeo/psalm/releases/latest/download/psalm.phar' +
 | 
			
		||||
                                ' ' +
 | 
			
		||||
                                'psalm';
 | 
			
		||||
                        break;
 | 
			
		||||
                    case 'phinx':
 | 
			
		||||
                        script +=
 | 
			
		||||
                            'composer global require robmorgan/phinx' +
 | 
			
		||||
                                (yield utils.suppressOutput(os_version));
 | 
			
		||||
                        break;
 | 
			
		||||
                    case 'composer':
 | 
			
		||||
                        script +=
 | 
			
		||||
                            (yield getToolCommand(os_version)) +
 | 
			
		||||
                                'https://getcomposer.org/composer.phar' +
 | 
			
		||||
                                'https://github.com/composer/composer/releases/latest/download/composer.phar' +
 | 
			
		||||
                                ' ' +
 | 
			
		||||
                                'composer';
 | 
			
		||||
                        break;
 | 
			
		||||
 | 
			
		||||
@ -51,11 +51,15 @@ remove_extension() {
 | 
			
		||||
add_tool() {
 | 
			
		||||
  url=$1
 | 
			
		||||
  tool=$2
 | 
			
		||||
  if [ ! -e /usr/local/bin/"$tool" ]; then
 | 
			
		||||
    rm -rf /usr/local/bin/"${tool:?}"
 | 
			
		||||
  if [ "$tool" = "composer" ]; then
 | 
			
		||||
    brew install composer >/dev/null 2>&1
 | 
			
		||||
  else
 | 
			
		||||
    if [ ! -e /usr/local/bin/"$tool" ]; then
 | 
			
		||||
      rm -rf /usr/local/bin/"${tool:?}"
 | 
			
		||||
    fi
 | 
			
		||||
    sudo curl -o /usr/local/bin/"$tool" -L "$url" >/dev/null 2>&1
 | 
			
		||||
    sudo chmod a+x /usr/local/bin/"$tool"
 | 
			
		||||
  fi
 | 
			
		||||
  sudo curl -o /usr/local/bin/"$tool" -L "$url" >/dev/null 2>&1
 | 
			
		||||
  sudo chmod a+x /usr/local/bin/"$tool"
 | 
			
		||||
  add_log "$tick" "$tool" "Added"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -89,17 +89,22 @@ Function Add-Tool() {
 | 
			
		||||
    [string]
 | 
			
		||||
    $tool
 | 
			
		||||
  )
 | 
			
		||||
  if (Test-Path $php_dir\$tool) {
 | 
			
		||||
    Remove-Item $php_dir\$tool
 | 
			
		||||
  if($tool -eq "composer") {
 | 
			
		||||
    Install-Composer -Scope System -Path $php_dir -PhpPath $php_dir
 | 
			
		||||
  } else {
 | 
			
		||||
    if (Test-Path $php_dir\$tool)
 | 
			
		||||
    {
 | 
			
		||||
      Remove-Item $php_dir\$tool
 | 
			
		||||
    }
 | 
			
		||||
    Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $php_dir\$tool > $null 2>&1
 | 
			
		||||
    $bat_content = @()
 | 
			
		||||
    $bat_content += "@ECHO off"
 | 
			
		||||
    $bat_content += "setlocal DISABLEDELAYEDEXPANSION"
 | 
			
		||||
    $bat_content += "SET BIN_TARGET=%~dp0/" + $tool
 | 
			
		||||
    $bat_content += "php %BIN_TARGET% %*"
 | 
			
		||||
    Set-Content -Path $php_dir\$tool.bat -Value $bat_content
 | 
			
		||||
    Add-Content -Path $PsHome\profile.ps1 -Value "New-Alias $tool $php_dir\$tool.bat"
 | 
			
		||||
  }
 | 
			
		||||
  Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $php_dir\$tool > $null 2>&1
 | 
			
		||||
  $bat_content = @()
 | 
			
		||||
  $bat_content += "@ECHO off"
 | 
			
		||||
  $bat_content += "setlocal DISABLEDELAYEDEXPANSION"
 | 
			
		||||
  $bat_content += "SET BIN_TARGET=%~dp0/" + $tool
 | 
			
		||||
  $bat_content += "php %BIN_TARGET% %*"
 | 
			
		||||
  Set-Content -Path $php_dir\$tool.bat -Value $bat_content
 | 
			
		||||
  Add-Content -Path $PsHome\profile.ps1 -Value "New-Alias $tool $php_dir\$tool.bat"
 | 
			
		||||
  Add-Log $tick $tool "Added"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										16
									
								
								src/tools.ts
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								src/tools.ts
									
									
									
									
									
								
							@ -42,7 +42,7 @@ export async function addTools(
 | 
			
		||||
  tools_csv: string,
 | 
			
		||||
  os_version: string
 | 
			
		||||
): Promise<string> {
 | 
			
		||||
  let script = await utils.stepLog('Setup Tools', os_version);
 | 
			
		||||
  let script = '\n' + (await utils.stepLog('Setup Tools', os_version));
 | 
			
		||||
  let tools: Array<string> = await utils.CSVArray(tools_csv);
 | 
			
		||||
  tools = tools.filter(tool => tool !== 'composer');
 | 
			
		||||
  tools.unshift('composer');
 | 
			
		||||
@ -91,10 +91,22 @@ export async function addTools(
 | 
			
		||||
          ' ' +
 | 
			
		||||
          'phpmd';
 | 
			
		||||
        break;
 | 
			
		||||
      case 'psalm':
 | 
			
		||||
        script +=
 | 
			
		||||
          (await getToolCommand(os_version)) +
 | 
			
		||||
          'https://github.com/vimeo/psalm/releases/latest/download/psalm.phar' +
 | 
			
		||||
          ' ' +
 | 
			
		||||
          'psalm';
 | 
			
		||||
        break;
 | 
			
		||||
      case 'phinx':
 | 
			
		||||
        script +=
 | 
			
		||||
          'composer global require robmorgan/phinx' +
 | 
			
		||||
          (await utils.suppressOutput(os_version));
 | 
			
		||||
        break;
 | 
			
		||||
      case 'composer':
 | 
			
		||||
        script +=
 | 
			
		||||
          (await getToolCommand(os_version)) +
 | 
			
		||||
          'https://getcomposer.org/composer.phar' +
 | 
			
		||||
          'https://github.com/composer/composer/releases/latest/download/composer.phar' +
 | 
			
		||||
          ' ' +
 | 
			
		||||
          'composer';
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user