From 5c2618165a2d496229261205a07a486e4d59c625 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Thu, 7 May 2020 17:14:15 +0530 Subject: [PATCH] Fetch blackfire latest versions --- __tests__/extensions.test.ts | 12 ++++----- __tests__/tools.test.ts | 2 +- __tests__/utils.test.ts | 10 -------- dist/index.js | 39 ++++++----------------------- src/extensions.ts | 14 +++++------ src/scripts/ext/blackfire.ps1 | 10 +++++--- src/scripts/ext/blackfire.sh | 6 ++++- src/scripts/ext/blackfire_darwin.sh | 6 ++++- src/scripts/win32.ps1 | 9 ++----- src/tools.ts | 5 +--- src/utils.ts | 25 ------------------ 11 files changed, 42 insertions(+), 96 deletions(-) diff --git a/__tests__/extensions.test.ts b/__tests__/extensions.test.ts index 4e06f4a3..81734487 100644 --- a/__tests__/extensions.test.ts +++ b/__tests__/extensions.test.ts @@ -42,10 +42,10 @@ describe('Extension tests', () => { expect(win32).toContain('Platform fedora is not supported'); win32 = await extensions.addExtension('blackfire', '7.3', 'win32'); - expect(win32).toContain('blackfire.ps1 7.3 1.31.0'); + expect(win32).toContain('blackfire.ps1 7.3 blackfire'); win32 = await extensions.addExtension('blackfire-1.31.0', '7.3', 'win32'); - expect(win32).toContain('blackfire.ps1 7.3 1.31.0'); + expect(win32).toContain('blackfire.ps1 7.3 blackfire-1.31.0'); }); it('checking addExtensionOnLinux', async () => { @@ -92,10 +92,10 @@ describe('Extension tests', () => { expect(linux).toContain('phalcon.sh phalcon4 7.3'); linux = await extensions.addExtension('blackfire', '7.3', 'linux'); - expect(linux).toContain('blackfire.sh 7.3 1.31.0'); + expect(linux).toContain('blackfire.sh 7.3 blackfire'); linux = await extensions.addExtension('blackfire-1.31.0', '7.3', 'linux'); - expect(linux).toContain('blackfire.sh 7.3 1.31.0'); + expect(linux).toContain('blackfire.sh 7.3 blackfire-1.31.0'); }); it('checking addExtensionOnDarwin', async () => { @@ -156,10 +156,10 @@ describe('Extension tests', () => { expect(darwin).toContain('sudo pecl install -f imagick'); darwin = await extensions.addExtension('blackfire', '7.3', 'darwin'); - expect(darwin).toContain('blackfire_darwin.sh 7.3 1.31.0'); + expect(darwin).toContain('blackfire_darwin.sh 7.3 blackfire'); darwin = await extensions.addExtension('blackfire-1.31.0', '7.3', 'darwin'); - expect(darwin).toContain('blackfire_darwin.sh 7.3 1.31.0'); + expect(darwin).toContain('blackfire_darwin.sh 7.3 blackfire-1.31.0'); darwin = await extensions.addExtension( 'does_not_exist', diff --git a/__tests__/tools.test.ts b/__tests__/tools.test.ts index 1de2efe3..8a16d45c 100644 --- a/__tests__/tools.test.ts +++ b/__tests__/tools.test.ts @@ -450,7 +450,7 @@ describe('Tools tests', () => { '7.4', 'win32' ); - expect(script).toContain('Add-Blackfire 1.32.0'); + expect(script).toContain('Add-Blackfire'); expect(script).toContain( 'Add-Tool https://get.blackfire.io/blackfire-player-v1.8.1.phar blackfire-player' ); diff --git a/__tests__/utils.test.ts b/__tests__/utils.test.ts index 92e29b85..c4dfdfc3 100644 --- a/__tests__/utils.test.ts +++ b/__tests__/utils.test.ts @@ -161,14 +161,4 @@ describe('Utils tests', () => { 'Platform fedora is not supported' ); }); - - it('checking getBlackfireVersion', async () => { - expect(await utils.getBlackfireVersion('')).toEqual('1.31.0'); - expect(await utils.getBlackfireVersion(undefined)).toEqual('1.31.0'); - 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/dist/index.js b/dist/index.js index f814feb0..129b7101 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1214,29 +1214,6 @@ async function suppressOutput(os_version) { } } exports.suppressOutput = suppressOutput; -/** - * Function to get Blackfire version - * - * @param blackfire_version - */ -async function getBlackfireVersion(blackfire_version) { - switch (blackfire_version) { - case null: - case undefined: - case '': - return '1.31.0'; - default: - return blackfire_version; - } -} -exports.getBlackfireVersion = getBlackfireVersion; -/** - * Function to get Blackfire Agent version - */ -async function getBlackfireAgentVersion() { - return '1.32.0'; -} -exports.getBlackfireAgentVersion = getBlackfireAgentVersion; /***/ }), @@ -1940,7 +1917,7 @@ async function addTools(tools_csv, php_version, os_version) { switch (tool) { case 'blackfire': case 'blackfire-agent': - script += await getCommand(os_version, 'blackfire ' + (await utils.getBlackfireAgentVersion())); + script += await getCommand(os_version, 'blackfire'); break; case 'blackfire-player': url = await getPharUrl('https://get.blackfire.io', tool, 'v', version); @@ -2620,7 +2597,7 @@ async function addExtensionDarwin(extension_csv, version, pipe) { ' ' + version + ' ' + - (await utils.getBlackfireVersion(ext_version)); + extension; break; // match pre-release versions. For example - xdebug-beta case /.*-(beta|alpha|devel|snapshot)/.test(version_extension): @@ -2692,7 +2669,7 @@ async function addExtensionDarwin(extension_csv, version, pipe) { break; } add_script += - '\nadd_extension ' + extension + ' "' + command + '" ' + ext_prefix; + '\nadd_extension ' + ext_name + ' "' + command + '" ' + ext_prefix; }); return add_script + remove_script; } @@ -2725,7 +2702,7 @@ async function addExtensionWindows(extension_csv, version) { ' ' + version + ' ' + - (await utils.getBlackfireVersion(ext_version)); + extension; return; // match pre-release versions. For example - xdebug-beta case /.*-(beta|alpha|devel|snapshot)/.test(version_extension): @@ -2771,7 +2748,7 @@ async function addExtensionWindows(extension_csv, version) { '\n'; break; default: - add_script += '\nAdd-Extension ' + extension; + add_script += '\nAdd-Extension ' + ext_name; break; } }); @@ -2801,7 +2778,7 @@ async function addExtensionLinux(extension_csv, version, pipe) { remove_script += '\nremove_extension ' + ext_name.slice(1); return; // 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 + // match 5.3blackfire-{semver}...5.6blackfire-{semver}, 7.0blackfire-{semver}...7.4blackfire-{semver} case /^(5\.[3-6]|7\.[0-4])blackfire(-\d+\.\d+\.\d+)?$/.test(version_extension): command = 'bash ' + @@ -2809,7 +2786,7 @@ async function addExtensionLinux(extension_csv, version, pipe) { ' ' + version + ' ' + - (await utils.getBlackfireVersion(ext_version)); + extension; break; // match pre-release versions. For example - xdebug-beta case /.*-(beta|alpha|devel|snapshot)/.test(version_extension): @@ -2877,7 +2854,7 @@ async function addExtensionLinux(extension_csv, version, pipe) { break; } add_script += - '\nadd_extension ' + extension + ' "' + command + '" ' + ext_prefix; + '\nadd_extension ' + ext_name + ' "' + command + '" ' + ext_prefix; }); return add_script + remove_script; } diff --git a/src/extensions.ts b/src/extensions.ts index 23703243..f38c565a 100644 --- a/src/extensions.ts +++ b/src/extensions.ts @@ -38,7 +38,7 @@ export async function addExtensionDarwin( ' ' + version + ' ' + - (await utils.getBlackfireVersion(ext_version)); + extension; break; // match pre-release versions. For example - xdebug-beta case /.*-(beta|alpha|devel|snapshot)/.test(version_extension): @@ -110,7 +110,7 @@ export async function addExtensionDarwin( break; } add_script += - '\nadd_extension ' + extension + ' "' + command + '" ' + ext_prefix; + '\nadd_extension ' + ext_name + ' "' + command + '" ' + ext_prefix; }); return add_script + remove_script; } @@ -148,7 +148,7 @@ export async function addExtensionWindows( ' ' + version + ' ' + - (await utils.getBlackfireVersion(ext_version)); + extension; return; // match pre-release versions. For example - xdebug-beta case /.*-(beta|alpha|devel|snapshot)/.test(version_extension): @@ -198,7 +198,7 @@ export async function addExtensionWindows( '\n'; break; default: - add_script += '\nAdd-Extension ' + extension; + add_script += '\nAdd-Extension ' + ext_name; break; } }); @@ -232,7 +232,7 @@ export async function addExtensionLinux( remove_script += '\nremove_extension ' + ext_name.slice(1); return; // 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 + // match 5.3blackfire-{semver}...5.6blackfire-{semver}, 7.0blackfire-{semver}...7.4blackfire-{semver} case /^(5\.[3-6]|7\.[0-4])blackfire(-\d+\.\d+\.\d+)?$/.test( version_extension ): @@ -242,7 +242,7 @@ export async function addExtensionLinux( ' ' + version + ' ' + - (await utils.getBlackfireVersion(ext_version)); + extension; break; // match pre-release versions. For example - xdebug-beta case /.*-(beta|alpha|devel|snapshot)/.test(version_extension): @@ -310,7 +310,7 @@ export async function addExtensionLinux( break; } add_script += - '\nadd_extension ' + extension + ' "' + command + '" ' + ext_prefix; + '\nadd_extension ' + ext_name + ' "' + command + '" ' + ext_prefix; }); return add_script + remove_script; } diff --git a/src/scripts/ext/blackfire.ps1 b/src/scripts/ext/blackfire.ps1 index 084eb544..2b391d29 100644 --- a/src/scripts/ext/blackfire.ps1 +++ b/src/scripts/ext/blackfire.ps1 @@ -3,10 +3,10 @@ Param ( [ValidateNotNull()] [string] $version, - [Parameter(Position = 2, Mandatory = $false)] + [Parameter(Position = 1, Mandatory = $true)] [ValidateNotNull()] [string] - $extension_version + $extension ) $tick = ([char]8730) @@ -15,7 +15,11 @@ $ext_dir = $php_dir + '\ext' $arch='x64' if ($version -lt '7.0') { $arch='x86' } $version = $version.replace('.', '') - +$extension_version = $extension.split('-')[1] +if ($extension_version -notmatch "\S") { + $ext_data = Invoke-WebRequest https://blackfire.io/docs/up-and-running/update | ForEach-Object { $_.tostring() -split "[`r`n]" | Select-String '' | Select-Object -Index 2 } + $extension_version = [regex]::Matches($ext_data, '(.+)') | ForEach-Object { $_.Captures[0].Groups[1].value } +} if (Test-Path $ext_dir\blackfire.dll) { Enable-PhpExtension -Extension blackfire -Path $php_dir $status="Enabled" diff --git a/src/scripts/ext/blackfire.sh b/src/scripts/ext/blackfire.sh index 889397f2..ed499108 100644 --- a/src/scripts/ext/blackfire.sh +++ b/src/scripts/ext/blackfire.sh @@ -1,5 +1,9 @@ version=${1/./} -extension_version=$2 +extension=${2} +extension_version=$(echo "$extension" | cut -d '-' -f 2) +if [ "$extension_version" = "blackfire" ]; then + extension_version=$(curl -sSL https://blackfire.io/docs/up-and-running/update | grep 'class="version"' | sed -e 's/<[^>]*>\| //g' | sed -n '3,3p') +fi ext_dir=$(php -i | grep "extension_dir => /" | sed -e "s|.*=> s*||") scan_dir=$(php --ini | grep additional | sed -e "s|.*: s*||") ini_file="$scan_dir/50-blackfire.ini" diff --git a/src/scripts/ext/blackfire_darwin.sh b/src/scripts/ext/blackfire_darwin.sh index 07773077..34a7bfdd 100644 --- a/src/scripts/ext/blackfire_darwin.sh +++ b/src/scripts/ext/blackfire_darwin.sh @@ -1,5 +1,9 @@ version=${1/./} -extension_version=$2 +extension=${2} +extension_version=$(echo "$extension" | cut -d '-' -f 2) +if [ "$extension_version" = "blackfire" ]; then + extension_version=$(curl -sSL https://blackfire.io/docs/up-and-running/update | grep 'class="version"' | sed -e "s/ //g" | sed -n '3,3p' | cut -d '>' -f 2 | cut -d '<' -f 1) +fi ext_dir=$(php -i | grep -Ei "extension_dir => /usr" | sed -e "s|.*=> s*||") scan_dir=$(php --ini | grep additional | sed -e "s|.*: s*||") ini_file="$scan_dir/50-blackfire.ini" diff --git a/src/scripts/win32.ps1 b/src/scripts/win32.ps1 index 2c1875d9..6691bb85 100644 --- a/src/scripts/win32.ps1 +++ b/src/scripts/win32.ps1 @@ -216,13 +216,8 @@ Function Add-Pecl() { } Function Add-Blackfire() { - Param ( - [Parameter(Position = 0, Mandatory = $true)] - [ValidateNotNull()] - [ValidateLength(1, [int]::MaxValue)] - [string] - $agent_version - ) + $agent_data = Invoke-WebRequest https://blackfire.io/docs/up-and-running/update | ForEach-Object { $_.tostring() -split "[`r`n]" | Select-String '' | Select-Object -Index 0 } + $agent_version = [regex]::Matches($agent_data, '(.+)') | ForEach-Object {$_.Captures[0].Groups[1].value } $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 Expand-Archive -Path $php_dir\blackfire.zip -DestinationPath $php_dir -Force >$null 2>&1 diff --git a/src/tools.ts b/src/tools.ts index 05bdd22c..9b59a745 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -438,10 +438,7 @@ export async function addTools( switch (tool) { case 'blackfire': case 'blackfire-agent': - script += await getCommand( - os_version, - 'blackfire ' + (await utils.getBlackfireAgentVersion()) - ); + script += await getCommand(os_version, 'blackfire'); break; case 'blackfire-player': url = await getPharUrl('https://get.blackfire.io', tool, 'v', version); diff --git a/src/utils.ts b/src/utils.ts index 7fcf90a6..28173434 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -255,28 +255,3 @@ export async function suppressOutput(os_version: string): Promise { ); } } - -/** - * Function to get Blackfire version - * - * @param blackfire_version - */ -export async function getBlackfireVersion( - blackfire_version: null | undefined | string -): Promise { - switch (blackfire_version) { - case null: - case undefined: - case '': - return '1.31.0'; - default: - return blackfire_version; - } -} - -/** - * Function to get Blackfire Agent version - */ -export async function getBlackfireAgentVersion(): Promise { - return '1.32.0'; -}