diff --git a/__tests__/tools.test.ts b/__tests__/tools.test.ts index abf43219..8a1a8343 100644 --- a/__tests__/tools.test.ts +++ b/__tests__/tools.test.ts @@ -2,28 +2,10 @@ import * as tools from '../src/tools'; describe('Tools tests', () => { it('checking getCommand', async () => { - expect(await tools.getArchiveCommand('linux')).toBe('add_tool '); - expect(await tools.getArchiveCommand('darwin')).toBe('add_tool '); - expect(await tools.getArchiveCommand('win32')).toBe('Add-Tool '); - expect(await tools.getArchiveCommand('fedora')).toContain( - 'Platform fedora is not supported' - ); - }); - - it('checking getCommand', async () => { - expect(await tools.getPackageCommand('linux')).toBe('add_composer_tool '); - expect(await tools.getPackageCommand('darwin')).toBe('add_composer_tool '); - expect(await tools.getPackageCommand('win32')).toBe('Add-Composer-Tool '); - expect(await tools.getPackageCommand('fedora')).toContain( - 'Platform fedora is not supported' - ); - }); - - it('checking getPECLCommand', async () => { - expect(await tools.getPECLCommand('linux')).toBe('add_pecl '); - expect(await tools.getPECLCommand('darwin')).toBe('add_pecl '); - expect(await tools.getPECLCommand('win32')).toBe('Add-PECL '); - expect(await tools.getPECLCommand('fedora')).toContain( + expect(await tools.getCommand('linux', 'tool')).toBe('add_tool '); + expect(await tools.getCommand('darwin', 'tool')).toBe('add_tool '); + expect(await tools.getCommand('win32', 'tool')).toBe('Add-Tool '); + expect(await tools.getCommand('fedora', 'tool')).toContain( 'Platform fedora is not supported' ); }); @@ -205,12 +187,12 @@ describe('Tools tests', () => { ); }); - it('checking getPhpunitUri', async () => { - expect(await tools.getPhpunitUrl('tool', 'latest')).toBe( - 'https://phar.phpunit.de/tool.phar' + it('checking getPharUri', async () => { + expect(await tools.getPharUrl('domain', 'tool', '', 'latest')).toBe( + 'domain/tool.phar' ); - expect(await tools.getPhpunitUrl('tool', '1.2.3')).toBe( - 'https://phar.phpunit.de/tool-1.2.3.phar' + expect(await tools.getPharUrl('domain', 'tool', 'v', '1.2.3')).toBe( + 'domain/tool-v1.2.3.phar' ); }); @@ -353,13 +335,13 @@ describe('Tools tests', () => { 'user/', 'linux' ); - expect(script).toContain('add_composer_tool tool tool:1.2.3 user/'); + expect(script).toContain('add_composertool tool tool:1.2.3 user/'); script = await tools.addPackage('tool', 'tool:1.2.3', 'user/', 'darwin'); - expect(script).toContain('add_composer_tool tool tool:1.2.3 user/'); + expect(script).toContain('add_composertool tool tool:1.2.3 user/'); script = await tools.addPackage('tool', 'tool:1.2.3', 'user/', 'win32'); - expect(script).toContain('Add-Composer-Tool tool tool:1.2.3 user/'); + expect(script).toContain('Add-Composertool tool tool:1.2.3 user/'); script = await tools.addPackage('tool', 'tool:1.2.3', 'user/', 'fedora'); expect(script).toContain('Platform fedora is not supported'); @@ -367,10 +349,14 @@ describe('Tools tests', () => { it('checking addTools on linux', async () => { const script: string = await tools.addTools( - 'cs2pr, flex, php-cs-fixer, phpstan, phpunit, pecl, phinx, phinx:1.2.3, phive, php-config, phpize, symfony, wp-cli', + 'blackfire, blackfire-player, cs2pr, flex, php-cs-fixer, phpstan, phpunit, pecl, phinx, phinx:1.2.3, phive, php-config, phpize, symfony, wp-cli', '7.4', 'linux' ); + expect(script).toContain('add_blackfire'); + expect(script).toContain( + 'add_tool https://get.blackfire.io/blackfire-player.phar blackfire-player' + ); expect(script).toContain( 'add_tool https://getcomposer.org/composer-stable.phar composer' ); @@ -396,19 +382,23 @@ describe('Tools tests', () => { 'add_tool https://github.com/wp-cli/builds/blob/gh-pages/phar/wp-cli.phar?raw=true wp-cli' ); expect(script).toContain('add_pecl'); - expect(script).toContain('add_composer_tool flex flex symfony/'); - expect(script).toContain('add_composer_tool phinx phinx robmorgan/'); - expect(script).toContain('add_composer_tool phinx phinx:1.2.3 robmorgan/'); + expect(script).toContain('add_composertool flex flex symfony/'); + expect(script).toContain('add_composertool phinx phinx robmorgan/'); + 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"'); }); it('checking addTools on darwin', async () => { const script: string = await tools.addTools( - 'flex, phpcs, phpcbf, phpcpd, phpmd, psalm, phinx, phive:1.2.3, cs2pr:1.2.3, composer-prefetcher:1.2.3, phpize, php-config, symfony, symfony:1.2.3, wp-cli', + 'blackfire, blackfire-player, flex, phpcs, phpcbf, phpcpd, phpmd, psalm, phinx, phive:1.2.3, cs2pr:1.2.3, composer-prefetcher:1.2.3, phpize, php-config, symfony, symfony:1.2.3, wp-cli', '7.4', 'darwin' ); + expect(script).toContain('add_blackfire'); + expect(script).toContain( + 'add_tool https://get.blackfire.io/blackfire-player.phar blackfire-player' + ); expect(script).toContain( 'add_tool https://getcomposer.org/composer-stable.phar composer' ); @@ -430,13 +420,13 @@ describe('Tools tests', () => { expect(script).toContain( 'https://github.com/vimeo/psalm/releases/latest/download/psalm.phar psalm' ); - expect(script).toContain('add_composer_tool flex flex symfony/'); - expect(script).toContain('add_composer_tool phinx phinx robmorgan/'); + expect(script).toContain('add_composertool flex flex symfony/'); + expect(script).toContain('add_composertool phinx phinx robmorgan/'); 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_composer_tool composer-prefetcher composer-prefetcher:1.2.3 narrowspark/automatic-' + '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' @@ -452,27 +442,29 @@ describe('Tools tests', () => { }); it('checking addTools on windows', async () => { const script: string = await tools.addTools( - 'codeception, cs2pr, deployer, flex, prestissimo, phpmd, phinx, phive:0.13.2, php-config, phpize, symfony, wp-cli, does_not_exit', + 'blackfire, blackfire-player:1.8.1, codeception, cs2pr, deployer, flex, prestissimo, phpmd, phinx, phive:0.13.2, php-config, phpize, symfony, wp-cli, does_not_exit', '7.4', 'win32' ); + expect(script).toContain('Add-Blackfire 1.32.0'); + expect(script).toContain( + 'Add-Tool https://get.blackfire.io/blackfire-player-v1.8.1.phar blackfire-player' + ); expect(script).toContain( 'Add-Tool 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' ); - expect(script).toContain('Add-Composer-Tool flex flex symfony/'); + expect(script).toContain('Add-Composertool flex flex symfony/'); expect(script).toContain( 'Add-Tool https://deployer.org/deployer.phar deployer' ); - expect(script).toContain( - 'Add-Composer-Tool prestissimo prestissimo hirak/' - ); + expect(script).toContain('Add-Composertool prestissimo prestissimo hirak/'); expect(script).toContain( 'Add-Tool https://github.com/phpmd/phpmd/releases/latest/download/phpmd.phar phpmd' ); - expect(script).toContain('Add-Composer-Tool phinx phinx robmorgan/'); + 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' ); @@ -496,12 +488,10 @@ describe('Tools tests', () => { expect(script).toContain( 'Add-Tool https://getcomposer.org/composer-stable.phar composer' ); + expect(script).toContain('Add-Composertool prestissimo prestissimo hirak/'); + expect(script).toContain('Add-Composertool phinx phinx robmorgan/'); expect(script).toContain( - 'Add-Composer-Tool prestissimo prestissimo hirak/' - ); - expect(script).toContain('Add-Composer-Tool phinx phinx robmorgan/'); - expect(script).toContain( - 'Add-Composer-Tool composer-prefetcher composer-prefetcher narrowspark/automatic-' + 'Add-Composertool composer-prefetcher composer-prefetcher narrowspark/automatic-' ); }); }); diff --git a/__tests__/utils.test.ts b/__tests__/utils.test.ts index c8e54a00..874d5813 100644 --- a/__tests__/utils.test.ts +++ b/__tests__/utils.test.ts @@ -168,4 +168,7 @@ describe('Utils tests', () => { expect(await utils.getBlackfireVersion(null)).toEqual('1.31.0'); expect(await utils.getBlackfireVersion('1.32.0')).toEqual('1.32.0'); }); + it('checking getBlackfireAgentVersion', async () => { + expect(await utils.getBlackfireAgentVersion()).toEqual('1.32.0'); + }); }); diff --git a/action.yml b/action.yml index 7de890b4..e36238e0 100644 --- a/action.yml +++ b/action.yml @@ -3,6 +3,7 @@ author: shivammathur description: 'Setup PHP with required extensions, php.ini configuration, code-coverage support and various tools like composer' branding: color: 'purple' + icon: 'play-circle' inputs: php-version: description: 'Setup PHP version.' diff --git a/dist/index.js b/dist/index.js index 9c05b432..a863fabd 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1265,6 +1265,15 @@ function getBlackfireVersion(blackfire_version) { }); } exports.getBlackfireVersion = getBlackfireVersion; +/** + * Function to get Blackfire Agent version + */ +function getBlackfireAgentVersion() { + return __awaiter(this, void 0, void 0, function* () { + return '1.32.0'; + }); +} +exports.getBlackfireAgentVersion = getBlackfireAgentVersion; /***/ }), @@ -1594,63 +1603,24 @@ var __importStar = (this && this.__importStar) || function (mod) { Object.defineProperty(exports, "__esModule", { value: true }); const utils = __importStar(__webpack_require__(163)); /** - * Function to get command to setup tool + * Function to get command to setup tools * * @param os_version */ -function getArchiveCommand(os_version) { +function getCommand(os_version, suffix) { return __awaiter(this, void 0, void 0, function* () { switch (os_version) { case 'linux': case 'darwin': - return 'add_tool '; + return 'add_' + suffix + ' '; case 'win32': - return 'Add-Tool '; + return 'Add-' + suffix.charAt(0).toUpperCase() + suffix.slice(1) + ' '; default: return yield utils.log('Platform ' + os_version + ' is not supported', os_version, 'error'); } }); } -exports.getArchiveCommand = getArchiveCommand; -/** - * Function to get command to setup tools using composer - * - * @param os_version - */ -function getPackageCommand(os_version) { - return __awaiter(this, void 0, void 0, function* () { - switch (os_version) { - case 'linux': - case 'darwin': - return 'add_composer_tool '; - case 'win32': - return 'Add-Composer-Tool '; - default: - return yield utils.log('Platform ' + os_version + ' is not supported', os_version, 'error'); - } - }); -} -exports.getPackageCommand = getPackageCommand; -/** - * - * Function to get command to setup PECL - * - * @param os_version - */ -function getPECLCommand(os_version) { - return __awaiter(this, void 0, void 0, function* () { - switch (os_version) { - case 'linux': - case 'darwin': - return 'add_pecl '; - case 'win32': - return 'Add-PECL '; - default: - return yield utils.log('Platform ' + os_version + ' is not supported', os_version, 'error'); - } - }); -} -exports.getPECLCommand = getPECLCommand; +exports.getCommand = getCommand; /** * Function to get tool version * @@ -1805,10 +1775,10 @@ function addPhive(version, os_version) { return __awaiter(this, void 0, void 0, function* () { switch (version) { case 'latest': - return ((yield getArchiveCommand(os_version)) + + return ((yield getCommand(os_version, 'tool')) + 'https://phar.io/releases/phive.phar phive'); default: - return ((yield getArchiveCommand(os_version)) + + return ((yield getCommand(os_version, 'tool')) + 'https://github.com/phar-io/phive/releases/download/' + version + '/phive-' + @@ -1819,22 +1789,21 @@ function addPhive(version, os_version) { } exports.addPhive = addPhive; /** - * Function to get the PHPUnit url + * Function to get the phar url in domain/tool-version.phar format * * @param version */ -function getPhpunitUrl(tool, version) { +function getPharUrl(domain, tool, prefix, version) { return __awaiter(this, void 0, void 0, function* () { - const phpunit = 'https://phar.phpunit.de'; switch (version) { case 'latest': - return phpunit + '/' + tool + '.phar'; + return domain + '/' + tool + '.phar'; default: - return phpunit + '/' + tool + '-' + version + '.phar'; + return domain + '/' + tool + '-' + prefix + version + '.phar'; } }); } -exports.getPhpunitUrl = getPhpunitUrl; +exports.getPharUrl = getPharUrl; /** * Function to get the Deployer url * @@ -1948,7 +1917,7 @@ exports.getCleanedToolsList = getCleanedToolsList; */ function addArchive(tool, version, url, os_version) { return __awaiter(this, void 0, void 0, function* () { - return (yield getArchiveCommand(os_version)) + url + ' ' + tool; + return (yield getCommand(os_version, 'tool')) + url + ' ' + tool; }); } exports.addArchive = addArchive; @@ -1985,7 +1954,7 @@ exports.addDevTools = addDevTools; */ function addPackage(tool, release, prefix, os_version) { return __awaiter(this, void 0, void 0, function* () { - const tool_command = yield getPackageCommand(os_version); + const tool_command = yield getCommand(os_version, 'composertool'); return tool_command + tool + ' ' + release + ' ' + prefix; }); } @@ -2010,6 +1979,14 @@ function addTools(tools_csv, php_version, os_version) { script += '\n'; let url = ''; switch (tool) { + case 'blackfire': + case 'blackfire-agent': + script += yield getCommand(os_version, 'blackfire ' + (yield utils.getBlackfireAgentVersion())); + break; + case 'blackfire-player': + url = yield getPharUrl('https://get.blackfire.io', tool, 'v', version); + script += yield addArchive(tool, version, url, os_version); + break; case 'cs2pr': uri = yield getUri(tool, '', version, 'releases', '', 'download'); url = github + 'staabm/annotate-pull-request-from-checkstyle/' + uri; @@ -2055,7 +2032,7 @@ function addTools(tools_csv, php_version, os_version) { break; case 'phpcpd': case 'phpunit': - url = yield getPhpunitUrl(tool, version); + url = yield getPharUrl('https://phar.phpunit.de', tool, '', version); script += yield addArchive(tool, version, url, os_version); break; case 'deployer': @@ -2075,7 +2052,7 @@ function addTools(tools_csv, php_version, os_version) { script += yield addPackage(tool, release, 'narrowspark/automatic-', os_version); break; case 'pecl': - script += yield getPECLCommand(os_version); + script += yield getCommand(os_version, 'pecl'); break; case 'php-config': case 'phpize': @@ -2724,6 +2701,8 @@ function addExtensionDarwin(extension_csv, version, pipe) { const prefix = yield utils.getExtensionPrefix(ext_name); let install_command = ''; switch (true) { + // match 5.3blackfire...5.6blackfire, 7.0blackfire...7.4blackfire + // match 5.3blackfire-1.31.0...5.6blackfire-1.31.0, 7.0blackfire-1.31.0...7.4blackfire-1.31.0 case /^(5\.[3-6]|7\.[0-4])blackfire(-\d+\.\d+\.\d+)?$/.test(version_extension): install_command = 'bash ' + @@ -2814,7 +2793,8 @@ function addExtensionWindows(extension_csv, version, pipe) { const version_extension = version + extension; let matches; switch (true) { - // match blackfire...blackfire-1.31.0 + // match 5.4blackfire...5.6blackfire, 7.0blackfire...7.4blackfire + // match 5.4blackfire-1.31.0...5.6blackfire-1.31.0, 7.0blackfire-1.31.0...7.4blackfire-1.31.0 case /^(5\.[4-6]|7\.[0-4])blackfire(-\d+\.\d+\.\d+)?$/.test(version_extension): script += '\n& ' + @@ -2877,7 +2857,8 @@ function addExtensionLinux(extension_csv, version, pipe) { const prefix = yield utils.getExtensionPrefix(ext_name); let install_command = ''; switch (true) { - // match blackfire... blackfire-1.31.0 + // match 5.3blackfire...5.6blackfire, 7.0blackfire...7.4blackfire + // match 5.3blackfire-1.31.0...5.6blackfire-1.31.0, 7.0blackfire-1.31.0...7.4blackfire-1.31.0 case /^(5\.[3-6]|7\.[0-4])blackfire(-\d+\.\d+\.\d+)?$/.test(version_extension): install_command = 'bash ' + diff --git a/src/extensions.ts b/src/extensions.ts index 2e77894b..a0d35cfb 100644 --- a/src/extensions.ts +++ b/src/extensions.ts @@ -22,6 +22,8 @@ export async function addExtensionDarwin( const prefix = await utils.getExtensionPrefix(ext_name); let install_command = ''; switch (true) { + // match 5.3blackfire...5.6blackfire, 7.0blackfire...7.4blackfire + // match 5.3blackfire-1.31.0...5.6blackfire-1.31.0, 7.0blackfire-1.31.0...7.4blackfire-1.31.0 case /^(5\.[3-6]|7\.[0-4])blackfire(-\d+\.\d+\.\d+)?$/.test( version_extension ): @@ -114,7 +116,8 @@ export async function addExtensionWindows( const version_extension: string = version + extension; let matches: RegExpExecArray; switch (true) { - // match blackfire...blackfire-1.31.0 + // match 5.4blackfire...5.6blackfire, 7.0blackfire...7.4blackfire + // match 5.4blackfire-1.31.0...5.6blackfire-1.31.0, 7.0blackfire-1.31.0...7.4blackfire-1.31.0 case /^(5\.[4-6]|7\.[0-4])blackfire(-\d+\.\d+\.\d+)?$/.test( version_extension ): @@ -183,7 +186,8 @@ export async function addExtensionLinux( const prefix = await utils.getExtensionPrefix(ext_name); let install_command = ''; switch (true) { - // match blackfire... blackfire-1.31.0 + // match 5.3blackfire...5.6blackfire, 7.0blackfire...7.4blackfire + // match 5.3blackfire-1.31.0...5.6blackfire-1.31.0, 7.0blackfire-1.31.0...7.4blackfire-1.31.0 case /^(5\.[3-6]|7\.[0-4])blackfire(-\d+\.\d+\.\d+)?$/.test( version_extension ): diff --git a/src/scripts/darwin.sh b/src/scripts/darwin.sh index 6598f68a..33c368f7 100644 --- a/src/scripts/darwin.sh +++ b/src/scripts/darwin.sh @@ -123,7 +123,7 @@ add_tool() { } # Function to add a tool using composer -add_composer_tool() { +add_composertool() { tool=$1 release=$2 prefix=$3 @@ -134,6 +134,16 @@ add_composer_tool() { ) || add_log "$cross" "$tool" "Could not setup $tool" } +add_blackfire() { + sudo mkdir -p usr/local/var/run + brew tap blackfireio/homebrew-blackfire >/dev/null 2>&1 + brew install blackfire-agent >/dev/null 2>&1 + sudo blackfire-agent --register --server-id="$BLACKFIRE_SERVER_ID" --server-token="$BLACKFIRE_SERVER_TOKEN" >/dev/null 2>&1 + brew services start blackfire-agent >/dev/null 2>&1 + sudo blackfire --config --client-id="$BLACKFIRE_CLIENT_ID" --client-token="$BLACKFIRE_CLIENT_TOKEN" >/dev/null 2>&1 + +} + # Function to configure PECL configure_pecl() { for tool in pear pecl; do diff --git a/src/scripts/linux.sh b/src/scripts/linux.sh index 716fc08f..d1c9de50 100644 --- a/src/scripts/linux.sh +++ b/src/scripts/linux.sh @@ -173,7 +173,7 @@ add_tool() { } # Function to setup a tool using composer -add_composer_tool() { +add_composertool() { tool=$1 release=$2 prefix=$3 @@ -194,6 +194,18 @@ add_devtools() { configure_pecl } +add_blackfire() { + sudo mkdir -p /var/run/blackfire + sudo curl -o /tmp/blackfire-gpg.key -sSL https://packages.blackfire.io/gpg.key >/dev/null 2>&1 + sudo apt-key add /tmp/blackfire-gpg.key >/dev/null 2>&1 + echo "deb http://packages.blackfire.io/debian any main" | sudo tee /etc/apt/sources.list.d/blackfire.list >/dev/null 2>&1 + find /etc/apt/sources.list.d -type f -name blackfire.list -exec sudo "$debconf_fix" apt-fast update -o Dir::Etc::sourcelist="{}" ';' >/dev/null 2>&1 + $apt_install blackfire-agent >/dev/null 2>&1 + sudo blackfire-agent --register --server-id="$BLACKFIRE_SERVER_ID" --server-token="$BLACKFIRE_SERVER_TOKEN" >/dev/null 2>&1 + sudo /etc/init.d/blackfire-agent restart >/dev/null 2>&1 + sudo blackfire --config --client-id="$BLACKFIRE_CLIENT_ID" --client-token="$BLACKFIRE_CLIENT_TOKEN" >/dev/null 2>&1 +} + # Function to setup the nightly build from master branch setup_master() { tar_file=php_"$version"%2Bubuntu"$(lsb_release -r -s)".tar.xz diff --git a/src/scripts/win32.ps1 b/src/scripts/win32.ps1 index 447022cf..d453e6fb 100644 --- a/src/scripts/win32.ps1 +++ b/src/scripts/win32.ps1 @@ -103,7 +103,7 @@ Function Add-Tool() { } if ($tool -eq "symfony") { Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $php_dir\$tool.exe - Add-Content -Path $PsHome\profile.ps1 -Value "New-Alias $tool $php_dir\$tool.exe" > $null 2>&1 + Add-Content -Path $PsHome\profile.ps1 -Value "New-Alias $tool $php_dir\$tool.exe" >$null 2>&1 } else { try { Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $php_dir\$tool @@ -113,7 +113,7 @@ Function Add-Tool() { $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" > $null 2>&1 + Add-Content -Path $PsHome\profile.ps1 -Value "New-Alias $tool $php_dir\$tool.bat" >$null 2>&1 } catch { } } if($tool -eq "phive") { @@ -134,7 +134,7 @@ Function Add-Tool() { } } -Function Add-Composer-Tool() { +Function Add-Composertool() { Param ( [Parameter(Position = 0, Mandatory = $true)] [ValidateNotNull()] @@ -162,10 +162,31 @@ Function Add-Composer-Tool() { } } -Function Add-PECL() { +Function Add-Pecl() { Add-Log $tick "PECL" "Use extensions input to setup PECL extensions on windows" } +Function Add-Blackfire() { + Param ( + [Parameter(Position = 0, Mandatory = $true)] + [ValidateNotNull()] + [ValidateLength(1, [int]::MaxValue)] + [string] + $agent_version + ) + $url = "https://packages.blackfire.io/binaries/blackfire-agent/${agent_version}/blackfire-agent-windows_${arch_name}.zip" + Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $php_dir\blackfire.zip >$null 2>&1 + 7z e $php_dir\blackfire.zip -o"$php_dir" -y >$null 2>&1 + Add-Content -Path $PsHome\profile.ps1 -Value "New-Alias blackfire $php_dir\blackfire.exe" + Add-Content -Path $PsHome\profile.ps1 -Value "New-Alias blackfire-agent $php_dir\blackfire-agent.exe" + if ((Test-Path env:BLACKFIRE_SERVER_ID) -and (Test-Path env:BLACKFIRE_SERVER_TOKEN)) { + blackfire-agent --register --server-id=$env:BLACKFIRE_SERVER_ID --server-token=$env:BLACKFIRE_SERVER_TOKEN >$null 2>&1 + } + 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 + } +} + # Variables $tick = ([char]8730) $cross = ([char]10007) @@ -174,6 +195,7 @@ $ext_dir = $php_dir + '\ext' $ProgressPreference = 'SilentlyContinue' $master_version = '8.0' $arch = 'x64' +$arch_name='amd64' $ts = $false if((Test-Path env:PHPTS) -and $env:PHPTS -eq 'ts') { $ts = $true @@ -197,6 +219,7 @@ if ($null -eq $installed -or -not("$($installed.Version).".StartsWith(($version if ($version -lt '7.0') { Install-Module -Name VcRedist -Force $arch='x86' + $arch_name='386' } if ($version -eq $master_version) { $version = 'master' @@ -205,7 +228,7 @@ if ($null -eq $installed -or -not("$($installed.Version).".StartsWith(($version Install-Php -Version $version -Architecture $arch -ThreadSafe $ts -InstallVC -Path $php_dir -TimeZone UTC -InitialPhpIni Production -Force >$null 2>&1 } else { if((Test-Path env:update) -and $env:update -eq 'true') { - Update-Php $php_dir > $null 2>&1 + Update-Php $php_dir >$null 2>&1 $status = "Updated to" } else { $status = "Found" diff --git a/src/tools.ts b/src/tools.ts index 522769db..dc8cd1a7 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -1,60 +1,20 @@ import * as utils from './utils'; /** - * Function to get command to setup tool + * Function to get command to setup tools * * @param os_version */ -export async function getArchiveCommand(os_version: string): Promise { +export async function getCommand( + os_version: string, + suffix: string +): Promise { switch (os_version) { case 'linux': case 'darwin': - return 'add_tool '; + return 'add_' + suffix + ' '; case 'win32': - return 'Add-Tool '; - default: - return await utils.log( - 'Platform ' + os_version + ' is not supported', - os_version, - 'error' - ); - } -} - -/** - * Function to get command to setup tools using composer - * - * @param os_version - */ -export async function getPackageCommand(os_version: string): Promise { - switch (os_version) { - case 'linux': - case 'darwin': - return 'add_composer_tool '; - case 'win32': - return 'Add-Composer-Tool '; - default: - return await utils.log( - 'Platform ' + os_version + ' is not supported', - os_version, - 'error' - ); - } -} - -/** - * - * Function to get command to setup PECL - * - * @param os_version - */ -export async function getPECLCommand(os_version: string): Promise { - switch (os_version) { - case 'linux': - case 'darwin': - return 'add_pecl '; - case 'win32': - return 'Add-PECL '; + return 'Add-' + suffix.charAt(0).toUpperCase() + suffix.slice(1) + ' '; default: return await utils.log( 'Platform ' + os_version + ' is not supported', @@ -226,12 +186,12 @@ export async function addPhive( switch (version) { case 'latest': return ( - (await getArchiveCommand(os_version)) + + (await getCommand(os_version, 'tool')) + 'https://phar.io/releases/phive.phar phive' ); default: return ( - (await getArchiveCommand(os_version)) + + (await getCommand(os_version, 'tool')) + 'https://github.com/phar-io/phive/releases/download/' + version + '/phive-' + @@ -242,20 +202,21 @@ export async function addPhive( } /** - * Function to get the PHPUnit url + * Function to get the phar url in domain/tool-version.phar format * * @param version */ -export async function getPhpunitUrl( +export async function getPharUrl( + domain: string, tool: string, + prefix: string, version: string ): Promise { - const phpunit = 'https://phar.phpunit.de'; switch (version) { case 'latest': - return phpunit + '/' + tool + '.phar'; + return domain + '/' + tool + '.phar'; default: - return phpunit + '/' + tool + '-' + version + '.phar'; + return domain + '/' + tool + '-' + prefix + version + '.phar'; } } @@ -382,7 +343,7 @@ export async function addArchive( url: string, os_version: string ): Promise { - return (await getArchiveCommand(os_version)) + url + ' ' + tool; + return (await getCommand(os_version, 'tool')) + url + ' ' + tool; } /** @@ -434,7 +395,7 @@ export async function addPackage( prefix: string, os_version: string ): Promise { - const tool_command = await getPackageCommand(os_version); + const tool_command = await getCommand(os_version, 'composertool'); return tool_command + tool + ' ' + release + ' ' + prefix; } @@ -467,6 +428,17 @@ export async function addTools( script += '\n'; let url = ''; switch (tool) { + case 'blackfire': + case 'blackfire-agent': + script += await getCommand( + os_version, + 'blackfire ' + (await utils.getBlackfireAgentVersion()) + ); + break; + case 'blackfire-player': + url = await getPharUrl('https://get.blackfire.io', tool, 'v', version); + script += await addArchive(tool, version, url, os_version); + break; case 'cs2pr': uri = await getUri(tool, '', version, 'releases', '', 'download'); url = github + 'staabm/annotate-pull-request-from-checkstyle/' + uri; @@ -512,7 +484,7 @@ export async function addTools( break; case 'phpcpd': case 'phpunit': - url = await getPhpunitUrl(tool, version); + url = await getPharUrl('https://phar.phpunit.de', tool, '', version); script += await addArchive(tool, version, url, os_version); break; case 'deployer': @@ -537,7 +509,7 @@ export async function addTools( ); break; case 'pecl': - script += await getPECLCommand(os_version); + script += await getCommand(os_version, 'pecl'); break; case 'php-config': case 'phpize': diff --git a/src/utils.ts b/src/utils.ts index 4a23db50..ceb58bc3 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -279,3 +279,10 @@ export async function getBlackfireVersion( return blackfire_version; } } + +/** + * Function to get Blackfire Agent version + */ +export async function getBlackfireAgentVersion(): Promise { + return '1.32.0'; +}