mirror of
https://github.com/shivammathur/setup-php.git
synced 2024-11-22 03:41:06 +07:00
Merge pull request #193 from jaapio/feature/ext-blackfire
🎉 Add blackfire extenstion
This commit is contained in:
commit
bbdc4e3b67
@ -107,6 +107,8 @@ with:
|
||||
extensions: xdebug-beta
|
||||
```
|
||||
|
||||
- Blackfire PHP extension is available for install.
|
||||
|
||||
- Extensions which cannot be installed gracefully leave an error message in the logs, the action is not interrupted.
|
||||
|
||||
## :wrench: Tools Support
|
||||
@ -489,6 +491,7 @@ Examples for setting up this GitHub Action with different PHP Frameworks/Package
|
||||
|Yii2 Starter Kit with `MySQL`|`ubuntu`|[yii2-mysql.yml](./examples/yii2-mysql.yml "GitHub Action for Yii2 Starter Kit with MySQL")|
|
||||
|Yii2 Starter Kit with `PostgreSQL`|`ubuntu`|[yii2-postgres.yml](./examples/yii2-postgres.yml "GitHub Action for Yii2 Starter Kit with PostgreSQL")|
|
||||
|Zend Framework|`macOS`, `ubuntu` and `windows`|[zend-framework.yml](./examples/zend-framework.yml "GitHub Action for Zend Framework")|
|
||||
|Blackfire|`macOS`, `ubuntu` and `windows`|[blackfire.yml](./examples/blackfire.yml "GitHub Action using blackfire")|
|
||||
|
||||
## :scroll: License
|
||||
|
||||
|
@ -25,6 +25,12 @@ describe('Extension tests', () => {
|
||||
|
||||
win32 = await extensions.addExtension('xdebug', '7.2', 'fedora');
|
||||
expect(win32).toContain('Platform fedora is not supported');
|
||||
|
||||
win32 = await extensions.addExtension('blackfire', '7.3', 'win32');
|
||||
expect(win32).toContain('blackfire.ps1 73');
|
||||
|
||||
win32 = await extensions.addExtension('blackfire-1.31.0', '7.3', 'win32');
|
||||
expect(win32).toContain('blackfire.ps1 73 1.31.0');
|
||||
});
|
||||
|
||||
it('checking addExtensionOnLinux', async () => {
|
||||
@ -63,6 +69,12 @@ describe('Extension tests', () => {
|
||||
linux = await extensions.addExtension('phalcon3, phalcon4', '7.3', 'linux');
|
||||
expect(linux).toContain('phalcon.sh phalcon3 7.3');
|
||||
expect(linux).toContain('phalcon.sh phalcon4 7.3');
|
||||
|
||||
linux = await extensions.addExtension('blackfire', '7.3', 'linux');
|
||||
expect(linux).toContain('blackfire.sh 7.3 73');
|
||||
|
||||
linux = await extensions.addExtension('blackfire-1.31.0', '7.3', 'linux');
|
||||
expect(linux).toContain('blackfire.sh 7.3 73 1.31.0');
|
||||
});
|
||||
|
||||
it('checking addExtensionOnDarwin', async () => {
|
||||
@ -120,6 +132,12 @@ describe('Extension tests', () => {
|
||||
expect(darwin).toContain('brew install pkg-config imagemagick');
|
||||
expect(darwin).toContain('sudo pecl install -f imagick');
|
||||
|
||||
darwin = await extensions.addExtension('blackfire', '7.3', 'darwin');
|
||||
expect(darwin).toContain('blackfire_darwin.sh 7.3 73');
|
||||
|
||||
darwin = await extensions.addExtension('blackfire-1.31.0', '7.3', 'darwin');
|
||||
expect(darwin).toContain('blackfire_darwin.sh 7.3 73 1.31.0');
|
||||
|
||||
darwin = await extensions.addExtension(
|
||||
'does_not_exist',
|
||||
'7.2',
|
||||
|
@ -161,4 +161,11 @@ describe('Utils tests', () => {
|
||||
'Platform fedora is not supported'
|
||||
);
|
||||
});
|
||||
|
||||
it('checking getMinorVersion', async () => {
|
||||
expect(await utils.getMinorVersion('7.14.0')).toEqual('7.14');
|
||||
expect(await utils.getMinorVersion('7.4')).toEqual('7.4');
|
||||
expect(await utils.getMinorVersion('7.4.1')).toEqual('7.4');
|
||||
expect(await utils.getMinorVersion('7.aa')).toEqual('7.aa');
|
||||
});
|
||||
});
|
||||
|
47
dist/index.js
vendored
47
dist/index.js
vendored
@ -1247,6 +1247,17 @@ function suppressOutput(os_version) {
|
||||
});
|
||||
}
|
||||
exports.suppressOutput = suppressOutput;
|
||||
function getMinorVersion(version) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const regex = /^\d+\.\d+/;
|
||||
const match = version.match(regex);
|
||||
if (match === null) {
|
||||
return version;
|
||||
}
|
||||
return match[0];
|
||||
});
|
||||
}
|
||||
exports.getMinorVersion = getMinorVersion;
|
||||
|
||||
|
||||
/***/ }),
|
||||
@ -2706,6 +2717,18 @@ function addExtensionDarwin(extension_csv, version, pipe) {
|
||||
const prefix = yield utils.getExtensionPrefix(ext_name);
|
||||
let install_command = '';
|
||||
switch (true) {
|
||||
case /^blackfire(-\d+\.\d+\.\d+)?$/.test(extension):
|
||||
script +=
|
||||
'\nsh ' +
|
||||
path.join(__dirname, '../src/scripts/ext/blackfire_darwin.sh') +
|
||||
' ' +
|
||||
version +
|
||||
' ' +
|
||||
(yield utils.getMinorVersion(version)).replace('.', '');
|
||||
if (ext_version) {
|
||||
script += ' ' + ext_version;
|
||||
}
|
||||
return;
|
||||
// match pre-release versions
|
||||
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
|
||||
script +=
|
||||
@ -2787,6 +2810,17 @@ function addExtensionWindows(extension_csv, version, pipe) {
|
||||
const version_extension = version + extension;
|
||||
let matches;
|
||||
switch (true) {
|
||||
// match blackfire...blackfire-1.31.0
|
||||
case /^blackfire(-\d+\.\d+\.\d+)?$/.test(extension):
|
||||
script +=
|
||||
'\n& ' +
|
||||
path.join(__dirname, '../src/scripts/ext/blackfire.ps1') +
|
||||
' ' +
|
||||
(yield utils.getMinorVersion(version)).replace('.', '');
|
||||
if (ext_version) {
|
||||
script += ' ' + ext_version;
|
||||
}
|
||||
return;
|
||||
// match pre-release versions
|
||||
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
|
||||
script += '\nAdd-Extension ' + ext_name + ' ' + ext_version;
|
||||
@ -2840,6 +2874,19 @@ function addExtensionLinux(extension_csv, version, pipe) {
|
||||
const prefix = yield utils.getExtensionPrefix(ext_name);
|
||||
let install_command = '';
|
||||
switch (true) {
|
||||
// match blackfire... blackfire-1.31.0
|
||||
case /^blackfire(-\d+\.\d+\.\d+)?$/.test(extension):
|
||||
script +=
|
||||
'\nsh ' +
|
||||
path.join(__dirname, '../src/scripts/ext/blackfire.sh') +
|
||||
' ' +
|
||||
version +
|
||||
' ' +
|
||||
(yield utils.getMinorVersion(version)).replace('.', '');
|
||||
if (ext_version) {
|
||||
script += ' ' + ext_version;
|
||||
}
|
||||
return;
|
||||
// match pre-release versions
|
||||
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
|
||||
script +=
|
||||
|
32
examples/blackfire.yml
Normal file
32
examples/blackfire.yml
Normal file
@ -0,0 +1,32 @@
|
||||
# GitHub Action for blackfire
|
||||
name: Profiling with blackfire
|
||||
on: [push, pull_request]
|
||||
jobs:
|
||||
bedrock:
|
||||
name: Blackfire (PHP ${{ matrix.php-versions }})
|
||||
runs-on: ${{ matrix.operating-system }}
|
||||
services:
|
||||
blackfire:
|
||||
image: blackfire/blackfire
|
||||
ports:
|
||||
- 8707:8707
|
||||
env:
|
||||
BLACKFIRE_SERVER_ID: "<id>"
|
||||
BLACKFIRE_SERVER_TOKEN: "<token>"
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
operating-system: [ubuntu-latest, windows-latest, macos-latest]
|
||||
php-versions: ['7.1', '7.2', '7.3', '7.4']
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Setup PHP, with composer and extensions
|
||||
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
|
||||
with:
|
||||
php-version: ${{ matrix.php-versions }}
|
||||
extensions: blackfire-1.30.0
|
||||
ini-values: blackfire.agent_socket=tcp://localhost:8707
|
||||
- name: Profile
|
||||
# Note that blackfire agent is not installed. So an implementation with the sdk is required!
|
||||
run: php your-blackfire-sdk-script.php
|
@ -22,6 +22,19 @@ export async function addExtensionDarwin(
|
||||
const prefix = await utils.getExtensionPrefix(ext_name);
|
||||
let install_command = '';
|
||||
switch (true) {
|
||||
case /^blackfire(-\d+\.\d+\.\d+)?$/.test(extension):
|
||||
script +=
|
||||
'\nsh ' +
|
||||
path.join(__dirname, '../src/scripts/ext/blackfire_darwin.sh') +
|
||||
' ' +
|
||||
version +
|
||||
' ' +
|
||||
(await utils.getMinorVersion(version)).replace('.', '');
|
||||
|
||||
if (ext_version) {
|
||||
script += ' ' + ext_version;
|
||||
}
|
||||
return;
|
||||
// match pre-release versions
|
||||
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
|
||||
script +=
|
||||
@ -103,6 +116,18 @@ export async function addExtensionWindows(
|
||||
const version_extension: string = version + extension;
|
||||
let matches: RegExpExecArray;
|
||||
switch (true) {
|
||||
// match blackfire...blackfire-1.31.0
|
||||
case /^blackfire(-\d+\.\d+\.\d+)?$/.test(extension):
|
||||
script +=
|
||||
'\n& ' +
|
||||
path.join(__dirname, '../src/scripts/ext/blackfire.ps1') +
|
||||
' ' +
|
||||
(await utils.getMinorVersion(version)).replace('.', '');
|
||||
|
||||
if (ext_version) {
|
||||
script += ' ' + ext_version;
|
||||
}
|
||||
return;
|
||||
// match pre-release versions
|
||||
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
|
||||
script += '\nAdd-Extension ' + ext_name + ' ' + ext_version;
|
||||
@ -160,6 +185,20 @@ export async function addExtensionLinux(
|
||||
const prefix = await utils.getExtensionPrefix(ext_name);
|
||||
let install_command = '';
|
||||
switch (true) {
|
||||
// match blackfire... blackfire-1.31.0
|
||||
case /^blackfire(-\d+\.\d+\.\d+)?$/.test(extension):
|
||||
script +=
|
||||
'\nsh ' +
|
||||
path.join(__dirname, '../src/scripts/ext/blackfire.sh') +
|
||||
' ' +
|
||||
version +
|
||||
' ' +
|
||||
(await utils.getMinorVersion(version)).replace('.', '');
|
||||
|
||||
if (ext_version) {
|
||||
script += ' ' + ext_version;
|
||||
}
|
||||
return;
|
||||
// match pre-release versions
|
||||
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
|
||||
script +=
|
||||
|
27
src/scripts/ext/blackfire.ps1
Normal file
27
src/scripts/ext/blackfire.ps1
Normal file
@ -0,0 +1,27 @@
|
||||
Param (
|
||||
[Parameter(Position = 0, Mandatory = $true)]
|
||||
[ValidateNotNull()]
|
||||
[string]
|
||||
$phpversion,
|
||||
[Parameter(Position = 1, Mandatory = $true)]
|
||||
[ValidateNotNull()]
|
||||
[ValidateLength(1, [int]::MaxValue)]
|
||||
[string]
|
||||
$version = '1.31.0'
|
||||
)
|
||||
|
||||
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)
|
||||
$php_dir = 'C:\tools\php'
|
||||
$ext_dir = $php_dir + '\ext'
|
||||
|
||||
Install-Blackfire
|
||||
|
23
src/scripts/ext/blackfire.sh
Normal file
23
src/scripts/ext/blackfire.sh
Normal file
@ -0,0 +1,23 @@
|
||||
add_log() {
|
||||
mark=$1
|
||||
subject=$2
|
||||
message=$3
|
||||
if [ "$mark" = "$tick" ]; then
|
||||
printf "\033[32;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message"
|
||||
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
|
||||
}
|
||||
|
||||
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"
|
||||
|
23
src/scripts/ext/blackfire_darwin.sh
Normal file
23
src/scripts/ext/blackfire_darwin.sh
Normal file
@ -0,0 +1,23 @@
|
||||
# Function to log result of a operation
|
||||
add_log() {
|
||||
mark=$1
|
||||
subject=$2
|
||||
message=$3
|
||||
if [ "$mark" = "$tick" ]; then
|
||||
printf "\033[32;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message"
|
||||
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"
|
11
src/utils.ts
11
src/utils.ts
@ -261,3 +261,14 @@ export async function suppressOutput(os_version: string): Promise<string> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function getMinorVersion(version: string): Promise<string> {
|
||||
const regex = /^\d+\.\d+/;
|
||||
const match = version.match(regex);
|
||||
|
||||
if (match === null) {
|
||||
return version;
|
||||
}
|
||||
|
||||
return match[0];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user