From c4606c9269b018b9b43be15937b70be8b1ae1046 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Mon, 28 Sep 2020 10:58:02 +0530 Subject: [PATCH] Log versions in tools setup --- __tests__/tools.test.ts | 105 +++++++++++++------------- dist/index.js | 57 +++++++------- src/scripts/darwin.sh | 36 ++++++++- src/scripts/linux.sh | 35 +++++++-- src/scripts/tools/blackfire.ps1 | 4 +- src/scripts/tools/blackfire.sh | 5 +- src/scripts/tools/grpc_php_plugin.ps1 | 5 +- src/scripts/tools/grpc_php_plugin.sh | 2 +- src/scripts/tools/protoc.ps1 | 2 +- src/scripts/tools/protoc.sh | 2 +- src/scripts/win32.ps1 | 39 ++++++++-- src/tools.ts | 62 ++++++++------- 12 files changed, 216 insertions(+), 138 deletions(-) diff --git a/__tests__/tools.test.ts b/__tests__/tools.test.ts index 79a62574..d9224892 100644 --- a/__tests__/tools.test.ts +++ b/__tests__/tools.test.ts @@ -301,44 +301,46 @@ describe('Tools tests', () => { let script: string = await tools.addArchive( 'tool', 'https://tool.com/tool.phar', - 'linux' + 'linux', + '-v' ); expect(script).toContain('add_tool https://tool.com/tool.phar tool'); script = await tools.addArchive( 'tool', 'https://tool.com/tool.phar', - 'darwin' + 'darwin', + '-v' ); expect(script).toContain('add_tool https://tool.com/tool.phar tool'); script = await tools.addArchive( 'tool', 'https://tool.com/tool.phar', - 'win32' + 'win32', + '-v' ); expect(script).toContain('Add-Tool https://tool.com/tool.phar tool'); script = await tools.addArchive( 'tool', 'https://tool.com/tool.phar', - 'openbsd' + 'openbsd', + '-v' ); expect(script).toContain('Platform openbsd is not supported'); }); it('checking addDevTools', async () => { let script: string = await tools.addDevTools('phpize', 'linux'); - expect(script).toContain('add_devtools'); - expect(script).toContain('add_log "$tick" "phpize" "Added"'); + expect(script).toContain('add_devtools phpize'); script = await tools.addDevTools('php-config', 'linux'); - expect(script).toContain('add_devtools'); - expect(script).toContain('add_log "$tick" "php-config" "Added"'); + expect(script).toContain('add_devtools php-config'); script = await tools.addDevTools('phpize', 'darwin'); - expect(script).toContain('add_log "$tick" "phpize" "Added"'); + expect(script).toContain('add_devtools phpize'); script = await tools.addDevTools('php-config', 'darwin'); - expect(script).toContain('add_log "$tick" "php-config" "Added"'); + expect(script).toContain('add_devtools php-config'); script = await tools.addDevTools('phpize', 'win32'); expect(script).toContain( @@ -381,34 +383,34 @@ describe('Tools tests', () => { ); expect(script).toContain('add_blackfire'); expect(script).toContain( - 'add_tool https://get.blackfire.io/blackfire-player.phar blackfire-player' + 'add_tool https://get.blackfire.io/blackfire-player.phar blackfire-player "-V"' ); expect(script).toContain( 'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-stable.phar,https://getcomposer.org/composer-stable.phar composer' ); expect(script).toContain( - 'add_tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/latest/download/cs2pr cs2pr' + 'add_tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/latest/download/cs2pr cs2pr "-V"' ); expect(script).toContain( - 'add_tool https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/latest/download/php-cs-fixer.phar php-cs-fixer' + 'add_tool https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/latest/download/php-cs-fixer.phar php-cs-fixer "-V"' ); expect(script).toContain( - 'add_tool https://github.com/phpstan/phpstan/releases/latest/download/phpstan.phar phpstan' + 'add_tool https://github.com/phpstan/phpstan/releases/latest/download/phpstan.phar phpstan "-V"' ); expect(script).toContain( - 'add_tool https://www.phing.info/get/phing-latest.phar phing' + 'add_tool https://www.phing.info/get/phing-latest.phar phing "-v"' ); expect(script).toContain( - 'add_tool https://phar.io/releases/phive.phar phive' + 'add_tool https://phar.io/releases/phive.phar phive status' ); expect(script).toContain( - 'add_tool https://phar.phpunit.de/phpunit.phar phpunit' + 'add_tool https://phar.phpunit.de/phpunit.phar phpunit "--version"' ); expect(script).toContain( - 'add_tool https://github.com/symfony/cli/releases/latest/download/symfony_linux_amd64 symfony' + 'add_tool https://github.com/symfony/cli/releases/latest/download/symfony_linux_amd64 symfony version' ); expect(script).toContain( - 'add_tool https://github.com/wp-cli/builds/blob/gh-pages/phar/wp-cli.phar?raw=true wp-cli' + 'add_tool https://github.com/wp-cli/builds/blob/gh-pages/phar/wp-cli.phar?raw=true wp-cli "--version"' ); expect(script).toContain('add_protoc latest'); expect(script).toContain('add_grpc_php_plugin latest'); @@ -417,9 +419,8 @@ describe('Tools tests', () => { expect(script).toContain('add_composertool phinx phinx robmorgan/'); expect(script).toContain('add_composertool phplint phplint overtrue/'); expect(script).toContain('add_composertool phinx phinx:1.2.3 robmorgan/'); - expect(script).toContain('add_devtools'); - expect(script).toContain('add_log "$tick" "php-config" "Added"'); - expect(script).toContain('add_log "$tick" "phpize" "Added"'); + expect(script).toContain('add_devtools php-config'); + expect(script).toContain('add_devtools phpize'); }); it('checking addTools on darwin', async () => { const listOfTools = [ @@ -460,46 +461,43 @@ describe('Tools tests', () => { expect(script).toContain('add_blackfire'); expect(script).toContain( - 'add_tool https://get.blackfire.io/blackfire-player.phar blackfire-player' + 'add_tool https://get.blackfire.io/blackfire-player.phar blackfire-player "-V"' ); expect(script).toContain( 'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-stable.phar,https://getcomposer.org/composer-stable.phar composer' ); expect(script).toContain( - 'add_tool https://github.com/ergebnis/composer-normalize/releases/latest/download/composer-normalize.phar composer-normalize' + 'add_tool https://github.com/ergebnis/composer-normalize/releases/latest/download/composer-normalize.phar composer-normalize "-V"' ); expect(script).toContain( - 'add_tool https://github.com/maglnet/ComposerRequireChecker/releases/latest/download/composer-require-checker.phar composer-require-checker' + 'add_tool https://github.com/maglnet/ComposerRequireChecker/releases/latest/download/composer-require-checker.phar composer-require-checker "-V"' ); expect(script).toContain( - 'add_tool https://github.com/composer-unused/composer-unused/releases/latest/download/composer-unused.phar composer-unused' + 'add_tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/download/1.2.3/cs2pr cs2pr "-V"' ); expect(script).toContain( - 'add_tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/download/1.2.3/cs2pr cs2pr' + 'add_tool https://github.com/infection/infection/releases/latest/download/infection.phar infection "-V"' ); expect(script).toContain( - 'add_tool https://github.com/infection/infection/releases/latest/download/infection.phar infection' + 'add_tool https://github.com/phan/phan/releases/latest/download/phan.phar phan "-v"' ); expect(script).toContain( - 'add_tool https://github.com/phan/phan/releases/latest/download/phan.phar phan' + 'add_tool https://www.phing.info/get/phing-1.2.3.phar phing "-v"' ); expect(script).toContain( - 'add_tool https://www.phing.info/get/phing-1.2.3.phar phing' + 'add_tool https://github.com/squizlabs/PHP_CodeSniffer/releases/latest/download/phpcs.phar phpcs "--version"' ); expect(script).toContain( - 'add_tool https://github.com/squizlabs/PHP_CodeSniffer/releases/latest/download/phpcs.phar phpcs' + 'add_tool https://github.com/squizlabs/PHP_CodeSniffer/releases/latest/download/phpcbf.phar phpcbf "--version"' ); expect(script).toContain( - 'add_tool https://github.com/squizlabs/PHP_CodeSniffer/releases/latest/download/phpcbf.phar phpcbf' + 'add_tool https://phar.phpunit.de/phpcpd.phar phpcpd "--version"' ); expect(script).toContain( - 'add_tool https://phar.phpunit.de/phpcpd.phar phpcpd' + 'add_tool https://github.com/phpmd/phpmd/releases/latest/download/phpmd.phar phpmd "--version"' ); 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' + 'https://github.com/vimeo/psalm/releases/latest/download/psalm.phar psalm "-v"' ); expect(script).toContain('add_grpc_php_plugin 1.2.3'); expect(script).toContain('add_protoc 1.2.3'); @@ -507,25 +505,28 @@ describe('Tools tests', () => { expect(script).toContain('add_composertool flex flex symfony/'); expect(script).toContain('add_composertool phinx phinx robmorgan/'); expect(script).toContain( - 'add_tool https://github.com/phan/phan/releases/download/2.7.2/phan.phar phan' + 'add_tool https://github.com/phan/phan/releases/download/2.7.2/phan.phar phan "-v"' ); expect(script).toContain( 'add_tool https://github.com/phar-io/phive/releases/download/1.2.3/phive-1.2.3.phar phive' ); + expect(script).toContain( + 'add_composertool composer-unused composer-unused icanhazstring/' + ); expect(script).toContain( 'add_composertool composer-prefetcher composer-prefetcher:1.2.3 narrowspark/automatic-' ); expect(script).toContain( - 'add_tool https://github.com/symfony/cli/releases/latest/download/symfony_darwin_amd64 symfony' + 'add_tool https://github.com/symfony/cli/releases/latest/download/symfony_darwin_amd64 symfony version' ); expect(script).toContain( - 'add_tool https://github.com/symfony/cli/releases/download/v1.2.3/symfony_darwin_amd64 symfony' + 'add_tool https://github.com/symfony/cli/releases/download/v1.2.3/symfony_darwin_amd64 symfony version' ); expect(script).toContain( - 'add_tool https://github.com/wp-cli/builds/blob/gh-pages/phar/wp-cli.phar?raw=true wp-cli' + 'add_tool https://github.com/wp-cli/builds/blob/gh-pages/phar/wp-cli.phar?raw=true wp-cli "--version"' ); - expect(script).toContain('add_log "$tick" "phpize" "Added"'); - expect(script).toContain('add_log "$tick" "php-config" "Added"'); + expect(script).toContain('add_devtools phpize'); + expect(script).toContain('add_devtools php-config'); }); it('checking addTools on windows', async () => { const listOfTools = [ @@ -554,31 +555,31 @@ describe('Tools tests', () => { expect(script).toContain('Add-Blackfire'); expect(script).toContain( - 'Add-Tool https://get.blackfire.io/blackfire-player-v1.8.1.phar blackfire-player' + 'Add-Tool https://get.blackfire.io/blackfire-player-v1.8.1.phar blackfire-player "-V"' ); expect(script).toContain( 'Add-Tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-stable.phar,https://getcomposer.org/composer-stable.phar composer' ); expect(script).toContain( - 'Add-Tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/latest/download/cs2pr cs2pr' + 'Add-Tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/latest/download/cs2pr cs2pr "-V"' ); expect(script).toContain('Add-Composertool flex flex symfony/'); expect(script).toContain( - 'Add-Tool https://deployer.org/deployer.phar deployer' + 'Add-Tool https://deployer.org/deployer.phar deployer "-V"' ); expect(script).toContain('Add-Composertool prestissimo prestissimo hirak/'); expect(script).toContain( - 'Add-Tool https://github.com/phpmd/phpmd/releases/latest/download/phpmd.phar phpmd' + 'Add-Tool https://github.com/phpmd/phpmd/releases/latest/download/phpmd.phar phpmd "--version"' ); expect(script).toContain('Add-Composertool phinx phinx robmorgan/'); expect(script).toContain( - 'Add-Tool https://github.com/phar-io/phive/releases/download/0.13.2/phive-0.13.2.phar phive' + 'Add-Tool https://github.com/phar-io/phive/releases/download/0.13.2/phive-0.13.2.phar phive status' ); expect(script).toContain( - 'Add-Tool https://github.com/symfony/cli/releases/latest/download/symfony_windows_amd64.exe symfony' + 'Add-Tool https://github.com/symfony/cli/releases/latest/download/symfony_windows_amd64.exe symfony version' ); expect(script).toContain( - 'Add-Tool https://github.com/wp-cli/builds/blob/gh-pages/phar/wp-cli.phar?raw=true wp-cli' + 'Add-Tool https://github.com/wp-cli/builds/blob/gh-pages/phar/wp-cli.phar?raw=true wp-cli "--version"' ); expect(script).toContain('phpize is not a windows tool'); expect(script).toContain('php-config is not a windows tool'); @@ -621,7 +622,7 @@ describe('Tools tests', () => { script = await tools.addTools('composer:preview', '7.4', 'linux'); expect(script).toContain( - 'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-preview.phar,https://getcomposer.org/composer-preview.phar composer' + 'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-preview.phar,https://getcomposer.org/composer-preview.phar composer preview' ); script = await tools.addTools( 'composer:v1, composer:preview, composer:snapshot', @@ -629,7 +630,7 @@ describe('Tools tests', () => { 'linux' ); expect(script).toContain( - 'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-snapshot.phar,https://getcomposer.org/composer.phar composer' + 'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-snapshot.phar,https://getcomposer.org/composer.phar composer snapshot' ); }); }); diff --git a/dist/index.js b/dist/index.js index 8afc200d..ce8f8047 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1837,14 +1837,14 @@ async function addPhive(version, os_version) { switch (version) { case 'latest': return ((await utils.getCommand(os_version, 'tool')) + - 'https://phar.io/releases/phive.phar phive'); + 'https://phar.io/releases/phive.phar phive status'); default: return ((await utils.getCommand(os_version, 'tool')) + 'https://github.com/phar-io/phive/releases/download/' + version + '/phive-' + version + - '.phar phive'); + '.phar phive status'); } } exports.addPhive = addPhive; @@ -1976,7 +1976,7 @@ async function getCleanedToolsList(tools_csv) { .map(function (extension) { return extension .trim() - .replace(/-agent|hirak\/|laravel\/|narrowspark\/automatic-|overtrue\/|robmorgan\/|symfony\//, ''); + .replace(/-agent|hirak\/|icanhazstring\/|laravel\/|narrowspark\/automatic-|overtrue\/|robmorgan\/|symfony\//, ''); }) .filter(Boolean); return [...new Set(tools_list)]; @@ -1988,9 +1988,11 @@ exports.getCleanedToolsList = getCleanedToolsList; * @param tool * @param url * @param os_version + * @param ver_param */ -async function addArchive(tool, url, os_version) { - return (await utils.getCommand(os_version, 'tool')) + url + ' ' + tool; +async function addArchive(tool, url, os_version, ver_param) { + return ((await utils.getCommand(os_version, 'tool')) + + (await utils.joins(url, tool, ver_param))); } exports.addArchive = addArchive; /** @@ -2002,11 +2004,8 @@ exports.addArchive = addArchive; async function addDevTools(tool, os_version) { switch (os_version) { case 'linux': - return ('add_devtools' + - '\n' + - (await utils.addLog('$tick', tool, 'Added', 'linux'))); case 'darwin': - return await utils.addLog('$tick', tool, 'Added', 'darwin'); + return 'add_devtools ' + tool; case 'win32': return await utils.addLog('$cross', tool, tool + ' is not a windows tool', 'win32'); default: @@ -2053,22 +2052,22 @@ async function addTools(tools_csv, php_version, os_version) { break; case 'blackfire-player': url = await getPharUrl('https://get.blackfire.io', tool, 'v', version); - script += await addArchive(tool, url, os_version); + script += await addArchive(tool, url, os_version, '"-V"'); break; case 'codeception': url = 'https://codeception.com/' + (await getCodeceptionUri(version, php_version)); - script += await addArchive(tool, url, os_version); + script += await addArchive(tool, url, os_version, '"-V"'); break; case 'composer': url = await getComposerUrl(version); - script += await addArchive('composer', url, os_version); + script += await addArchive('composer', url, os_version, version); break; case 'composer-normalize': uri = await getUri(tool, '.phar', version, 'releases', '', 'download'); url = github + 'ergebnis/composer-normalize/' + uri; - script += await addArchive(tool, url, os_version); + script += await addArchive(tool, url, os_version, '"-V"'); break; case 'composer-prefetcher': script += await addPackage(tool, release, 'narrowspark/automatic-', os_version); @@ -2076,39 +2075,37 @@ async function addTools(tools_csv, php_version, os_version) { case 'composer-require-checker': uri = await getUri(tool, '.phar', version, 'releases', '', 'download'); url = github + 'maglnet/ComposerRequireChecker/' + uri; - script += await addArchive(tool, url, os_version); + script += await addArchive(tool, url, os_version, '"-V"'); break; case 'composer-unused': - uri = await getUri(tool, '.phar', version, 'releases', '', 'download'); - url = github + 'composer-unused/composer-unused/' + uri; - script += await addArchive(tool, url, os_version); + script += await addPackage(tool, release, 'icanhazstring/', os_version); break; case 'cs2pr': uri = await getUri(tool, '', version, 'releases', '', 'download'); url = github + 'staabm/annotate-pull-request-from-checkstyle/' + uri; - script += await addArchive(tool, url, os_version); + script += await addArchive(tool, url, os_version, '"-V"'); break; case 'deployer': url = await getDeployerUrl(version); - script += await addArchive(tool, url, os_version); + script += await addArchive(tool, url, os_version, '"-V"'); break; case 'flex': script += await addPackage(tool, release, 'symfony/', os_version); break; case 'infection': url = github + 'infection/infection/' + uri; - script += await addArchive(tool, url, os_version); + script += await addArchive(tool, url, os_version, '"-V"'); break; case 'pecl': script += await utils.getCommand(os_version, 'pecl'); break; case 'phan': url = github + 'phan/phan/' + uri; - script += await addArchive(tool, url, os_version); + script += await addArchive(tool, url, os_version, '"-v"'); break; case 'phing': url = 'https://www.phing.info/get/phing-' + version + '.phar'; - script += await addArchive(tool, url, os_version); + script += await addArchive(tool, url, os_version, '"-v"'); break; case 'phinx': script += await addPackage(tool, release, 'robmorgan/', os_version); @@ -2123,48 +2120,48 @@ async function addTools(tools_csv, php_version, os_version) { case 'php-cs-fixer': uri = await getUri(tool, '.phar', version, 'releases', 'v', 'download'); url = github + 'FriendsOfPHP/PHP-CS-Fixer/' + uri; - script += await addArchive(tool, url, os_version); + script += await addArchive(tool, url, os_version, '"-V"'); break; case 'phpcbf': case 'phpcs': url = github + 'squizlabs/PHP_CodeSniffer/' + uri; - script += await addArchive(tool, url, os_version); + script += await addArchive(tool, url, os_version, '"--version"'); break; case 'phpcpd': case 'phpunit': url = await getPharUrl('https://phar.phpunit.de', tool, '', version); - script += await addArchive(tool, url, os_version); + script += await addArchive(tool, url, os_version, '"--version"'); break; case 'phplint': script += await addPackage(tool, release, 'overtrue/', os_version); break; case 'phpmd': url = github + 'phpmd/phpmd/' + uri; - script += await addArchive(tool, url, os_version); + script += await addArchive(tool, url, os_version, '"--version"'); break; case 'phpstan': url = github + 'phpstan/phpstan/' + uri; - script += await addArchive(tool, url, os_version); + script += await addArchive(tool, url, os_version, '"-V"'); break; case 'prestissimo': script += await addPackage(tool, release, 'hirak/', os_version); break; case 'psalm': url = github + 'vimeo/psalm/' + uri; - script += await addArchive(tool, url, os_version); + script += await addArchive(tool, url, os_version, '"-v"'); break; case 'symfony': case 'symfony-cli': uri = await getSymfonyUri(version, os_version); url = github + 'symfony/cli/' + uri; - script += await addArchive('symfony', url, os_version); + script += await addArchive('symfony', url, os_version, 'version'); break; case 'vapor-cli': script += await addPackage(tool, release, 'laravel/', os_version); break; case 'wp-cli': url = github + (await getWpCliUrl(version)); - script += await addArchive(tool, url, os_version); + script += await addArchive(tool, url, os_version, '"--version"'); break; default: script += await utils.addLog('$cross', tool, 'Tool ' + tool + ' is not supported', os_version); diff --git a/src/scripts/darwin.sh b/src/scripts/darwin.sh index e5053c6e..2a65d6cd 100644 --- a/src/scripts/darwin.sh +++ b/src/scripts/darwin.sh @@ -158,10 +158,29 @@ configure_composer() { fi } +# Function to extract tool version. +get_tool_version() { + tool=$1 + param=$2 + version_regex="[0-9]+((\.{1}[0-9]+)+)(\.{0})(-[a-zA-Z0-9]+){0,1}" + if [ "$tool" = "composer" ]; then + if [ "$param" != "snapshot" ]; then + grep -Ea "const\sVERSION" "$tool_path_dir/composer" | grep -Eo "$version_regex" + else + trunk=$(grep -Ea "const\sBRANCH_ALIAS_VERSION" "$tool_path_dir/composer" | grep -Eo "$version_regex") + commit=$(grep -Ea "const\sVERSION" "$tool_path_dir/composer" | grep -Eo "[a-zA-z0-9]+" | tail -n 1) + echo "$trunk+$commit" + fi + else + $tool "$param" 2>/dev/null | sed -Ee "s/[Cc]omposer(.)?$version_regex//g" | grep -Eo "$version_regex" | head -n 1 + fi +} + # Function to setup a remote tool. add_tool() { url=$1 tool=$2 + ver_param=$3 tool_path="$tool_path_dir/$tool" if [ ! -e "$tool_path" ]; then rm -rf "$tool_path" @@ -191,7 +210,8 @@ add_tool() { elif [ "$tool" = "wp-cli" ]; then sudo cp -p "$tool_path" "$tool_path_dir"/wp fi - add_log "$tick" "$tool" "Added" + tool_version=$(get_tool_version "$tool" "$ver_param") + add_log "$tick" "$tool" "Added $tool $tool_version" else add_log "$cross" "$tool" "Could not setup $tool" fi @@ -203,10 +223,19 @@ add_composertool() { release=$2 prefix=$3 ( - composer global require "$prefix$release" >/dev/null 2>&1 && add_log "$tick" "$tool" "Added" + composer global require "$prefix$release" >/dev/null 2>&1 && + json=$(grep "$prefix$tool" /Users/$USER/.composer/composer.json) && + tool_version=$(get_tool_version 'echo' "$json") && + add_log "$tick" "$tool" "Added $tool $tool_version" ) || add_log "$cross" "$tool" "Could not setup $tool" } +# Function to handle request to add phpize and php-config. +add_devtools() { + tool=$1 + add_log "$tick" "$tool" "Added $tool $semver" +} + # Function to configure PECL configure_pecl() { for tool in pear pecl; do @@ -217,7 +246,8 @@ configure_pecl() { # Function to handle request to add PECL. add_pecl() { - add_log "$tick" "PECL" "Added" + pecl_version=$(get_tool_version "pecl" "version") + add_log "$tick" "PECL" "Found PECL $pecl_version" } # Function to setup PHP 5.6 and newer. diff --git a/src/scripts/linux.sh b/src/scripts/linux.sh index 60440a24..0ec3368f 100644 --- a/src/scripts/linux.sh +++ b/src/scripts/linux.sh @@ -231,7 +231,7 @@ add_extension_from_source() { args=$4 prefix=$5 ( - add_devtools + add_devtools phpize delete_extension "$extension" curl -o /tmp/"$extension".tar.gz "${curl_opts[@]}" https://github.com/"$repo"/archive/"$release".tar.gz tar xf /tmp/"$extension".tar.gz -C /tmp @@ -258,10 +258,29 @@ configure_composer() { fi } +# Function to extract tool version. +get_tool_version() { + tool=$1 + param=$2 + version_regex="[0-9]+((\.{1}[0-9]+)+)(\.{0})(-[a-zA-Z0-9]+){0,1}" + if [ "$tool" = "composer" ]; then + if [ "$param" != "snapshot" ]; then + grep -Ea "const\sVERSION" "$tool_path_dir/composer" | grep -Eo "$version_regex" + else + trunk=$(grep -Ea "const\sBRANCH_ALIAS_VERSION" "$tool_path_dir/composer" | grep -Eo "$version_regex") + commit=$(grep -Ea "const\sVERSION" "$tool_path_dir/composer" | grep -Eo "[a-zA-z0-9]+" | tail -n 1) + echo "$trunk+$commit" + fi + else + $tool "$param" 2>/dev/null | sed -Ee "s/[Cc]omposer(.)?$version_regex//g" | grep -Eo "$version_regex" | head -n 1 + fi +} + # Function to setup a remote tool. add_tool() { url=$1 tool=$2 + ver_param=$3 tool_path="$tool_path_dir/$tool" if [ ! -e "$tool_path" ]; then rm -rf "$tool_path" @@ -289,7 +308,8 @@ add_tool() { elif [ "$tool" = "wp-cli" ]; then sudo cp -p "$tool_path" "$tool_path_dir"/wp fi - add_log "$tick" "$tool" "Added" + tool_version=$(get_tool_version "$tool" "$ver_param") + add_log "$tick" "$tool" "Added $tool $tool_version" else add_log "$cross" "$tool" "Could not setup $tool" fi @@ -302,18 +322,22 @@ add_composertool() { prefix=$3 ( composer global require "$prefix$release" >/dev/null 2>&1 && - add_log "$tick" "$tool" "Added" + json=$(grep "$prefix$tool" /home/$USER/.composer/composer.json) && + tool_version=$(get_tool_version 'echo' "$json") && + add_log "$tick" "$tool" "Added $tool $tool_version" ) || add_log "$cross" "$tool" "Could not setup $tool" } # Function to setup phpize and php-config. add_devtools() { + tool=$1 if ! [ -e "/usr/bin/phpize$version" ] || ! [ -e "/usr/bin/php-config$version" ]; then update_lists && $apt_install php"$version"-dev php"$version"-xml >/dev/null 2>&1 fi sudo update-alternatives --set php-config /usr/bin/php-config"$version" >/dev/null 2>&1 sudo update-alternatives --set phpize /usr/bin/phpize"$version" >/dev/null 2>&1 configure_pecl >/dev/null 2>&1 + add_log "$tick" "$tool" "Added $tool $semver" } # Function to setup the nightly build from master branch. @@ -330,12 +354,13 @@ setup_old_versions() { # Function to add PECL. add_pecl() { - add_devtools >/dev/null 2>&1 + add_devtools phpize >/dev/null 2>&1 if [ ! -e /usr/bin/pecl ]; then $apt_install php-pear >/dev/null 2>&1 || update_lists && $apt_install php-pear >/dev/null 2>&1 fi configure_pecl >/dev/null 2>&1 - add_log "$tick" "PECL" "Added" + pecl_version=$(get_tool_version "pecl" "version") + add_log "$tick" "PECL" "Added PECL $pecl_version" } # Function to switch versions of PHP binaries. diff --git a/src/scripts/tools/blackfire.ps1 b/src/scripts/tools/blackfire.ps1 index ac83fdb0..c1d6c0df 100644 --- a/src/scripts/tools/blackfire.ps1 +++ b/src/scripts/tools/blackfire.ps1 @@ -16,6 +16,6 @@ Function Add-Blackfire() { if ((Test-Path env:BLACKFIRE_CLIENT_ID) -and (Test-Path env:BLACKFIRE_CLIENT_TOKEN)) { blackfire config --client-id=$env:BLACKFIRE_CLIENT_ID --client-token=$env:BLACKFIRE_CLIENT_TOKEN --ca-cert=$php_dir\ssl\cacert.pem >$null 2>&1 } - Add-Log $tick "blackfire" "Added" - Add-Log $tick "blackfire-agent" "Added" + Add-Log $tick "blackfire" "Added blackfire $agent_version" + Add-Log $tick "blackfire-agent" "Added blackfire-agent $agent_version" } diff --git a/src/scripts/tools/blackfire.sh b/src/scripts/tools/blackfire.sh index a41b8717..2f689c9c 100644 --- a/src/scripts/tools/blackfire.sh +++ b/src/scripts/tools/blackfire.sh @@ -29,6 +29,7 @@ add_blackfire() { [ "$os" = "Linux" ] && add_blackfire_linux >/dev/null 2>&1 [ "$os" = "Darwin" ] && add_blackfire_darwin >/dev/null 2>&1 blackfire_config >/dev/null 2>&1 - add_log "${tick:?}" "blackfire" "Added" - add_log "${tick:?}" "blackfire-agent" "Added" + tool_version=$(get_tool_version "blackfire" "version") + add_log "${tick:?}" "blackfire" "Added blackfire $tool_version" + add_log "${tick:?}" "blackfire-agent" "Added blackfire-agent $tool_version" } diff --git a/src/scripts/tools/grpc_php_plugin.ps1 b/src/scripts/tools/grpc_php_plugin.ps1 index 103b2f61..ac0a74ed 100644 --- a/src/scripts/tools/grpc_php_plugin.ps1 +++ b/src/scripts/tools/grpc_php_plugin.ps1 @@ -9,11 +9,12 @@ Function Add-Msys2() { Function Add-Grpc_php_plugin() { $msys_location = Add-Msys2 - . $msys_location\usr\bin\bash -l -c "pacman -S --noconfirm mingw-w64-x86_64-grpc" >$null 2>&1 + $logs = . $msys_location\usr\bin\bash -l -c "pacman -S --noconfirm mingw-w64-x86_64-grpc" >$null 2>&1 + $grpc_version = Get-ToolVersion 'Write-Output' "$logs" Write-Output "::add-path::$msys_location\mingw64\bin" Write-Output "::set-output name=grpc_php_plugin_path::$msys_location\mingw64\bin\grpc_php_plugin.exe" Add-ToProfile $current_profile 'grpc_php_plugin' "New-Alias grpc_php_plugin $msys_location\mingw64\bin\grpc_php_plugin.exe" - Add-Log $tick "grpc_php_plugin" "Added" + Add-Log $tick "grpc_php_plugin" "Added grpc_php_plugin $grpc_version" printf "::group::\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "grpc_php_plugin" "Click to read the grpc_php_plugin related license information" Write-Output (Invoke-WebRequest https://raw.githubusercontent.com/grpc/grpc/master/LICENSE).Content Write-Output "::endgroup::" diff --git a/src/scripts/tools/grpc_php_plugin.sh b/src/scripts/tools/grpc_php_plugin.sh index a209a4ab..a0c13b83 100644 --- a/src/scripts/tools/grpc_php_plugin.sh +++ b/src/scripts/tools/grpc_php_plugin.sh @@ -44,7 +44,7 @@ add_grpc_php_plugin() { sudo chmod a+x /usr/local/bin/grpc_php_plugin ) >/dev/null 2>&1 echo "::set-output name=grpc_php_plugin_path::/usr/local/bin/grpc_php_plugin" - add_log "${tick:?}" "grpc_php_plugin" "Added" + add_log "${tick:?}" "grpc_php_plugin" "Added grpc_php_plugin ${grpc_tag:1}" printf "::group::\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "grpc_php_plugin" "Click to read the grpc_php_plugin related license information" cat "/tmp/grpc-${grpc_tag:1}/LICENSE" echo "::endgroup::" diff --git a/src/scripts/tools/protoc.ps1 b/src/scripts/tools/protoc.ps1 index 48680f86..d3b2e55d 100644 --- a/src/scripts/tools/protoc.ps1 +++ b/src/scripts/tools/protoc.ps1 @@ -31,7 +31,7 @@ Function Add-Protoc() { Expand-Archive -Path $bin_dir\protoc.zip -DestinationPath $bin_dir\protoc -Force >$null 2>&1 Move-Item -Path $bin_dir\protoc\bin\protoc.exe -Destination $bin_dir\protoc.exe Add-ToProfile $current_profile 'protoc' "New-Alias protoc $bin_dir\protoc.exe" - Add-Log $tick "protoc" "Added" + Add-Log $tick "protoc" "Added protoc $($protobuf_tag -replace 'v', '')" printf "::group::\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "protoc" "Click to read the protoc related license information" Write-Output (Invoke-WebRequest https://raw.githubusercontent.com/protocolbuffers/protobuf/master/LICENSE).Content Write-Output "::endgroup::" diff --git a/src/scripts/tools/protoc.sh b/src/scripts/tools/protoc.sh index 5558cbdd..ad357abf 100644 --- a/src/scripts/tools/protoc.sh +++ b/src/scripts/tools/protoc.sh @@ -21,7 +21,7 @@ add_protoc() { sudo unzip /tmp/protobuf.zip -d /usr/local/ sudo chmod 777 /usr/local/bin/protoc -R /usr/local/include/google ) >/dev/null 2>&1 - add_log "${tick:?}" "protoc" "Added" + add_log "${tick:?}" "protoc" "Added protoc ${protobuf_tag:1}" printf "::group::\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "protoc" "Click to read the protoc related license information" curl "${curl_opts[@]:?}" https://raw.githubusercontent.com/protocolbuffers/protobuf/master/LICENSE echo "::endgroup::" diff --git a/src/scripts/win32.ps1 b/src/scripts/win32.ps1 index 28df8092..d8ec4162 100644 --- a/src/scripts/win32.ps1 +++ b/src/scripts/win32.ps1 @@ -195,6 +195,27 @@ Function Edit-ComposerConfig() { } } +# Function to extract tool version. +Function Get-ToolVersion() { + Param ( + [Parameter(Position = 0, Mandatory = $true)] + $tool, + [Parameter(Position = 1, Mandatory = $true)] + $param + ) + $version_regex = "[0-9]+((\.{1}[0-9]+)+)(\.{0})(-[a-z0-9]+){0,1}" + if($tool -eq 'composer') { + if ($param -eq 'snapshot') { + $trunk = Select-String -Pattern "const\sBRANCH_ALIAS_VERSION" -Path $bin_dir\composer -Raw | Select-String -Pattern $version_regex | ForEach-Object { $_.matches.Value } + $commit = Select-String -Pattern "const\sVERSION" -Path $bin_dir\composer -Raw | Select-String -Pattern "[a-zA-Z0-9]+" -AllMatches | ForEach-Object { $_.matches[2].Value } + return "$trunk+$commit" + } else { + return Select-String -Pattern "const\sVERSION" -Path $bin_dir\composer -Raw | Select-String -Pattern $version_regex | ForEach-Object { $_.matches.Value } + } + } + return . $tool $param 2> $null | ForEach-Object { $_ -replace "composer $version_regex", '' } | Select-String -Pattern $version_regex | Select-Object -First 1 | ForEach-Object { $_.matches.Value } +} + # Function to add tools. Function Add-Tool() { Param ( @@ -203,9 +224,10 @@ Function Add-Tool() { $url, [Parameter(Position = 1, Mandatory = $true)] [ValidateNotNull()] - [ValidateLength(1, [int]::MaxValue)] - [string] - $tool + $tool, + [Parameter(Position = 2, Mandatory = $true)] + [ValidateNotNull()] + $ver_param ) if (Test-Path $bin_dir\$tool) { Remove-Item $bin_dir\$tool @@ -239,7 +261,8 @@ Function Add-Tool() { Copy-Item $bin_dir\wp-cli.bat -Destination $bin_dir\wp.bat } if (((Get-ChildItem -Path $bin_dir/* | Where-Object Name -Match "^$tool(.exe|.phar)*$").Count -gt 0)) { - Add-Log $tick $tool "Added" + $tool_version = Get-ToolVersion $tool $ver_param + Add-Log $tick $tool "Added $tool $tool_version" } else { Add-Log $cross $tool "Could not add $tool" } @@ -264,9 +287,11 @@ Function Add-Composertool() { [string] $prefix ) - composer -q global require $prefix$release 2>&1 | out-null - if($?) { - Add-Log $tick $tool "Added" + composer global require $prefix$release 2>&1 | out-null + $json = findstr $prefix$tool $env:APPDATA\Composer\composer.json + if($json) { + $tool_version = Get-ToolVersion "Write-Output" "$json" + Add-Log $tick $tool "Added $tool $tool_version" } else { Add-Log $cross $tool "Could not setup $tool" } diff --git a/src/tools.ts b/src/tools.ts index c0e2b044..0400eae9 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -167,7 +167,7 @@ export async function addPhive( case 'latest': return ( (await utils.getCommand(os_version, 'tool')) + - 'https://phar.io/releases/phive.phar phive' + 'https://phar.io/releases/phive.phar phive status' ); default: return ( @@ -176,7 +176,7 @@ export async function addPhive( version + '/phive-' + version + - '.phar phive' + '.phar phive status' ); } } @@ -334,7 +334,7 @@ export async function getCleanedToolsList( return extension .trim() .replace( - /-agent|hirak\/|laravel\/|narrowspark\/automatic-|overtrue\/|robmorgan\/|symfony\//, + /-agent|hirak\/|icanhazstring\/|laravel\/|narrowspark\/automatic-|overtrue\/|robmorgan\/|symfony\//, '' ); }) @@ -348,13 +348,18 @@ export async function getCleanedToolsList( * @param tool * @param url * @param os_version + * @param ver_param */ export async function addArchive( tool: string, url: string, - os_version: string + os_version: string, + ver_param: string ): Promise { - return (await utils.getCommand(os_version, 'tool')) + url + ' ' + tool; + return ( + (await utils.getCommand(os_version, 'tool')) + + (await utils.joins(url, tool, ver_param)) + ); } /** @@ -369,13 +374,8 @@ export async function addDevTools( ): Promise { switch (os_version) { case 'linux': - return ( - 'add_devtools' + - '\n' + - (await utils.addLog('$tick', tool, 'Added', 'linux')) - ); case 'darwin': - return await utils.addLog('$tick', tool, 'Added', 'darwin'); + return 'add_devtools ' + tool; case 'win32': return await utils.addLog( '$cross', @@ -447,22 +447,22 @@ export async function addTools( break; case 'blackfire-player': url = await getPharUrl('https://get.blackfire.io', tool, 'v', version); - script += await addArchive(tool, url, os_version); + script += await addArchive(tool, url, os_version, '"-V"'); break; case 'codeception': url = 'https://codeception.com/' + (await getCodeceptionUri(version, php_version)); - script += await addArchive(tool, url, os_version); + script += await addArchive(tool, url, os_version, '"-V"'); break; case 'composer': url = await getComposerUrl(version); - script += await addArchive('composer', url, os_version); + script += await addArchive('composer', url, os_version, version); break; case 'composer-normalize': uri = await getUri(tool, '.phar', version, 'releases', '', 'download'); url = github + 'ergebnis/composer-normalize/' + uri; - script += await addArchive(tool, url, os_version); + script += await addArchive(tool, url, os_version, '"-V"'); break; case 'composer-prefetcher': script += await addPackage( @@ -475,39 +475,37 @@ export async function addTools( case 'composer-require-checker': uri = await getUri(tool, '.phar', version, 'releases', '', 'download'); url = github + 'maglnet/ComposerRequireChecker/' + uri; - script += await addArchive(tool, url, os_version); + script += await addArchive(tool, url, os_version, '"-V"'); break; case 'composer-unused': - uri = await getUri(tool, '.phar', version, 'releases', '', 'download'); - url = github + 'composer-unused/composer-unused/' + uri; - script += await addArchive(tool, url, os_version); + script += await addPackage(tool, release, 'icanhazstring/', os_version); break; case 'cs2pr': uri = await getUri(tool, '', version, 'releases', '', 'download'); url = github + 'staabm/annotate-pull-request-from-checkstyle/' + uri; - script += await addArchive(tool, url, os_version); + script += await addArchive(tool, url, os_version, '"-V"'); break; case 'deployer': url = await getDeployerUrl(version); - script += await addArchive(tool, url, os_version); + script += await addArchive(tool, url, os_version, '"-V"'); break; case 'flex': script += await addPackage(tool, release, 'symfony/', os_version); break; case 'infection': url = github + 'infection/infection/' + uri; - script += await addArchive(tool, url, os_version); + script += await addArchive(tool, url, os_version, '"-V"'); break; case 'pecl': script += await utils.getCommand(os_version, 'pecl'); break; case 'phan': url = github + 'phan/phan/' + uri; - script += await addArchive(tool, url, os_version); + script += await addArchive(tool, url, os_version, '"-v"'); break; case 'phing': url = 'https://www.phing.info/get/phing-' + version + '.phar'; - script += await addArchive(tool, url, os_version); + script += await addArchive(tool, url, os_version, '"-v"'); break; case 'phinx': script += await addPackage(tool, release, 'robmorgan/', os_version); @@ -522,48 +520,48 @@ export async function addTools( case 'php-cs-fixer': uri = await getUri(tool, '.phar', version, 'releases', 'v', 'download'); url = github + 'FriendsOfPHP/PHP-CS-Fixer/' + uri; - script += await addArchive(tool, url, os_version); + script += await addArchive(tool, url, os_version, '"-V"'); break; case 'phpcbf': case 'phpcs': url = github + 'squizlabs/PHP_CodeSniffer/' + uri; - script += await addArchive(tool, url, os_version); + script += await addArchive(tool, url, os_version, '"--version"'); break; case 'phpcpd': case 'phpunit': url = await getPharUrl('https://phar.phpunit.de', tool, '', version); - script += await addArchive(tool, url, os_version); + script += await addArchive(tool, url, os_version, '"--version"'); break; case 'phplint': script += await addPackage(tool, release, 'overtrue/', os_version); break; case 'phpmd': url = github + 'phpmd/phpmd/' + uri; - script += await addArchive(tool, url, os_version); + script += await addArchive(tool, url, os_version, '"--version"'); break; case 'phpstan': url = github + 'phpstan/phpstan/' + uri; - script += await addArchive(tool, url, os_version); + script += await addArchive(tool, url, os_version, '"-V"'); break; case 'prestissimo': script += await addPackage(tool, release, 'hirak/', os_version); break; case 'psalm': url = github + 'vimeo/psalm/' + uri; - script += await addArchive(tool, url, os_version); + script += await addArchive(tool, url, os_version, '"-v"'); break; case 'symfony': case 'symfony-cli': uri = await getSymfonyUri(version, os_version); url = github + 'symfony/cli/' + uri; - script += await addArchive('symfony', url, os_version); + script += await addArchive('symfony', url, os_version, 'version'); break; case 'vapor-cli': script += await addPackage(tool, release, 'laravel/', os_version); break; case 'wp-cli': url = github + (await getWpCliUrl(version)); - script += await addArchive(tool, url, os_version); + script += await addArchive(tool, url, os_version, '"--version"'); break; default: script += await utils.addLog(