From 234594684c25344523a4d3fa69d689d6ada8a0e3 Mon Sep 17 00:00:00 2001
From: Graham Campbell
Date: Wed, 21 Oct 2020 22:08:40 +0100
Subject: [PATCH 01/23] PHP 8.1 supported too
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 6e942af2..a978909f 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,7 @@
-
+
From 04a9e3b56222ece8d07ce7df2297616d61de7e95 Mon Sep 17 00:00:00 2001
From: Shivam Mathur
Date: Fri, 23 Oct 2020 07:11:23 +0530
Subject: [PATCH 02/23] Update dependencies as per runner on macOS
---
src/scripts/darwin.sh | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/src/scripts/darwin.sh b/src/scripts/darwin.sh
index 5a445543..532eafaf 100644
--- a/src/scripts/darwin.sh
+++ b/src/scripts/darwin.sh
@@ -251,11 +251,23 @@ add_pecl() {
add_log "$tick" "PECL" "Found PECL $pecl_version"
}
+# Function to update dependencies.
+update_dependencies() {
+ if [[ "$version" =~ $nightly_versions ]] && [ "$runner" != "self-hosted" ]; then
+ while read -r formula; do
+ curl -o "$(brew --prefix)/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/$formula.rb" "${curl_opts[@]}" "https://raw.githubusercontent.com/Homebrew/homebrew-core/master/Formula/$formula.rb" &
+ to_wait+=( $! )
+ done < "$(brew --prefix)/Homebrew/Library/Taps/shivammathur/homebrew-php/.github/deps/${ImageOS:?}_${ImageVersion:?}"
+ wait "${to_wait[@]}"
+ fi
+}
+
# Function to setup PHP 5.6 and newer.
setup_php() {
action=$1
export HOMEBREW_NO_INSTALL_CLEANUP=TRUE
brew tap --shallow shivammathur/homebrew-php
+ update_dependencies
if brew list php@"$version" 2>/dev/null | grep -q "Error" && [ "$action" != "upgrade" ]; then
brew unlink php@"$version"
else
@@ -271,6 +283,7 @@ version=$1
dist=$2
fail_fast=$3
nodot_version=${1/./}
+nightly_versions="8.[0-1]"
old_versions="5.[3-5]"
tool_path_dir="/usr/local/bin"
curl_opts=(-sL)
From 2c29e8b9a1c056867138dc4d3e8695c158d0042f Mon Sep 17 00:00:00 2001
From: Shivam Mathur
Date: Fri, 23 Oct 2020 20:34:56 +0530
Subject: [PATCH 03/23] Fix version change if composer is a dependency
---
src/scripts/darwin.sh | 8 ++++++--
src/scripts/linux.sh | 8 ++++++--
src/scripts/win32.ps1 | 7 ++++++-
3 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/src/scripts/darwin.sh b/src/scripts/darwin.sh
index 532eafaf..8af59034 100644
--- a/src/scripts/darwin.sh
+++ b/src/scripts/darwin.sh
@@ -153,7 +153,7 @@ configure_composer() {
exit 1
fi
composer -q global config process-timeout 0
- echo "/Users/$USER/.composer/vendor/bin" >> "$GITHUB_PATH"
+ echo "$composer_bin" >> "$GITHUB_PATH"
if [ -n "$COMPOSER_TOKEN" ]; then
composer -q global config github-oauth.github.com "$COMPOSER_TOKEN"
fi
@@ -229,6 +229,9 @@ add_composertool() {
tool_version=$(get_tool_version 'echo' "$json") &&
add_log "$tick" "$tool" "Added $tool $tool_version"
) || add_log "$cross" "$tool" "Could not setup $tool"
+ if [ -e "$composer_bin/composer" ]; then
+ sudo cp -p "$tool_path_dir/composer" "$composer_bin"
+ fi
}
# Function to handle request to add phpize and php-config.
@@ -285,6 +288,7 @@ fail_fast=$3
nodot_version=${1/./}
nightly_versions="8.[0-1]"
old_versions="5.[3-5]"
+composer_bin="/Users/$USER/.composer/vendor/bin"
tool_path_dir="/usr/local/bin"
curl_opts=(-sL)
existing_version=$(php-config --version 2>/dev/null | cut -c 1-3)
@@ -318,7 +322,7 @@ sudo chmod 777 "$ini_file" "$tool_path_dir"
echo -e "date.timezone=UTC\nmemory_limit=-1" >>"$ini_file"
ext_dir=$(php -i | grep -Ei "extension_dir => /" | sed -e "s|.*=> s*||")
scan_dir=$(php --ini | grep additional | sed -e "s|.*: s*||")
-sudo mkdir -p "$ext_dir"
+sudo mkdir -m 777 -p "$ext_dir" "/Users/$USER/.composer"
semver=$(php -v | head -n 1 | cut -f 2 -d ' ')
if [[ ! "$version" =~ $old_versions ]]; then configure_pecl >/dev/null 2>&1; fi
sudo cp "$dist"/../src/configs/*.json "$RUNNER_TOOL_CACHE/"
diff --git a/src/scripts/linux.sh b/src/scripts/linux.sh
index cd1b3cc1..b939da8a 100644
--- a/src/scripts/linux.sh
+++ b/src/scripts/linux.sh
@@ -252,7 +252,7 @@ configure_composer() {
exit 1;
fi
composer -q global config process-timeout 0
- echo "/home/$USER/.composer/vendor/bin" >> "$GITHUB_PATH"
+ echo "$composer_bin" >> "$GITHUB_PATH"
if [ -n "$COMPOSER_TOKEN" ]; then
composer -q global config github-oauth.github.com "$COMPOSER_TOKEN"
fi
@@ -326,6 +326,9 @@ add_composertool() {
tool_version=$(get_tool_version 'echo' "$json") &&
add_log "$tick" "$tool" "Added $tool $tool_version"
) || add_log "$cross" "$tool" "Could not setup $tool"
+ if [ -e "$composer_bin/composer" ]; then
+ sudo cp -p "$tool_path_dir/composer" "$composer_bin"
+ fi
}
# Function to setup phpize and php-config.
@@ -430,6 +433,7 @@ debconf_fix="DEBIAN_FRONTEND=noninteractive"
github="https://github.com/shivammathur"
apt_install="sudo $debconf_fix apt-get install -y"
apt_remove="sudo $debconf_fix apt-get remove -y"
+composer_bin="/home/$USER/.composer/vendor/bin"
tool_path_dir="/usr/local/bin"
curl_opts=(-sL)
existing_version=$(php-config --version 2>/dev/null | cut -c 1-3)
@@ -446,7 +450,7 @@ fi
# Setup PHP
step_log "Setup PHP"
-sudo mkdir -p /var/run /run/php
+sudo mkdir -m 777 -p /home/"$USER"/.composer /var/run /run/php
if [ "$existing_version" != "$version" ]; then
if [ ! -e "/usr/bin/php$version" ]; then
add_php >/dev/null 2>&1
diff --git a/src/scripts/win32.ps1 b/src/scripts/win32.ps1
index e0623d82..e95a527e 100644
--- a/src/scripts/win32.ps1
+++ b/src/scripts/win32.ps1
@@ -197,7 +197,7 @@ Function Edit-ComposerConfig() {
exit 1;
}
composer -q global config process-timeout 0
- Write-Output "$env:APPDATA\Composer\vendor\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8
+ Write-Output $composer_bin | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8
if (Test-Path env:COMPOSER_TOKEN) {
composer -q global config github-oauth.github.com $env:COMPOSER_TOKEN
}
@@ -297,6 +297,9 @@ Function Add-Composertool() {
)
composer global require $prefix$release 2>&1 | out-null
$json = findstr $prefix$tool $env:APPDATA\Composer\composer.json
+ if(Test-Path $composer_bin\composer) {
+ Copy-Item -Path "$bin_dir\composer" -Destination "$composer_bin\composer" -Force
+ }
if($json) {
$tool_version = Get-ToolVersion "Write-Output" "$json"
Add-Log $tick $tool "Added $tool $tool_version"
@@ -316,6 +319,7 @@ $cross = ([char]10007)
$php_dir = 'C:\tools\php'
$ext_dir = "$php_dir\ext"
$bin_dir = $php_dir
+$composer_bin = "$env:APPDATA\Composer\vendor\bin"
$current_profile = "$env:TEMP\setup-php.ps1"
$ProgressPreference = 'SilentlyContinue'
$nightly_version = '8.[0-9]'
@@ -401,4 +405,5 @@ if($version -lt "5.5") {
}
Update-PhpCAInfo -Path $php_dir -Source $cert_source
Copy-Item -Path $dist\..\src\configs\*.json -Destination $env:RUNNER_TOOL_CACHE
+New-Item -ItemType Directory -Path $composer_bin -Force 2>&1 | Out-Null
Add-Log $tick "PHP" "$status PHP $($installed.FullVersion)"
From 87e62cbb7f1f196fda82cb871c31d8a6c51387d9 Mon Sep 17 00:00:00 2001
From: Shivam Mathur
Date: Sun, 25 Oct 2020 00:55:01 +0530
Subject: [PATCH 04/23] Fix composer version for prestissimo &
composer-prefetcher to v1
---
__tests__/tools.test.ts | 15 +++++----------
dist/index.js | 8 ++++++--
src/tools.ts | 8 ++++++--
3 files changed, 17 insertions(+), 14 deletions(-)
diff --git a/__tests__/tools.test.ts b/__tests__/tools.test.ts
index 632724e0..9b527ead 100644
--- a/__tests__/tools.test.ts
+++ b/__tests__/tools.test.ts
@@ -228,6 +228,9 @@ describe('Tools tests', () => {
expect(
await tools.addComposer(['a', 'b', 'c', 'composer:v2'])
).toStrictEqual(['composer:2', 'a', 'b', 'c']);
+ expect(
+ await tools.addComposer(['hirak', 'b', 'c', 'composer:v2'])
+ ).toStrictEqual(['composer:1', 'hirak', 'b', 'c']);
});
it('checking getComposerUrl', async () => {
@@ -277,7 +280,7 @@ describe('Tools tests', () => {
it('checking getCleanedToolsList', async () => {
const tools_list: string[] = await tools.getCleanedToolsList(
- 'tool, composer:1.2.3, behat/behat, icanhazstring/composer-unused, laravel/vapor-cli, robmorgan/phinx, hirak/prestissimo, narrowspark/automatic-composer-prefetcher, phpspec/phpspec, symfony/flex'
+ 'tool, composer:1.2.3, behat/behat, icanhazstring/composer-unused, laravel/vapor-cli, robmorgan/phinx, phpspec/phpspec, symfony/flex'
);
expect(tools_list).toStrictEqual([
'composer',
@@ -286,8 +289,6 @@ describe('Tools tests', () => {
'composer-unused',
'vapor-cli',
'phinx',
- 'prestissimo',
- 'composer-prefetcher',
'phpspec',
'flex'
]);
@@ -433,7 +434,6 @@ describe('Tools tests', () => {
'blackfire',
'blackfire-player',
'composer-normalize',
- 'composer-prefetcher:1.2.3',
'composer-require-checker',
'composer-unused',
'cs2pr:1.2.3',
@@ -522,9 +522,6 @@ describe('Tools tests', () => {
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 version'
);
@@ -551,7 +548,6 @@ describe('Tools tests', () => {
'php-config',
'phpize',
'phpmd',
- 'prestissimo',
'symfony',
'wp-cli'
];
@@ -576,7 +572,6 @@ describe('Tools tests', () => {
expect(script).toContain(
'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 "--version"'
);
@@ -608,7 +603,7 @@ describe('Tools tests', () => {
);
expect(script).toContain(
- 'Add-Tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-stable.phar,https://getcomposer.org/composer-stable.phar composer'
+ 'Add-Tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-1.phar,https://getcomposer.org/composer-1.phar composer'
);
expect(script).toContain('Add-Composertool prestissimo prestissimo hirak/');
expect(script).toContain('Add-Composertool phinx phinx robmorgan/');
diff --git a/dist/index.js b/dist/index.js
index d4ab418a..67e39ec8 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -2006,11 +2006,15 @@ exports.getWpCliUrl = getWpCliUrl;
async function addComposer(tools_list) {
const regex_any = /^composer($|:.*)/;
const regex_valid = /^composer:?($|preview$|snapshot$|v?[1-2]$)/;
+ const regex_composer1_tools = /hirak|prestissimo|narrowspark|composer-prefetcher/;
const matches = tools_list.filter(tool => regex_valid.test(tool));
let composer = 'composer';
tools_list = tools_list.filter(tool => !regex_any.test(tool));
- switch (matches[0]) {
- case undefined:
+ switch (true) {
+ case regex_composer1_tools.test(tools_list.join(' ')):
+ composer = 'composer:1';
+ break;
+ case matches[0] == undefined:
break;
default:
composer = matches[matches.length - 1].replace(/v([1-2])/, '$1');
diff --git a/src/tools.ts b/src/tools.ts
index 922a1678..75aace92 100644
--- a/src/tools.ts
+++ b/src/tools.ts
@@ -281,11 +281,15 @@ export async function getWpCliUrl(version: string): Promise {
export async function addComposer(tools_list: string[]): Promise {
const regex_any = /^composer($|:.*)/;
const regex_valid = /^composer:?($|preview$|snapshot$|v?[1-2]$)/;
+ const regex_composer1_tools = /hirak|prestissimo|narrowspark|composer-prefetcher/;
const matches: string[] = tools_list.filter(tool => regex_valid.test(tool));
let composer = 'composer';
tools_list = tools_list.filter(tool => !regex_any.test(tool));
- switch (matches[0]) {
- case undefined:
+ switch (true) {
+ case regex_composer1_tools.test(tools_list.join(' ')):
+ composer = 'composer:1';
+ break;
+ case matches[0] == undefined:
break;
default:
composer = matches[matches.length - 1].replace(/v([1-2])/, '$1');
From 5d27b8f90ea9479ac7af4fcaad6b411eb19d7170 Mon Sep 17 00:00:00 2001
From: Shivam Mathur
Date: Wed, 28 Oct 2020 22:21:08 +0530
Subject: [PATCH 05/23] Use PECL directly for nightly versions
---
src/scripts/linux.sh | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/scripts/linux.sh b/src/scripts/linux.sh
index b939da8a..8224e6fe 100644
--- a/src/scripts/linux.sh
+++ b/src/scripts/linux.sh
@@ -186,8 +186,12 @@ add_extension() {
if [[ "$version" =~ 5.[4-5] ]]; then
install_command="update_lists && ${install_command/5\.[4-5]-$extension/5-$extension=$release_version}"
fi
- eval "$install_command" >/dev/null 2>&1 ||
- (update_lists && eval "$install_command" >/dev/null 2>&1) || pecl_install "$extension"
+ if [[ "$version" =~ $nightly_versions ]]; then
+ pecl_install "$extension"
+ else
+ eval "$install_command" >/dev/null 2>&1 ||
+ (update_lists && eval "$install_command" >/dev/null 2>&1) || pecl_install "$extension"
+ fi
add_extension_log "$extension" "Installed and enabled"
fi
sudo chmod 777 "$ini_file"
From 294f03454a1a38dbf189c508a2a9136b56bd40a0 Mon Sep 17 00:00:00 2001
From: Shivam Mathur
Date: Fri, 30 Oct 2020 11:28:54 +0530
Subject: [PATCH 06/23] Install VcRedist from GitHub
---
README.md | 1 +
src/scripts/win32.ps1 | 27 ++++++++++++++++++---------
2 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/README.md b/README.md
index a978909f..e4160e86 100644
--- a/README.md
+++ b/README.md
@@ -769,6 +769,7 @@ Examples of using `setup-php` with various PHP Frameworks and Packages.
## :package: Dependencies
- [Node.js dependencies](https://github.com/shivammathur/setup-php/network/dependencies "Node.js dependencies")
+- [aaronparker/VcRedist](https://github.com/aaronparker/VcRedist "VcRedist PowerShell package")
- [gplessis/dotdeb-php](https://github.com/gplessis/dotdeb-php "Packaging for end of life PHP versions")
- [mlocati/powershell-phpmanager](https://github.com/mlocati/powershell-phpmanager "Package to handle PHP on windows")
- [ppa:ondrej/php](https://launchpad.net/~ondrej/+archive/ubuntu/php "Packaging active PHP packages")
diff --git a/src/scripts/win32.ps1 b/src/scripts/win32.ps1
index e95a527e..2ccf30dc 100644
--- a/src/scripts/win32.ps1
+++ b/src/scripts/win32.ps1
@@ -79,7 +79,7 @@ Function Add-Printf {
if(Test-Path "C:\msys64\usr\bin\printf.exe") {
New-Item -Path $bin_dir\printf.exe -ItemType SymbolicLink -Value C:\msys64\usr\bin\printf.exe
} else {
- Invoke-WebRequest -UseBasicParsing -Uri "https://github.com/shivammathur/printf/releases/latest/download/printf-x64.zip" -OutFile "$bin_dir\printf.zip"
+ Invoke-WebRequest -UseBasicParsing -Uri "$github/shivammathur/printf/releases/latest/download/printf-x64.zip" -OutFile "$bin_dir\printf.zip"
Expand-Archive -Path $bin_dir\printf.zip -DestinationPath $bin_dir -Force
}
} else {
@@ -96,16 +96,24 @@ Function Get-CleanPSProfile {
Add-ToProfile $profile $current_profile.replace('\', '\\') ". $current_profile"
}
-# Function to install PhpManager.
-Function Install-PhpManager() {
- $module_path = "$bin_dir\PhpManager\PhpManager.psm1"
+# Function to install a powershell package from GitHub.
+Function Install-GitHubPackage() {
+ param(
+ [Parameter(Position = 0, Mandatory = $true)]
+ $package,
+ [Parameter(Position = 1, Mandatory = $true)]
+ $psm1_path,
+ [Parameter(Position = 2, Mandatory = $true)]
+ $url
+ )
+ $module_path = "$bin_dir\$psm1_path.psm1"
if(-not (Test-Path $module_path -PathType Leaf)) {
- $zip_file = "$bin_dir\PhpManager.zip"
- Invoke-WebRequest -UseBasicParsing -Uri 'https://github.com/mlocati/powershell-phpmanager/releases/latest/download/PhpManager.zip' -OutFile $zip_file
+ $zip_file = "$bin_dir\$package.zip"
+ Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $zip_file
Expand-Archive -Path $zip_file -DestinationPath $bin_dir -Force
}
Import-Module $module_path
- Add-ToProfile $current_profile 'powershell-phpmanager' "Import-Module $module_path"
+ Add-ToProfile $current_profile "$package-search" "Import-Module $module_path"
}
# Function to add PHP extensions.
@@ -319,6 +327,7 @@ $cross = ([char]10007)
$php_dir = 'C:\tools\php'
$ext_dir = "$php_dir\ext"
$bin_dir = $php_dir
+$github = 'https://github.com'
$composer_bin = "$env:APPDATA\Composer\vendor\bin"
$current_profile = "$env:TEMP\setup-php.ps1"
$ProgressPreference = 'SilentlyContinue'
@@ -362,7 +371,7 @@ if($env:RUNNER -eq 'self-hosted') {
Add-Printf >$null 2>&1
Step-Log "Setup PhpManager"
-Install-PhpManager >$null 2>&1
+Install-GitHubPackage PhpManager PhpManager\PhpManager "$github/mlocati/powershell-phpmanager/releases/latest/download/PhpManager.zip" >$null 2>&1
Add-Log $tick "PhpManager" "Installed"
Step-Log "Setup PHP"
@@ -375,7 +384,7 @@ if (Test-Path -LiteralPath $php_dir -PathType Container) {
$status = "Installed"
if ($null -eq $installed -or -not("$($installed.Version).".StartsWith(($version -replace '^(\d+(\.\d+)*).*', '$1.'))) -or $ts -ne $installed.ThreadSafe) {
if ($version -lt '7.0' -and (Get-InstalledModule).Name -notcontains 'VcRedist') {
- Install-Module -Name VcRedist -Force
+ Install-GitHubPackage VcRedist VcRedist-main\VcRedist\VcRedist "$github/aaronparker/VcRedist/archive/main.zip" >$null 2>&1
}
if ($version -match $nightly_version) {
Invoke-WebRequest -UseBasicParsing -Uri https://dl.bintray.com/shivammathur/php/Install-PhpNightly.ps1 -OutFile $php_dir\Install-PhpNightly.ps1 > $null 2>&1
From c8111b053ce16819ffe587729145b22b6b986f7a Mon Sep 17 00:00:00 2001
From: Shivam Mathur
Date: Fri, 30 Oct 2020 10:35:13 +0530
Subject: [PATCH 07/23] Fix blackfire-player to v1.9.3 for PHP 5.5 to PHP 7.0
---
__tests__/tools.test.ts | 15 +++++++++++++++
dist/index.js | 21 +++++++++++++++++++--
src/tools.ts | 27 ++++++++++++++++++++++++++-
3 files changed, 60 insertions(+), 3 deletions(-)
diff --git a/__tests__/tools.test.ts b/__tests__/tools.test.ts
index 9b527ead..1a6b1acf 100644
--- a/__tests__/tools.test.ts
+++ b/__tests__/tools.test.ts
@@ -187,6 +187,21 @@ describe('Tools tests', () => {
);
});
+ it('checking getBlackfirePlayerUrl', async () => {
+ expect(await tools.getBlackfirePlayerUrl('latest', '7.4')).toBe(
+ 'https://get.blackfire.io/blackfire-player.phar'
+ );
+ expect(await tools.getBlackfirePlayerUrl('latest', '5.5')).toBe(
+ 'https://get.blackfire.io/blackfire-player-v1.9.3.phar'
+ );
+ expect(await tools.getBlackfirePlayerUrl('latest', '7.0')).toBe(
+ 'https://get.blackfire.io/blackfire-player-v1.9.3.phar'
+ );
+ expect(await tools.getBlackfirePlayerUrl('1.2.3', '7.0')).toBe(
+ 'https://get.blackfire.io/blackfire-player-v1.2.3.phar'
+ );
+ });
+
it('checking getDeployerUri', async () => {
expect(await tools.getDeployerUrl('latest')).toBe(
'https://deployer.org/deployer.phar'
diff --git a/dist/index.js b/dist/index.js
index 67e39ec8..83836f34 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -1764,7 +1764,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
-exports.addTools = exports.addPackage = exports.addDevTools = exports.addArchive = exports.getCleanedToolsList = exports.getComposerUrl = exports.addComposer = exports.getWpCliUrl = exports.getSymfonyUri = exports.getDeployerUrl = exports.getPharUrl = exports.addPhive = exports.getCodeceptionUri = exports.getCodeceptionUriBuilder = exports.getUri = exports.parseTool = exports.getToolVersion = void 0;
+exports.addTools = exports.addPackage = exports.addDevTools = exports.addArchive = exports.getCleanedToolsList = exports.getComposerUrl = exports.addComposer = exports.getWpCliUrl = exports.getSymfonyUri = exports.getDeployerUrl = exports.getBlackfirePlayerUrl = exports.getPharUrl = exports.addPhive = exports.getCodeceptionUri = exports.getCodeceptionUriBuilder = exports.getUri = exports.parseTool = exports.getToolVersion = void 0;
const utils = __importStar(__webpack_require__(163));
/**
* Function to get tool version
@@ -1942,6 +1942,23 @@ async function getPharUrl(domain, tool, prefix, version) {
}
}
exports.getPharUrl = getPharUrl;
+/**
+ * Function to get blackfire player url for a PHP version.
+ *
+ * @param version
+ * @param php_version
+ */
+async function getBlackfirePlayerUrl(version, php_version) {
+ switch (true) {
+ case /5\.[5-6]|7\.0/.test(php_version) && version == 'latest':
+ version = '1.9.3';
+ break;
+ default:
+ break;
+ }
+ return await getPharUrl('https://get.blackfire.io', 'blackfire-player', 'v', version);
+}
+exports.getBlackfirePlayerUrl = getBlackfirePlayerUrl;
/**
* Function to get the Deployer url
*
@@ -2136,7 +2153,7 @@ async function addTools(tools_csv, php_version, os_version) {
script += await addPackage(tool, release, tool + '/', os_version);
break;
case 'blackfire-player':
- url = await getPharUrl('https://get.blackfire.io', tool, 'v', version);
+ url = await getBlackfirePlayerUrl(version, php_version);
script += await addArchive(tool, url, os_version, '"-V"');
break;
case 'codeception':
diff --git a/src/tools.ts b/src/tools.ts
index 75aace92..8a05a44a 100644
--- a/src/tools.ts
+++ b/src/tools.ts
@@ -203,6 +203,31 @@ export async function getPharUrl(
}
}
+/**
+ * Function to get blackfire player url for a PHP version.
+ *
+ * @param version
+ * @param php_version
+ */
+export async function getBlackfirePlayerUrl(
+ version: string,
+ php_version: string
+): Promise {
+ switch (true) {
+ case /5\.[5-6]|7\.0/.test(php_version) && version == 'latest':
+ version = '1.9.3';
+ break;
+ default:
+ break;
+ }
+ return await getPharUrl(
+ 'https://get.blackfire.io',
+ 'blackfire-player',
+ 'v',
+ version
+ );
+}
+
/**
* Function to get the Deployer url
*
@@ -454,7 +479,7 @@ export async function addTools(
script += await addPackage(tool, release, tool + '/', os_version);
break;
case 'blackfire-player':
- url = await getPharUrl('https://get.blackfire.io', tool, 'v', version);
+ url = await getBlackfirePlayerUrl(version, php_version);
script += await addArchive(tool, url, os_version, '"-V"');
break;
case 'codeception':
From f51d00d35093385491d63ab9bbab83efd02173e6 Mon Sep 17 00:00:00 2001
From: Michele Locati
Date: Fri, 30 Oct 2020 11:15:26 +0100
Subject: [PATCH 08/23] Allow installing a specific Composer version
---
__tests__/tools.test.ts | 9 +++++++++
dist/index.js | 4 ++++
src/tools.ts | 6 ++++++
3 files changed, 19 insertions(+)
diff --git a/__tests__/tools.test.ts b/__tests__/tools.test.ts
index 1a6b1acf..4bc7db4f 100644
--- a/__tests__/tools.test.ts
+++ b/__tests__/tools.test.ts
@@ -267,6 +267,15 @@ describe('Tools tests', () => {
expect(await tools.getComposerUrl('2')).toContain(
'https://getcomposer.org/composer-2.phar'
);
+ expect(await tools.getComposerUrl('1.7.2')).toContain(
+ 'https://github.com/composer/composer/releases/download/1.7.2/composer.phar'
+ );
+ expect(await tools.getComposerUrl('2.0.0-RC2')).toContain(
+ 'https://github.com/composer/composer/releases/download/2.0.0-RC2/composer.phar'
+ );
+ expect(await tools.getComposerUrl('wrong')).toContain(
+ 'https://getcomposer.org/composer-stable.phar'
+ );
});
it('checking getSymfonyUri', async () => {
diff --git a/dist/index.js b/dist/index.js
index 83836f34..a44fb254 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -2058,6 +2058,10 @@ async function getComposerUrl(version) {
case '2':
return (cache_url + 'https://getcomposer.org/composer-' + version + '.phar');
default:
+ if (/^\d+\.\d+\.\d+[\w-]*$/.test(version)) {
+ return (cache_url +
+ `https://github.com/composer/composer/releases/download/${version}/composer.phar`);
+ }
return cache_url + 'https://getcomposer.org/composer-stable.phar';
}
}
diff --git a/src/tools.ts b/src/tools.ts
index 8a05a44a..050802d4 100644
--- a/src/tools.ts
+++ b/src/tools.ts
@@ -344,6 +344,12 @@ export async function getComposerUrl(version: string): Promise {
cache_url + 'https://getcomposer.org/composer-' + version + '.phar'
);
default:
+ if (/^\d+\.\d+\.\d+[\w-]*$/.test(version)) {
+ return (
+ cache_url +
+ `https://github.com/composer/composer/releases/download/${version}/composer.phar`
+ );
+ }
return cache_url + 'https://getcomposer.org/composer-stable.phar';
}
}
From 808e74aed58c90c67bf261a16c9cd553266b3549 Mon Sep 17 00:00:00 2001
From: Michele Locati
Date: Fri, 30 Oct 2020 11:35:39 +0100
Subject: [PATCH 09/23] Adjust filtered composer version
---
__tests__/tools.test.ts | 12 ++++++++++--
dist/index.js | 4 ++--
src/tools.ts | 4 ++--
3 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/__tests__/tools.test.ts b/__tests__/tools.test.ts
index 4bc7db4f..015caf08 100644
--- a/__tests__/tools.test.ts
+++ b/__tests__/tools.test.ts
@@ -222,9 +222,17 @@ describe('Tools tests', () => {
'a',
'b'
]);
+ expect(await tools.addComposer(['a', 'b', 'composer:1.2'])).toStrictEqual([
+ 'composer',
+ 'a',
+ 'b'
+ ]);
expect(
await tools.addComposer(['a', 'b', 'composer:1.2.3'])
- ).toStrictEqual(['composer', 'a', 'b']);
+ ).toStrictEqual(['composer:1.2.3', 'a', 'b']);
+ expect(
+ await tools.addComposer(['a', 'b', 'composer:v1.2.3'])
+ ).toStrictEqual(['composer:1.2.3', 'a', 'b']);
expect(
await tools.addComposer(['a', 'b', 'composer:snapshot'])
).toStrictEqual(['composer:snapshot', 'a', 'b']);
@@ -304,7 +312,7 @@ describe('Tools tests', () => {
it('checking getCleanedToolsList', async () => {
const tools_list: string[] = await tools.getCleanedToolsList(
- 'tool, composer:1.2.3, behat/behat, icanhazstring/composer-unused, laravel/vapor-cli, robmorgan/phinx, phpspec/phpspec, symfony/flex'
+ 'tool, composer:1.2, behat/behat, icanhazstring/composer-unused, laravel/vapor-cli, robmorgan/phinx, phpspec/phpspec, symfony/flex'
);
expect(tools_list).toStrictEqual([
'composer',
diff --git a/dist/index.js b/dist/index.js
index a44fb254..a13b9c05 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -2022,7 +2022,7 @@ exports.getWpCliUrl = getWpCliUrl;
*/
async function addComposer(tools_list) {
const regex_any = /^composer($|:.*)/;
- const regex_valid = /^composer:?($|preview$|snapshot$|v?[1-2]$)/;
+ const regex_valid = /^composer:?($|preview$|snapshot$|v?[1-2]$|v?\d+\.\d+\.\d+[\w-]*$)/;
const regex_composer1_tools = /hirak|prestissimo|narrowspark|composer-prefetcher/;
const matches = tools_list.filter(tool => regex_valid.test(tool));
let composer = 'composer';
@@ -2034,7 +2034,7 @@ async function addComposer(tools_list) {
case matches[0] == undefined:
break;
default:
- composer = matches[matches.length - 1].replace(/v([1-2])/, '$1');
+ composer = matches[matches.length - 1].replace(/v(\d\S*)/, '$1');
break;
}
tools_list.unshift(composer);
diff --git a/src/tools.ts b/src/tools.ts
index 050802d4..5914099b 100644
--- a/src/tools.ts
+++ b/src/tools.ts
@@ -305,7 +305,7 @@ export async function getWpCliUrl(version: string): Promise {
*/
export async function addComposer(tools_list: string[]): Promise {
const regex_any = /^composer($|:.*)/;
- const regex_valid = /^composer:?($|preview$|snapshot$|v?[1-2]$)/;
+ const regex_valid = /^composer:?($|preview$|snapshot$|v?[1-2]$|v?\d+\.\d+\.\d+[\w-]*$)/;
const regex_composer1_tools = /hirak|prestissimo|narrowspark|composer-prefetcher/;
const matches: string[] = tools_list.filter(tool => regex_valid.test(tool));
let composer = 'composer';
@@ -317,7 +317,7 @@ export async function addComposer(tools_list: string[]): Promise {
case matches[0] == undefined:
break;
default:
- composer = matches[matches.length - 1].replace(/v([1-2])/, '$1');
+ composer = matches[matches.length - 1].replace(/v(\d\S*)/, '$1');
break;
}
tools_list.unshift(composer);
From 925ede25899cf1b223e68ee8512c111ab68b5c23 Mon Sep 17 00:00:00 2001
From: Shivam Mathur
Date: Fri, 30 Oct 2020 18:29:39 +0530
Subject: [PATCH 10/23] Refactor composer setup
---
README.md | 4 +++-
__tests__/tools.test.ts | 6 ++++++
dist/index.js | 25 ++++++++++---------------
src/tools.ts | 33 +++++++++++++--------------------
4 files changed, 32 insertions(+), 36 deletions(-)
diff --git a/README.md b/README.md
index e4160e86..29238638 100644
--- a/README.md
+++ b/README.md
@@ -193,7 +193,7 @@ These tools can be setup globally using the `tools` input.
tools: php-cs-fixer, phpunit
```
-- To set up a particular version of a tool, specify it in the form `tool:version`. The latest stable version of `composer` is set up by default. You can set up the required version by specifying `v1`, `v2`, `snapshot` or `preview` as version.
+- To set up a particular version of a tool, specify it in the form `tool:version`. The latest stable version of `composer` is set up by default. You can set up the required `composer` version by specifying `v1`, `v2`, `snapshot` or `preview` as versions or the exact version in semver format.
```yaml
- name: Setup PHP with composer v2
@@ -203,6 +203,8 @@ These tools can be setup globally using the `tools` input.
tools: composer:v2
```
+- If you have specified composer plugins `prestissimo` or `composer-prefetcher` in tools, the latest stable version of `composer v1` will be setup. Unless some of your packages require `composer v1`, it is recommended to drop `prestissimo` and use `composer v2`.
+
- The latest versions of both agent `blackfire-agent` and client `blackfire` are setup when `blackfire` is specified in tools input. Please refer to the [official documentation](https://blackfire.io/docs/integrations/ci/github-actions "Blackfire.io documentation for GitHub Actions") for using `blackfire` with GitHub Actions.
- Version for other tools should be in `semver` format and a valid release of the tool. This is useful for installing tools for older versions of PHP. For example to set up `PHPUnit` on `PHP 7.2`.
diff --git a/__tests__/tools.test.ts b/__tests__/tools.test.ts
index 015caf08..1a371458 100644
--- a/__tests__/tools.test.ts
+++ b/__tests__/tools.test.ts
@@ -278,9 +278,15 @@ describe('Tools tests', () => {
expect(await tools.getComposerUrl('1.7.2')).toContain(
'https://github.com/composer/composer/releases/download/1.7.2/composer.phar'
);
+ expect(await tools.getComposerUrl('1.7.2')).toContain(
+ 'https://getcomposer.org/composer-1.7.2.phar'
+ );
expect(await tools.getComposerUrl('2.0.0-RC2')).toContain(
'https://github.com/composer/composer/releases/download/2.0.0-RC2/composer.phar'
);
+ expect(await tools.getComposerUrl('2.0.0-RC2')).toContain(
+ 'https://getcomposer.org/composer-2.0.0-RC2.phar'
+ );
expect(await tools.getComposerUrl('wrong')).toContain(
'https://getcomposer.org/composer-stable.phar'
);
diff --git a/dist/index.js b/dist/index.js
index a13b9c05..8cc3b12d 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -2047,22 +2047,17 @@ exports.addComposer = addComposer;
* @param version
*/
async function getComposerUrl(version) {
- const cache_url = 'https://github.com/shivammathur/composer-cache/releases/latest/download/composer-' +
- version.replace('latest', 'stable') +
- '.phar,';
- switch (version) {
- case 'snapshot':
- return cache_url + 'https://getcomposer.org/composer.phar';
- case 'preview':
- case '1':
- case '2':
- return (cache_url + 'https://getcomposer.org/composer-' + version + '.phar');
+ let cache_url = `https://github.com/shivammathur/composer-cache/releases/latest/download/composer-${version.replace('latest', 'stable')}.phar`;
+ switch (true) {
+ case /^snapshot$/.test(version):
+ return `${cache_url},https://getcomposer.org/composer.phar`;
+ case /^preview$|^[1-2]$/.test(version):
+ return `${cache_url},https://getcomposer.org/composer-${version}.phar`;
+ case /^\d+\.\d+\.\d+[\w-]*$/.test(version):
+ cache_url = `https://github.com/composer/composer/releases/download/${version}/composer.phar`;
+ return `${cache_url},https://getcomposer.org/composer-${version}.phar`;
default:
- if (/^\d+\.\d+\.\d+[\w-]*$/.test(version)) {
- return (cache_url +
- `https://github.com/composer/composer/releases/download/${version}/composer.phar`);
- }
- return cache_url + 'https://getcomposer.org/composer-stable.phar';
+ return `${cache_url},https://getcomposer.org/composer-stable.phar`;
}
}
exports.getComposerUrl = getComposerUrl;
diff --git a/src/tools.ts b/src/tools.ts
index 5914099b..1a17502c 100644
--- a/src/tools.ts
+++ b/src/tools.ts
@@ -330,27 +330,20 @@ export async function addComposer(tools_list: string[]): Promise {
* @param version
*/
export async function getComposerUrl(version: string): Promise {
- const cache_url =
- 'https://github.com/shivammathur/composer-cache/releases/latest/download/composer-' +
- version.replace('latest', 'stable') +
- '.phar,';
- switch (version) {
- case 'snapshot':
- return cache_url + 'https://getcomposer.org/composer.phar';
- case 'preview':
- case '1':
- case '2':
- return (
- cache_url + 'https://getcomposer.org/composer-' + version + '.phar'
- );
+ let cache_url = `https://github.com/shivammathur/composer-cache/releases/latest/download/composer-${version.replace(
+ 'latest',
+ 'stable'
+ )}.phar`;
+ switch (true) {
+ case /^snapshot$/.test(version):
+ return `${cache_url},https://getcomposer.org/composer.phar`;
+ case /^preview$|^[1-2]$/.test(version):
+ return `${cache_url},https://getcomposer.org/composer-${version}.phar`;
+ case /^\d+\.\d+\.\d+[\w-]*$/.test(version):
+ cache_url = `https://github.com/composer/composer/releases/download/${version}/composer.phar`;
+ return `${cache_url},https://getcomposer.org/composer-${version}.phar`;
default:
- if (/^\d+\.\d+\.\d+[\w-]*$/.test(version)) {
- return (
- cache_url +
- `https://github.com/composer/composer/releases/download/${version}/composer.phar`
- );
- }
- return cache_url + 'https://getcomposer.org/composer-stable.phar';
+ return `${cache_url},https://getcomposer.org/composer-stable.phar`;
}
}
From 215b040f0d8cd69af13e1796acab01aa94f19aa2 Mon Sep 17 00:00:00 2001
From: Shivam Mathur
Date: Sat, 31 Oct 2020 14:55:27 +0530
Subject: [PATCH 11/23] Fix contribution docs
---
.github/CONTRIBUTING.md | 20 +++++++++++++-------
.github/PULL_REQUEST_TEMPLATE.md | 2 +-
package.json | 2 +-
3 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md
index ba2c7186..4620654f 100644
--- a/.github/CONTRIBUTING.md
+++ b/.github/CONTRIBUTING.md
@@ -18,13 +18,6 @@ Due to time constraints, you may not always get a quick response. Please do not
## Coding Guidelines
-This project comes with `.prettierrc.json` and `eslintrc.json` configuration files. Please run the following commands to format the code before committing it.
-
-```bash
-$ npm run format
-$ npm run lint
-```
-
## Using setup-php from a Git checkout
The following commands can be used to perform the initial checkout of setup-php:
@@ -41,6 +34,19 @@ Install setup-php dependencies using [npm](https://www.npmjs.com/):
$ npm install
```
+If you are using `Windows` configure `git` to handle line endings.
+
+```cmd
+git config --local core.autocrlf true
+```
+
+This project comes with `.prettierrc.json` and `eslintrc.json` configuration files. Please run the following commands to fix and verify the code quality.
+
+```bash
+$ npm run format
+$ npm run lint
+```
+
## Running the test suite
After following the steps shown above, The `setup-php` tests in the `__tests__` directory can be run using this command:
diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md
index 6eb548a2..524b7de4 100644
--- a/.github/PULL_REQUEST_TEMPLATE.md
+++ b/.github/PULL_REQUEST_TEMPLATE.md
@@ -30,7 +30,7 @@ This PR [briefly explain what it does]
> In case this PR edits any scripts:
- [ ] I have checked the edited scripts for syntax.
-- [ ] I have tested the changes in an integration test (If yes, provide workflow link).
+- [ ] I have tested the changes in an integration test (If yes, provide workflow YAML and link).