mirror of
https://github.com/shivammathur/setup-php.git
synced 2024-11-22 20:01:06 +07:00
Fix and refactor ext-blackfire
This commit is contained in:
parent
bbdc4e3b67
commit
84e88e382f
@ -27,10 +27,10 @@ describe('Extension tests', () => {
|
|||||||
expect(win32).toContain('Platform fedora is not supported');
|
expect(win32).toContain('Platform fedora is not supported');
|
||||||
|
|
||||||
win32 = await extensions.addExtension('blackfire', '7.3', 'win32');
|
win32 = await extensions.addExtension('blackfire', '7.3', 'win32');
|
||||||
expect(win32).toContain('blackfire.ps1 73');
|
expect(win32).toContain('blackfire.ps1 7.3 1.31.0');
|
||||||
|
|
||||||
win32 = await extensions.addExtension('blackfire-1.31.0', '7.3', 'win32');
|
win32 = await extensions.addExtension('blackfire-1.31.0', '7.3', 'win32');
|
||||||
expect(win32).toContain('blackfire.ps1 73 1.31.0');
|
expect(win32).toContain('blackfire.ps1 7.3 1.31.0');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('checking addExtensionOnLinux', async () => {
|
it('checking addExtensionOnLinux', async () => {
|
||||||
@ -71,10 +71,10 @@ describe('Extension tests', () => {
|
|||||||
expect(linux).toContain('phalcon.sh phalcon4 7.3');
|
expect(linux).toContain('phalcon.sh phalcon4 7.3');
|
||||||
|
|
||||||
linux = await extensions.addExtension('blackfire', '7.3', 'linux');
|
linux = await extensions.addExtension('blackfire', '7.3', 'linux');
|
||||||
expect(linux).toContain('blackfire.sh 7.3 73');
|
expect(linux).toContain('blackfire.sh 7.3 1.31.0');
|
||||||
|
|
||||||
linux = await extensions.addExtension('blackfire-1.31.0', '7.3', 'linux');
|
linux = await extensions.addExtension('blackfire-1.31.0', '7.3', 'linux');
|
||||||
expect(linux).toContain('blackfire.sh 7.3 73 1.31.0');
|
expect(linux).toContain('blackfire.sh 7.3 1.31.0');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('checking addExtensionOnDarwin', async () => {
|
it('checking addExtensionOnDarwin', async () => {
|
||||||
@ -133,10 +133,10 @@ describe('Extension tests', () => {
|
|||||||
expect(darwin).toContain('sudo pecl install -f imagick');
|
expect(darwin).toContain('sudo pecl install -f imagick');
|
||||||
|
|
||||||
darwin = await extensions.addExtension('blackfire', '7.3', 'darwin');
|
darwin = await extensions.addExtension('blackfire', '7.3', 'darwin');
|
||||||
expect(darwin).toContain('blackfire_darwin.sh 7.3 73');
|
expect(darwin).toContain('blackfire_darwin.sh 7.3 1.31.0');
|
||||||
|
|
||||||
darwin = await extensions.addExtension('blackfire-1.31.0', '7.3', 'darwin');
|
darwin = await extensions.addExtension('blackfire-1.31.0', '7.3', 'darwin');
|
||||||
expect(darwin).toContain('blackfire_darwin.sh 7.3 73 1.31.0');
|
expect(darwin).toContain('blackfire_darwin.sh 7.3 1.31.0');
|
||||||
|
|
||||||
darwin = await extensions.addExtension(
|
darwin = await extensions.addExtension(
|
||||||
'does_not_exist',
|
'does_not_exist',
|
||||||
|
@ -162,10 +162,10 @@ describe('Utils tests', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('checking getMinorVersion', async () => {
|
it('checking getBlackfireVersion', async () => {
|
||||||
expect(await utils.getMinorVersion('7.14.0')).toEqual('7.14');
|
expect(await utils.getBlackfireVersion('')).toEqual('1.31.0');
|
||||||
expect(await utils.getMinorVersion('7.4')).toEqual('7.4');
|
expect(await utils.getBlackfireVersion(undefined)).toEqual('1.31.0');
|
||||||
expect(await utils.getMinorVersion('7.4.1')).toEqual('7.4');
|
expect(await utils.getBlackfireVersion(null)).toEqual('1.31.0');
|
||||||
expect(await utils.getMinorVersion('7.aa')).toEqual('7.aa');
|
expect(await utils.getBlackfireVersion('1.32.0')).toEqual('1.32.0');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
56
dist/index.js
vendored
56
dist/index.js
vendored
@ -1247,17 +1247,24 @@ function suppressOutput(os_version) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.suppressOutput = suppressOutput;
|
exports.suppressOutput = suppressOutput;
|
||||||
function getMinorVersion(version) {
|
/**
|
||||||
|
* Function to get Blackfire version
|
||||||
|
*
|
||||||
|
* @param blackfire_version
|
||||||
|
*/
|
||||||
|
function getBlackfireVersion(blackfire_version) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const regex = /^\d+\.\d+/;
|
switch (blackfire_version) {
|
||||||
const match = version.match(regex);
|
case null:
|
||||||
if (match === null) {
|
case undefined:
|
||||||
return version;
|
case '':
|
||||||
|
return '1.31.0';
|
||||||
|
default:
|
||||||
|
return blackfire_version;
|
||||||
}
|
}
|
||||||
return match[0];
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.getMinorVersion = getMinorVersion;
|
exports.getBlackfireVersion = getBlackfireVersion;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
@ -2717,18 +2724,15 @@ function addExtensionDarwin(extension_csv, version, pipe) {
|
|||||||
const prefix = yield utils.getExtensionPrefix(ext_name);
|
const prefix = yield utils.getExtensionPrefix(ext_name);
|
||||||
let install_command = '';
|
let install_command = '';
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case /^blackfire(-\d+\.\d+\.\d+)?$/.test(extension):
|
case /^(5\.[3-6]|7\.[0-4])blackfire(-\d+\.\d+\.\d+)?$/.test(version_extension):
|
||||||
script +=
|
install_command =
|
||||||
'\nsh ' +
|
'bash ' +
|
||||||
path.join(__dirname, '../src/scripts/ext/blackfire_darwin.sh') +
|
path.join(__dirname, '../src/scripts/ext/blackfire_darwin.sh') +
|
||||||
' ' +
|
' ' +
|
||||||
version +
|
version +
|
||||||
' ' +
|
' ' +
|
||||||
(yield utils.getMinorVersion(version)).replace('.', '');
|
(yield utils.getBlackfireVersion(ext_version));
|
||||||
if (ext_version) {
|
break;
|
||||||
script += ' ' + ext_version;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
// match pre-release versions
|
// match pre-release versions
|
||||||
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
|
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
|
||||||
script +=
|
script +=
|
||||||
@ -2811,15 +2815,14 @@ function addExtensionWindows(extension_csv, version, pipe) {
|
|||||||
let matches;
|
let matches;
|
||||||
switch (true) {
|
switch (true) {
|
||||||
// match blackfire...blackfire-1.31.0
|
// match blackfire...blackfire-1.31.0
|
||||||
case /^blackfire(-\d+\.\d+\.\d+)?$/.test(extension):
|
case /^(5\.[4-6]|7\.[0-4])blackfire(-\d+\.\d+\.\d+)?$/.test(version_extension):
|
||||||
script +=
|
script +=
|
||||||
'\n& ' +
|
'\n& ' +
|
||||||
path.join(__dirname, '../src/scripts/ext/blackfire.ps1') +
|
path.join(__dirname, '../src/scripts/ext/blackfire.ps1') +
|
||||||
' ' +
|
' ' +
|
||||||
(yield utils.getMinorVersion(version)).replace('.', '');
|
version +
|
||||||
if (ext_version) {
|
' ' +
|
||||||
script += ' ' + ext_version;
|
(yield utils.getBlackfireVersion(ext_version));
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
// match pre-release versions
|
// match pre-release versions
|
||||||
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
|
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
|
||||||
@ -2875,18 +2878,15 @@ function addExtensionLinux(extension_csv, version, pipe) {
|
|||||||
let install_command = '';
|
let install_command = '';
|
||||||
switch (true) {
|
switch (true) {
|
||||||
// match blackfire... blackfire-1.31.0
|
// match blackfire... blackfire-1.31.0
|
||||||
case /^blackfire(-\d+\.\d+\.\d+)?$/.test(extension):
|
case /^(5\.[3-6]|7\.[0-4])blackfire(-\d+\.\d+\.\d+)?$/.test(version_extension):
|
||||||
script +=
|
install_command =
|
||||||
'\nsh ' +
|
'bash ' +
|
||||||
path.join(__dirname, '../src/scripts/ext/blackfire.sh') +
|
path.join(__dirname, '../src/scripts/ext/blackfire.sh') +
|
||||||
' ' +
|
' ' +
|
||||||
version +
|
version +
|
||||||
' ' +
|
' ' +
|
||||||
(yield utils.getMinorVersion(version)).replace('.', '');
|
(yield utils.getBlackfireVersion(ext_version));
|
||||||
if (ext_version) {
|
break;
|
||||||
script += ' ' + ext_version;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
// match pre-release versions
|
// match pre-release versions
|
||||||
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
|
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
|
||||||
script +=
|
script +=
|
||||||
|
@ -22,19 +22,17 @@ export async function addExtensionDarwin(
|
|||||||
const prefix = await utils.getExtensionPrefix(ext_name);
|
const prefix = await utils.getExtensionPrefix(ext_name);
|
||||||
let install_command = '';
|
let install_command = '';
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case /^blackfire(-\d+\.\d+\.\d+)?$/.test(extension):
|
case /^(5\.[3-6]|7\.[0-4])blackfire(-\d+\.\d+\.\d+)?$/.test(
|
||||||
script +=
|
version_extension
|
||||||
'\nsh ' +
|
):
|
||||||
|
install_command =
|
||||||
|
'bash ' +
|
||||||
path.join(__dirname, '../src/scripts/ext/blackfire_darwin.sh') +
|
path.join(__dirname, '../src/scripts/ext/blackfire_darwin.sh') +
|
||||||
' ' +
|
' ' +
|
||||||
version +
|
version +
|
||||||
' ' +
|
' ' +
|
||||||
(await utils.getMinorVersion(version)).replace('.', '');
|
(await utils.getBlackfireVersion(ext_version));
|
||||||
|
break;
|
||||||
if (ext_version) {
|
|
||||||
script += ' ' + ext_version;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
// match pre-release versions
|
// match pre-release versions
|
||||||
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
|
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
|
||||||
script +=
|
script +=
|
||||||
@ -117,16 +115,16 @@ export async function addExtensionWindows(
|
|||||||
let matches: RegExpExecArray;
|
let matches: RegExpExecArray;
|
||||||
switch (true) {
|
switch (true) {
|
||||||
// match blackfire...blackfire-1.31.0
|
// match blackfire...blackfire-1.31.0
|
||||||
case /^blackfire(-\d+\.\d+\.\d+)?$/.test(extension):
|
case /^(5\.[4-6]|7\.[0-4])blackfire(-\d+\.\d+\.\d+)?$/.test(
|
||||||
|
version_extension
|
||||||
|
):
|
||||||
script +=
|
script +=
|
||||||
'\n& ' +
|
'\n& ' +
|
||||||
path.join(__dirname, '../src/scripts/ext/blackfire.ps1') +
|
path.join(__dirname, '../src/scripts/ext/blackfire.ps1') +
|
||||||
' ' +
|
' ' +
|
||||||
(await utils.getMinorVersion(version)).replace('.', '');
|
version +
|
||||||
|
' ' +
|
||||||
if (ext_version) {
|
(await utils.getBlackfireVersion(ext_version));
|
||||||
script += ' ' + ext_version;
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
// match pre-release versions
|
// match pre-release versions
|
||||||
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
|
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
|
||||||
@ -186,19 +184,17 @@ export async function addExtensionLinux(
|
|||||||
let install_command = '';
|
let install_command = '';
|
||||||
switch (true) {
|
switch (true) {
|
||||||
// match blackfire... blackfire-1.31.0
|
// match blackfire... blackfire-1.31.0
|
||||||
case /^blackfire(-\d+\.\d+\.\d+)?$/.test(extension):
|
case /^(5\.[3-6]|7\.[0-4])blackfire(-\d+\.\d+\.\d+)?$/.test(
|
||||||
script +=
|
version_extension
|
||||||
'\nsh ' +
|
):
|
||||||
|
install_command =
|
||||||
|
'bash ' +
|
||||||
path.join(__dirname, '../src/scripts/ext/blackfire.sh') +
|
path.join(__dirname, '../src/scripts/ext/blackfire.sh') +
|
||||||
' ' +
|
' ' +
|
||||||
version +
|
version +
|
||||||
' ' +
|
' ' +
|
||||||
(await utils.getMinorVersion(version)).replace('.', '');
|
(await utils.getBlackfireVersion(ext_version));
|
||||||
|
break;
|
||||||
if (ext_version) {
|
|
||||||
script += ' ' + ext_version;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
// match pre-release versions
|
// match pre-release versions
|
||||||
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
|
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
|
||||||
script +=
|
script +=
|
||||||
|
@ -2,26 +2,29 @@ Param (
|
|||||||
[Parameter(Position = 0, Mandatory = $true)]
|
[Parameter(Position = 0, Mandatory = $true)]
|
||||||
[ValidateNotNull()]
|
[ValidateNotNull()]
|
||||||
[string]
|
[string]
|
||||||
$phpversion,
|
$version,
|
||||||
[Parameter(Position = 1, Mandatory = $true)]
|
[Parameter(Position = 2, Mandatory = $false)]
|
||||||
[ValidateNotNull()]
|
[ValidateNotNull()]
|
||||||
[ValidateLength(1, [int]::MaxValue)]
|
|
||||||
[string]
|
[string]
|
||||||
$version = '1.31.0'
|
$extension_version
|
||||||
)
|
)
|
||||||
|
|
||||||
Function Install-Blackfire() {
|
|
||||||
$installed = Get-Php -Path $php_dir
|
|
||||||
$nts = if (!$installed.ThreadSafe) { "_nts" } else { "" }
|
|
||||||
Invoke-WebRequest -UseBasicParsing -Uri "https://packages.blackfire.io/binaries/blackfire-php/${version}/blackfire-php-windows_x64-php-${phpversion}${nts}.dll" -OutFile $ENV:RUNNER_TOOL_CACHE\blackfire.dll > $null 2>&1
|
|
||||||
Copy-Item -Path "$ENV:RUNNER_TOOL_CACHE\blackfire.dll" -Destination "$ext_dir\blackfire.dll"
|
|
||||||
Enable-PhpExtension -Extension blackfire -Path $php_dir
|
|
||||||
printf "\033[%s;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "32" $tick "Blackfire" "Installed and enabled"
|
|
||||||
}
|
|
||||||
|
|
||||||
$tick = ([char]8730)
|
$tick = ([char]8730)
|
||||||
$php_dir = 'C:\tools\php'
|
$php_dir = 'C:\tools\php'
|
||||||
$ext_dir = $php_dir + '\ext'
|
$ext_dir = $php_dir + '\ext'
|
||||||
|
$arch='x64'
|
||||||
|
if ($version -lt '7.0') { $arch='x86' }
|
||||||
|
$version = $version.replace('.', '')
|
||||||
|
|
||||||
Install-Blackfire
|
if (Test-Path $ext_dir\blackfire.dll) {
|
||||||
|
Enable-PhpExtension -Extension blackfire -Path $php_dir
|
||||||
|
$status="Enabled"
|
||||||
|
} else {
|
||||||
|
$installed = Get-Php -Path $php_dir
|
||||||
|
$nts = if (!$installed.ThreadSafe) { "_nts" } else { "" }
|
||||||
|
Invoke-WebRequest -UseBasicParsing -Uri "https://packages.blackfire.io/binaries/blackfire-php/${extension_version}/blackfire-php-windows_${arch}-php-${version}${nts}.dll" -OutFile $ext_dir\blackfire.dll > $null 2>&1
|
||||||
|
Enable-PhpExtension -Extension blackfire -Path $php_dir
|
||||||
|
$status="Installed and enabled"
|
||||||
|
}
|
||||||
|
printf "\033[%s;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "32" $tick "blackfire" "$status"
|
||||||
|
|
||||||
|
@ -1,23 +1,7 @@
|
|||||||
add_log() {
|
version=${1/./}
|
||||||
mark=$1
|
extension_version=$2
|
||||||
subject=$2
|
ext_dir=$(php -i | grep "extension_dir => /" | sed -e "s|.*=> s*||")
|
||||||
message=$3
|
scan_dir=$(php --ini | grep additional | sed -e "s|.*: s*||")
|
||||||
if [ "$mark" = "$tick" ]; then
|
ini_file="$scan_dir/50-blackfire.ini"
|
||||||
printf "\033[32;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message"
|
sudo curl -o $ext_dir/blackfire.so -SL https://packages.blackfire.io/binaries/blackfire-php/$extension_version/blackfire-php-linux_amd64-php-$version.so
|
||||||
else
|
echo "extension=blackfire.so" | sudo tee -a "$ini_file"
|
||||||
printf "\033[31;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
phpversion=$2
|
|
||||||
blackfireVersion=${3:-1.31.0}
|
|
||||||
ini_file="/etc/php/$1/cli/conf.d/50-blackfire.ini"
|
|
||||||
tick="✓"
|
|
||||||
cross="✗"
|
|
||||||
|
|
||||||
(curl -A "Github action" -o /tmp/blackfire.so -L -s https://packages.blackfire.io/binaries/blackfire-php/$blackfireVersion/blackfire-php-linux_amd64-php-$phpversion.so >/dev/null 2>&1 && \
|
|
||||||
sudo mv /tmp/blackfire.so $(php -r "echo ini_get ('extension_dir');")/blackfire.so >/dev/null 2>&1 && \
|
|
||||||
echo "extension=blackfire.so" | sudo tee -a "$ini_file" >/dev/null 2>&1 && \
|
|
||||||
add_log "$tick" "blackfire" "Installed and enabled") || \
|
|
||||||
add_log "$cross" "blackfire" "Could not install blackfire"
|
|
||||||
|
|
@ -1,23 +1,7 @@
|
|||||||
# Function to log result of a operation
|
version=${1/./}
|
||||||
add_log() {
|
extension_version=$2
|
||||||
mark=$1
|
ext_dir=$(php -i | grep -Ei "extension_dir => /usr" | sed -e "s|.*=> s*||")
|
||||||
subject=$2
|
scan_dir=$(php --ini | grep additional | sed -e "s|.*: s*||")
|
||||||
message=$3
|
ini_file="$scan_dir/50-blackfire.ini"
|
||||||
if [ "$mark" = "$tick" ]; then
|
sudo curl -o $ext_dir/blackfire.so -SL https://packages.blackfire.io/binaries/blackfire-php/$extension_version/blackfire-php-darwin_amd64-php-$version.so
|
||||||
printf "\033[32;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message"
|
echo "extension=blackfire.so" | sudo tee -a "$ini_file"
|
||||||
else
|
|
||||||
printf "\033[31;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
tick="✓"
|
|
||||||
cross="✗"
|
|
||||||
phpversion=$2
|
|
||||||
blackfireVersion=${3:-1.31.0}
|
|
||||||
ini_file=$(php -d "date.timezone=UTC" --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g")
|
|
||||||
|
|
||||||
(curl -A "Github action" -o /tmp/blackfire.so -L -s https://packages.blackfire.io/binaries/blackfire-php/$blackfireVersion/blackfire-php-darwin_amd64-php-$phpversion.so && \
|
|
||||||
sudo mv /tmp/blackfire.so $(php -r "echo ini_get ('extension_dir');")/blackfire.so && \
|
|
||||||
echo "extension=blackfire.so" >>"$ini_file" && \
|
|
||||||
add_log "$tick" "blackfire" "Installed and enabled") || \
|
|
||||||
add_log "$cross" "blackfire" "Could not install blackfire"
|
|
23
src/utils.ts
23
src/utils.ts
@ -262,13 +262,20 @@ export async function suppressOutput(os_version: string): Promise<string> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getMinorVersion(version: string): Promise<string> {
|
/**
|
||||||
const regex = /^\d+\.\d+/;
|
* Function to get Blackfire version
|
||||||
const match = version.match(regex);
|
*
|
||||||
|
* @param blackfire_version
|
||||||
if (match === null) {
|
*/
|
||||||
return version;
|
export async function getBlackfireVersion(
|
||||||
|
blackfire_version: null | undefined | string
|
||||||
|
): Promise<string> {
|
||||||
|
switch (blackfire_version) {
|
||||||
|
case null:
|
||||||
|
case undefined:
|
||||||
|
case '':
|
||||||
|
return '1.31.0';
|
||||||
|
default:
|
||||||
|
return blackfire_version;
|
||||||
}
|
}
|
||||||
|
|
||||||
return match[0];
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user