Compare commits

...

140 Commits

Author SHA1 Message Date
4c5c122aa6 PHP 8.1 is now stable and marked as default version 2021-11-25 17:34:13 +05:30
bee5abe269 Bump extension cache key in workflow.yml 2021-11-24 18:23:02 +05:30
220d0c24c7 Fix reading build commit on Windows 2021-11-24 18:01:01 +05:30
2f5c2edb22 Fix upgrading nightly versions 2021-11-18 19:40:47 +05:30
721e4c3367 Add dev package for PHP by default on self-hosted 2021-11-18 16:51:20 +05:30
2f2a90e464 Add workaround to ensure PHPUnit installed by setup-php is used along with PHPUnit-Polyfills 2021-11-16 08:23:46 +05:30
81a06ff6ed Fix shellcheck warning in add_tools.sh 2021-11-16 08:14:06 +05:30
dfc02c42d9 Bump extension cache key in workflow.yml 2021-11-11 19:55:50 +05:30
ac7d3d7f84 Merge pull request #528 from shivammathur/develop
Stop using Install-PhpExtensionPrerequisite for imagick
2021-11-11 19:29:43 +05:30
874e5099b0 Stop using Install-PhpExtensionPrerequisite for imagick 2021-11-11 19:22:29 +05:30
4a3337d069 Add release badge 2021-11-11 07:32:02 +05:30
123f6df529 Improve npm release workflow [skip ci] 2021-11-11 05:26:21 +05:30
341cf69e13 Add allowed endpoints to node workflow 2021-11-10 08:36:00 +05:30
f7b503e36b Add action to harden runner in node workflow 2021-11-10 06:17:07 +05:30
beaceb0089 Fix to only copy problem-matchers configs to RUNNER_TOOL_CACHE 2021-11-10 05:45:18 +05:30
03509eca9b Fix error while opening blackfire configuration file on Linux 2021-10-19 00:16:05 +05:30
2c9c274411 Fix dependency support in self-hosted macOS 2021-10-15 22:32:24 +05:30
1c85db7f9e Add patch for Debian 12 and the distributions based on it 2021-10-15 18:34:06 +05:30
d259dd49a2 Improve package checks for extensions 2021-10-15 17:53:09 +05:30
ea20ae1fbd Fix minor bug in checking lists on Linux 2021-10-15 15:58:06 +05:30
383c74bb06 Improve adding CA certificates on Windows 2021-10-14 22:08:11 +05:30
b4593b7df0 Revert "Add patch to update ca-certificates on windows-2016"
This reverts commit d7c3e33a96.
2021-10-14 21:00:58 +05:30
9b92c9db92 Revert "Add patch to update brew core repo"
This reverts commit dab978c436.
2021-10-14 20:59:16 +05:30
a357b6a054 Revert "Fetch CA certificate from Curl on all Windows versions"
This reverts commit a7f90656b3.
2021-10-14 20:58:09 +05:30
0bc2f7ce96 Revert "Fix macOS patch to allow link libraries"
This reverts commit e2e76ea34f.
2021-10-14 20:57:18 +05:30
e2e76ea34f Fix macOS patch to allow link libraries 2021-10-13 15:25:38 +05:30
719018955c Add support for xlswriter on macOS using shivammathur/extensions tap 2021-10-12 20:56:58 +05:30
4c903565c9 Merge pull request #518 from jrfnl/feature/readme-improve-tool-discoverability
README: improve discoverability of tools
2021-10-11 10:49:10 +05:30
fc60088a95 README: improve discoverability of tools
Not every developer will be familiar with all tools.

By linking the tools listed to the relevant documentation website, the discoverability of tools new to a developer is improved.
2021-10-11 05:54:18 +02:00
a7f90656b3 Fetch CA certificate from Curl on all Windows versions 2021-10-10 05:43:54 +05:30
0cd4af837e Merge pull request #516 from aneeshrelan/feature/refactor-install-tests-to-use-jest-each
tests: refactor install.test.ts to use jest.each
2021-10-09 19:18:17 +05:30
96e47f9be7 tests: have a strict assertion using toBe 2021-10-09 19:01:59 +05:30
eca40cad4d tests: resolve windows path matching 2021-10-09 18:59:50 +05:30
4e864eae3b tests: move os to a parameter 2021-10-09 18:44:47 +05:30
49a0bad962 tests: refactor install.test.ts to use jest.each 2021-10-09 17:30:06 +05:30
b971d8f4ad use brew_extensions config for testing add_brew_extension 2021-10-09 08:11:39 +05:30
fca0924fa9 Use custom support for phalcon 2021-10-09 06:26:16 +05:30
8dfe214356 Merge pull request #514 from aneeshrelan/feature/refactor-tests-to-use-jest-each
tests: use parameterised testing using `jest.each` for extensions.test.ts
2021-10-08 22:33:11 +05:30
f2d6820ca2 tests: sort test data in alphabetic order and merge duplicates 2021-10-08 22:24:17 +05:30
705c2a5785 tests: increase test coverage for extensions.test.ts 2021-10-08 20:28:41 +05:30
5e33fdb0d9 tests: refactor extensions.test.ts to use jest.each 2021-10-08 20:02:42 +05:30
dab978c436 Add patch to update brew core repo 2021-10-06 18:12:11 +05:30
2cc925b655 tests: refactor extensions test to use jest-each 2021-10-06 01:05:47 +05:30
4ce6f3c3df Merge pull request #513 from aneeshrelan/feature/automate-publish-to-npm-github
ci: add github action to publish to npm and github packages
2021-10-05 23:39:12 +05:30
b3bf0f3990 fix: remove dry run 2021-10-05 23:23:05 +05:30
8426bf89fd ci: add github action to publish to npm and github packages 2021-10-05 23:10:58 +05:30
d7c3e33a96 Add patch to update ca-certificates on windows-2016 2021-10-04 19:41:33 +05:30
17ef667e04 Bump version to 2.15.0
Update Node.js dependencies

Replace husky with simple-git-hooks

Cleanup whitespace in README

Fix git command in format script
2021-09-28 04:19:39 +05:30
295b5da700 Add config to resolve extensions from shivammathur/extensions 2021-09-23 18:55:16 +05:30
e820a5d75b Merge pull request #503 from jrfnl/feature/tools-add-phpunit-polyfills
Tools: add PHPUnit Polyfills
2021-09-20 19:38:29 +05:30
2c8682d5e6 Tools: add support for phpunit-polyfills
Ref: https://github.com/Yoast/PHPUnit-Polyfills
2021-09-20 16:04:04 +02:00
87993cd853 Add lowercase alias for phpDocumentor on unix 2021-09-20 06:23:13 +05:30
e0dd9c9560 Merge pull request #501 from jrfnl/feature/fix-typo
Fix apparent typo
2021-09-20 06:19:02 +05:30
28853c9f3b Merge pull request #500 from jrfnl/feature/tools-add-parallel-lint
Tools: add support for PHP Parallel Lint
2021-09-20 06:18:47 +05:30
608ad1a0cf Tools: fix typo
While the PHPCPD and PHPUnit tools use the [same function under the hood](1fa3ba1b16/src/tools.ts (L461-L473)), I have the impression that the `function` keyword should be the tool name.

If that's correct, this should fix it.
2021-09-20 02:22:42 +02:00
257e4c088d Tools: add support for parallel-lint 2021-09-20 02:22:22 +02:00
7b145b5fae Add fileinfo extension with phpdoc
Add aliases for phpdoc
2021-09-20 05:46:02 +05:30
253459691c Merge pull request #498 from jrfnl/feature/tools-add-phpdocumentor
Tools: add support for phpDocumentor
2021-09-20 04:52:15 +05:30
cb5db3f888 Fix enabling cached extensions with custom support 2021-09-20 01:55:38 +05:30
52d2b3b70b Fix Blackfire extensions logs when cached 2021-09-19 21:42:29 +05:30
fa5fbefff9 Tools: add support for phpDocumentor 2021-09-19 13:41:39 +02:00
256b466cc4 Make all extension variables local 2021-09-19 15:33:45 +05:30
57f4a60e24 Fix enabling firebird when cached 2021-09-19 10:05:07 +05:30
2e289f30e2 Fix Ioncube logs if cached 2021-09-19 10:05:06 +05:30
bc0d607611 Fix cache support for phalcon4 2021-09-19 10:04:57 +05:30
1fa3ba1b16 Fix php_extra_version on macOS 2021-09-19 03:58:05 +05:30
d8d1da5d6d Fix version for PECL extensions in logs 2021-09-19 03:17:13 +05:30
094bc8ae17 Fix parsing php-src tag 2021-09-19 02:54:02 +05:30
48aac87d46 Fix setup for cached OCI extensions 2021-09-19 02:41:04 +05:30
31971c78cd Fix parsing extra version 2021-09-19 02:38:31 +05:30
13760f5b16 Add support for expect and ssh2 using shivammathur/extensions tap on macOS 2021-09-16 18:41:02 +05:30
c644f654ce Add check for package files when adding PPA 2021-09-15 00:25:36 +05:30
9adda12e86 Add automated single SVG for corporate sponsors 2021-09-14 00:03:18 +05:30
6db8a6c378 Improve docs for extensions: none 2021-09-13 19:55:06 +05:30
a34eeedd37 Bump version to 2.14.0
Add config to generate types

Fix build error in install.ts after TypeScript upgrade

Minor refactor in install.test.ts

Add bugs, directories, files and types entries in package.json

Update Node.js dependencies

Update SECURITY.md
2021-09-11 05:25:45 +05:30
35bc046b26 Improve documentation for disabling extensions 2021-09-11 05:25:43 +05:30
64e9bb0e79 Add special cases to config.test.ts 2021-09-09 07:19:49 +05:30
19a01870e7 Refactor config.test.ts 2021-09-09 07:08:12 +05:30
c4560dd084 Refactor coverage.test.ts 2021-09-09 06:54:17 +05:30
0313f578ce Add sponsor svg 2021-09-08 12:19:06 +05:30
d068c17d9e Add support for nightly alias 2021-09-06 11:58:31 +05:30
8eebeae48a Use commit hash in url for nightly builds in darwin.sh 2021-09-05 12:32:28 +05:30
da9dadf09c Fix parsing 8.1 version 2021-09-02 19:24:08 +05:30
e06e40278f Specify version in Windows nightly setup 2021-09-02 00:35:19 +05:30
6473b1c04c Add 8.2 to the workflows 2021-09-02 00:18:50 +05:30
7694412cb0 Update documentation for PHP 8.2.0-dev 2021-09-01 19:34:48 +05:30
e990e98a54 Use shivammathur/extensions tap to install vips on macOS 2021-09-01 15:53:05 +05:30
b2d037d560 Add support to remove all shared extensions 2021-08-28 12:17:23 +05:30
4beeea41b4 Fix logs of disabled dependent extensions
Use shared_extension function on unix
2021-08-28 12:17:22 +05:30
8e80635955 Fix parsing extensions input if Zend OPcache is specified instead of opcache 2021-08-28 12:17:21 +05:30
c8837583fc Do not check dependents for PCOV and Xdebug 2021-08-28 12:17:21 +05:30
bb36513e49 Add support to disable dependent extensions 2021-08-28 12:17:20 +05:30
5402397d9f Do not delete extensions, just disable them 2021-08-28 12:17:19 +05:30
f6b4601c63 Run New-Item with -Force as items can pre-exist on self-hosted environments
Pipe output to $null as that is removed for verbose and not Out-Null, and is also faster
2021-08-28 12:17:18 +05:30
ed62711289 Update sponsor options [skip ci] 2021-08-28 12:14:51 +05:30
2cb9b82943 Fix extension logs 2021-08-24 19:29:33 +05:30
4f420be5bd Add windows-2022 to the README 2021-08-24 18:53:16 +05:30
cf40c1e950 Bump version to 2.13.0
Update dependencies
2021-08-23 16:19:24 +05:30
91936faf85 Update README 2021-08-23 16:19:19 +05:30
ca319bd10e Use AdditionalFilesPath parameter in Install-PhpExtension
AdditionalFilesPath allows to specify a directory inside extension directory (which can be cached) for installing dependencies which are in the same archive as the extension

Fix dependency directory name to correctly use VCVersion in win32.ps1

Fix exception in phalcon4 setup on Windows.
2021-08-23 14:31:00 +05:30
4d3cfaa653 Fixed support for php-cs-fixer
Added fetch_latest to tools.json. When fetch_latest is true for a tool
it will fetch the release.atom for the tool and parse that to get the
latest release.

Bumped lib version to ES2020 in tsconfig.json for string.matchAll.
2021-08-20 09:14:39 +05:30
c8b716540c Stop doing shallow clones on macOS self-hosted 2021-08-18 09:53:35 +05:30
1cecc2cc99 Use systemctl only if systemd is present else use the service wrapper 2021-08-18 09:53:33 +05:30
5137c78ee5 Use shivammathur/extensions tap for yaml extension on macOS 2021-08-18 09:53:32 +05:30
c37021df01 Set HOMEBREW_DEVELOPER=1 in macOS 2021-08-18 09:53:31 +05:30
c6e99860cd Improve adding PPAs on Linux 2021-08-18 09:53:30 +05:30
05b4ac2afb Use --no-install-recommends with APT on Linux 2021-08-18 09:53:29 +05:30
91bd11146c Add support for self-hosted debian runner 2021-08-18 09:53:28 +05:30
8ace7bdc6e Switch to /etc/os-release on Linux
Improve self-hosted support
2021-08-18 09:53:27 +05:30
4bb4f1812c Fix to make utils.readEnv more resilient to user input 2021-08-18 09:53:26 +05:30
7bd9f10bef Add no_tools_cache flag 2021-08-18 09:53:25 +05:30
0b38e86c65 Use shivammathur/extensions tap on macOS for mongodb on PHP 5.6 to 8.1 2021-08-18 09:53:24 +05:30
b717b2fcde Rename macos-11.0 to macos-11 2021-08-18 09:52:47 +05:30
216d501175 Merge pull request #483 from lolautruche/patch-1
Use systemctl instead of services to install blackfire
2021-08-17 13:15:43 +05:30
c2e811ce23 Use systemctl instead of services to install blackfire 2021-08-17 13:06:19 +05:30
dbf50bf9e0 Upgrade blackfire to v2 2021-08-17 13:06:05 +05:30
947009a717 Sunset support for Ubuntu 16.04 2021-08-02 23:10:43 +05:30
ca910e5511 Merge pull request #481 from jrfnl/feature/update-phive-config
Update Phive configuration
2021-08-01 23:30:47 +05:30
f31d416e6e Update Phive configuration
Phive has released version `0.15.0` which ups the minimum supported PHP version to PHP 7.3.

This adds the switch statement for Phive to take this into account.

Ref: https://github.com/phar-io/phive/releases
2021-08-01 19:52:48 +02:00
36cb9fb0fc Fix composer permissions on unix 2021-07-21 19:00:00 +05:30
6a8a2abd3c Improve symfony examples 2021-07-17 11:49:03 +05:30
c88f07696b Add support for phpunit-bridge 2021-07-17 08:42:11 +05:30
0b33ef444f Revert "Add patch for PCRE2"
This reverts commit fefbd7a497.
2021-07-16 15:55:40 +05:30
604ffba8e1 Update status-page link in README 2021-07-16 15:14:15 +05:30
a3727c20a4 Bump version to 2.12.0
Update Node.js dependencies
2021-07-14 14:38:18 +05:30
6a9b0017a4 Update README 2021-07-14 14:17:38 +05:30
3b2ce6cae6 Update Ubuntu 16.04 warning in install.ts 2021-07-14 14:17:38 +05:30
c61b9256d1 Improve grpc_php_plugin support 2021-07-14 14:17:37 +05:30
09e08a3554 More fixes in fetching tool versions 2021-07-14 14:17:32 +05:30
f31bef6a30 Set firebird client version to 3.0.7 on macOS 2021-07-12 10:45:57 +05:30
1a216636c5 Use composer for composer-require-checker 2021-07-12 10:45:56 +05:30
7eec3d790d Fix repeated version_prefix 2021-07-10 02:10:33 +05:30
5afed16e5f Fix support for imagick for PHP 5.3 to 5.5 on macOS 2021-07-10 00:50:50 +05:30
14fa980966 Improve error handling in utils.fetch and its uses
Minor fixes in tests

Revert to ES2019
2021-07-09 11:26:38 +05:30
39491a0fba Add authorization header to GitHub API call when COMPOSER_TOKEN is set 2021-07-07 22:40:05 +05:30
c6b6dabbb9 Refactor tests for tools using jest.Each 2021-07-07 22:40:04 +05:30
e1a9afe11c Add support to specify major or major.minor versions for tools with GitHub repository 2021-07-07 22:40:03 +05:30
6449431df2 Move tools config to tools.json
Refactor tools functions to use Records and object literals
2021-07-07 22:40:02 +05:30
60ff774608 Fix replacing v prefix in tool version 2021-07-07 22:40:01 +05:30
dd591f1661 Use shivammathur/extensions tap for rdkafka on macOS 2021-07-07 22:39:59 +05:30
57 changed files with 5526 additions and 5292 deletions

6
.github/FUNDING.yml vendored
View File

@ -1,7 +1,3 @@
# These are supported funding model platforms
open_collective: setup-php
tidelift: "npm/setup-php"
community_bridge: setup-php
patreon: shivammathur
custom: https://www.paypal.me/shivammathur
github: shivammathur

3
.github/SECURITY.md vendored
View File

@ -7,7 +7,7 @@ The following versions of this project are supported for security updates.
| Version | Supported |
| ------- | ------------------ |
| 1.11.x | :white_check_mark: |
| 2.11.x | :white_check_mark: |
| 2.14.x | :white_check_mark: |
## Supported PHP Versions
@ -18,6 +18,7 @@ This security policy only applies to the latest patches of the following PHP ver
| 7.3 | :white_check_mark: |
| 7.4 | :white_check_mark: |
| 8.0 | :white_check_mark: |
| 8.1 | :white_check_mark: |
## Reporting a Vulnerability

View File

@ -10,8 +10,8 @@ jobs:
strategy:
fail-fast: false
matrix:
operating-system: [ubuntu-20.04, ubuntu-18.04, ubuntu-16.04, windows-2019, macos-10.15]
php-versions: ['5.3', '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
operating-system: [ubuntu-20.04, ubuntu-18.04, windows-2019, macos-10.15]
php-versions: ['5.3', '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2']
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
@ -59,10 +59,10 @@ jobs:
run: |
git config --local user.email "${{ secrets.email }}"
git config --local user.name "${{ github.repository_owner }}"
for os in ubuntu-20.04 ubuntu-18.04 ubuntu-16.04 windows-2019 macos-10.15 macos-11.0; do
for os in ubuntu-20.04 ubuntu-18.04 windows-2019 macos-10.15 macos-11; do
echo "These are extensions which are loaded by default on the following PHP versions. More extensions which are available as packages and available on pecl are supported by setup-php. Refer to [php extension support](https://github.com/shivammathur/setup-php#heavy_plus_sign-php-extension-support) for more details." > Php-extensions-loaded-on-"$os".md
for version in 5.3 5.4 5.5 5.6 7.0 7.1 7.2 7.3 7.4 8.0 8.1; do
if [ "$os" = "macos-11.0" ]; then
for version in 5.3 5.4 5.5 5.6 7.0 7.1 7.2 7.3 7.4 8.0 8.1 8.2; do
if [ "$os" = "macos-11" ]; then
cat lists/php"$version"-macos-10.15.md >> Php-extensions-loaded-on-"$os".md
else
cat lists/php"$version"-"$os".md >> Php-extensions-loaded-on-"$os".md

62
.github/workflows/node-release.yml vendored Normal file
View File

@ -0,0 +1,62 @@
name: Publish Package
on:
release:
types: [created]
workflow_dispatch:
inputs:
skip:
description: Skip release to repository
required: false
tag:
description: Tag name
required: true
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Harden Runner
uses: step-security/harden-runner@main
- name: Checkout release
if: github.event_name != 'workflow_dispatch'
uses: actions/checkout@v2
- name: Checkout tag
uses: actions/checkout@v2
if: github.event_name == 'workflow_dispatch'
with:
ref: ${{ github.event.inputs.tag }}
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '14.x'
registry-url: https://registry.npmjs.org
- name: Install dependencies
run: npm install
- name: Publish to NPM
if: "!contains(github.event.inputs.skip, 'skip-npm')"
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Change to GitHub Packages registry
uses: actions/setup-node@v2
with:
registry-url: https://npm.pkg.github.com
scope: '@shivammathur'
- name: Patch package.json
run: |
sed -i 's#"name": "#"name": "@shivammathur/#' package.json
- name: Publish to GitHub Packages
if: "!contains(github.event.inputs.skip, 'skip-github-packages')"
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@ -25,6 +25,20 @@ jobs:
matrix:
operating-system: [ubuntu-latest, windows-latest, macos-latest]
steps:
- name: Harden Runner
if: runner.os == 'Linux'
uses: step-security/harden-runner@main
with:
allowed-endpoints:
beta.api.stepsecurity.io.:443
codecov.io.:443
github.com.:443
nodejs.org.:443
raw.githubusercontent.com.:443
registry.npmjs.org.:443
setup-php.com.:443
storage.googleapis.com.:443
- name: Checkout
uses: actions/checkout@v2

View File

@ -24,11 +24,11 @@ jobs:
strategy:
fail-fast: false
matrix:
operating-system: [ubuntu-20.04, ubuntu-18.04, ubuntu-16.04, windows-latest, macos-latest]
php-versions: ['5.3', '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
operating-system: [ubuntu-20.04, ubuntu-18.04, windows-latest, macos-latest]
php-versions: ['5.3', '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2']
env:
extensions: xml, opcache, xdebug, pcov
key: cache-v3
key: cache-v5
steps:
- name: Checkout
uses: actions/checkout@v2

390
README.md
View File

@ -10,12 +10,13 @@
<a href="https://github.com/shivammathur/setup-php" title="GitHub action to setup PHP"><img alt="GitHub Actions status" src="https://github.com/shivammathur/setup-php/workflows/Main%20workflow/badge.svg"></a>
<a href="https://codecov.io/gh/shivammathur/setup-php" title="Code coverage"><img alt="Codecov Code Coverage" src="https://img.shields.io/codecov/c/github/shivammathur/setup-php?logo=codecov"></a>
<a href="https://github.com/shivammathur/setup-php/blob/master/LICENSE" title="license"><img alt="LICENSE" src="https://img.shields.io/badge/license-MIT-428f7e.svg?logo=open%20source%20initiative&logoColor=white&labelColor=555555"></a>
<a href="#tada-php-support" title="PHP Versions Supported"><img alt="PHP Versions Supported" src="https://img.shields.io/badge/php-5.3%20to%208.1-777bb3.svg?logo=php&logoColor=white&labelColor=555555"></a>
<a href="#tada-php-support" title="PHP Versions Supported"><img alt="PHP Versions Supported" src="https://img.shields.io/badge/php-5.3%20to%208.2-777bb3.svg?logo=php&logoColor=white&labelColor=555555"></a>
<a href="https://beta.stepsecurity.io/npm/setup-php"><img alt="release verified" src="https://img.shields.io/endpoint?url=https://beta.api.stepsecurity.io/v1/npm/setup-php/badge?q=1"></a>
</p>
<p align="center">
<p align="center">
<a href="https://reddit.com/r/setup_php" title="setup-php reddit"><img alt="setup-php reddit" src="https://img.shields.io/badge/reddit-join-FF5700?logo=reddit&logoColor=FF5700&labelColor=555555"></a>
<a href="https://twitter.com/setup_php" title="setup-php twitter"><img alt="setup-php twitter" src="https://img.shields.io/badge/twitter-follow-1DA1F2?logo=twitter&logoColor=1DA1F2&labelColor=555555"></a>
<a href="https://setup-php.statuspage.io/" title="setup-php status"><img alt="setup-php status" src="https://img.shields.io/badge/status-subscribe-28A745?logo=statuspage&logoColor=28A745&labelColor=555555"></a>
<a href="https://status.setup-php.com" title="setup-php status"><img alt="setup-php status" src="https://img.shields.io/badge/status-subscribe-28A745?logo=statuspage&logoColor=28A745&labelColor=555555"></a>
</p>
Setup PHP with required extensions, php.ini configuration, code-coverage support and various tools like composer in [GitHub Actions](https://github.com/features/actions "GitHub Actions"). This action gives you a cross platform interface to set up the PHP environment you need to test your application. Refer to [Usage](#memo-usage "How to use this") section and [examples](#examples "Examples of use") to see how to use this.
@ -34,6 +35,7 @@ Setup PHP with required extensions, php.ini configuration, code-coverage support
- [Disable Coverage](#disable-coverage)
- [Usage](#memo-usage)
- [Inputs](#inputs)
- [Outputs](#outputs)
- [Flags](#flags)
- [Basic Setup](#basic-setup)
- [Matrix Setup](#matrix-setup)
@ -47,8 +49,8 @@ Setup PHP with required extensions, php.ini configuration, code-coverage support
- [JIT Configuration](#jit-configuration)
- [Cache Extensions](#cache-extensions)
- [Cache Composer Dependencies](#cache-composer-dependencies)
- [Cache Node.js Dependencies](#cache-nodejs-dependencies)
- [Composer GitHub OAuth](#composer-github-oauth)
- [Inline PHP Scripts](#inline-php-scripts)
- [Problem Matchers](#problem-matchers)
- [Examples](#examples)
- [Versioning](#bookmark-versioning)
@ -66,12 +68,12 @@ Both `GitHub-hosted` and `self-hosted` runners are suppported by `setup-php` on
|Virtual environment|YAML workflow label|Pre-installed PHP|
|--- |--- |--- |
|Ubuntu 16.04 [(deprecated)](https://setup-php.com/i/452)|`ubuntu-16.04`|`PHP 5.6` to `PHP 8.0`|
|Ubuntu 18.04|`ubuntu-18.04`|`PHP 7.1` to `PHP 8.0`|
|Ubuntu 20.04|`ubuntu-latest` or `ubuntu-20.04`|`PHP 7.4` to `PHP 8.0`|
|Windows Server 2019|`windows-latest` or `windows-2019`|`PHP 8.0`|
|Windows Server 2022|`windows-2022`|`PHP 8.0`|
|macOS Catalina 10.15|`macos-latest` or `macos-10.15`|`PHP 8.0`|
|macOS Big Sur 11.x|`macos-11.0`|`PHP 8.0`|
|macOS Big Sur 11.x|`macos-11`|`PHP 8.0`|
### Self-Hosted Runners
@ -79,20 +81,25 @@ Both `GitHub-hosted` and `self-hosted` runners are suppported by `setup-php` on
|--- |--- |
|Ubuntu 18.04|`self-hosted` or `Linux`|
|Ubuntu 20.04|`self-hosted` or `Linux`|
|Ubuntu 21.04|`self-hosted` or `Linux`|
|Debian 9|`self-hosted` or `Linux`|
|Debian 10|`self-hosted` or `Linux`|
|Debian 11|`self-hosted` or `Linux`|
|Windows 7 and newer|`self-hosted` or `Windows`|
|Windows Server 2012 R2 and newer|`self-hosted` or `Windows`|
|macOS Catalina 10.15|`self-hosted` or `macOS`|
|macOS Big Sur 11.x x86_64/arm64|`self-hosted` or `macOS`|
- Refer to the [self-hosted setup](#self-hosted-setup) to use the action on self-hosted runners.
- Operating systems based on the above Ubuntu and Debian versions are also supported on a best effort basis.
- If the requested PHP version is pre-installed, `setup-php` switches to it, otherwise it installs the PHP version.
## :tada: PHP Support
On all supported OS/Platforms the following PHP versions are supported as per the runner.
- PHP 5.3 to PHP 8.1 on GitHub-hosted runners.
- PHP 5.6 to PHP 8.1 on self-hosted runners.
- PHP 5.3 to PHP 8.2 on GitHub-hosted runners.
- PHP 5.6 to PHP 8.2 on self-hosted runners.
|PHP Version|Stability|Release Support|Runner Support|
|--- |--- |--- |--- |
@ -106,15 +113,16 @@ On all supported OS/Platforms the following PHP versions are supported as per th
|`7.3`|`Stable`|`Security fixes only`|`GitHub-hosted`, `self-hosted`|
|`7.4`|`Stable`|`Active`|`GitHub-hosted`, `self-hosted`|
|`8.0`|`Stable`|`Active`|`GitHub-hosted`, `self-hosted`|
|`8.1`|`Nightly`|`In development`|`GitHub-hosted`, `self-hosted`|
|`8.1`|`Stable`|`Active`|`GitHub-hosted`, `self-hosted`|
|`8.2`|`Nightly`|`In development`|`GitHub-hosted`, `self-hosted`|
**Notes:**
- Specifying `8.1` in `php-version` input installs a nightly build of `PHP 8.1.0-dev`. See [nightly build setup](#nightly-build-setup) for more information.
- To use JIT on `PHP 8.0` and `PHP 8.1` refer to the [JIT configuration](#jit-configuration) section.
- Specifying `8.2` in `php-version` input installs a nightly build of `PHP 8.2.0-dev`. See [nightly build setup](#nightly-build-setup) for more information.
- To use JIT on `PHP 8.0` and above, refer to the [JIT configuration](#jit-configuration) section.
## :heavy_plus_sign: PHP Extension Support
PHP extensions can be setup using the `extensions` input. It accepts a `string` in csv-format.
PHP extensions can be set up using the `extensions` input. It accepts a `string` in csv-format.
- On `Ubuntu`, extensions which are available as a package, available on `PECL` or a git repository can be set up.
@ -122,7 +130,7 @@ PHP extensions can be setup using the `extensions` input. It accepts a `string`
- name: Setup PHP with PECL extension
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.0'
extensions: imagick, swoole
```
@ -134,7 +142,7 @@ PHP extensions can be setup using the `extensions` input. It accepts a `string`
- Extensions installed along with PHP if specified are enabled.
- Specific versions of extensions available on `PECL` can be setup by suffixing the extension's name with the version. This is useful for installing old versions of extensions which support end of life PHP versions.
- Specific versions of extensions available on `PECL` can be set up by suffixing the extension's name with the version. This is useful for installing old versions of extensions which support end of life PHP versions.
```yaml
- name: Setup PHP with specific version of PECL extension
@ -144,33 +152,45 @@ PHP extensions can be setup using the `extensions` input. It accepts a `string`
extensions: swoole-1.9.3
```
- Pre-release versions extensions available on `PECL` can be setup by suffixing the extension's name with its state i.e `alpha`, `beta`, `devel` or `snapshot`.
- Pre-release versions extensions available on `PECL` can be set up by suffixing the extension's name with its state i.e `alpha`, `beta`, `devel` or `snapshot`.
```yaml
- name: Setup PHP with pre-release PECL extension
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.0'
extensions: xdebug-beta
```
- Shared extensions can be removed by prefixing them with a `:`.
- Shared extensions can be disabled by prefixing them with a `:`. All extensions depending on the specified extension will also be disabled.
```yaml
- name: Setup PHP and remove shared extension
- name: Setup PHP and disable opcache
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.0'
extensions: :opcache
```
- Extension `intl` can be setup with specific `ICU` version for `PHP 5.6` and above in `Ubuntu` workflows by suffixing `intl` with the `ICU` version. `ICU 50.2` and newer versions are supported. Refer to [`ICU builds`](https://github.com/shivammathur/icu-intl#icu4c-builds) for the specific versions supported.
- All shared extensions can be disabled by specifying `none`. When `none` is specified along with other extensions, it is hoisted to the start of the input. So, all the shared extensions will be disabled first, then rest of the extensions in the input will be processed.
**Note:** This disables all core and third-party shared extensions and thus, can break some tools which need them. So, make sure you add the required extensions after `none` in the `extensions` input.
```yaml
- name: Setup PHP without any shared extensions except mbstring
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
extensions: none, mbstring
```
- Extension `intl` can be set up with specific `ICU` version for `PHP 5.6` and above in `Ubuntu` workflows by suffixing `intl` with the `ICU` version. `ICU 50.2` and newer versions are supported. Refer to [`ICU builds`](https://github.com/shivammathur/icu-intl#icu4c-builds) for the specific versions supported.
```yaml
- name: Setup PHP with intl
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.0'
extensions: intl-69.1
```
@ -181,13 +201,13 @@ PHP extensions can be setup using the `extensions` input. It accepts a `string`
- `geos` on `Ubuntu` and `macOS`.
- `blackfire`, `couchbase`, `ioncube`, `oci8`, `pdo_firebird`, `pdo_oci`, `pecl_http`, `phalcon3` and `phalcon4` on all supported OS.
- By default, extensions which cannot be added or removed gracefully leave an error message in the logs, the action is not interrupted. To change this behaviour you can set `fail-fast` flag to `true`.
- By default, extensions which cannot be added or disabled gracefully leave an error message in the logs, the action is not interrupted. To change this behaviour you can set `fail-fast` flag to `true`.
```yaml
- name: Setup PHP with fail-fast
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.0'
extensions: oci8
env:
fail-fast: true
@ -195,25 +215,56 @@ PHP extensions can be setup using the `extensions` input. It accepts a `string`
## :wrench: Tools Support
These tools can be setup globally using the `tools` input. It accepts a string in csv-format.
These tools can be set up globally using the `tools` input. It accepts a string in csv-format.
`behat`, `blackfire`, `blackfire-player`, `codeception`, `composer`, `composer-normalize`, `composer-prefetcher`, `composer-require-checker`, `composer-unused`, `cs2pr`, `deployer`, `flex`, `grpc_php_plugin`, `infection`, `pecl`, `phan`, `phing`, `phinx`, `phive`, `php-config`, `php-cs-fixer`, `phpcbf`, `phpcpd`, `phpcs`, `phpize`, `phplint`, `phpmd`, `phpspec`, `phpstan`, `phpunit`, `prestissimo`, `protoc`, `psalm`, `symfony` or `symfony-cli`, `vapor` or `vapor-cli`, `wp` or `wp-cli`
[`behat`], [`blackfire`], [`blackfire-player`], [`codeception`], [`composer`], [`composer-normalize`], [`composer-prefetcher`], [`composer-require-checker`], [`composer-unused`], [`cs2pr`], [`deployer`], [`flex`], [`grpc_php_plugin`], [`infection`], [`parallel-lint`], [`pecl`], [`phan`], [`phing`], [`phinx`], [`phive`], [`php-config`], [`php-cs-fixer`], [`phpcbf`], [`phpcpd`], [`phpcs`], [`phpdoc`] or [`phpDocumentor`], [`phpize`], [`phplint`], [`phpmd`], [`phpspec`], [`phpstan`], [`phpunit`], [`phpunit-bridge`], [`phpunit-polyfills`], [`prestissimo`], [`protoc`], [`psalm`], [`symfony`] or [`symfony-cli`], [`vapor`] or [`vapor-cli`], [`wp`] or [`wp-cli`]
```yaml
- name: Setup PHP with tools
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.0'
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 `composer` version by specifying `v1`, `v2`, `snapshot` or `preview` as versions, or the exact version in semver format.
- In addition to above tools any composer tool or package can also be set up globally by specifying it as `vendor/package` matching the listing on Packagist. This format accepts the same [version constraints](https://getcomposer.org/doc/articles/versions.md#writing-version-constraints "Composer version constraints") as `composer`.
```yaml
- name: Setup PHP with tools
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
tools: vimeo/psalm
```
- To set up a particular version of a tool, specify it in the form `tool:version`.
Version can be in the following format:
- Semver. For example `tool:1.2.3` or `tool:1.2.3-beta1`.
- Major version. For example `tool:1` or `tool:1.x`.
- Major and minor version. For example `tool:1.2` or `tool:1.2.x`.
When you specify just the major version or the version in `major.minor` format, the latest patch version matching the input will be setup.
Except for major versions of `composer`, For other tools when you specify only the `major` version or the version in `major.minor` format for any tool you can get rate limited by GitHub's API. To avoid this, it is recommended to provide a [`GitHub` OAuth token](https://github.com/shivammathur/setup-php#composer-github-oauth "Composer GitHub OAuth"). You can do that by setting `COMPOSER_TOKEN` environment variable.
```yaml
- name: Setup PHP with tools
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
tools: php-cs-fixer:3, phpunit:8.5
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
- The latest stable version of `composer` is set up by default. You can set up the required `composer` version by specifying the major version `v1` or `v2`, or the version in `major.minor` or `semver` format, Additionally for composer `snapshot` and `preview` can also be specified to set up the respective releases.
```yaml
- name: Setup PHP with composer v2
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.0'
tools: composer:v2
```
@ -223,41 +274,23 @@ These tools can be setup globally using the `tools` input. It accepts a string i
- name: Setup PHP without composer
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.0'
tools: none
```
- Scripts `phpize` and `php-config` are set up with the same version as of the input PHP version.
- The latest version of `blackfire` cli is set up 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.
- Tools `prestissimo` and `composer-prefetcher` will be skipped unless `composer:v1` is also specified in tools input. 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`.
```yaml
- name: Setup PHP with tools
uses: shivammathur/setup-php@v2
with:
php-version: '7.2'
tools: phpunit:8.5.8
```
- Any composer tool or package can also be set up globally by specifying it as `vendor/package`. For example to set up `psalm`.
```yaml
- name: Setup PHP with tools
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
tools: vimeo/psalm
```
- By default, tools which cannot be set up gracefully leave an error message in the logs, the action is not interrupted. To change this behaviour you can set `fail-fast` flag to `true`.
```yaml
- name: Setup PHP with fail-fast
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.0'
tools: deployer
env:
fail-fast: true
@ -279,7 +312,7 @@ Runs on all [PHP versions supported](#tada-php-support "List of PHP versions sup
- name: Setup PHP with Xdebug
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.0'
coverage: xdebug
```
@ -305,7 +338,7 @@ Runs on PHP 7.1 and newer PHP versions.
- name: Setup PHP with PCOV
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.0'
ini-values: pcov.directory=api #optional, see above for usage.
coverage: pcov
```
@ -322,12 +355,12 @@ Runs on PHP 7.1 and newer PHP versions.
### Disable Coverage
Specify `coverage: none` to remove both `Xdebug` and `PCOV`.
Specify `coverage: none` to disable both `Xdebug` and `PCOV`.
Disable coverage for these reasons:
- You are not generating coverage reports while testing.
- It will remove `Xdebug`, which will have a positive impact on PHP performance.
- It will disable `Xdebug`, which will have a positive impact on PHP performance.
- You are using `phpdbg` for running your tests.
- You are profiling your code using `blackfire`.
- You are using PHP in JIT mode. Please refer to [JIT configuration](#jit-configuration) section for more details.
@ -336,7 +369,7 @@ Disable coverage for these reasons:
- name: Setup PHP with no coverage driver
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.0'
coverage: none
```
@ -349,16 +382,18 @@ Disable coverage for these reasons:
#### `php-version` (required)
- Specify the PHP version you want to set up.
- Accepts a `string`. For example `'7.4'`.
- Accepts a `string`. For example `'8.0'`.
- Accepts `latest` to set up the latest stable PHP version.
- Accepts `nightly` to set up a nightly build from the master branch of PHP.
- Accepts the format `d.x`, where `d` is the major version. For example `5.x`, `7.x` and `8.x`.
- See [PHP support](#tada-php-support) for supported PHP versions.
#### `extensions` (optional)
- Specify the extensions you want to add or remove.
- Specify the extensions you want to add or disable.
- Accepts a `string` in csv-format. For example `mbstring, :opcache`.
- Non-default extensions prefixed with `:` are removed.
- Accepts `none` to disable all shared extensions.
- Shared extensions prefixed with `:` are disabled.
- See [PHP extension support](#heavy_plus_sign-php-extension-support) for more info.
#### `ini-values` (optional)
@ -369,7 +404,7 @@ Disable coverage for these reasons:
#### `coverage` (optional)
- Specify the code coverage driver you want to set up.
- Specify the code-coverage driver you want to set up.
- Accepts `xdebug`, `pcov` or `none`.
- See [coverage support](#signal_strength-coverage-support) for more info.
@ -379,6 +414,25 @@ Disable coverage for these reasons:
- Accepts a `string` in csv-format. For example: `phpunit, phpcs`
- See [tools Support](#wrench-tools-support) for tools supported.
### Outputs
#### `php-version`
To use outputs, give the `setup-php` step an `id`, you can use the same to get the outputs in a later step.
- Provides the PHP version in semver format.
```yaml
- name: Setup PHP
id: setup-php
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
- name: Print PHP version
run: echo ${{ steps.setup-php.outputs.php-version }}
```
### Flags
> Specify using `env` keyword
@ -412,16 +466,13 @@ See below for more info.
```yaml
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.0'
extensions: mbstring, intl
ini-values: post_max_size=256M, max_execution_time=180
coverage: xdebug
coverage: xdebug
tools: php-cs-fixer, phpunit
```
@ -436,42 +487,36 @@ jobs:
strategy:
matrix:
operating-system: ['ubuntu-latest', 'windows-latest', 'macos-latest']
php-versions: ['7.3', '7.4']
php-versions: ['7.3', '7.4', '8.0']
phpunit-versions: ['latest']
include:
- operating-system: 'ubuntu-latest'
php-versions: '7.2'
phpunit-versions: '8.5.13'
phpunit-versions: '8.5.21'
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, intl
ini-values: post_max_size=256M, max_execution_time=180
coverage: xdebug
coverage: xdebug
tools: php-cs-fixer, phpunit:${{ matrix.phpunit-versions }}
```
### Nightly Build Setup
> Setup a nightly build of `PHP 8.1`.
> Setup a nightly build of `PHP 8.2`.
- This version is currently in development.
- Some user space extensions might not support this version currently.
```yaml
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup nightly PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
php-version: '8.2'
extensions: mbstring
ini-values: post_max_size=256M, max_execution_time=180
coverage: xdebug
@ -482,7 +527,7 @@ steps:
> Setup `TS` or `NTS` PHP on `Windows`.
- `NTS` versions are setup by default.
- `NTS` versions are set up by default.
- On `Ubuntu` and `macOS` only `NTS` versions are supported.
- On `Windows` both `TS` and `NTS` versions are supported.
@ -492,13 +537,10 @@ jobs:
runs-on: windows-latest
name: Setup PHP TS on Windows
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.0'
env:
phpts: ts # specify ts or nts
```
@ -514,7 +556,7 @@ jobs:
- name: Setup PHP with latest versions
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.0'
env:
update: true # specify true or false
```
@ -529,17 +571,16 @@ To debug any issues, you can use the `verbose` tag instead of `v2`.
- name: Setup PHP with logs
uses: shivammathur/setup-php@verbose
with:
php-version: '7.4'
php-version: '8.0'
```
### Multi-Arch Setup
> Setup PHP on multiple architecture on Ubuntu GitHub Runners.
- `PHP 5.6` to `PHP 7.4` are supported by `setup-php` on multiple architecture on `Ubuntu`.
- For this, you can use `shivammathur/node` images as containers. These have compatible `Nodejs` and `spc` utility.
- Using `spc` you can run `setup-php` on both `i386` and `amd64` containers as opposed to [default syntax](#basic-setup), which only supports `amd64`.
- Currently, for `Arm` based setup, you will need [self-hosted runners](#self-hosted-setup).
- `PHP 5.6` to `PHP 8.0` are supported by `setup-php` on multiple architecture on `Ubuntu`.
- For this, you can use `shivammathur/node` images as containers. These have compatible `Nodejs` installed for JavaScript based GitHub Actions.
- Currently, for `ARM` based setup, you will need [self-hosted runners](#self-hosted-setup).
```yaml
jobs:
@ -551,25 +592,21 @@ jobs:
arch: ["amd64", "i386"]
steps:
- name: Install PHP
run: |
# Update spc (See https://github.com/shivammathur/spc for options)
spc -U
# Install PHP
spc --php-version "7.4" \
--extensions "mbstring, intl" \
--ini-values "post_max_size=256M, max_execution_time=180" \
--coverage "xdebug" \
--tools "php-cs-fixer, phpunit"
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
```
### Self Hosted Setup
> Setup PHP on a self-hosted runner.
- To set up a dockerized self-hosted runner, refer to this [guide](https://github.com/shivammathur/setup-php/wiki/Dockerized-self-hosted-runner-on-Ubuntu) to set up in an `Ubuntu` container and refer to this [guide](https://github.com/shivammathur/setup-php/wiki/Dockerized-self-hosted-runner-on-Windows) to set up in a `Windows` container.
- To set up a containerised self-hosted runner, refer to the following guides as per your base operating system.
- [Linux](https://github.com/shivammathur/setup-php/wiki/Dockerized-self-hosted-runner-on-Linux)
- [Windows](https://github.com/shivammathur/setup-php/wiki/Dockerized-self-hosted-runner-on-Windows)
- To set up the runner directly on the host OS or in a virtual machine, follow this [requirements guide](https://github.com/shivammathur/setup-php/wiki/Requirements-for-self-hosted-runners "Requirements guide for self-hosted runner to run setup-php") before setting up the self-hosted runner.
- If your workflow uses [service containers](https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idservices "GitHub Actions Services"), then setup the runner on a Linux host or in a Linux virtual machine. GitHub Actions does not support nested virtualization on Linux, so services will not work in a dockerized container.
- If your workflow uses [service containers](https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idservices "GitHub Actions Services"), then set up the runner on a Linux host or in a Linux virtual machine. GitHub Actions does not support nested virtualization on Linux, so services will not work in a dockerized container.
Specify the environment variable `runner` with the value `self-hosted`. Without this your workflow will fail.
@ -578,13 +615,10 @@ jobs:
run:
runs-on: self-hosted
strategy:
matrix:
matrix:
php-versions: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0']
name: PHP ${{ matrix.php-versions }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
@ -606,15 +640,11 @@ jobs:
jobs:
run:
runs-on: ubuntu-latest
name: PHP 7.4 Test
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: '8.0'
```
Run the workflow locally with `act` using [`shivammathur/node`](https://github.com/shivammathur/node-docker "Docker image to run setup-php") docker images.
@ -630,17 +660,14 @@ act -P ubuntu-20.04=shivammathur/node:2004
# For runs-on: ubuntu-18.04
act -P ubuntu-18.04=shivammathur/node:1804
# For runs-on: ubuntu-16.04 (deprecated)
act -P ubuntu-16.04=shivammathur/node:1604
```
### JIT Configuration
> Enable Just-in-time(JIT) on PHP 8.0 and PHP 8.1.
> Enable Just-in-time(JIT) on PHP 8.0 and above.
- To enable JIT, enable `opcache` in cli mode by setting `opcache.enable_cli=1`.
- JIT conflicts with `Xdebug`, `PCOV`, and any other extension which overrides `zend_execute_ex` function, so set `coverage: none` and remove those extensions if added.
- JIT conflicts with `Xdebug`, `PCOV`, and other extensions which override `zend_execute_ex` function, so set `coverage: none` and disable any such extension if added.
- By default, `opcache.jit=1235` and `opcache.jit_buffer_size=256M` are set which can be changed using `ini-values` input.
- For detailed information about JIT related directives refer to the [`official PHP documentation`](https://www.php.net/manual/en/opcache.configuration.php#ini.opcache.jit "opcache.jit documentation").
@ -693,38 +720,39 @@ key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}-${{ matrix.p
restore-keys: ${{ runner.os }}-composer-${{ matrix.prefer }}-
```
### Cache Node.js Dependencies
If your project has node.js dependencies, you can persist NPM or yarn cache directory. The cached files are available across check-runs and will reduce the workflow execution time.
```yaml
- name: Get node.js cache directory
id: node-cache-dir
run: echo "::set-output name=dir::$(npm config get cache)" # Use $(yarn cache dir) for yarn
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.node-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} # Use '**/yarn.lock' for yarn
restore-keys: ${{ runner.os }}-node-
```
**Note:** Please do not cache `node_modules` directory as that will have side effects.
### Composer GitHub OAuth
If you have a number of workflows which setup multiple tools or have many composer dependencies, you might hit the GitHub's rate limit for composer. To avoid that you can add an `OAuth` token to the composer's config by setting `COMPOSER_TOKEN` environment variable. You can use [`GITHUB_TOKEN`](https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token "GITHUB_TOKEN documentation") secret for this purpose.
If you have a number of workflows which set up multiple tools or have many composer dependencies, you might hit the GitHub's rate limit for composer. Also, if you specify only the major version or the version in `major.minor` format, you can hit the rate limit. To avoid this you can specify an `OAuth` token by setting `COMPOSER_TOKEN` environment variable. You can use [`GITHUB_TOKEN`](https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token "GITHUB_TOKEN documentation") secret for this purpose.
```yaml
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.0'
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
### Inline PHP Scripts
If you have to run multiple lines of PHP code in your workflow, you can do that easily without saving it to a file.
Put the code in the run property of a step and specify the shell as `php {0}`.
```yaml
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
- name: Run PHP code
shell: php {0}
run: |
<?php
$welcome = "Hello, world";
echo $welcome;
```
### Problem Matchers
Problem matchers are `json` configurations which identify errors and warnings in your logs and surface them prominently in the GitHub Actions UI by highlighting them and creating code annotations.
@ -755,7 +783,7 @@ PHPStan supports error reporting in GitHub Actions, so it does not require probl
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.0'
tools: phpstan
- name: Run PHPStan
@ -770,7 +798,7 @@ Psalm supports error reporting in GitHub Actions with an output format `github`.
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.0'
tools: psalm
- name: Run Psalm
@ -788,7 +816,7 @@ For examples refer to [cs2pr documentation](https://github.com/staabm/annotate-p
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.0'
tools: cs2pr, phpcs
- name: Run phpcs
@ -856,31 +884,26 @@ Examples of using `setup-php` with various PHP Frameworks and Packages.
## :sparkling_heart: Support This Project
- This project is provided as Free and Open-Source software. We need funds to maintain and do future improvements. Please sponsor setup-php using the below options:
- [Open Collective](https://opencollective.com/setup-php "setup-php Open Collective")
- [Paypal](https://www.paypal.me/shivammathur "Shivam Mathur PayPal")
- [Patreon](https://www.patreon.com/shivammathur "Shivam Mathur Patreon")
- Please [reach out](mailto:contact@setup-php.com) if you have any questions about sponsoring setup-php.
- Please star the project and share it. If you blog, please share your experience of using this action.
- Please sponsor setup-php using [GitHub sponsors](https://github.com/sponsors/shivammathur).
- Please [reach out](mailto:contact@setup-php.com) if you have any questions about sponsoring setup-php.
*`setup-php` is generously supported by*
[![Sponsor shivammathur](https://img.shields.io/badge/-Sponsor-fafbfc?logo=GitHub%20Sponsors)](https://github.com/sponsors/shivammathur)
<p>
<a href="https://www.jetbrains.com/?from=setup-php">
<img src="https://setup-php.com/sponsors/jetbrains.svg" alt="JetBrains" width="106" height="60">
### Corporate Sponsors
<p align="center">
<a href="https://setup-php.com/sponsors-corp/?">
<img src="https://setup-php.com/sponsors-corp/?" alt="Corporate sponsors of setup-php and related projects" width="100%">
</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://blackfire.io/?utm_source=setup-php">
<img src="https://setup-php.com/sponsors//blackfire.svg" alt="Blackfire" width="212" height="60">
</p>
### Individual Sponsors
<p align="center">
<a href="https://setup-php.com/sponsors/?">
<img src="https://setup-php.com/sponsors/?" alt="Individual sponsors of setup-php and related projects" width="100%">
</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://www.macstadium.com/?source=setup-php">
<img src="https://setup-php.com/sponsors//macstadium.png" alt="Mac Stadium" width="148" height="60">
</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://tidelift.com/subscription/pkg/npm-setup-php">
<img src="https://setup-php.com/sponsors//tidelift.png" alt="Tidelift" width="70" height="60">
</a>
</p>
## :package: Dependencies
@ -897,11 +920,58 @@ Examples of using `setup-php` with various PHP Frameworks and Packages.
- [shivammathur/php-builder](https://github.com/shivammathur/php-builder "Nightly PHP package for Ubuntu")
- [shivammathur/php-builder-windows](https://github.com/shivammathur/php-builder-windows "Nightly PHP package for Windows")
- [shivammathur/php-ubuntu](https://github.com/shivammathur/php-ubuntu "Cache stable PHP Packages for Ubuntu")
- [shivammathur/php5-darwin](https://github.com/shivammathur/php5-darwin "Scripts to setup PHP5 versions on darwin")
- [shivammathur/php5-ubuntu](https://github.com/shivammathur/php5-ubuntu "Scripts to setup PHP5 versions on ubuntu")
- [shivammathur/php5-darwin](https://github.com/shivammathur/php5-darwin "Scripts to set up PHP5 versions on darwin")
- [shivammathur/php5-ubuntu](https://github.com/shivammathur/php5-ubuntu "Scripts to set up PHP5 versions on ubuntu")
## :bookmark_tabs: Further Reading
- [About GitHub Actions](https://github.com/features/actions "GitHub Actions")
- [GitHub Actions Syntax](https://help.github.com/en/articles/workflow-syntax-for-github-actions "GitHub Actions Syntax")
- [Other Awesome Actions](https://github.com/sdras/awesome-actions "List of Awesome GitHub Actions")
<!-- Links to tools -->
[`behat`]: https://docs.behat.org/en/latest/
[`blackfire`]: https://blackfire.io/docs/php/index
[`blackfire-player`]: https://blackfire.io/docs/builds-cookbooks/player
[`codeception`]: https://codeception.com/
[`composer`]: https://getcomposer.org/
[`composer-normalize`]: https://github.com/ergebnis/composer-normalize
[`composer-prefetcher`]: https://github.com/narrowspark/automatic-composer-prefetcher
[`composer-require-checker`]: https://github.com/maglnet/ComposerRequireChecker
[`composer-unused`]: https://github.com/composer-unused/composer-unused
[`cs2pr`]: https://github.com/staabm/annotate-pull-request-from-checkstyle
[`deployer`]: https://deployer.org/
[`flex`]: https://flex.symfony.com/
[`grpc_php_plugin`]: https://grpc.io/
[`infection`]: https://infection.github.io/
[`parallel-lint`]: https://github.com/php-parallel-lint/PHP-Parallel-Lint
[`pecl`]: https://pecl.php.net/
[`phan`]: https://github.com/phan/phan/wiki
[`phing`]: https://www.phing.info/
[`phinx`]: https://phinx.org/
[`phive`]: https://phar.io/
[`php-config`]: https://www.php.net/manual/en/install.pecl.php-config.php
[`php-cs-fixer`]: https://cs.symfony.com/
[`phpcbf`]: https://github.com/squizlabs/php_codesniffer
[`phpcpd`]: https://github.com/sebastianbergmann/phpcpd
[`phpcs`]: https://github.com/squizlabs/php_codesniffer
[`phpdoc`]: https://phpdoc.org/
[`phpDocumentor`]: https://phpdoc.org/
[`phpize`]: https://www.php.net/manual/en/install.pecl.phpize.php
[`phplint`]: https://github.com/overtrue/phplint
[`phpmd`]: https://phpmd.org/
[`phpspec`]: https://www.phpspec.net/
[`phpstan`]: https://phpstan.org/
[`phpunit`]: https://phpunit.de/
[`phpunit-bridge`]: https://symfony.com/doc/current/components/phpunit_bridge.html
[`phpunit-polyfills`]: https://github.com/Yoast/PHPUnit-Polyfills
[`prestissimo`]: https://github.com/hirak/prestissimo
[`protoc`]: https://developers.google.com/protocol-buffers/
[`psalm`]: https://psalm.dev/
[`symfony`]: https://symfony.com/download
[`symfony-cli`]: https://symfony.com/download
[`vapor`]: https://docs.vapor.build/
[`vapor-cli`]: https://docs.vapor.build/
[`wp`]: https://wp-cli.org/
[`wp-cli`]: https://wp-cli.org/

View File

@ -1,52 +1,21 @@
import * as config from '../src/config';
describe('Config tests', () => {
it('checking addINIValuesOnWindows', async () => {
let win32: string = await config.addINIValues(
'post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata',
'win32'
);
expect(win32).toContain(
'Add-Content "$php_dir\\php.ini" "post_max_size=256M\nshort_open_tag=On\ndate.timezone=Asia/Kolkata"'
);
win32 = await config.addINIValues(
'post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata',
'openbsd'
);
expect(win32).toContain('Platform openbsd is not supported');
});
it('checking addINIValuesOnLinux', async () => {
let linux: string = await config.addINIValues(
'post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata',
'linux',
true
);
expect(linux).toContain(
'echo "post_max_size=256M\nshort_open_tag=On\ndate.timezone=Asia/Kolkata" | sudo tee -a "${pecl_file:-${ini_file[@]}}"'
);
linux = await config.addINIValues(
'post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata',
'openbsd'
);
expect(linux).toContain('Platform openbsd is not supported');
});
it('checking addINIValuesOnDarwin', async () => {
let darwin: string = await config.addINIValues(
'post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata',
'darwin'
);
expect(darwin).toContain(
'echo "post_max_size=256M\nshort_open_tag=On\ndate.timezone=Asia/Kolkata" | sudo tee -a "${pecl_file:-${ini_file[@]}}"'
);
darwin = await config.addINIValues(
'post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata',
'openbsd'
);
expect(darwin).toContain('Platform openbsd is not supported');
});
it.each`
ini_values | os_version | output
${'a=b, c=d'} | ${'win32'} | ${'Add-Content "$php_dir\\php.ini" "a=b\nc=d"'}
${'a=b, c=d'} | ${'linux'} | ${'echo "a=b\nc=d" | sudo tee -a "${pecl_file:-${ini_file[@]}}"'}
${'a=b, c=d'} | ${'darwin'} | ${'echo "a=b\nc=d" | sudo tee -a "${pecl_file:-${ini_file[@]}}"'}
${'a=b & ~c'} | ${'win32'} | ${'Add-Content "$php_dir\\php.ini" "a=\'b & ~c\'"'}
${'a="~(b)"'} | ${'win32'} | ${'Add-Content "$php_dir\\php.ini" "a=\'~(b)\'"'}
${'a="b, c"'} | ${'win32'} | ${'Add-Content "$php_dir\\php.ini" "a=b, c"'}
${'a=b, c=d'} | ${'openbsd'} | ${'Platform openbsd is not supported'}
`(
'checking addINIValues on $os_version',
async ({ini_values, os_version, output}) => {
expect(await config.addINIValues(ini_values, os_version)).toContain(
output
);
}
);
});

View File

@ -1,110 +1,39 @@
import * as coverage from '../src/coverage';
describe('Config tests', () => {
it('checking addCoverage with PCOV on windows', async () => {
let win32: string = await coverage.addCoverage('PCOV', '7.4', 'win32');
expect(win32).toContain('Add-Extension pcov');
expect(win32).toContain('Remove-Extension xdebug');
win32 = await coverage.addCoverage('pcov', '7.0', 'win32');
expect(win32).toContain('PHP 7.1 or newer is required');
win32 = await coverage.addCoverage('pcov', '5.6', 'win32');
expect(win32).toContain('PHP 7.1 or newer is required');
});
it('checking addCoverage with PCOV on linux', async () => {
const linux: string = await coverage.addCoverage('pcov', '7.4', 'linux');
expect(linux).toContain('add_extension pcov');
expect(linux).toContain('remove_extension xdebug');
});
it('checking addCoverage with PCOV on darwin', async () => {
const darwin: string = await coverage.addCoverage('pcov', '7.4', 'darwin');
expect(darwin).toContain('add_brew_extension pcov');
expect(darwin).toContain('remove_extension xdebug');
});
it('checking addCoverage with Xdebug on windows', async () => {
const win32: string = await coverage.addCoverage('xdebug', '7.4', 'win32');
expect(win32).toContain('Add-Extension xdebug');
});
it('checking addCoverage with Xdebug3 on windows', async () => {
const win32: string = await coverage.addCoverage('xdebug3', '7.4', 'win32');
expect(win32).toContain('Add-Extension xdebug');
});
it('checking addCoverage with Xdebug2 on windows', async () => {
const win32: string = await coverage.addCoverage('xdebug2', '7.4', 'win32');
expect(win32).toContain('Add-Extension xdebug stable 2.9.8');
});
it('checking addCoverage with Xdebug on linux', async () => {
const linux: string = await coverage.addCoverage('xdebug', '8.0', 'linux');
expect(linux).toContain('add_extension xdebug');
});
it('checking addCoverage with Xdebug3 on linux', async () => {
const linux: string = await coverage.addCoverage('xdebug3', '8.0', 'linux');
expect(linux).toContain('add_extension xdebug');
});
it('checking addCoverage with Xdebug2 on linux', async () => {
const linux: string = await coverage.addCoverage('xdebug2', '7.4', 'linux');
expect(linux).toContain('add_pecl_extension xdebug 2.9.8 zend_extension');
});
it('checking addCoverage with Xdebug on darwin', async () => {
const darwin: string = await coverage.addCoverage(
'xdebug',
'7.4',
'darwin'
);
expect(darwin).toContain('add_brew_extension xdebug');
});
it('checking addCoverage with Xdebug3 on darwin', async () => {
const darwin: string = await coverage.addCoverage(
'xdebug3',
'7.4',
'darwin'
);
expect(darwin).toContain('add_brew_extension xdebug');
});
it('checking addCoverage with Xdebug2 on darwin', async () => {
const darwin: string = await coverage.addCoverage(
'xdebug2',
'7.4',
'darwin'
);
expect(darwin).toContain('add_brew_extension xdebug2');
});
it('checking disableCoverage windows', async () => {
const win32 = await coverage.addCoverage('none', '7.4', 'win32');
expect(win32).toContain('Remove-Extension xdebug');
expect(win32).toContain('Remove-Extension pcov');
});
it('checking disableCoverage on linux', async () => {
const linux: string = await coverage.addCoverage('none', '7.4', 'linux');
expect(linux).toContain('remove_extension xdebug');
expect(linux).toContain('remove_extension pcov');
});
it('checking disableCoverage on darwin', async () => {
const darwin: string = await coverage.addCoverage('none', '7.4', 'darwin');
expect(darwin).toContain('remove_extension xdebug');
expect(darwin).toContain('remove_extension pcov');
});
it('checking no or invalid coverage driver', async () => {
let nocov: string = await coverage.addCoverage('nocov', '7.x', 'any');
expect(nocov).toEqual('');
nocov = await coverage.addCoverage('', '7.x', 'any');
expect(nocov).toEqual('');
});
it.each`
driver | php | os | output
${'PCOV'} | ${'7.4'} | ${'win32'} | ${'Add-Extension pcov,Disable-Extension xdebug false'}
${'pcov'} | ${'7.0'} | ${'win32'} | ${'PHP 7.1 or newer is required'}
${'pcov'} | ${'5.6'} | ${'win32'} | ${'PHP 7.1 or newer is required'}
${'pcov'} | ${'7.4'} | ${'win32'} | ${'Add-Extension pcov,Disable-Extension xdebug false'}
${'pcov'} | ${'7.4'} | ${'linux'} | ${'add_extension pcov,disable_extension xdebug false'}
${'pcov'} | ${'7.4'} | ${'darwin'} | ${'add_brew_extension pcov,disable_extension xdebug false'}
${'xdebug'} | ${'7.4'} | ${'win32'} | ${'Add-Extension xdebug'}
${'xdebug3'} | ${'7.4'} | ${'win32'} | ${'Add-Extension xdebug'}
${'xdebug2'} | ${'7.4'} | ${'win32'} | ${'Add-Extension xdebug stable 2.9.8'}
${'xdebug'} | ${'8.0'} | ${'linux'} | ${'add_extension xdebug'}
${'xdebug3'} | ${'8.0'} | ${'linux'} | ${'add_extension xdebug'}
${'xdebug2'} | ${'7.4'} | ${'linux'} | ${'add_pecl_extension xdebug 2.9.8 zend_extension'}
${'xdebug'} | ${'7.4'} | ${'darwin'} | ${'add_brew_extension xdebug'}
${'xdebug3'} | ${'7.4'} | ${'darwin'} | ${'add_brew_extension xdebug'}
${'xdebug2'} | ${'7.4'} | ${'darwin'} | ${'add_brew_extension xdebug2'}
${'none'} | ${'7.4'} | ${'win32'} | ${'Disable-Extension xdebug false,Disable-Extension pcov false'}
${'none'} | ${'7.4'} | ${'linux'} | ${'disable_extension xdebug false,disable_extension pcov false'}
${'none'} | ${'7.4'} | ${'darwin'} | ${'disable_extension xdebug false,disable_extension pcov false'}
${'nocov'} | ${'7.x'} | ${'any'} | ${''}
${''} | ${'7.x'} | ${'any'} | ${''}
`(
'checking addCoverage with $driver on $os',
async ({driver, php, os, output}) => {
const script: string = await coverage.addCoverage(driver, php, os);
if (output) {
output.split(',').forEach((command: string) => {
expect(script).toContain(command);
});
} else {
expect(script).toEqual(output);
}
}
);
});

View File

@ -1,260 +1,138 @@
import * as fs from 'fs';
import * as extensions from '../src/extensions';
describe('Extension tests', () => {
it('checking addExtensionOnWindows', async () => {
let win32: string = await extensions.addExtension(
'Xdebug, pcov, sqlite, :intl, phalcon4, pecl_http, ioncube, oci8, pdo_oci, ast-beta, grpc-1.2.3, inotify-1.2.3alpha2, sqlsrv-1.2.3preview1',
'7.4',
'win32'
);
expect(win32).toContain('Add-Extension xdebug');
expect(win32).toContain('Add-Extension pcov');
expect(win32).toContain('Add-Extension sqlite3');
expect(win32).toContain('Remove-Extension intl');
expect(win32).toContain('Add-Phalcon phalcon4');
expect(win32).toContain('Add-Http');
expect(win32).toContain('Add-Ioncube');
expect(win32).toContain('Add-Oci oci8');
expect(win32).toContain('Add-Oci pdo_oci');
expect(win32).toContain('Add-Extension ast beta');
expect(win32).toContain('Add-Extension grpc stable 1.2.3');
expect(win32).toContain('Add-Extension inotify alpha 1.2.3');
expect(win32).toContain('Add-Extension sqlsrv devel 1.2.3');
it.each`
extension | version | output
${'none'} | ${'7.4'} | ${'Disable-AllShared'}
${':intl'} | ${'7.4'} | ${'Disable-Extension intl'}
${'ast-beta'} | ${'7.4'} | ${'Add-Extension ast beta'}
${'blackfire'} | ${'7.3'} | ${'Add-Blackfire blackfire'}
${'blackfire-1.31.0'} | ${'7.3'} | ${'Add-Blackfire blackfire-1.31.0'}
${'grpc-1.2.3'} | ${'7.4'} | ${'Add-Extension grpc stable 1.2.3'}
${'inotify-1.2.3alpha2'} | ${'7.4'} | ${'Add-Extension inotify alpha 1.2.3'}
${'ioncube'} | ${'7.4'} | ${'Add-Ioncube'}
${'mongodb-mongodb/mongo-php-driver@master'} | ${'7.3'} | ${'Add-Log "$cross" "mongodb-mongodb/mongo-php-driver@master" "mongodb-mongodb/mongo-php-driver@master is not supported on PHP 7.3"'}
${'mysql'} | ${'7.4'} | ${'Add-Extension mysqli\nAdd-Extension mysqlnd'}
${'mysql'} | ${'5.5'} | ${'Add-Extension mysql\nAdd-Extension mysqli\nAdd-Extension mysqlnd'}
${'oci8'} | ${'7.4'} | ${'Add-Oci oci8'}
${'pcov'} | ${'5.6'} | ${'Add-Log "$cross" "pcov" "pcov is not supported on PHP 5.6"'}
${'pdo_oci'} | ${'7.4'} | ${'Add-Oci pdo_oci'}
${'pecl_http'} | ${'7.4'} | ${'Add-Http'}
${'phalcon3'} | ${'7.2'} | ${'Add-Phalcon phalcon3'}
${'phalcon4'} | ${'7.4'} | ${'Add-Phalcon phalcon4'}
${'sqlite'} | ${'7.4'} | ${'Add-Extension sqlite3'}
${'sqlsrv-1.2.3preview1'} | ${'7.4'} | ${'Add-Extension sqlsrv devel 1.2.3'}
${'Xdebug'} | ${'7.4'} | ${'Add-Extension xdebug'}
${'xdebug2'} | ${'7.2'} | ${'Add-Extension xdebug stable 2.9.8'}
`(
'checking addExtensionOnWindows for extension $extension on version $version',
async ({extension, version, output}) => {
expect(
await extensions.addExtension(extension, version, 'win32')
).toContain(output);
}
);
win32 = await extensions.addExtension('pcov', '5.6', 'win32');
expect(win32).toContain(
'Add-Log "$cross" "pcov" "pcov is not supported on PHP 5.6"'
);
it.each`
extension | version | output
${'none'} | ${'7.4'} | ${'disable_all_shared'}
${':intl'} | ${'7.4'} | ${'disable_extension intl'}
${'ast-beta'} | ${'7.4'} | ${'add_unstable_extension ast beta extension'}
${'blackfire'} | ${'7.3'} | ${'add_blackfire blackfire'}
${'blackfire-1.31.0'} | ${'7.3'} | ${'add_blackfire blackfire-1.31.0'}
${'couchbase'} | ${'7.4'} | ${'add_couchbase'}
${'gearman'} | ${'5.6'} | ${'add_gearman'}
${'geos'} | ${'7.3'} | ${'add_geos'}
${'grpc-1.2.3'} | ${'7.4'} | ${'add_pecl_extension grpc 1.2.3 extension'}
${'http-1.2.3'} | ${'7.3'} | ${'add_http http-1.2.3'}
${'intl-65.1'} | ${'5.6'} | ${'add_intl intl-65.1'}
${'ioncube'} | ${'7.3'} | ${'add_ioncube'}
${'mongodb-mongodb/mongo-php-driver@master'} | ${'7.3'} | ${'add_extension_from_source mongodb https://github.com mongodb mongo-php-driver master extension'}
${'oci8'} | ${'7.3'} | ${'add_oci oci8'}
${'pcov'} | ${'5.6'} | ${'add_log "$cross" "pcov" "pcov is not supported on PHP 5.6'}
${'pdo-odbc'} | ${'7.4'} | ${'add_pdo_extension odbc'}
${'pdo_cubrid'} | ${'7.0'} | ${'add_cubrid pdo_cubrid'}
${'pdo_cubrid'} | ${'7.4'} | ${'add_pdo_extension cubrid'}
${'pdo_mysql'} | ${'7.4'} | ${'add_pdo_extension mysql'}
${'pdo_oci'} | ${'7.3'} | ${'add_oci pdo_oci'}
${'pecl_http'} | ${'7.3'} | ${'add_http'}
${'phalcon3'} | ${'7.3'} | ${'add_phalcon phalcon3'}
${'sqlite'} | ${'7.4'} | ${'add_extension sqlite3'}
${'Xdebug'} | ${'7.4'} | ${'add_extension xdebug'}
${'xdebug-alpha'} | ${'7.4'} | ${'add_unstable_extension xdebug alpha zend_extension'}
${'xdebug2'} | ${'7.2'} | ${'add_pecl_extension xdebug 2.9.8 zend_extension'}
`(
'checking addExtensionOnLinux for extension $extension on version $version',
async ({extension, version, output}) => {
expect(
await extensions.addExtension(extension, version, 'linux')
).toContain(output);
}
);
win32 = await extensions.addExtension('xdebug2', '7.2', 'win32');
expect(win32).toContain('Add-Extension xdebug stable 2.9.8');
it.each`
extension | version | output
${'none'} | ${'7.2'} | ${'disable_all_shared'}
${':intl'} | ${'7.2'} | ${'disable_extension intl'}
${'ast-beta'} | ${'7.2'} | ${'add_unstable_extension ast beta extension'}
${'blackfire'} | ${'7.3'} | ${'add_blackfire blackfire'}
${'blackfire-1.31.0'} | ${'7.3'} | ${'add_blackfire blackfire-1.31.0'}
${'couchbase'} | ${'5.6'} | ${'add_couchbase'}
${'does_not_exist'} | ${'7.2'} | ${'add_extension does_not_exist'}
${'geos'} | ${'7.3'} | ${'add_geos'}
${'grpc-1.2.3'} | ${'7.2'} | ${'add_pecl_extension grpc 1.2.3 extension'}
${'http-1.2.3'} | ${'7.3'} | ${'add_http http-1.2.3'}
${'imagick'} | ${'5.5'} | ${'add_extension imagick'}
${'ioncube'} | ${'7.3'} | ${'add_ioncube'}
${'mongodb-mongodb/mongo-php-driver@master'} | ${'7.2'} | ${'add_extension_from_source mongodb https://github.com mongodb mongo-php-driver master extension'}
${'oci8'} | ${'7.3'} | ${'add_oci oci8'}
${'pcov'} | ${'5.6'} | ${'add_log "$cross" "pcov" "pcov is not supported on PHP 5.6"'}
${'pdo_oci'} | ${'7.3'} | ${'add_oci pdo_oci'}
${'pecl_http'} | ${'7.3'} | ${'add_http'}
${'sqlite'} | ${'7.2'} | ${'add_extension sqlite3'}
`(
'checking addExtensionOnDarwin for extension $extension on version $version',
async ({extension, version, output}) => {
expect(
await extensions.addExtension(extension, version, 'darwin')
).toContain(output);
}
);
win32 = await extensions.addExtension('mysql', '7.4', 'win32');
expect(win32).toContain('Add-Extension mysqli');
expect(win32).toContain('Add-Extension mysqlnd');
const data: string[][] = fs
.readFileSync('src/configs/brew_extensions')
.toString()
.split(/\r?\n/)
.filter(Boolean)
.map(line => {
const [formula, extension]: string[] = line.split('=');
const prefix: string =
extension == 'xdebug' ? 'zend_extension' : 'extension';
const output: string = fs.existsSync(`src/scripts/ext/${extension}.sh`)
? `add_${extension}`
: `add_brew_extension ${formula} ${prefix}`;
return [formula, '7.3', output];
});
win32 = await extensions.addExtension('mysql', '8.0', 'win32');
expect(win32).toContain('Add-Extension mysqli');
expect(win32).toContain('Add-Extension mysqlnd');
it.each(data)(
'checking addExtensionOnDarwin for brew extension %s',
async (extension, version, output) => {
expect(
await extensions.addExtension(extension, version, 'darwin')
).toContain(output);
}
);
win32 = await extensions.addExtension('mysql', '5.5', 'win32');
expect(win32).toContain('Add-Extension mysql');
expect(win32).toContain('Add-Extension mysqli');
expect(win32).toContain('Add-Extension mysqlnd');
win32 = await extensions.addExtension(
'phalcon3, does_not_exist',
'7.2',
'win32',
true
);
expect(win32).toContain('Add-Phalcon phalcon3');
expect(win32).toContain('Add-Extension does_not_exist');
win32 = await extensions.addExtension('xdebug', '7.2', 'openbsd');
expect(win32).toContain('Platform openbsd is not supported');
win32 = await extensions.addExtension('blackfire', '7.3', 'win32');
expect(win32).toContain('Add-Blackfire blackfire');
win32 = await extensions.addExtension('blackfire-1.31.0', '7.3', 'win32');
expect(win32).toContain('Add-Blackfire blackfire-1.31.0');
win32 = await extensions.addExtension(
'mongodb-mongodb/mongo-php-driver@master',
'7.3',
'win32'
);
expect(win32).toContain(
'Add-Log "$cross" "mongodb-mongodb/mongo-php-driver@master" "mongodb-mongodb/mongo-php-driver@master is not supported on PHP 7.3"'
);
});
it('checking addExtensionOnLinux', async () => {
let linux: string = await extensions.addExtension(
'Xdebug, pcov, sqlite, :intl, ast, ast-beta, pdo_mysql, pdo-odbc, xdebug-alpha, grpc-1.2.3',
'7.4',
'linux'
);
expect(linux).toContain('add_extension xdebug');
expect(linux).toContain('add_extension sqlite3');
expect(linux).toContain('remove_extension intl');
expect(linux).toContain('add_unstable_extension ast beta extension');
expect(linux).toContain('add_pdo_extension mysql');
expect(linux).toContain('add_pdo_extension odbc');
expect(linux).toContain('add_pecl_extension grpc 1.2.3 extension');
expect(linux).toContain(
'add_unstable_extension xdebug alpha zend_extension'
);
linux = await extensions.addExtension('pcov', '5.6', 'linux');
expect(linux).toContain(
'add_log "$cross" "pcov" "pcov is not supported on PHP 5.6"'
);
linux = await extensions.addExtension('gearman', '5.6', 'linux');
expect(linux).toContain('add_gearman');
linux = await extensions.addExtension('gearman', '7.4', 'linux');
expect(linux).toContain('add_gearman');
linux = await extensions.addExtension('couchbase', '5.6', 'linux');
expect(linux).toContain('add_couchbase');
linux = await extensions.addExtension('couchbase', '7.4', 'linux');
expect(linux).toContain('add_couchbase');
linux = await extensions.addExtension('pdo_cubrid', '7.0', 'linux');
expect(linux).toContain('add_cubrid pdo_cubrid');
linux = await extensions.addExtension('cubrid', '7.4', 'linux');
expect(linux).toContain('add_cubrid cubrid');
linux = await extensions.addExtension('xdebug2', '7.2', 'linux');
expect(linux).toContain('add_pecl_extension xdebug 2.9.8 zend_extension');
linux = await extensions.addExtension('xdebug', '7.2', 'openbsd');
expect(linux).toContain('Platform openbsd is not supported');
linux = await extensions.addExtension('phalcon3, phalcon4', '7.3', 'linux');
expect(linux).toContain('add_phalcon phalcon3');
expect(linux).toContain('add_phalcon phalcon4');
linux = await extensions.addExtension('ioncube', '7.3', 'linux');
expect(linux).toContain('add_ioncube');
linux = await extensions.addExtension('geos', '7.3', 'linux');
expect(linux).toContain('add_geos');
linux = await extensions.addExtension('pecl_http', '7.3', 'linux');
expect(linux).toContain('add_http');
linux = await extensions.addExtension('http-1.2.3', '7.3', 'linux');
expect(linux).toContain('add_http http-1.2.3');
linux = await extensions.addExtension('oci8, pdo_oci', '7.3', 'linux');
expect(linux).toContain('add_oci oci8');
expect(linux).toContain('add_oci pdo_oci');
linux = await extensions.addExtension('blackfire', '7.3', 'linux');
expect(linux).toContain('add_blackfire blackfire');
linux = await extensions.addExtension('blackfire-1.31.0', '7.3', 'linux');
expect(linux).toContain('add_blackfire blackfire-1.31.0');
linux = await extensions.addExtension('intl-65.1', '5.6', 'linux');
expect(linux).toContain('add_intl intl-65.1');
linux = await extensions.addExtension('intl-67.1', '7.3', 'linux');
expect(linux).toContain('add_intl intl-67.1');
linux = await extensions.addExtension('intl-68.2', '8.0', 'linux');
expect(linux).toContain('add_intl intl-68.2');
linux = await extensions.addExtension(
'mongodb-mongodb/mongo-php-driver@master',
'7.3',
'linux'
);
expect(linux).toContain(
'add_extension_from_source mongodb https://github.com mongodb mongo-php-driver master extension'
);
});
it('checking addExtensionOnDarwin', async () => {
let darwin: string = await extensions.addExtension(
'amqp, apcu, Xdebug, pcov, grpc, igbinary, imagick, imap, memcache, memcached, msgpack, phalcon3, phalcon4, protobuf, psr, redis, swoole, sqlite, oci8, pdo_oci, :intl, ast-beta, grpc-1.2.3',
'7.2',
'darwin'
);
expect(darwin).toContain('add_brew_extension amqp extension');
expect(darwin).toContain('add_brew_extension apcu extension');
expect(darwin).toContain('add_brew_extension xdebug zend_extension');
expect(darwin).toContain('add_brew_extension pcov extension');
expect(darwin).toContain('add_brew_extension grpc extension');
expect(darwin).toContain('add_brew_extension igbinary extension');
expect(darwin).toContain('add_brew_extension imagick extension');
expect(darwin).toContain('add_brew_extension imap extension');
expect(darwin).toContain('add_brew_extension memcache extension');
expect(darwin).toContain('add_brew_extension memcached extension');
expect(darwin).toContain('add_brew_extension msgpack extension');
expect(darwin).toContain('add_brew_extension phalcon3 extension');
expect(darwin).toContain('add_brew_extension phalcon4 extension');
expect(darwin).toContain('add_brew_extension protobuf extension');
expect(darwin).toContain('add_brew_extension psr extension');
expect(darwin).toContain('add_brew_extension redis extension');
expect(darwin).toContain('add_brew_extension swoole extension');
expect(darwin).toContain('add_extension sqlite3');
expect(darwin).toContain('remove_extension intl');
expect(darwin).toContain('add_unstable_extension ast beta extension');
expect(darwin).toContain('add_pecl_extension grpc 1.2.3 extension');
darwin = await extensions.addExtension('couchbase', '5.6', 'darwin');
expect(darwin).toContain('add_couchbase');
darwin = await extensions.addExtension('couchbase', '7.3', 'darwin');
expect(darwin).toContain('add_couchbase');
darwin = await extensions.addExtension('ioncube', '7.3', 'darwin');
expect(darwin).toContain('add_ioncube');
darwin = await extensions.addExtension('geos', '7.3', 'darwin');
expect(darwin).toContain('add_geos');
darwin = await extensions.addExtension('pecl_http', '7.3', 'darwin');
expect(darwin).toContain('add_http');
darwin = await extensions.addExtension('http-1.2.3', '7.3', 'darwin');
expect(darwin).toContain('add_http http-1.2.3');
darwin = await extensions.addExtension('oci8, pdo_oci', '7.3', 'darwin');
expect(darwin).toContain('add_oci oci8');
expect(darwin).toContain('add_oci pdo_oci');
darwin = await extensions.addExtension('pcov', '5.6', 'darwin');
expect(darwin).toContain(
'add_log "$cross" "pcov" "pcov is not supported on PHP 5.6"'
);
darwin = await extensions.addExtension('pcov', '7.2', 'darwin');
expect(darwin).toContain('add_brew_extension pcov');
darwin = await extensions.addExtension('xdebug', '5.6', 'darwin');
expect(darwin).toContain('add_brew_extension xdebug');
darwin = await extensions.addExtension('xdebug', '7.0', 'darwin');
expect(darwin).toContain('add_brew_extension xdebug');
darwin = await extensions.addExtension('xdebug', '7.2', 'darwin');
expect(darwin).toContain('add_brew_extension xdebug');
darwin = await extensions.addExtension('xdebug2', '7.2', 'darwin');
expect(darwin).toContain('add_brew_extension xdebug2');
darwin = await extensions.addExtension('imagick', '5.5', 'darwin');
expect(darwin).toContain('add_extension imagick');
darwin = await extensions.addExtension('blackfire', '7.3', 'darwin');
expect(darwin).toContain('add_blackfire blackfire');
darwin = await extensions.addExtension('blackfire-1.31.0', '7.3', 'darwin');
expect(darwin).toContain('add_blackfire blackfire-1.31.0');
darwin = await extensions.addExtension(
'does_not_exist',
'7.2',
'darwin',
false
);
expect(darwin).toContain('add_extension does_not_exist');
darwin = await extensions.addExtension('xdebug', '7.2', 'openbsd');
expect(darwin).toContain('Platform openbsd is not supported');
darwin = await extensions.addExtension(
'mongodb-mongodb/mongo-php-driver@master',
'7.3',
'darwin'
);
expect(darwin).toContain(
'add_extension_from_source mongodb https://github.com mongodb mongo-php-driver master extension'
);
});
it.each`
extension | version | output
${'xdebug'} | ${'7.2'} | ${'Platform openbsd is not supported'}
`(
'checking addExtension on openbsd for extension $extension on version $version',
async ({extension, version, output}) => {
expect(
await extensions.addExtension(extension, version, 'openbsd')
).toContain(output);
}
);
});

View File

@ -5,40 +5,18 @@ import * as utils from '../src/utils';
* Mock install.ts
*/
jest.mock('../src/install', () => ({
getScript: jest
.fn()
.mockImplementation(
async (
filename: string,
version: string,
os_version: string
): Promise<string> => {
const extension_csv: string = process.env['extensions'] || '';
const ini_values_csv: string = process.env['ini-values'] || '';
const coverage_driver: string = process.env['coverage'] || '';
let tools_csv: string = process.env['tools'] || '';
const pecl: string = process.env['pecl'] || '';
if (pecl == 'true') {
tools_csv = 'pecl, ' + tools_csv;
}
let script = 'initial script ' + filename + version + os_version;
if (tools_csv) {
script += 'add_tool';
}
if (extension_csv) {
script += 'install extensions';
}
if (coverage_driver) {
script += 'set coverage driver';
}
if (ini_values_csv) {
script += 'edit php.ini';
}
return script;
}
),
getScript: jest.fn().mockImplementation(async (): Promise<string> => {
const extension_csv: string = process.env['extensions'] || '';
const ini_values_csv: string = process.env['ini-values'] || '';
const coverage_driver: string = process.env['coverage'] || '';
const tools_csv: string = process.env['tools'] || '';
let script = 'initial script';
script += tools_csv ? ' add_tool' : '';
script += extension_csv ? ' install extensions' : '';
script += coverage_driver ? ' set coverage driver' : '';
script += ini_values_csv ? ' edit php.ini' : '';
return script;
}),
run: jest.fn().mockImplementation(async (): Promise<string> => {
const os_version: string = process.env['RUNNER_OS'] || '';
const version: string = await utils.parseVersion(
@ -83,93 +61,41 @@ function setEnv(
}
describe('Install', () => {
it('Test install on windows', async () => {
setEnv('7.0', 'win32', '', '', '', '');
it.each`
version | os | extension_csv | ini_values_csv | coverage_driver | tools | output
${'7.3'} | ${'darwin'} | ${''} | ${''} | ${''} | ${''} | ${'initial script bash darwin.sh 7.3 ' + __dirname}
${'7.3'} | ${'darwin'} | ${'a, b'} | ${'a=b'} | ${'x'} | ${''} | ${'initial script install extensions set coverage driver edit php.ini bash darwin.sh 7.3 ' + __dirname}
${'7.4.1'} | ${'darwin'} | ${''} | ${''} | ${''} | ${''} | ${'initial script bash darwin.sh 7.4 ' + __dirname}
${'8'} | ${'darwin'} | ${''} | ${''} | ${''} | ${''} | ${'initial script bash darwin.sh 8.0 ' + __dirname}
${'8.0'} | ${'darwin'} | ${''} | ${''} | ${''} | ${''} | ${'initial script bash darwin.sh 8.0 ' + __dirname}
${'8.1'} | ${'darwin'} | ${''} | ${''} | ${''} | ${''} | ${'initial script bash darwin.sh 8.1 ' + __dirname}
${'7.3'} | ${'linux'} | ${''} | ${''} | ${''} | ${''} | ${'initial script bash linux.sh 7.3 ' + __dirname}
${'7.3'} | ${'linux'} | ${'a, b'} | ${'a=b'} | ${'x'} | ${'phpunit'} | ${'initial script add_tool install extensions set coverage driver edit php.ini bash linux.sh 7.3 ' + __dirname}
${'latest'} | ${'linux'} | ${''} | ${''} | ${''} | ${''} | ${'initial script bash linux.sh 8.1 ' + __dirname}
${'7.0'} | ${'win32'} | ${''} | ${''} | ${''} | ${''} | ${'initial script pwsh win32.ps1 7.0 ' + __dirname}
${'7.3'} | ${'win32'} | ${''} | ${''} | ${''} | ${''} | ${'initial script pwsh win32.ps1 7.3 ' + __dirname}
${'7.3'} | ${'win32'} | ${'a, b'} | ${'a=b'} | ${'x'} | ${''} | ${'initial script install extensions set coverage driver edit php.ini pwsh win32.ps1 7.3 ' + __dirname}
`(
'Test install on $os for $version with extensions=$extension_csv, ini_values=$ini_values_csv, coverage_driver=$coverage_driver, tools=$tools',
async ({
version,
os,
extension_csv,
ini_values_csv,
coverage_driver,
tools,
output
}) => {
setEnv(
version,
os,
extension_csv,
ini_values_csv,
coverage_driver,
tools
);
let script: string = '' + (await install.run());
expect(script).toContain('initial script');
expect(script).toContain('pwsh win32.ps1 7.0 ' + __dirname);
setEnv('7.3', 'win32', '', '', '', '');
script = '' + (await install.run());
expect(script).toContain('initial script');
expect(script).toContain('pwsh win32.ps1 7.3 ' + __dirname);
setEnv('7.3', 'win32', 'a, b', 'a=b', 'x', '');
script = '' + (await install.run());
expect(script).toContain('initial script');
expect(script).toContain('install extensions');
expect(script).toContain('edit php.ini');
expect(script).toContain('set coverage driver');
expect(script).toContain('pwsh win32.ps1 7.3 ' + __dirname);
});
it('Test install on linux', async () => {
setEnv('7.3', 'linux', '', '', '', '');
let script: string = '' + (await install.run());
expect(script).toContain('initial script');
expect(script).toContain('bash linux.sh 7.3 ');
setEnv('latest', 'linux', '', '', '', '');
script = '' + (await install.run());
expect(script).toContain('initial script');
expect(script).toContain('bash linux.sh 8.0 ');
setEnv('7.3', 'linux', 'a, b', 'a=b', 'x', 'phpunit');
script = '' + (await install.run());
expect(script).toContain('initial script');
expect(script).toContain('install extensions');
expect(script).toContain('edit php.ini');
expect(script).toContain('set coverage driver');
expect(script).toContain('bash linux.sh 7.3');
expect(script).toContain('add_tool');
});
it('Test install on darwin', async () => {
setEnv('7.3', 'darwin', '', '', '', '');
let script: string = '' + (await install.run());
expect(script).toContain('initial script');
expect(script).toContain('bash darwin.sh 7.3 ' + __dirname);
setEnv('7.3', 'darwin', 'a, b', 'a=b', 'x', '');
script = '' + (await install.run());
expect(script).toContain('initial script');
expect(script).toContain('install extensions');
expect(script).toContain('edit php.ini');
expect(script).toContain('set coverage driver');
expect(script).toContain('bash darwin.sh 7.3 ' + __dirname);
});
it('Test malformed version inputs', async () => {
setEnv('7.4.1', 'darwin', '', '', '', '');
let script: string = '' + '' + (await install.run());
expect(script).toContain('initial script');
expect(script).toContain('bash darwin.sh 7.4 ' + __dirname);
setEnv(8.0, 'darwin', '', '', '', '');
script = '' + (await install.run());
expect(script).toContain('initial script');
expect(script).toContain('bash darwin.sh 8.0 ' + __dirname);
setEnv(8, 'darwin', '', '', '', '');
script = '' + (await install.run());
expect(script).toContain('initial script');
expect(script).toContain('bash darwin.sh 8.0 ' + __dirname);
setEnv(8.1, 'darwin', '', '', '', '');
script = '' + (await install.run());
expect(script).toContain('initial script');
expect(script).toContain('bash darwin.sh 8.1 ' + __dirname);
});
expect(await install.run()).toBe(output);
}
);
});

File diff suppressed because it is too large Load Diff

View File

@ -8,10 +8,6 @@ jest.mock('@actions/core', () => ({
})
}));
jest.spyOn(utils, 'fetch').mockImplementation(async (url): Promise<string> => {
return `{ "latest": "8.0", "5.x": "5.6", "url": "${url}" }`;
});
async function cleanup(path: string): Promise<void> {
fs.unlink(path, error => {
if (error) {
@ -23,7 +19,11 @@ async function cleanup(path: string): Promise<void> {
describe('Utils tests', () => {
it('checking readEnv', async () => {
process.env['test'] = 'setup-php';
process.env['test-hyphen'] = 'setup-php';
expect(await utils.readEnv('test')).toBe('setup-php');
expect(await utils.readEnv('TEST')).toBe('setup-php');
expect(await utils.readEnv('test_hyphen')).toBe('setup-php');
expect(await utils.readEnv('TEST_HYPHEN')).toBe('setup-php');
expect(await utils.readEnv('undefined')).toBe('');
});
@ -32,19 +32,39 @@ describe('Utils tests', () => {
expect(await utils.getInput('test', false)).toBe('setup-php');
expect(await utils.getInput('setup-php', false)).toBe('setup-php');
expect(await utils.getInput('DoesNotExist', false)).toBe('');
expect(async () => {
await expect(async () => {
await utils.getInput('DoesNotExist', true);
}).rejects.toThrow('Input required and not supplied: DoesNotExist');
});
it('checking fetch', async () => {
expect(await utils.fetch('test_url')).toBe(
'{ "latest": "8.0", "5.x": "5.6", "url": "test_url" }'
);
const manifest = await utils.getManifestURL();
let response: Record<string, string> = await utils.fetch(manifest);
expect(response.error).toBe(undefined);
expect(response.data).toContain('latest');
response = await utils.fetch(manifest, 'invalid_token');
expect(response.error).not.toBe(undefined);
expect(response.data).toBe(undefined);
});
it('checking getManifestURL', async () => {
expect(await utils.getManifestURL()).toContain('php-versions.json');
});
it('checking parseVersion', async () => {
expect(await utils.parseVersion('latest')).toBe('8.0');
jest
.spyOn(utils, 'fetch')
.mockImplementation(
async (url, token?): Promise<Record<string, string>> => {
if (!token || token === 'valid_token') {
return {data: `{ "latest": "8.0", "5.x": "5.6", "url": "${url}" }`};
} else {
return {error: 'Invalid token'};
}
}
);
expect(await utils.parseVersion('latest')).toBe('8.1');
expect(await utils.parseVersion('7')).toBe('7.0');
expect(await utils.parseVersion('7.4')).toBe('7.4');
expect(await utils.parseVersion('5.x')).toBe('5.6');
@ -70,7 +90,7 @@ describe('Utils tests', () => {
expect(await utils.color('warning')).toBe('33');
});
it('checking readScripts', async () => {
it('checking readFile', async () => {
const darwin: string = fs.readFileSync(
path.join(__dirname, '../src/scripts/darwin.sh'),
'utf8'
@ -83,12 +103,12 @@ describe('Utils tests', () => {
path.join(__dirname, '../src/scripts/win32.ps1'),
'utf8'
);
expect(await utils.readScript('darwin.sh')).toBe(darwin);
expect(await utils.readScript('darwin.sh')).toBe(darwin);
expect(await utils.readScript('linux.sh')).toBe(linux);
expect(await utils.readScript('linux.sh')).toBe(linux);
expect(await utils.readScript('win32.ps1')).toBe(win32);
expect(await utils.readScript('win32.ps1')).toBe(win32);
expect(await utils.readFile('darwin.sh', 'src/scripts')).toBe(darwin);
expect(await utils.readFile('darwin.sh', 'src/scripts')).toBe(darwin);
expect(await utils.readFile('linux.sh', 'src/scripts')).toBe(linux);
expect(await utils.readFile('linux.sh', 'src/scripts')).toBe(linux);
expect(await utils.readFile('win32.ps1', 'src/scripts')).toBe(win32);
expect(await utils.readFile('win32.ps1', 'src/scripts')).toBe(win32);
});
it('checking writeScripts', async () => {
@ -106,12 +126,9 @@ describe('Utils tests', () => {
});
it('checking extensionArray', async () => {
expect(await utils.extensionArray('a, b, php_c, php-d')).toEqual([
'a',
'b',
'c',
'd'
]);
expect(
await utils.extensionArray('a, :b, php_c, none, php-d, Zend e, :Zend f')
).toEqual(['none', 'a', ':b', 'c', 'd', 'e', ':f']);
expect(await utils.extensionArray('')).toEqual([]);
expect(await utils.extensionArray(' ')).toEqual([]);

View File

@ -7,7 +7,7 @@ branding:
inputs:
php-version:
description: 'Setup PHP version.'
default: '8.0'
default: '8.1'
required: true
extensions:
description: 'Setup PHP extensions.'
@ -21,6 +21,9 @@ inputs:
tools:
description: 'Setup popular tools globally.'
required: false
outputs:
php-version:
description: 'PHP version in semver format'
runs:
using: 'node12'
main: 'dist/index.js'

1076
dist/index.js vendored

File diff suppressed because it is too large Load Diff

View File

@ -25,7 +25,7 @@ jobs:
with:
php-version: ${{ matrix.php-versions }}
extensions: blackfire
tools: blackfire #Setup Blackfire client and agent
tools: blackfire #Setup Blackfire cli
coverage: none
- name: Profile
run: blackfire run php my-script.php # Refer to https://blackfire.io/docs/cookbooks/profiling-cli

View File

@ -26,6 +26,7 @@ jobs:
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with:
php-version: ${{ matrix.php-versions }}
tools: phpunit-bridge
extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, mysql
coverage: xdebug #optional
- name: Start mysql service
@ -42,15 +43,15 @@ jobs:
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Composer dependencies
run: |
composer require --dev symfony/orm-pack symfony/phpunit-bridge
composer install --no-progress --prefer-dist --optimize-autoloader
php bin/phpunit install
run: composer install --no-progress --prefer-dist --optimize-autoloader
- name: Run Migration
run: |
composer require --dev symfony/orm-pack
php bin/console doctrine:schema:update --force || echo "No migrations found or schema update failed"
php bin/console doctrine:migrations:migrate || echo "No migrations found or migration failed"
env:
DATABASE_URL: mysql://root:symfony@127.0.0.1:${{ job.services.mysql.ports['3306'] }}/symfony
- name: Run Tests
run: php bin/phpunit --coverage-text
- name: Install PHPUnit
run: simple-phpunit install
- name: Run tests
run: simple-phpunit --coverage-text

View File

@ -26,6 +26,7 @@ jobs:
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with:
php-version: ${{ matrix.php-versions }}
tools: phpunit-bridge
extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, pgsql
coverage: xdebug #optional
- name: Get composer cache directory
@ -40,15 +41,15 @@ jobs:
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Composer dependencies
run: |
composer require --dev symfony/orm-pack symfony/phpunit-bridge
composer install --no-progress --prefer-dist --optimize-autoloader
php bin/phpunit install
run: composer install --no-progress --prefer-dist --optimize-autoloader
- name: Run Migration
run: |
composer require --dev symfony/orm-pack
php bin/console doctrine:schema:update --force || echo "No migrations found or schema update failed"
php bin/console doctrine:migrations:migrate || echo "No migrations found or migration failed"
env:
DATABASE_URL: postgres://postgres:postgres@127.0.0.1:${{ job.services.postgres.ports[5432] }}/postgres?charset=UTF-8
- name: Run Tests
run: php bin/phpunit --coverage-text
- name: Install PHPUnit
run: simple-phpunit install
- name: Run tests
run: simple-phpunit --coverage-text

View File

@ -17,6 +17,7 @@ jobs:
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with:
php-version: ${{ matrix.php-versions }}
tools: phpunit-bridge
extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite
coverage: xdebug #optional
- name: Get composer cache directory
@ -31,9 +32,8 @@ jobs:
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Composer dependencies
run: |
composer require --dev symfony/phpunit-bridge
composer install --no-progress --prefer-dist --optimize-autoloader
php bin/phpunit install
- name: Run Tests
run: php bin/phpunit --coverage-text
run: composer install --no-progress --prefer-dist --optimize-autoloader
- name: Install PHPUnit
run: simple-phpunit install
- name: Run tests
run: simple-phpunit --coverage-text

4753
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,14 +1,24 @@
{
"name": "setup-php",
"version": "2.11.0",
"version": "2.15.0",
"private": false,
"description": "Setup PHP for use with GitHub Actions",
"main": "lib/install.js",
"types": "lib/install.d.ts",
"directories": {
"lib": "lib",
"test": "__tests__",
"src": "src"
},
"files": [
"lib",
"src"
],
"scripts": {
"build": "tsc",
"lint": "eslint **/*.ts --cache --fix",
"format": "prettier --write **/*.ts && git add .",
"format-check": "prettier --check **/*.ts",
"lint": "eslint **/src/*.ts --cache --fix",
"format": "prettier --write **/src/*.ts && git add -f src/",
"format-check": "prettier --check **/src/*.ts",
"release": "ncc build -o dist && git add -f dist/",
"test": "jest"
},
@ -24,33 +34,33 @@
"author": "shivammathur",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.3.0",
"@actions/exec": "^1.0.4",
"@actions/io": "^1.1.0",
"@actions/core": "^1.5.0",
"@actions/exec": "^1.1.0",
"@actions/io": "^1.1.1",
"fs": "0.0.1-security"
},
"devDependencies": {
"@types/jest": "^26.0.23",
"@types/node": "^15.6.1",
"@typescript-eslint/eslint-plugin": "^4.25.0",
"@typescript-eslint/parser": "^4.25.0",
"@vercel/ncc": "^0.28.6",
"eslint": "^7.27.0",
"@types/jest": "^27.0.2",
"@types/node": "^16.10.1",
"@typescript-eslint/eslint-plugin": "^4.32.0",
"@typescript-eslint/parser": "^4.32.0",
"@vercel/ncc": "^0.31.1",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jest": "^24.3.6",
"eslint-plugin-prettier": "^3.4.0",
"husky": "^4.3.8",
"jest": "^27.0.3",
"jest-circus": "^27.0.3",
"prettier": "^2.3.0",
"ts-jest": "^27.0.1",
"typescript": "^4.3.2"
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-jest": "^24.4.2",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^27.2.2",
"jest-circus": "^27.2.2",
"prettier": "^2.4.1",
"simple-git-hooks": "^2.6.1",
"ts-jest": "^27.0.5",
"typescript": "^4.4.3"
},
"husky": {
"skipCI": true,
"hooks": {
"pre-commit": "npm run format && npm run lint && npm run test && npm run build && npm run release"
}
"bugs": {
"url": "https://github.com/shivammathur/setup-php/issues"
},
"simple-git-hooks": {
"pre-commit": "npm run format && npm run lint && npm run test && npm run build && npm run release"
}
}

View File

@ -0,0 +1,29 @@
amqp=amqp
apcu=apcu
expect=expect
grpc=grpc
igbinary=igbinary
imagick=imagick
imap=imap
memcache=memcache
memcached=memcached
mongodb=mongodb
msgpack=msgpack
pcov=pcov
pecl_http=http
phalcon3=phalcon
phalcon4=phalcon
propro=propro
protobuf=protobuf
psr=psr
raphf=raphf
rdkafka=rdkafka
redis=redis
ssh2=ssh2
swoole=swoole
vips=vips
xdebug=xdebug
xdebug2=xdebug
xlswriter=xlswriter
yaml=yaml
zmq=zmq

View File

@ -0,0 +1,17 @@
8,jessie
9,stretch
10,buster
11,bullseye
12,bookworm
16.04 LTS,xenial
16.10,yakkety
17.04,zesty
17.10,artful
18.04 LTS,bionic
18.10,cosmic
19.04,disco
19.10,eoan
20.04 LTS,focal
20.10,groovy
21.04,hirsute
21.10,impish
1 8 jessie
2 9 stretch
3 10 buster
4 11 bullseye
5 12 bookworm
6 16.04 LTS xenial
7 16.10 yakkety
8 17.04 zesty
9 17.10 artful
10 18.04 LTS bionic
11 18.10 cosmic
12 19.04 disco
13 19.10 eoan
14 20.04 LTS focal
15 20.10 groovy
16 21.04 hirsute
17 21.10 impish

View File

@ -1,6 +1,7 @@
{
"latest": "8.0",
"latest": "8.1",
"nightly": "8.2",
"5.x": "5.6",
"7.x": "7.4",
"8.x": "8.0"
"8.x": "8.1"
}

257
src/configs/tools.json Normal file
View File

@ -0,0 +1,257 @@
{
"composer-normalize": {
"type": "phar",
"repository": "ergebnis/composer-normalize",
"extension": ".phar",
"domain": "https://github.com",
"version_prefix": "",
"version_parameter": "-V"
},
"cs2pr": {
"type": "phar",
"repository": "staabm/annotate-pull-request-from-checkstyle",
"extension": "",
"domain": "https://github.com",
"version_prefix": "",
"version_parameter": "-V"
},
"infection": {
"type": "phar",
"repository": "infection/infection",
"extension": ".phar",
"domain": "https://github.com",
"version_prefix": "",
"version_parameter": "-V"
},
"phan": {
"type": "phar",
"repository": "phan/phan",
"extension": ".phar",
"domain": "https://github.com",
"version_prefix": "",
"version_parameter": "-v"
},
"parallel-lint": {
"type": "phar",
"repository": "php-parallel-lint/PHP-Parallel-Lint",
"extension": ".phar",
"domain": "https://github.com",
"version_prefix": "v",
"version_parameter": "--version"
},
"php-cs-fixer": {
"type": "phar",
"repository": "FriendsOfPHP/PHP-CS-Fixer",
"extension": ".phar",
"domain": "https://github.com",
"fetch_latest": "true",
"version_prefix": "v",
"version_parameter": "-V"
},
"phpcbf": {
"type": "phar",
"repository": "squizlabs/PHP_CodeSniffer",
"extension": ".phar",
"domain": "https://github.com",
"version_prefix": "",
"version_parameter": "--version"
},
"phpcs": {
"type": "phar",
"repository": "squizlabs/PHP_CodeSniffer",
"extension": ".phar",
"domain": "https://github.com",
"version_prefix": "",
"version_parameter": "--version"
},
"phpDocumentor": {
"type": "phar",
"repository": "phpDocumentor/phpDocumentor",
"extension": ".phar",
"domain": "https://github.com",
"alias": "phpdoc",
"version_prefix": "v",
"version_parameter": "--version"
},
"phpmd": {
"type": "phar",
"repository": "phpmd/phpmd",
"extension": ".phar",
"domain": "https://github.com",
"version_prefix": "",
"version_parameter": "--version"
},
"phpstan": {
"type": "phar",
"repository": "phpstan/phpstan",
"extension": ".phar",
"domain": "https://github.com",
"version_prefix": "",
"version_parameter": "-V"
},
"psalm": {
"type": "phar",
"repository": "vimeo/psalm",
"extension": ".phar",
"domain": "https://github.com",
"version_prefix": "",
"version_parameter": "-v"
},
"behat": {
"type": "composer",
"repository": "behat/behat"
},
"codeception": {
"type": "composer",
"repository": "codeception/codeception"
},
"automatic-composer-prefetcher": {
"type": "composer",
"alias": "composer-prefetcher",
"repository": "narrowspark/automatic-composer-prefetcher"
},
"composer-require-checker": {
"type": "composer",
"repository": "maglnet/composer-require-checker"
},
"composer-unused": {
"type": "composer",
"repository": "icanhazstring/composer-unused"
},
"flex": {
"type": "composer",
"repository": "symfony/flex"
},
"phinx": {
"type": "composer",
"repository": "robmorgan/phinx"
},
"phplint": {
"type": "composer",
"repository": "overtrue/phplint"
},
"phpspec": {
"type": "composer",
"repository": "phpspec/phpspec"
},
"phpunit-bridge": {
"alias": "simple-phpunit",
"type": "composer",
"repository": "symfony/phpunit-bridge"
},
"phpunit-polyfills": {
"type": "composer",
"repository": "yoast/phpunit-polyfills"
},
"prestissimo": {
"type": "composer",
"repository": "hirak/prestissimo"
},
"vapor-cli": {
"type": "composer",
"alias": "vapor",
"repository": "laravel/vapor-cli"
},
"blackfire": {
"type": "custom-package",
"alias": "blackfire-agent"
},
"grpc_php_plugin": {
"type": "custom-package",
"repository": "grpc/grpc",
"domain": "https://github.com",
"version_prefix": "v"
},
"protoc": {
"type": "custom-package",
"repository": "protocolbuffers/protobuf",
"domain": "https://github.com",
"version_prefix": "v"
},
"blackfire-player": {
"type": "custom-function",
"domain": "https://get.blackfire.io",
"function": "blackfire_player",
"version_prefix": "v",
"version_parameter": "-V"
},
"composer": {
"type": "custom-function",
"domain": "https://getcomposer.org",
"repository": "composer/composer",
"function": "composer"
},
"deployer": {
"type": "custom-function",
"domain": "https://deployer.org",
"repository": "deployphp/deployer",
"function": "deployer",
"version_prefix": "v",
"version_parameter": "-V"
},
"pecl": {
"type": "custom-function",
"function": "pecl"
},
"phing": {
"type": "custom-function",
"domain": "https://www.phing.info",
"repository": "phingofficial/phing",
"function": "phing",
"extension": ".phar",
"version_prefix": "",
"version_parameter": "-v"
},
"phive": {
"type": "custom-function",
"repository": "phar-io/phive",
"domain": "https://phar.io",
"function": "phive",
"version_prefix": "",
"version_parameter": "status"
},
"phpcpd": {
"type": "custom-function",
"repository": "sebastianbergmann/phpcpd",
"domain": "https://phar.phpunit.de",
"function": "phpcpd",
"version_prefix": "",
"version_parameter": "--version"
},
"phpunit": {
"type": "custom-function",
"repository": "sebastianbergmann/phpunit",
"domain": "https://phar.phpunit.de",
"function": "phpunit",
"version_prefix": "",
"version_parameter": "--version"
},
"phpize": {
"type": "custom-function",
"function": "dev_tools",
"alias": "php-config"
},
"php-config": {
"type": "custom-function",
"function": "dev_tools"
},
"symfony-cli": {
"type": "custom-function",
"function": "symfony",
"alias": "symfony",
"domain": "https://github.com",
"repository": "symfony/cli",
"version_prefix": "v",
"version_parameter": "version"
},
"wp-cli": {
"type": "custom-function",
"function": "wp_cli",
"repository": "wp-cli/wp-cli",
"domain": "https://github.com",
"alias": "wp",
"extension": ".phar",
"version_parameter": "--version",
"version_prefix": "v"
}
}

View File

@ -0,0 +1,115 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://raw.githubusercontent.com/shivammathur/setup-php/develop/src/configs/tools_schema.json",
"type": "object",
"title": "Tools",
"default": {},
"examples": [
{
"tool": {
"alias": "tool_alias",
"domain": "https://example.com",
"extension": ".ext",
"fetch_latest": "true",
"function": "function_name",
"repository": "user/tool",
"type": "phar, composer, custom-package or custom-function",
"version_parameter": "--version",
"version_prefix": "v"
}
}
],
"items": {
"properties": {
"alias": {
"$id": "#/items/properties/alias",
"type": "string",
"title": "The alias schema",
"description": "Alias for a tool.",
"examples": [
"tool_alias"
]
},
"domain": {
"$id": "#/items/properties/domain",
"type": "string",
"title": "The domain schema",
"description": "Domain URL of the tool.",
"examples": [
"https://example.com"
]
},
"extension": {
"$id": "#/items/properties/extension",
"type": "string",
"title": "The extension schema",
"description": "File extension of the tool.",
"examples": [
".ext"
]
},
"fetch_latest": {
"$id": "#/items/properties/fetch_latest",
"type": "string",
"title": "The fetch_latest schema",
"description": "Fetch the latest version from GitHub releases.",
"enum": [
"true",
"false"
]
},
"function": {
"$id": "#/items/properties/function",
"type": "string",
"title": "The function schema",
"description": "Function name in tools.ts which returns the script to setup the tool.",
"examples": [
"function_name"
]
},
"repository": {
"$id": "#/items/properties/repository",
"type": "string",
"title": "The repository schema",
"description": "GitHub repository of the tool.",
"examples": [
"user/tool"
]
},
"type": {
"$id": "#/items/properties/type",
"type": "string",
"title": "The type schema",
"description": "Type of tool: phar, composer, custom-package or custom-function.",
"enum": [
"phar",
"composer",
"custom-package",
"custom-function"
]
},
"version_parameter": {
"$id": "#/items/properties/version_parameter",
"type": "string",
"title": "The version_parameter schema",
"description": "Parameter to get the tool version.",
"examples": [
"--version"
]
},
"version_prefix": {
"$id": "#/items/properties/version_prefix",
"type": "string",
"title": "The version_prefix schema",
"description": "Prefix of the version in the download URL.",
"examples": [
"v"
]
}
},
"required": [
"type"
],
"additionalProperties": true
}
}

View File

@ -18,7 +18,8 @@ export async function addCoverageXdebug(
): Promise<string> {
let script = '\n';
script +=
(await extensions.addExtension(':pcov', version, os_version, true)) + pipe;
(await extensions.addExtension(':pcov:false', version, os_version, true)) +
pipe;
script +=
(await extensions.addExtension(extension, version, os_version, true)) +
pipe;
@ -47,8 +48,12 @@ export async function addCoveragePCOV(
switch (true) {
default:
script +=
(await extensions.addExtension(':xdebug', version, os_version, true)) +
pipe;
(await extensions.addExtension(
':xdebug:false',
version,
os_version,
true
)) + pipe;
script +=
(await extensions.addExtension('pcov', version, os_version, true)) +
pipe;
@ -92,10 +97,15 @@ export async function disableCoverage(
): Promise<string> {
let script = '\n';
script +=
(await extensions.addExtension(':pcov', version, os_version, true)) + pipe;
script +=
(await extensions.addExtension(':xdebug', version, os_version, true)) +
(await extensions.addExtension(':pcov:false', version, os_version, true)) +
pipe;
script +=
(await extensions.addExtension(
':xdebug:false',
version,
os_version,
true
)) + pipe;
script += await utils.addLog(
'$tick',
'none',

View File

@ -21,7 +21,11 @@ export async function addExtensionDarwin(
switch (true) {
// match :extension
case /^:/.test(ext_name):
remove_script += '\nremove_extension ' + ext_name.slice(1);
remove_script += '\ndisable_extension' + ext_name.replace(/:/g, ' ');
return;
// Match none
case /^none$/.test(ext_name):
add_script += '\ndisable_all_shared';
return;
// match extensions for compiling from source
case /.+-.+\/.+@.+/.test(extension):
@ -39,6 +43,7 @@ export async function addExtensionDarwin(
extension
):
case /^(5\.[3-6]|7\.[0-4])ioncube$/.test(version_extension):
case /(5\.6|7\.[0-3])phalcon3|7\.[2-4]phalcon4/.test(version_extension):
add_script += await utils.customPackage(
ext_name,
'ext',
@ -68,15 +73,16 @@ export async function addExtensionDarwin(
case /(5\.[3-6]|7\.0)pcov/.test(version_extension):
add_script += await utils.getUnsupportedLog('pcov', version, 'darwin');
return;
// match 5.6 and newer - amqp, apcu, grpc, igbinary, imagick, imap, msgpack, protobuf, raphf, redis, swoole, xdebug, xdebug2, zmq
// match 5.6 and newer - amqp, apcu, expect, grpc, igbinary, imagick, imap, memcache, memcached, mongodb, msgpack, protobuf, raphf, rdkafka, redis, ssh2, swoole, xdebug, xdebug2, yaml, zmq
// match 7.1 and newer - pcov
// match 5.6 to 7.4 - propro
case /(?<!5\.[3-5])(amqp|apcu|grpc|igbinary|imagick|imap|memcache|memcached|msgpack|protobuf|psr|raphf|redis|swoole|xdebug|xdebug2|zmq)/.test(
// match 7.0 and newer - vips, xlswriter
case /(?<!5\.[3-5])(amqp|apcu|expect|grpc|igbinary|imagick|imap|memcache|memcached|mongodb|msgpack|protobuf|psr|raphf|rdkafka|redis|ssh2|swoole|xdebug|xdebug2|yaml|zmq)/.test(
version_extension
):
case /(5\.6|7\.[0-4])propro/.test(version_extension):
case /(?<!5\.[3-6]|7\.0)pcov/.test(version_extension):
case /(5\.6|7\.[0-3])phalcon3|7\.[2-4]phalcon4/.test(version_extension):
case /(?<!5\.[3-6])(vips|xlswriter)/.test(version_extension):
add_script += await utils.joins(
'\nadd_brew_extension',
ext_name,
@ -115,7 +121,11 @@ export async function addExtensionWindows(
switch (true) {
// Match :extension
case /^:/.test(ext_name):
remove_script += '\nRemove-Extension ' + ext_name.slice(1);
remove_script += '\nDisable-Extension' + ext_name.replace(/:/g, ' ');
break;
// Match none
case /^none$/.test(ext_name):
add_script += '\nDisable-AllShared';
break;
// match 5.3blackfire...8.0blackfire
// match 5.3blackfire-(semver)...8.0blackfire-(semver)
@ -227,7 +237,11 @@ export async function addExtensionLinux(
switch (true) {
// Match :extension
case /^:/.test(ext_name):
remove_script += '\nremove_extension ' + ext_name.slice(1);
remove_script += '\ndisable_extension' + ext_name.replace(/:/g, ' ');
return;
// Match none
case /^none$/.test(ext_name):
add_script += '\ndisable_all_shared';
return;
// match extensions for compiling from source
case /.+-.+\/.+@.+/.test(extension):

View File

@ -18,8 +18,7 @@ export async function getScript(
version: string,
os_version: string
): Promise<string> {
const name = 'setup-php';
const url = 'https://setup-php.com/support';
const url = 'https://setup-php.com/sponsor';
// taking inputs
process.env['fail_fast'] = await utils.getInput('fail-fast', false);
const extension_csv: string = await utils.getInput('extensions', false);
@ -27,9 +26,8 @@ export async function getScript(
const coverage_driver: string = await utils.getInput('coverage', false);
const tools_csv: string = await utils.getInput('tools', false);
let script: string = await utils.readScript(filename);
let script: string = await utils.readFile(filename, 'src/scripts');
script += await tools.addTools(tools_csv, version, os_version);
if (extension_csv) {
script += await extensions.addExtension(extension_csv, version, os_version);
}
@ -39,9 +37,8 @@ export async function getScript(
if (ini_values_csv) {
script += await config.addINIValues(ini_values_csv, os_version);
}
script += '\n' + (await utils.stepLog('Support this project', os_version));
script += '\n' + (await utils.addLog('$tick', name, url, os_version));
script += '\n' + (await utils.stepLog(`Sponsor setup-php`, os_version));
script += '\n' + (await utils.addLog('$tick', 'setup-php', url, os_version));
return await utils.writeScript(filename, script);
}
@ -52,9 +49,10 @@ export async function getScript(
export async function run(): Promise<void> {
try {
if ((await utils.readEnv('ImageOS')) == 'ubuntu16') {
core.warning(
'Ubuntu 16.04 is deprecated.\nPlease upgrade to Ubuntu 18.04 or Ubuntu 20.04 - https://setup-php.com/i/452'
core.setFailed(
'setup-php is not supported on Ubuntu 16.04. Please upgrade to Ubuntu 18.04 or Ubuntu 20.04 - https://setup-php.com/i/452'
);
return;
}
const version: string = await utils.parseVersion(
await utils.getInput('php-version', true)
@ -69,7 +67,7 @@ export async function run(): Promise<void> {
core.setFailed('Unable to get the PHP version');
}
} catch (error) {
core.setFailed(error.message);
core.setFailed((error as Error).message);
}
}

View File

@ -7,9 +7,10 @@ export jit_versions="8.[0-9]"
export nightly_versions="8.[1-9]"
export xdebug3_versions="7.[2-4]|8.[0-9]"
export tool_path_dir="/usr/local/bin"
export composer_bin="$HOME/.composer/vendor/bin"
export composer_json="$HOME/.composer/composer.json"
export composer_lock="$HOME/.composer/composer.lock"
export composer_home="$HOME/.composer"
export composer_bin="$composer_home/vendor/bin"
export composer_json="$composer_home/composer.json"
export composer_lock="$composer_home/composer.lock"
export latest="releases/latest/download"
export github="https://github.com/shivammathur"
export jsdeliver="https://cdn.jsdelivr.net/gh/shivammathur"
@ -82,10 +83,6 @@ run_script() {
# Function to install required packages on self-hosted runners.
self_hosted_setup() {
if [ "$runner" = "self-hosted" ]; then
if [ "$DISTRIB_RELEASE" = "16.04" ] && [ "$CONTAINER" != "shivammathur/node" ]; then
add_log "$cross" "Ubuntu" "Ubuntu 16.04 (Xenial Xerus) is no longer supported on self-hosted runner"
exit 1
fi
if [[ "${version:?}" =~ $old_versions ]]; then
add_log "$cross" "PHP" "PHP $version is not supported on self-hosted runner"
exit 1
@ -97,7 +94,7 @@ self_hosted_setup() {
# Function to test if extension is loaded.
check_extension() {
extension=$1
local extension=$1
if [ "$extension" != "mysql" ]; then
php -m | grep -i -q -w "$extension"
else
@ -105,22 +102,23 @@ check_extension() {
fi
}
# Function to enable cached extensions.
enable_cache_extension() {
deps=()
for ext in /tmp/extcache/"$1"/*; do
deps+=("$(basename "$ext")")
done
if [ "x${deps[*]}" = "x" ]; then
sudo rm -rf /tmp/extcache/"$1"
enable_extension "$1" "$2"
else
deps+=("$1")
if php "${deps[@]/#/-d ${2}=}" -m 2>/dev/null | grep -i -q "$1"; then
for ext in "${deps[@]}"; do
sudo rm -rf /tmp/extcache/"$ext"
enable_extension "$ext" "$2"
done
# Function to check if extension is shared
shared_extension() {
[ -e "${ext_dir:?}/$1.so" ]
}
# Function to enable cached extension's dependencies.
enable_cache_extension_dependencies() {
if [ -d /tmp/extcache ] && shared_extension "$1"; then
cache_dir=$(find /tmp/extcache -maxdepth 1 -type d -regex ".*$1[0-9]*")
if [[ -n "$cache_dir" ]]; then
IFS=" " read -r -a deps <<<"$(find "$cache_dir" -maxdepth 1 -type f -name "*" -exec basename {} \; | tr '\n' ' ')"
if [[ -n "${deps[*]}" ]] && php "${deps[@]/#/-d ${2}=}" -d "${2}=$1" -m 2>/dev/null | grep -i -q "$1"; then
for ext in "${deps[@]}"; do
sudo rm -rf /tmp/extcache/"$ext"
enable_extension "$ext" "$2"
done
fi
fi
fi
}
@ -129,13 +127,64 @@ enable_cache_extension() {
enable_extension() {
modules_dir="/var/lib/php/modules/$version"
[ -d "$modules_dir" ] && sudo find "$modules_dir" -path "*disabled*$1" -delete
if [ -d /tmp/extcache/"$1" ]; then
enable_cache_extension "$1" "$2"
elif ! check_extension "$1" && [ -e "${ext_dir:?}/$1.so" ]; then
enable_extension_dependencies "$1" "$2"
enable_cache_extension_dependencies "$1" "$2"
if ! check_extension "$1" && shared_extension "$1"; then
echo "$2=${ext_dir:?}/$1.so" | sudo tee -a "${pecl_file:-${ini_file[@]}}" >/dev/null
fi
}
# Function to get a map of extensions and their dependent shared extensions.
get_extension_map() {
php -d'error_reporting=0' "${dist:?}"/../src/scripts/ext/extension_map.php
}
# Function to enable extension dependencies which are also extensions.
enable_extension_dependencies() {
local extension=$1
prefix=$2
if ! [ -e /tmp/map.orig ]; then
get_extension_map | sudo tee /tmp/map.orig >/dev/null
fi
for dependency in $(grep "$extension:" /tmp/map.orig | cut -d ':' -f 2 | tr '\n' ' '); do
enable_extension "$dependency" "$prefix"
done
}
# Function to disable dependent extensions.
disable_extension_dependents() {
local extension=$1
for dependent in $(get_extension_map | grep -E ".*:.*\s$extension(\s|$)" | cut -d ':' -f 1 | tr '\n' ' '); do
disable_extension_helper "$dependent" true
add_log "${tick:?}" ":$extension" "Disabled $dependent as it depends on $extension"
done
}
# Function to disable an extension.
disable_extension() {
local extension=$1
if check_extension "$extension"; then
if shared_extension "$extension"; then
disable_extension_helper "$extension" true
(! check_extension "$extension" && add_log "${tick:?}" ":$extension" "Disabled") ||
add_log "${cross:?}" ":$extension" "Could not disable $extension on PHP ${semver:?}"
else
add_log "${cross:?}" ":$extension" "Could not disable $extension on PHP $semver as it not a shared extension"
fi
elif shared_extension "$extension"; then
add_log "${tick:?}" ":$extension" "Disabled"
else
add_log "${tick:?}" ":$extension" "Could not find $extension on PHP $semver"
fi
}
# Function to disable shared extensions.
disable_all_shared() {
sudo sed -i.orig -E -e "/^(zend_)?extension\s*=/d" "${ini_file[@]}" "$pecl_file" 2>/dev/null || true
sudo find "${ini_dir:-$scan_dir}"/.. -name "*.ini" -not -path "*php.ini" -not -path "*mods-available*" -delete >/dev/null 2>&1 || true
add_log "${tick:?}" "none" "Disabled all shared extensions"
}
# Function to configure PHP
configure_php() {
(
@ -158,7 +207,7 @@ configure_pecl() {
# Function to get the PECL version of an extension.
get_pecl_version() {
extension=$1
local extension=$1
stability="$(echo "$2" | grep -m 1 -Eio "(stable|alpha|beta|rc|snapshot|preview)")"
pecl_rest='https://pecl.php.net/rest/r/'
response=$(get -s -n "" "$pecl_rest$extension"/allreleases.xml)
@ -178,7 +227,7 @@ pecl_install() {
# Function to install a specific version of PECL extension.
add_pecl_extension() {
extension=$1
local extension=$1
pecl_version=$2
prefix=$3
enable_extension "$extension" "$prefix"
@ -189,8 +238,7 @@ add_pecl_extension() {
if [ "$ext_version" = "$pecl_version" ]; then
add_log "${tick:?}" "$extension" "Enabled"
else
disable_extension "$extension" >/dev/null 2>&1
delete_extension "$extension" >/dev/null 2>&1
disable_extension_helper "$extension" >/dev/null 2>&1
pecl_install "$extension-$pecl_version"
add_extension_log "$extension-$pecl_version" "Installed and enabled"
fi
@ -198,7 +246,7 @@ add_pecl_extension() {
# Function to setup pre-release extensions using PECL.
add_unstable_extension() {
extension=$1
local extension=$1
stability=$2
prefix=$3
pecl_version=$(get_pecl_version "$extension" "$stability")
@ -232,10 +280,14 @@ configure_composer() {
add_log "$cross" "composer" "Could not download composer"
exit 1
fi
if ! [ -d "$composer_home" ]; then
sudo -u "$(id -un)" -g "$(id -gn)" mkdir -p -m=00755 "$composer_home"
else
sudo chown -R "$(id -un)":"$(id -gn)" "$composer_home"
fi
if ! [ -e "$composer_json" ]; then
sudo mkdir -p "$(dirname "$composer_json")"
echo '{}' | tee "$composer_json" >/dev/null
sudo chmod 644 "$composer_json"
chmod 644 "$composer_json"
fi
composer -q config -g process-timeout 0
echo "$composer_bin" >>"$GITHUB_PATH"
@ -300,14 +352,15 @@ add_composertool() {
# Function to get PHP version in semver format.
php_semver() {
php"$version" -v | grep -Eo -m 1 "[0-9]+\.[0-9]+\.[0-9]+" | head -n 1
php -v | grep -Eo -m 1 "[0-9]+\.[0-9]+\.[0-9]+((-?[a-zA-Z]+([0-9]+)?)?){2}" | head -n 1
}
# Function to get the tag for a php version.
php_src_tag() {
php_src_tag='master'
if ! [[ ${version:?} =~ $nightly_versions ]]; then
php_src_tag="php-$semver"
commit=$(php_extra_version | grep -Eo "[0-9a-zA-Z]+")
if [[ -n "${commit}" ]]; then
echo "$commit"
else
echo "php-$semver"
fi
echo "$php_src_tag"
}

View File

@ -7,31 +7,29 @@ self_hosted_helper() {
fi
}
# Function to delete extension.
delete_extension() {
extension=$1
sudo rm -rf "${scan_dir:?}"/*"$extension"* "${ext_dir:?}"/"$extension".so >/dev/null 2>&1
}
# Function to disable extension.
disable_extension() {
extension=$1
sudo sed -Ei '' "/=(.*\/)?\"?$extension(.so)?$/d" "${ini_file:?}"
}
# Function to remove extensions.
remove_extension() {
extension=$1
if check_extension "$extension"; then
disable_extension "$extension"
delete_extension "$extension"
(! check_extension "$extension" && add_log "${tick:?}" ":$extension" "Removed") ||
add_log "${cross:?}" ":$extension" "Could not remove $extension on PHP ${semver:?}"
else
add_log "${tick:?}" ":$extension" "Could not find $extension on PHP $semver"
# Disable dependency extensions
disable_dependency_extensions() {
local extension=$1
formula_file="$tap_dir/$ext_tap/Formula/$extension@${version:?}.rb"
if [ -e "$formula_file" ]; then
IFS=" " read -r -a dependency_extensions <<< "$(grep -Eo "shivammathur.*@" "$formula_file" | xargs -I {} -n 1 basename '{}' | cut -d '@' -f 1 | tr '\n' ' ')"
for dependency_extension in "${dependency_extensions[@]}"; do
sudo sed -Ei '' "/=(.*\/)?\"?$dependency_extension(.so)?$/d" "${ini_file:?}"
done
fi
}
# Helper function to disable an extension.
disable_extension_helper() {
local extension=$1
local disable_dependents=${2:-false}
if [ "$disable_dependents" = "true" ]; then
disable_extension_dependents "$extension"
fi
sudo sed -Ei '' "/=(.*\/)?\"?$extension(.so)?$/d" "${ini_file:?}"
sudo rm -rf "$scan_dir"/*"$extension"*
}
# Function to fetch a brew tap.
fetch_brew_tap() {
tap=$1
@ -49,11 +47,11 @@ add_brew_tap() {
tap=$1
if ! [ -d "$tap_dir/$tap" ]; then
if [ "${runner:?}" = "self-hosted" ]; then
brew tap --shallow "$tap" >/dev/null 2>&1
brew tap "$tap" >/dev/null 2>&1
else
fetch_brew_tap "$tap" >/dev/null 2>&1
if ! [ -d "$tap_dir/$tap" ]; then
brew tap --shallow "$tap" >/dev/null 2>&1
brew tap "$tap" >/dev/null 2>&1
fi
fi
fi
@ -63,15 +61,17 @@ add_brew_tap() {
add_brew_extension() {
formula=$1
prefix=$2
extension="$(echo "$formula" | sed -E "s/pecl_|[0-9]//g")"
extension=$(grep "$formula=" "$dist"/../src/configs/brew_extensions | cut -d '=' -f 2)
[[ -z "$extension" ]] && extension="$(echo "$formula" | sed -E "s/pecl_|[0-9]//g")"
enable_extension "$extension" "$prefix"
if check_extension "$extension"; then
add_log "${tick:?}" "$extension" "Enabled"
else
add_brew_tap shivammathur/homebrew-php
add_brew_tap shivammathur/homebrew-extensions
sudo mv "$tap_dir"/shivammathur/homebrew-extensions/.github/deps/"$formula"/* "$tap_dir/homebrew/homebrew-core/Formula/" 2>/dev/null || true
add_brew_tap "$php_tap"
add_brew_tap "$ext_tap"
sudo mv "$tap_dir"/"$ext_tap"/.github/deps/"$formula"/* "$core_repo/Formula/" 2>/dev/null || true
update_dependencies >/dev/null 2>&1
disable_dependency_extensions "$extension" >/dev/null 2>&1
brew install -f "$formula@$version" >/dev/null 2>&1
sudo cp "$brew_prefix/opt/$formula@$version/$extension.so" "$ext_dir"
add_extension_log "$extension" "Installed and enabled"
@ -80,15 +80,18 @@ add_brew_extension() {
# Function to setup extensions.
add_extension() {
extension=$1
local extension=$1
prefix=$2
enable_extension "$extension" "$prefix"
if check_extension "$extension"; then
add_log "${tick:?}" "$extension" "Enabled"
else
[[ "$version" =~ 5.[4-5] ]] && [ "$extension" = "imagick" ] && brew install -f pkg-config imagemagick >/dev/null 2>&1
pecl_install "$extension" >/dev/null 2>&1 &&
if [[ "$version" =~ ${old_versions:?} ]] && [ "$extension" = "imagick" ]; then
run_script "php5-darwin" "${version/./}" "$extension" >/dev/null 2>&1
else
pecl_install "$extension" >/dev/null 2>&1 &&
if [[ "$version" =~ ${old_versions:?} ]]; then echo "$prefix=$ext_dir/$extension.so" >>"$ini_file"; fi
fi
add_extension_log "$extension" "Installed and enabled"
fi
}
@ -102,8 +105,8 @@ add_devtools() {
# Function to handle request to add PECL.
add_pecl() {
configure_pecl >/dev/null 2>&1
pecl_version=$(get_tool_version "pecl" "version")
add_log "${tick:?}" "PECL" "Found PECL $pecl_version"
pear_version=$(get_tool_version "pecl" "version")
add_log "${tick:?}" "PECL" "Found PECL $pear_version"
}
# Function to link all libraries of a formula.
@ -129,23 +132,23 @@ patch_brew() {
# Helper function to update the dependencies.
update_dependencies_helper() {
dependency=$1
get -q -n "$tap_dir/homebrew/homebrew-core/Formula/$dependency.rb" "https://raw.githubusercontent.com/Homebrew/homebrew-core/master/Formula/$dependency.rb"
get -q -n "$core_repo/Formula/$dependency.rb" "https://raw.githubusercontent.com/Homebrew/homebrew-core/master/Formula/$dependency.rb"
link_libraries "$dependency"
}
# Function to update dependencies.
update_dependencies() {
if ! [ -e /tmp/update_dependencies ] && [ "${runner:?}" != "self-hosted" ] && [ "${ImageOS:-}" != "" ] && [ "${ImageVersion:-}" != "" ]; then
patch_brew
while read -r dependency; do
update_dependencies_helper "$dependency" &
to_wait+=($!)
done <"$tap_dir/shivammathur/homebrew-php/.github/deps/${ImageOS:?}_${ImageVersion:?}"
wait "${to_wait[@]}"
# Remove when PCRE2 on macOS images is updated to PCRE2 10.37
brew reinstall pcre2 >/dev/null 2>&1
if ! [ -e /tmp/update_dependencies ]; then
if [ "${runner:?}" != "self-hosted" ] && [ "${ImageOS:-}" != "" ] && [ "${ImageVersion:-}" != "" ]; then
patch_brew
while read -r dependency; do
update_dependencies_helper "$dependency" &
to_wait+=($!)
done <"$tap_dir/$php_tap/.github/deps/${ImageOS:?}_${ImageVersion:?}"
wait "${to_wait[@]}"
else
git -C "$core_repo" fetch origin master && git -C "$core_repo" reset --hard origin/master
fi
echo '' | sudo tee /tmp/update_dependencies >/dev/null 2>&1
fi
}
@ -175,7 +178,7 @@ get_brewed_php() {
add_php() {
action=$1
existing_version=$2
add_brew_tap shivammathur/homebrew-php
add_brew_tap "$php_tap"
update_dependencies
if [ "$existing_version" != "false" ]; then
([ "$action" = "upgrade" ] && brew upgrade -f "$php_formula") || brew unlink "$php_formula"
@ -185,6 +188,14 @@ add_php() {
brew link --force --overwrite "$php_formula"
}
# Function to get extra version.
php_extra_version() {
php_formula_file="$tap_dir"/"$php_tap"/Formula/php@"$version".rb
if [ -e "$php_formula_file" ] && ! grep -q "deprecate!" "$php_formula_file" && grep -Eq "archive/[0-9a-zA-Z]+" "$php_formula_file"; then
echo " ($(grep -Eo "archive/[0-9a-zA-Z]+" "$php_formula_file" | cut -d'/' -f 2))"
fi
}
# Function to Setup PHP.
setup_php() {
step_log "Setup PHP"
@ -208,13 +219,16 @@ setup_php() {
ext_dir=$(php -i | grep -Ei "extension_dir => /" | sed -e "s|.*=> s*||")
scan_dir=$(php --ini | grep additional | sed -e "s|.*: s*||")
sudo mkdir -m 777 -p "$ext_dir" "$HOME/.composer"
semver=$(php -v | head -n 1 | cut -f 2 -d ' ')
semver=$(php_semver)
extra_version=$(php_extra_version)
if [ "${semver%.*}" != "$version" ]; then
add_log "$cross" "PHP" "Could not setup PHP $version"
add_log "${cross:?}" "PHP" "Could not setup PHP $version"
exit 1
fi
sudo cp "$dist"/../src/configs/*.json "$RUNNER_TOOL_CACHE/"
add_log "$tick" "PHP" "$status PHP $semver"
sudo cp "$dist"/../src/configs/pm/*.json "$RUNNER_TOOL_CACHE/"
echo "::set-output name=php-version::$semver"
add_log "$tick" "PHP" "$status PHP $semver$extra_version"
}
# Variables
@ -224,8 +238,12 @@ php_formula=shivammathur/php/php@"$version"
brew_prefix="$(brew --prefix)"
brew_repo="$(brew --repository)"
tap_dir="$brew_repo"/Library/Taps
core_repo="$tap_dir"/homebrew/homebrew-core
scripts="${dist}"/../src/scripts
ext_tap=shivammathur/homebrew-extensions
php_tap=shivammathur/homebrew-php
export HOMEBREW_CHANGE_ARCH_TO_ARM=1
export HOMEBREW_DEVELOPER=1
export HOMEBREW_NO_INSTALL_CLEANUP=1
export HOMEBREW_NO_AUTO_UPDATE=1
export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1

View File

@ -1,12 +1,13 @@
# Function to install blackfire extension.
add_blackfire() {
extension=$1
local extension=$1
version=${version:?}
no_dot_version=${version/./}
platform=$(uname -s | tr '[:upper:]' '[:lower:]')
extension_version=$(echo "$extension" | cut -d '-' -f 2)
blackfire_ini_file="${pecl_file:-${ini_file[@]}}"
if [ ! -e "${ext_dir:?}/blackfire.so" ]; then
status='Enabled'
if ! shared_extension blackfire; then
status='Installed and enabled'
if [ "$extension_version" = "blackfire" ]; then
if [[ ${version:?} =~ 5.[3-6] ]]; then
extension_version='1.50.0'
@ -16,6 +17,6 @@ add_blackfire() {
fi
get -q -n "${ext_dir:?}/blackfire.so" https://packages.blackfire.io/binaries/blackfire-php/"$extension_version"/blackfire-php-"$platform"_amd64-php-"$no_dot_version".so >/dev/null 2>&1
fi
echo "extension=blackfire.so" | sudo tee -a "$blackfire_ini_file" >/dev/null 2>&1
add_extension_log "$extension-$extension_version" "Installed and enabled"
enable_extension blackfire extension
add_extension_log blackfire "$status"
}

View File

@ -7,7 +7,7 @@ add_couchbase_libs() {
else
release="$(curl -sL $trunk/latest | grep -Eo "libcouchbase-[0-9]+\.[0-9]+\.[0-9]+" | head -n 1 | cut -d'-' -f 2)"
fi
deb_url="$trunk/download/$release/libcouchbase-${release}_ubuntu${DISTRIB_RELEASE/./}_${DISTRIB_CODENAME}_amd64.tar"
deb_url="$trunk/download/$release/libcouchbase-${release}_ubuntu${VERSION_ID/./}_${VERSION_CODENAME}_amd64.tar"
get -q -n /tmp/libcouchbase.tar "$deb_url"
sudo tar -xf /tmp/libcouchbase.tar -C /tmp
install_packages libev4 libevent-dev

View File

@ -39,7 +39,6 @@ add_cubrid_helper() {
status='Installed and enabled'
set_cubrid_repo
set_cubrid_branch
[ "$DISTRIB_RELEASE" = "16.04" ] && setup_compiler
patch_phpize
read -r "${ext}_PREFIX_CONFIGURE_OPTS" <<< "CFLAGS=-Wno-implicit-function-declaration"
read -r "${ext}_CONFIGURE_OPTS" <<< "--with-php-config=$(command -v php-config)"

View File

@ -0,0 +1,109 @@
<?php
/**
* Class for a map of extensions and their dependent extensions.
*
* Class ExtensionMap
*/
class ExtensionMap {
/** @var string Directory in which shared extensions are stored. */
private $extension_dir;
/** @var string File extension for PHP extension file. */
private $file_extension;
/** @var string Prefix in PHP extension file. */
private $file_prefix;
/** @var string String to store the map */
private $map;
/**
* ExtensionMap constructor.
*/
function __construct() {
$this->extension_dir = ini_get('extension_dir');
$this->file_extension = (PHP_OS == 'WINNT' ? '.dll' : '.so');
$this->file_prefix = (PHP_OS == 'WINNT' ? 'php_' : '');
$this->map = '';
}
/**
* Function to check if a shared extension file exists.
*
* @param string $extension
* @return bool
*/
public function checkSharedExtension($extension) {
$extension_file = $this->extension_dir. DIRECTORY_SEPARATOR . $this->file_prefix . $extension . $this->file_extension;
return file_exists($extension_file);
}
/**
* Function to get all shared extensions.
*
* @return string[]
*/
public function getSharedExtensions() {
$files = scandir($this->extension_dir);
$extensions = array_diff($files, array('.','..'));
$filter_pattern = "/$this->file_extension|$this->file_prefix/";
return array_map(function ($extension) use($filter_pattern) {
return preg_replace($filter_pattern, '', $extension);
}, $extensions);
}
/**
* Function to patch dependencies if there are any bugs in Reflection data.
*
* @param string $extension
* @param array $dependencies
* @return array
*/
public function patchDependencies($extension, $dependencies) {
// memcached 2.2.0 has no dependencies in reflection data.
if($extension == 'memcached') {
$dependencies = array_unique(array_merge($dependencies, array('igbinary', 'json', 'msgpack')));
}
return $dependencies;
}
/**
* Function to add extension to the map.
*
* @param string $extension
* @throws ReflectionException
*/
public function addExtensionToMap($extension) {
// PHP 5.3 does not allow using $this.
$self = $this;
$ref = new ReflectionExtension($extension);
$dependencies = array_keys(array_map('strtolower', $ref->getDependencies()));
$dependencies = $this->patchDependencies($extension, $dependencies);
$dependencies = array_filter($dependencies, function ($dependency) use ($self) {
return $self->checkSharedExtension($dependency);
});
$self->map .= $extension . ': ' . implode(' ', $dependencies) . PHP_EOL;
}
/**
* Function to print the map of shared extensions and their dependent extensions.
*
* @return string
*/
public function __toString() {
$extensions = array_map('strtolower', $this->getSharedExtensions());
foreach ($extensions as $extension) {
try {
$this->addExtensionToMap($extension);
} catch (ReflectionException $e) {
}
}
return $this->map;
}
}
$extension_map = new ExtensionMap();
echo $extension_map;

View File

@ -1,6 +1,7 @@
add_firebird_client_darwin() {
pkg_name=$(get -s -n "" https://github.com/FirebirdSQL/firebird/releases/latest | grep -Eo "Firebird-.*.pkg" | head -n 1)
get -q -e "/tmp/firebird.pkg" https://github.com/FirebirdSQL/firebird/releases/latest/download/"$pkg_name"
firebird_tag='R3_0_7'
pkg_name=$(get -s -n "" https://github.com/FirebirdSQL/firebird/releases/tag/"$firebird_tag" | grep -Eo "Firebird-.*.pkg" | head -n 1)
get -q -e "/tmp/firebird.pkg" https://github.com/FirebirdSQL/firebird/releases/download/"$firebird_tag"/"$pkg_name"
sudo installer -pkg /tmp/firebird.pkg -target /
sudo mkdir -p /opt/firebird/include /opt/firebird/lib
sudo find /Library/Frameworks/Firebird.framework -name '*.h' -exec cp "{}" /opt/firebird/include \;
@ -17,8 +18,13 @@ add_firebird_helper() {
}
add_firebird() {
enable_extension pdo_firebird
if [ "$(uname -s )" = "Darwin" ]; then
add_firebird_client_darwin >/dev/null 2>&1
fi
enable_extension pdo_firebird extension
status="Enabled"
if ! check_extension pdo_firebird; then
status="Installed and enabled"
if [ "$(uname -s)" = "Linux" ]; then
if [[ "${version:?}" =~ 5.3|${nightly_versions:?} ]]; then
add_firebird_helper /usr >/dev/null 2>&1
@ -26,9 +32,8 @@ add_firebird() {
add_pdo_extension firebird >/dev/null 2>&1
fi
else
add_firebird_client_darwin >/dev/null 2>&1
add_firebird_helper /opt/firebird >/dev/null 2>&1
fi
add_extension_log pdo_firebird "Installed and enabled"
fi
add_extension_log pdo_firebird "$status"
}

View File

@ -31,7 +31,7 @@ Function Repair-ICU() {
}
$zip_url = Get-ICUUrl $icu.Groups[1].Value $installed.Architecture $vs
if ($zip_url -ne '') {
New-Item -Path "$php_dir" -Name "icu" -ItemType "directory" | Out-Null
New-Item -Path "$php_dir" -Name "icu" -ItemType "directory" -Force > $null 2>&1
Invoke-WebRequest -Uri $zip_url -OutFile "$php_dir\icu\icu.zip"
Expand-Archive -Path $php_dir\icu\icu.zip -DestinationPath $php_dir\icu -Force
Get-ChildItem $php_dir\icu\bin -Filter *.dll | Copy-Item -Destination $php_dir -Force

View File

@ -99,7 +99,7 @@ add_http_version() {
ext=$1
enable_http
if [ "x$(php -r "echo phpversion('http');")" != "x${ext##*-}" ]; then
remove_extension http >/dev/null
disable_extension_helper http >/dev/null
add_http_helper pecl_http-"${ext##*-}" "$os"
status="Installed and enabled"
fi

View File

@ -8,6 +8,7 @@ Function Add-LicenseLog() {
# Function to add ioncube extension.
Function Add-Ioncube() {
try {
$status = 'Enabled'
if (-not(Test-Path $ext_dir\php_ioncube.dll)) {
$status = 'Installed and enabled'
$arch_part = $arch

View File

@ -1,17 +1,19 @@
# Function to log result of a operation.
add_license_log() {
printf "::group::\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "ioncube" "Click to read the ioncube loader license information"
cat /tmp/ioncube/LICENSE.txt
cat "${ext_dir:?}"/IONCUBE_LICENSE.txt
echo "::endgroup::"
}
# Function to install ioncube.
add_ioncube() {
if [ ! -e "${ext_dir:?}/ioncube.so" ]; then
status='Enabled'
if ! shared_extension ioncube; then
status='Installed and enabled'
os_name='lin' && [ "$(uname -s)" = "Darwin" ] && os_name='mac'
get -s -n "" https://downloads.ioncube.com/loader_downloads/ioncube_loaders_"$os_name"_x86-64.tar.gz | tar -xzf - -C /tmp
sudo mv /tmp/ioncube/ioncube_loader_"$os_name"_"${version:?}".so "$ext_dir/ioncube.so"
sudo mv /tmp/ioncube/ioncube_loader_"$os_name"_"${version:?}".so "${ext_dir:?}/ioncube.so"
sudo cp /tmp/ioncube/LICENSE.txt "$ext_dir"/IONCUBE_LICENSE.txt
fi
echo "zend_extension=$ext_dir/ioncube.so" | sudo tee "${scan_dir:?}/00-ioncube.ini" >/dev/null 2>&1
add_extension_log "ioncube" "$status"

View File

@ -35,7 +35,7 @@ add_client() {
# Function to install oci8 and pdo_oci.
add_oci_helper() {
if ! [ -e "${ext_dir:?}/$ext.so" ]; then
if ! shared_extension "$ext"; then
status='Installed and enabled'
read -r "${ext}_LINUX_LIBS" <<< "libaio-dev"
read -r "${ext}_CONFIGURE_OPTS" <<< "--with-php-config=$(command -v php-config) --with-${ext/_/-}=instantclient,$oracle_client"
@ -43,6 +43,8 @@ add_oci_helper() {
patch_phpize
add_extension_from_source "$ext" https://github.com php php-src "$(php_src_tag)" extension get
restore_phpize
else
enable_extension "$ext" extension
fi
}

View File

@ -1,7 +1,7 @@
# Function to install phalcon
Function Add-PhalconHelper() {
if ($extension_version -eq '4') {
Install-Phpextension phalcon -MinimumStability stable -Path $php_dir
Install-Phpextension -Extension phalcon -MinimumStability stable -Path $php_dir
} else {
$domain = 'https://github.com'
$nts = if (!$installed.ThreadSafe) { "_nts" } else { "" }
@ -30,7 +30,7 @@ Function Add-Phalcon() {
if (Test-Path $ext_dir\php_psr.dll) {
Enable-PhpExtension -Extension psr -Path $php_dir
} else {
Install-Phpextension psr -MinimumStability stable -Path $php_dir
Install-Phpextension -Extension psr -MinimumStability stable -Path $php_dir
}
}
@ -49,7 +49,6 @@ Function Add-Phalcon() {
}
Add-Log $tick $extension $status
} catch [Exception] {
Write-Output $_.Exception|format-list -force
Add-Log $cross $extension "Could not install $extension on PHP $($installed.FullVersion)"
}
}

View File

@ -1,22 +1,25 @@
# Helper function to add phalcon.
add_phalcon_helper() {
status='Installed and enabled'
update_lists
if [ "$extension" = "phalcon4" ]; then
${apt_install:?} "php${version:?}-psr" "php${version:?}-$extension"
if [ "$(uname -s)" = "Darwin" ]; then
add_brew_extension "$extension" extension
else
${apt_install:?} "php${version:?}-$extension"
if [ "$extension" = "phalcon4" ]; then
install_packages "php${version:?}-psr" "php${version:?}-$extension"
else
install_packages "php${version:?}-$extension"
fi
fi
}
# Function to add phalcon3.
add_phalcon3() {
if [ -e "${ext_dir:?}/phalcon.so" ]; then
if shared_extension phalcon; then
phalcon_version=$(php -d="extension=phalcon.so" -r "echo phpversion('phalcon');" | cut -d'.' -f 1)
if [ "$phalcon_version" != "$extension_major_version" ]; then
add_phalcon_helper
else
echo "extension=phalcon.so" | sudo tee -a "$phalcon_ini_file"
enable_extension phalcon extension
fi
else
add_phalcon_helper
@ -25,16 +28,14 @@ add_phalcon3() {
# Function to add phalcon4.
add_phalcon4() {
if [ -e "${ext_dir:?}/psr.so" ] && ! php -m | grep -i -q -w psr; then
echo "extension=psr.so" | sudo tee -a "${ini_file:?}"
fi
if [ -e "$ext_dir/phalcon.so" ]; then
if php -m | grep -i -q -w psr; then
enable_extension psr extension
if shared_extension phalcon; then
if check_extension psr; then
phalcon_version=$(php -d="extension=phalcon" -r "echo phpversion('phalcon');" | cut -d'.' -f 1)
if [ "$phalcon_version" != "$extension_major_version" ]; then
add_phalcon_helper
else
echo "extension=phalcon.so" | sudo tee -a "$phalcon_ini_file"
enable_extension phalcon extension
fi
else
add_phalcon_helper
@ -48,7 +49,6 @@ add_phalcon4() {
add_phalcon() {
extension=$1
status='Enabled'
phalcon_ini_file="${pecl_file:-${ini_file[@]}}"
extension_major_version=${extension: -1}
if [ "$extension_major_version" = "4" ]; then
add_phalcon4 >/dev/null 2>&1

View File

@ -126,7 +126,7 @@ add_extension_from_source() {
step_log "Setup $slug"
(
add_devtools phpize >/dev/null 2>&1
delete_extension "$extension"
disable_extension_helper "$extension"
fetch_extension "$fetch"
if ! [ "$(find . -maxdepth 1 -name '*.m4' -exec grep -H 'PHP_NEW_EXTENSION' {} \; | wc -l)" != "0" ]; then
add_log "${cross:?}" "$source" "$source does not have a PHP extension"

View File

@ -1,85 +1,31 @@
# Function to setup environment for self-hosted runners.
self_hosted_helper() {
if ! command -v sudo >/dev/null; then
apt-get update
apt-get install -y sudo || add_log "${cross:?}" "sudo" "Could not install sudo"
fi
if ! command -v apt-fast >/dev/null; then
sudo ln -sf /usr/bin/apt-get /usr/bin/apt-fast
trap "sudo rm -f /usr/bin/apt-fast 2>/dev/null" exit
fi
install_packages apt-transport-https curl make software-properties-common unzip autoconf automake gcc g++
add_ppa ondrej/php
}
# Function to backup and cleanup package lists.
cleanup_lists() {
ppa_prefix=${1-ondrej}
if [ ! -e /etc/apt/sources.list.d.save ]; then
sudo mv /etc/apt/sources.list.d /etc/apt/sources.list.d.save
sudo mkdir /etc/apt/sources.list.d
sudo mv /etc/apt/sources.list.d.save/*"${ppa_prefix}"*.list /etc/apt/sources.list.d/
trap "sudo mv /etc/apt/sources.list.d.save/*.list /etc/apt/sources.list.d/ 2>/dev/null" exit
fi
}
# Function to add ppa:ondrej/php.
add_ppa() {
ppa=${1:-ondrej/php}
if [ "$DISTRIB_RELEASE" = "16.04" ] && [ "$ppa" = "ondrej/php" ]; then
LC_ALL=C.UTF-8 sudo apt-add-repository --remove ppa:"$ppa" -y || true
LC_ALL=C.UTF-8 sudo apt-add-repository http://setup-php.com/ondrej/php/ubuntu -y
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 4f4ea0aae5267a6c
elif ! apt-cache policy | grep -q "$ppa"; then
cleanup_lists "$(dirname "$ppa")"
LC_ALL=C.UTF-8 sudo apt-add-repository ppa:"$ppa" -y
fi
if [ "$DISTRIB_RELEASE" = "16.04" ]; then
sudo "$debconf_fix" apt-get update
fi
}
# Function to update the package lists.
update_lists() {
if [ ! -e /tmp/setup_php ]; then
[ "${runner:?}" != "self-hosted" ] && add_ppa >/dev/null 2>&1
cleanup_lists
sudo "$debconf_fix" apt-get update >/dev/null 2>&1
echo '' | sudo tee /tmp/setup_php >/dev/null 2>&1
fi
install_packages apt-transport-https ca-certificates curl file make jq unzip autoconf automake gcc g++ gnupg
}
# Function to install a package
install_packages() {
packages=("$@")
$apt_install "${packages[@]}" >/dev/null 2>&1 || update_lists && $apt_install "${packages[@]}" >/dev/null 2>&1
$apt_install "${packages[@]}" >/dev/null 2>&1 || (update_lists && $apt_install "${packages[@]}" >/dev/null 2>&1)
}
# Function to disable an extension.
disable_extension() {
extension=$1
sudo sed -Ei "/=(.*\/)?\"?$extension(.so)?$/d" "${ini_file[@]}"
sudo sed -Ei "/=(.*\/)?\"?$extension(.so)?$/d" "$pecl_file"
sudo find "$ini_dir"/.. -name "*$extension.ini" -delete >/dev/null 2>&1 || true
}
# Function to delete an extension.
delete_extension() {
extension=$1
disable_extension "$extension"
sudo rm -rf "$ext_dir"/"$extension".so >/dev/null 2>&1
sudo sed -i "/Package: php$version-$extension/,/^$/d" /var/lib/dpkg/status
}
# Function to disable and delete extensions.
remove_extension() {
extension=$1
if check_extension "$extension"; then
if [[ ! "$version" =~ ${old_versions:?} ]] && [ -e /etc/php/"$version"/mods-available/"$extension".ini ]; then
sudo phpdismod -v "$version" "$extension" >/dev/null 2>&1
fi
delete_extension "$extension"
(! check_extension "$extension" && add_log "${tick:?}" ":$extension" "Removed") ||
add_log "${cross:?}" ":$extension" "Could not remove $extension on PHP ${semver:?}"
else
delete_extension "$extension"
add_log "${tick:?}" ":$extension" "Could not find $extension on PHP $semver"
disable_extension_helper() {
local extension=$1
local disable_dependents=${2:-false}
if [ "$disable_dependents" = "true" ]; then
disable_extension_dependents "$extension"
fi
sudo sed -Ei "/=(.*\/)?\"?$extension(.so)?$/d" "${ini_file[@]}" "$pecl_file"
sudo find "$ini_dir"/.. -name "*$extension.ini" -not -path "*mods-available*" -delete >/dev/null 2>&1 || true
}
# Function to add PDO extension.
@ -90,8 +36,8 @@ add_pdo_extension() {
else
ext=$1
ext_name=$1
if [ -e "$ext_dir"/pdo.so ]; then
disable_extension pdo
if shared_extension pdo; then
disable_extension_helper pdo
echo "extension=pdo.so" | sudo tee "${ini_file[@]/php.ini/conf.d/10-pdo.ini}" >/dev/null 2>&1
fi
if [ "$ext" = "mysql" ]; then
@ -113,19 +59,22 @@ add_pdo_extension() {
fi
}
# Function to check if a package exists
check_package() {
sudo apt-cache policy "$1" 2>/dev/null | grep -q 'Candidate'
}
# Function to add extensions.
add_extension() {
extension=$1
local extension=$1
prefix=$2
package=php"$version"-"$extension"
enable_extension "$extension" "$prefix"
if check_extension "$extension"; then
add_log "${tick:?}" "$extension" "Enabled"
else
if [[ "$version" =~ ${nightly_versions:?} ]]; then
pecl_install "$extension"
else
install_packages "php$version-$extension" || pecl_install "$extension"
fi
add_ppa ondrej/php >/dev/null 2>&1 || update_ppa ondrej/php
(check_package "$package" && install_packages "$package") || pecl_install "$extension"
add_extension_log "$extension" "Installed and enabled"
fi
sudo chmod 777 "${ini_file[@]}"
@ -143,8 +92,7 @@ add_devtools() {
# Function to setup the nightly build from shivammathur/php-builder
setup_nightly() {
run_script "php-builder" "$runner" "$version"
extra_version="-dev ($(cat "/etc/php/$version/COMMIT"))"
run_script "php-builder" "${runner:?}" "$version"
}
# Function to setup PHP 5.3, PHP 5.4 and PHP 5.5.
@ -159,8 +107,8 @@ add_pecl() {
install_packages php-pear
fi
configure_pecl >/dev/null 2>&1
pecl_version=$(get_tool_version "pecl" "version")
add_log "${tick:?}" "PECL" "Added PECL $pecl_version"
pear_version=$(get_tool_version "pecl" "version")
add_log "${tick:?}" "PECL" "Added PECL $pear_version"
}
# Function to switch versions of PHP binaries.
@ -179,9 +127,9 @@ switch_version() {
# Function to install packaged PHP
add_packaged_php() {
if [ "$runner" = "self-hosted" ] || [ "${use_package_cache:-true}" = "false" ]; then
update_lists
IFS=' ' read -r -a packages <<<"$(echo "cli curl mbstring xml intl" | sed "s/[^ ]*/php$version-&/g")"
$apt_install "${packages[@]}"
add_ppa ondrej/php >/dev/null 2>&1 || update_ppa ondrej/php
IFS=' ' read -r -a packages <<<"$(echo "cli curl dev mbstring xml intl" | sed "s/[^ ]*/php$version-&/g")"
install_packages "${packages[@]}"
else
run_script "php-ubuntu" "$version"
fi
@ -189,13 +137,13 @@ add_packaged_php() {
# Function to update PHP.
update_php() {
initial_version=$(php_semver)
add_packaged_php
updated_version=$(php_semver)
initial_version="$(php_semver)$(php_extra_version)"
add_php
updated_version="$(php_semver)$(php_extra_version)"
if [ "$updated_version" != "$initial_version" ]; then
status="Updated to"
else
status="Switched to"
status="Found"
fi
}
@ -207,6 +155,7 @@ add_php() {
setup_old_versions
else
add_packaged_php
switch_version >/dev/null 2>&1
fi
status="Installed"
}
@ -220,6 +169,13 @@ link_pecl_file() {
done
}
# Function to get extra version.
php_extra_version() {
if [ -e /etc/php/"$version"/COMMIT ]; then
echo " ($(cat "/etc/php/$version/COMMIT"))"
fi
}
# Function to Setup PHP
setup_php() {
step_log "Setup PHP"
@ -228,15 +184,15 @@ setup_php() {
if [ ! -e "/usr/bin/php$version" ]; then
add_php >/dev/null 2>&1
else
if ! [[ "$version" =~ ${old_versions:?} ]]; then
switch_version >/dev/null 2>&1
fi
if [ "${update:?}" = "true" ]; then
update_php >/dev/null 2>&1
else
status="Switched to"
fi
fi
if ! [[ "$version" =~ ${old_versions:?}|${nightly_versions:?} ]]; then
switch_version >/dev/null 2>&1
fi
else
if [ "$update" = "true" ]; then
update_php >/dev/null 2>&1
@ -249,16 +205,19 @@ setup_php() {
exit 1
fi
semver=$(php_semver)
extra_version=$(php_extra_version)
ext_dir=$(php -i | grep "extension_dir => /" | sed -e "s|.*=> s*||")
scan_dir=$(php --ini | grep additional | sed -e "s|.*: s*||")
ini_dir=$(php --ini | grep "(php.ini)" | sed -e "s|.*: s*||")
pecl_file="$scan_dir"/99-pecl.ini
export ext_dir
mapfile -t ini_file < <(sudo find "$ini_dir/.." -name "php.ini" -exec readlink -m {} +)
link_pecl_file
configure_php
sudo rm -rf /usr/local/bin/phpunit >/dev/null 2>&1
sudo chmod 777 "${ini_file[@]}" "$pecl_file" "${tool_path_dir:?}"
sudo cp "$dist"/../src/configs/*.json "$RUNNER_TOOL_CACHE/"
sudo cp "$dist"/../src/configs/pm/*.json "$RUNNER_TOOL_CACHE/"
echo "::set-output name=php-version::$semver"
add_log "${tick:?}" "PHP" "$status PHP $semver$extra_version"
}
@ -266,14 +225,15 @@ setup_php() {
version=$1
dist=$2
debconf_fix="DEBIAN_FRONTEND=noninteractive"
apt_install="sudo $debconf_fix apt-fast install -y"
apt_install="sudo $debconf_fix apt-fast install -y --no-install-recommends"
scripts="${dist}"/../src/scripts
. /etc/os-release
# shellcheck source=.
. "${scripts:?}"/ext/source.sh
. "${scripts:?}"/tools/ppa.sh
. "${scripts:?}"/tools/add_tools.sh
. "${scripts:?}"/common.sh
. /etc/lsb-release
read_env
self_hosted_setup
setup_php

View File

@ -15,10 +15,13 @@ Function Add-ToolsHelper() {
Add-Extension ast >$null 2>&1
} elseif($tool -eq "phive") {
Add-Extension xml >$null 2>&1
} elseif($tool -eq "symfony") {
Add-ToProfile $current_profile "symfony" "New-Alias symfony $bin_dir\$tool.exe"
Add-ToProfile $current_profile "symfony-cli" "New-Alias symfony-cli $bin_dir\$tool.exe"
} elseif($tool -eq "vapor-cli") {
} elseif($tool -eq "phpDocumentor") {
Add-Extension fileinfo >$null 2>&1
Copy-Item $bin_dir\phpDocumentor.bat -Destination $bin_dir\phpdoc.bat
} elseif($tool -eq "symfony-cli") {
Add-ToProfile $current_profile "symfony" "New-Alias symfony $bin_dir\symfony-cli.exe"
Add-ToProfile $current_profile "symfony_cli" "New-Alias symfony-cli $bin_dir\symfony-cli.exe"
} elseif($tool -match "vapor-cli") {
Copy-Item $composer_bin\vapor.bat -Destination $composer_bin\vapor-cli.bat
} elseif($tool -eq "wp-cli") {
Copy-Item $bin_dir\wp-cli.bat -Destination $bin_dir\wp.bat

View File

@ -14,11 +14,15 @@ add_tools_helper() {
add_extension curl extension >/dev/null 2>&1
add_extension mbstring extension >/dev/null 2>&1
add_extension xml extension >/dev/null 2>&1
elif [ "$tool" = "symfony" ]; then
sudo ln -s "${tool_path:?}" "${tool_path_dir:?}"/symfony-cli
elif [ "$tool" = "vapor-cli" ]; then
sudo ln -s "${tool_path:?}" "${tool_path_dir:?}"/vapor-cli
elif [ "$tool" = "wp-cli" ]; then
sudo ln -s "${tool_path:?}" "${tool_path_dir:?}"/wp
elif [ "$tool" = "phpDocumentor" ]; then
add_extension fileinfo extension >/dev/null 2>&1
sudo ln -s "${tool_path:?}" "${tool_path_dir:?}"/phpdocumentor 2>/dev/null || true
sudo ln -s "${tool_path:?}" "${tool_path_dir:?}"/phpdoc
elif [[ "$tool" =~ phpunit(-polyfills)?$ ]]; then
if [ -e "${tool_path_dir:?}"/phpunit ]; then
sudo cp "${tool_path_dir:?}"/phpunit "${composer_bin:?}"
fi
elif [[ "$tool" =~ (symfony|vapor|wp)-cli ]]; then
sudo ln -s "${tool_path:?}" "${tool_path_dir:?}"/"${tool%-*}"
fi
}

View File

@ -1,21 +1,19 @@
# Function to add blackfire and blackfire-agent.
# Function to add blackfire cli.
Function Add-Blackfire() {
$arch_name ='amd64'
if(-not([Environment]::Is64BitOperatingSystem) -or $version -lt '7.0') {
$arch_name = '386'
}
$agent_version = (Invoke-RestMethod https://blackfire.io/api/v1/releases).agent
$url = "https://packages.blackfire.io/binaries/blackfire-agent/${agent_version}/blackfire-agent-windows_${arch_name}.zip"
$cli_version = (Invoke-RestMethod https://blackfire.io/api/v1/releases).cli
$url = "https://packages.blackfire.io/binaries/blackfire/${cli_version}/blackfire-windows_${arch_name}.zip"
Invoke-WebRequest -Uri $url -OutFile $bin_dir\blackfire.zip >$null 2>&1
Expand-Archive -Path $bin_dir\blackfire.zip -DestinationPath $bin_dir -Force >$null 2>&1
Add-ToProfile $current_profile 'blackfire' "New-Alias blackfire $bin_dir\blackfire.exe"
Add-ToProfile $current_profile 'blackfire-agent' "New-Alias blackfire-agent $bin_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
blackfire agent:config --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
blackfire client:config --client-id=$env:BLACKFIRE_CLIENT_ID --client-token=$env:BLACKFIRE_CLIENT_TOKEN --ca-cert=$php_dir\ssl\cacert.pem >$null 2>&1
}
Add-Log $tick "blackfire" "Added blackfire $agent_version"
Add-Log $tick "blackfire-agent" "Added blackfire-agent $agent_version"
Add-Log $tick "blackfire" "Added blackfire $cli_version"
}

View File

@ -1,29 +1,35 @@
add_blackfire_linux() {
sudo mkdir -p /var/run/blackfire
get -s -n "" https://packages.blackfire.io/gpg.key | sudo apt-key add -
echo "deb http://packages.blackfire.io/debian any main" | sudo tee /etc/apt/sources.list.d/blackfire.list
sudo "${debconf_fix:?}" apt-get update
${apt_install:?} blackfire-agent
sudo mkdir -p /var/run/blackfire /etc/blackfire
add_list debian/blackfire http://packages.blackfire.io/debian https://packages.blackfire.io/gpg.key any main
install_packages blackfire
sudo chmod 777 /etc/blackfire/agent
}
add_blackfire_darwin() {
sudo mkdir -p /usr/local/var/run
brew tap --shallow blackfireio/homebrew-blackfire
brew install blackfire-agent
add_brew_tap blackfireio/homebrew-blackfire
brew install blackfire
}
blackfire_config() {
if [[ -n $BLACKFIRE_SERVER_ID ]] && [[ -n $BLACKFIRE_SERVER_TOKEN ]]; then
sudo blackfire-agent --register --server-id="$BLACKFIRE_SERVER_ID" --server-token="$BLACKFIRE_SERVER_TOKEN"
[ "$os" = "Linux" ] && sudo /etc/init.d/blackfire-agent restart
[ "$os" = "Darwin" ] && brew services start blackfire-agent
blackfire agent:config --server-id="$BLACKFIRE_SERVER_ID" --server-token="$BLACKFIRE_SERVER_TOKEN"
if [ "$os" = "Linux" ]; then
if [ -d /run/systemd/system ]; then
sudo systemctl start blackfire-agent
else
sudo service blackfire-agent start
fi
elif [ "$os" = "Darwin" ]; then
brew services start blackfire
fi
fi
if [[ -n $BLACKFIRE_CLIENT_ID ]] && [[ -n $BLACKFIRE_CLIENT_TOKEN ]]; then
blackfire config --client-id="$BLACKFIRE_CLIENT_ID" --client-token="$BLACKFIRE_CLIENT_TOKEN"
blackfire client:config --client-id="$BLACKFIRE_CLIENT_ID" --client-token="$BLACKFIRE_CLIENT_TOKEN"
fi
}
# Function to add blackfire and blackfire-agent.
# Function to add blackfire cli.
add_blackfire() {
os="$(uname -s)"
[ "$os" = "Linux" ] && add_blackfire_linux >/dev/null 2>&1
@ -31,5 +37,4 @@ add_blackfire() {
blackfire_config >/dev/null 2>&1
tool_version=$(get_tool_version "blackfire" "version")
add_log "${tick:?}" "blackfire" "Added blackfire $tool_version"
add_log "${tick:?}" "blackfire-agent" "Added blackfire-agent $tool_version"
}

View File

@ -1,11 +1,8 @@
add_bazel() {
if ! command -v bazel; then
if [ "$(uname -s)" = "Linux" ]; then
${apt_install:?} curl gnupg
get -s -n "" https://bazel.build/bazel-release.pub.gpg | sudo apt-key add -
echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
sudo "${debconf_fix:?}" apt-get update -y
${apt_install:?} bazel
add_list bazel/apt https://storage.googleapis.com/bazel-apt https://bazel.build/bazel-release.pub.gpg stable jdk1.8
install_packages bazel
else
brew install bazel
fi
@ -24,35 +21,34 @@ get_grpc_tag() {
fi
}
add_grpc_php_plugin_macos() {
add_grpc_php_plugin_brew() {
brew install grpc
brew link --force --overwrite grpc >/dev/null 2>&1
grpc_tag="v$(brew info grpc | grep "grpc:" | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+")"
license_path="$(brew --prefix grpc)/LICENSE"
}
add_grpc_php_plugin_linux() {
add_grpc_php_plugin_compile() {
get_grpc_tag
get -s -n "" "https://github.com/grpc/grpc/archive/$grpc_tag.tar.gz" | tar -xz -C /tmp
cd "/tmp/grpc-${grpc_tag:1}" || exit
add_bazel
if [ "$DISTRIB_RELEASE" = "16.04" ]; then
CC="$(command -v gcc)" CXX="$(command -v g++)" ./tools/bazel build src/compiler:grpc_php_plugin
else
export DISABLE_BAZEL_WRAPPER=1
(
cd "/tmp/grpc-${grpc_tag:1}" || exit
add_bazel
./tools/bazel build src/compiler:grpc_php_plugin
fi
sudo mv ./bazel-bin/src/compiler/grpc_php_plugin /usr/local/bin/grpc_php_plugin
sudo chmod a+x /usr/local/bin/grpc_php_plugin
license_path="/tmp/grpc-${grpc_tag:1}/LICENSE"
sudo mv ./bazel-bin/src/compiler/grpc_php_plugin /usr/local/bin/grpc_php_plugin
sudo chmod a+x /usr/local/bin/grpc_php_plugin
license_path="/tmp/grpc-${grpc_tag:1}/LICENSE"
)
}
add_grpc_php_plugin() {
grpc_tag=$1
license_path=""
if [ "$(uname -s)" = "Darwin" ]; then
add_grpc_php_plugin_macos >/dev/null 2>&1
if [ "$grpc_tag" = "latest" ]; then
add_grpc_php_plugin_brew >/dev/null 2>&1
else
add_grpc_php_plugin_linux >/dev/null 2>&1
add_grpc_php_plugin_compile >/dev/null 2>&1
fi
echo "::set-output name=grpc_php_plugin_path::$(command -v grpc_php_plugin)"
add_log "${tick:?}" "grpc_php_plugin" "Added grpc_php_plugin ${grpc_tag:1}"

189
src/scripts/tools/ppa.sh Normal file
View File

@ -0,0 +1,189 @@
# Function to try to set ubuntu or debian version.
set_base_version_id() {
[[ "$ID" =~ ubuntu|debian ]] && return;
if ! [ -d "$dist_info_dir" ]; then
sudo mkdir -p "$dist_info_dir"
get -q -n "$dist_info_dir"/os_releases.csv https://raw.githubusercontent.com/shivammathur/setup-php/develop/src/configs/os_releases.csv
fi
for base in ubuntu debian; do
[[ "$ID_LIKE" =~ $base ]] && ID="$base" && VERSION_ID="$(grep -hr -m 1 "$VERSION_CODENAME" /usr/share/distro-info | cut -d ',' -f 1 | cut -d ' ' -f 1)" && break
done
}
# Function to try to set ubuntu or debian codename.
set_base_version_codename() {
[[ "$ID" =~ ubuntu|debian ]] && return;
if [[ "$ID_LIKE" =~ ubuntu ]]; then
[[ -n "$UBUNTU_CODENAME" ]] && VERSION_CODENAME="$UBUNTU_CODENAME" && return;
[ -e "$upstream_lsb" ] && VERSION_CODENAME=$(grep 'CODENAME' "$upstream_lsb" | cut -d '=' -f 2) && return;
VERSION_CODENAME=$(grep -E -m1 'deb .*ubuntu.com' "$list_file" | cut -d ' ' -f 3) && VERSION_CODENAME=${VERSION_CODENAME%-*}
elif [[ "$ID_LIKE" =~ debian ]] || command -v dpkg >/dev/null; then
ID_LIKE=debian
[[ -n "$DEBIAN_CODENAME" ]] && VERSION_CODENAME="$DEBIAN_CODENAME" && return;
update_lists && VERSION_CODENAME=$(apt-cache show tzdata | grep -m 1 Provides | cut -d '-' -f 2)
fi
}
# Function to set base os details
set_base_version() {
if [ -e /tmp/os-release ]; then
. /tmp/os-release
else
set_base_version_codename
set_base_version_id
# Remove once PPAs start having bookworm releases
[ "$VERSION_CODENAME" = 'bookworm' ] && VERSION_CODENAME="bullseye"
printf "ID=%s\nVERSION_ID=%s\nVERSION_CODENAME=%s\n" "$ID" "$VERSION_ID" "$VERSION_CODENAME" | tee /tmp/os-release >/dev/null 2>&1
fi
}
# Helper function to update package lists.
update_lists_helper() {
list=$1
command -v sudo >/dev/null && SUDO=sudo
if [[ -n "$list" ]]; then
${SUDO} apt-get update -o Dir::Etc::sourcelist="$list" -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0"
else
${SUDO} apt-get update
fi
}
# Function to update the package lists.
update_lists() {
local ppa=${1:-}
local ppa_search=${2:-}
if [ ! -e /tmp/setup_php ] || [[ -n $ppa && -n $ppa_search ]]; then
if [[ -n "$ppa" && -n "$ppa_search" ]]; then
list="$list_dir"/"$(basename "$(grep -lr "$ppa_search" "$list_dir")")"
elif grep -Eq '^deb ' "$list_file"; then
list="$list_file"
fi
update_lists_helper "$list" >/dev/null 2>&1
echo '' | tee /tmp/setup_php >/dev/null 2>&1
fi
}
# Function to get fingerprint from an Ubuntu PPA.
ubuntu_fingerprint() {
ppa=$1
get -s -n "" "$lp_api"/~"${ppa%/*}"/+archive/"${ppa##*/}" | jq -r '.signing_key_fingerprint'
}
# Function to get fingerprint from a Debian PPA.
debian_fingerprint() {
ppa=$1
ppa_url=$2
package_dist=$3
release_pub=/tmp/"${ppa/\//-}".gpg
get -q -n "$release_pub" "$ppa_url"/dists/"$package_dist"/Release.gpg
gpg --list-packets "$release_pub" | grep -Eo 'fpr\sv4\s.*[a-zA-Z0-9]+' | head -n 1 | cut -d ' ' -f 3
}
# Function to add a GPG key.
add_key() {
ppa=${1:-ondrej/php}
ppa_url=$2
package_dist=$3
key_source=$4
key_file=$5
key_urls=("$key_source")
if [[ "$key_source" =~ launchpad.net|debian.org|setup-php.com ]]; then
fingerprint="$("${ID}"_fingerprint "$ppa" "$ppa_url" "$package_dist")"
sks_params="op=get&options=mr&exact=on&search=0x$fingerprint"
key_urls=("${sks[@]/%/\/pks\/lookup\?"$sks_params"}")
fi
[ ! -e "$key_source" ] && get -q -n "$key_file" "${key_urls[@]}"
if [[ "$(file "$key_file")" =~ .*('Public-Key (old)'|'Secret-Key') ]]; then
sudo gpg --batch --yes --dearmor "$key_file" >/dev/null 2>&1 && sudo mv "$key_file".gpg "$key_file"
fi
}
# Function to check if a PPA and its lists exist
check_lists() {
ppa=$1
ppa_search=$2
if grep -Eqr "$ppa_search" "$list_dir"; then
list_count="$(sudo find /var/lib/apt/lists -type f -name "*${ppa/\//_}*" | wc -l)"
if [ "$list_count" = "0" ]; then
update_lists "$ppa" "$ppa_search"
fi
return 0;
else
return 1;
fi
}
# Function to add a sources list.
add_list() {
ppa=${1-ondrej/php}
ppa_url=${2:-"$lp_ppa/$ppa/ubuntu"}
key_source=${3:-"$ppa_url"}
package_dist=${4:-"$VERSION_CODENAME"}
branches=${5:-main}
ppa_search="deb .*$ppa_url $package_dist .*$branches"
if check_lists "$ppa" "$ppa_search"; then
echo "Repository $ppa already exists";
return 1;
else
arch=$(dpkg --print-architecture)
[ -e "$key_source" ] && key_file=$key_source || key_file="$key_dir"/"${ppa/\//-}"-keyring.gpg
add_key "$ppa" "$ppa_url" "$package_dist" "$key_source" "$key_file"
echo "deb [arch=$arch signed-by=$key_file] $ppa_url $package_dist $branches" | sudo tee -a "$list_dir"/"${ppa/\//-}".list >/dev/null 2>&1
update_lists "$ppa" "$ppa_search"
. /etc/os-release
fi
return 0;
}
# Function to remove a PPA.
remove_list() {
ppa=${1-ondrej/php}
ppa_url=${2:-"$lp_ppa/$ppa/ubuntu"}
grep -lr "$ppa_url" "$list_dir" | xargs -n1 sudo rm -f
sudo rm -f "$key_dir"/"${ppa/\//-}"-keyring || true
}
# Function to add a PPA.
add_ppa() {
set_base_version
ppa=${1:-ondrej/php}
if [[ "$ID" = "ubuntu" || "$ID_LIKE" =~ ubuntu ]] && [[ "$ppa" =~ "ondrej/" ]]; then
add_list "$ppa"
elif [[ "$ID" = "debian" || "$ID_LIKE" =~ debian ]] && [[ "$ppa" =~ "ondrej/" ]]; then
add_list "$ppa" "$sury"/"${ppa##*/}"/ "$sury"/"${ppa##*/}"/apt.gpg
else
add_list "$ppa"
fi
status="$?"
. /etc/os-release
return $status
}
# Function to update a PPA.
update_ppa() {
set_base_version
ppa=${1:-ondrej/php}
ppa_url=${2:-"$lp_ppa/$ppa/ubuntu"}
package_dist=${4:-"$VERSION_CODENAME"}
branches=${5:-main}
ppa_search="deb .*$ppa_url $package_dist .*$branches"
update_lists "$ppa" "$ppa_search"
. /etc/os-release
}
# Variables
list_file='/etc/apt/sources.list'
list_dir="$list_file.d"
upstream_lsb='/etc/upstream-release/lsb-release'
lp_api='https://api.launchpad.net/1.0'
lp_ppa='http://ppa.launchpad.net'
key_dir='/usr/share/keyrings'
dist_info_dir='/usr/share/distro-info'
sury='https://packages.sury.org'
sks=(
'https://keyserver.ubuntu.com'
'https://pgp.mit.edu'
'https://keys.openpgp.org'
)

View File

@ -3,7 +3,7 @@ param (
[ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
[string]
$version = '7.4',
$version = '8.1',
[Parameter(Position = 1, Mandatory = $true)]
[ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
@ -74,20 +74,20 @@ Function Add-Path {
Function Add-Printf {
if (-not(Test-Path "C:\Program Files\Git\usr\bin\printf.exe")) {
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
New-Item -Path $bin_dir\printf.exe -ItemType SymbolicLink -Value C:\msys64\usr\bin\printf.exe -Force > $null 2>&1
} else {
Invoke-WebRequest -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 {
New-Item -Path $bin_dir\printf.exe -ItemType SymbolicLink -Value "C:\Program Files\Git\usr\bin\printf.exe"
New-Item -Path $bin_dir\printf.exe -ItemType SymbolicLink -Value "C:\Program Files\Git\usr\bin\printf.exe" -Force > $null 2>&1
}
}
# Function to get a clean Powershell profile.
Function Get-CleanPSProfile {
if(-not(Test-Path -LiteralPath $profile)) {
New-Item -Path $profile -ItemType "file" -Force
New-Item -Path $profile -ItemType "file" -Force > $null 2>&1
}
Set-Content $current_profile -Value ''
Add-ToProfile $profile $current_profile.replace('\', '\\') ". $current_profile"
@ -119,24 +119,35 @@ Function Install-PSPackage() {
}
}
Function Add-ExtensionPrerequisites{
# Function to link dependencies to PHP directory.
Function Set-ExtensionPrerequisites
{
Param (
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
[string]
$extension
$deps_dir
)
$deps_dir = "$ext_dir\$extension-vc$installed.VCVersion-$arch"
$extensions_with_dependencies = ('imagick')
if($extensions_with_dependencies.Contains($extension)) {
if(-not(Test-Path $deps_dir)) {
New-Item $deps_dir -Type Directory 2>&1 | Out-Null
Install-PhpExtensionPrerequisite -Extension $extension -InstallPath $deps_dir -PhpPath $php_dir
}
Get-ChildItem -Recurse -Path $deps_dir | ForEach-Object {
New-Item -Itemtype SymbolicLink -Path $php_dir -Name $_.Name -Target $_.FullName -Force >$null 2>&1
$deps = Get-ChildItem -Recurse -Path $deps_dir
if ($deps.Count -ne 0) {
# Symlink dependencies instead of adding the directory to PATH ...
# as other actions change the PATH thus breaking extensions.
$deps | ForEach-Object {
New-Item -Itemtype SymbolicLink -Path $php_dir -Name $_.Name -Target $_.FullName -Force > $null 2>&1
}
} else {
Remove-Item $deps_dir -Recurse -Force
}
}
# Function to add CA certificates to PHP.
Function Add-PhpCAInfo {
try {
Update-PhpCAInfo -Path $php_dir -Source Curl
} catch {
Add-Log $cross PHP "Could not fetch CA certificate bundle from Curl"
Update-PhpCAInfo -Path $php_dir -Source CurrentUser
}
}
@ -161,6 +172,8 @@ Function Add-Extension {
)
try {
$extension_info = Get-PhpExtension -Path $php_dir | Where-Object { $_.Name -eq $extension -or $_.Handle -eq $extension }
$deps_dir = "$ext_dir\$extension-vc$($installed.VCVersion)-$arch"
New-Item $deps_dir -Type Directory -Force > $null 2>&1
if ($null -ne $extension_info) {
switch ($extension_info.State) {
'Builtin' {
@ -170,20 +183,20 @@ Function Add-Extension {
Add-Log $tick $extension "Enabled"
}
default {
Add-ExtensionPrerequisites $extension
Enable-ExtensionDependencies $extension
Enable-PhpExtension -Extension $extension_info.Handle -Path $php_dir
Set-ExtensionPrerequisites $deps_dir
Add-Log $tick $extension "Enabled"
}
}
}
else {
Add-ExtensionPrerequisites $extension
$params = @{ Extension = $extension; MinimumStability = $stability; MaximumStability = $stability; Path = $php_dir; AdditionalFilesPath = $deps_dir; NoDependencies = $true }
if($extension_version -ne '') {
Install-PhpExtension -Extension $extension -Version $extension_version -MinimumStability $stability -MaximumStability $stability -Path $php_dir -NoDependencies
} else {
Install-PhpExtension -Extension $extension -MinimumStability $stability -MaximumStability $stability -Path $php_dir -NoDependencies
$params["Version"] = $extension_version
}
Install-PhpExtension @params
Set-ExtensionPrerequisites $deps_dir
Add-Log $tick $extension "Installed and enabled"
}
}
@ -192,8 +205,13 @@ Function Add-Extension {
}
}
# Function to remove PHP extensions.
Function Remove-Extension() {
# Function to get a map of extensions and their dependent shared extensions.
Function Get-ExtensionMap {
php -d'error_reporting=0' $dist\..\src\scripts\ext\extension_map.php
}
# Function to enable extension dependencies which are also extensions.
Function Enable-ExtensionDependencies {
Param (
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()]
@ -201,21 +219,91 @@ Function Remove-Extension() {
[string]
$extension
)
if(php -m | findstr -i $extension) {
try {
Disable-PhpExtension $extension $php_dir
if (Test-Path $ext_dir\php_$extension.dll) {
Remove-Item $ext_dir\php_$extension.dll
if (-not(Test-Path $env:TEMP\map.orig)) {
Get-ExtensionMap | Set-Content -Path $env:TEMP\map.orig
}
$entry = findstr /r "$extension`:.*" $env:TEMP\map.orig
if($entry) {
$entry.split(':')[1].trim().split(' ') | ForEach-Object {
if (-not(php -m | findstr -i $_)) {
Enable-PhpExtension -Extension $_ -Path $php_dir
}
Add-Log $tick ":$extension" "Removed"
} catch {
Add-Log $cross ":$extension" "Could not remove $extension on PHP $($installed.FullVersion)"
}
}
}
# Function to disable dependent extensions.
Function Disable-DependentExtensions() {
Param (
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
[string]
$extension
)
Get-ExtensionMap | Select-String -Pattern ".*:.*\s$extension(\s|$)" | ForEach-Object {
$dependent = $_.Matches[0].Value.split(':')[0];
Disable-ExtensionHelper -Extension $dependent -DisableDependents
Add-Log $tick ":$extension" "Disabled $dependent as it depends on $extension"
}
}
# Helper function to disable an extension.
Function Disable-ExtensionHelper() {
Param (
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
[string]
$extension,
[switch] $DisableDependents
)
if($DisableDependents) {
Disable-DependentExtensions $extension
}
Disable-PhpExtension -Extension $extension -Path $php_dir
}
# Function to disable an extension.
Function Disable-Extension() {
Param (
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
[string]
$extension,
[Parameter(Position = 1, Mandatory = $false)]
[ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
[string]
$DisableDependents
)
if(php -m | findstr -i $extension) {
if(Test-Path $ext_dir\php_$extension.dll) {
try {
$params = @{ Extension = $extension; DisableDependents = ($DisableDependents -ne 'false') }
Disable-ExtensionHelper @params
Add-Log $tick ":$extension" "Disabled"
} catch {
Add-Log $cross ":$extension" "Could not disable $extension on PHP $($installed.FullVersion)"
}
} else {
Add-Log $cross ":$extension" "Could not disable $extension on PHP $($installed.FullVersion) as it not a shared extension"
}
} elseif(Test-Path $ext_dir\php_$extension.dll) {
Add-Log $tick ":$extension" "Disabled"
} else {
Add-Log $tick ":$extension" "Could not find $extension on PHP $($installed.FullVersion)"
}
}
# Function to disable shared extensions.
Function Disable-AllShared() {
(Get-Content $php_dir\php.ini) | Where-Object {$_ -notmatch '^(zend_)?extension\s*='} | Set-Content $php_dir\php.ini
Add-Log $tick "none" "Disabled all shared extensions"
}
# Function to configure composer.
Function Edit-ComposerConfig() {
Param(
[Parameter(Position = 0, Mandatory = $true)]
@ -302,8 +390,8 @@ Function Add-Tool() {
$bat_content += "SET BIN_TARGET=%~dp0/" + $tool
$bat_content += "php %BIN_TARGET% %*"
Set-Content -Path $bin_dir\$tool.bat -Value $bat_content
Add-ToProfile $current_profile $tool "New-Alias $tool $bin_dir\$tool.bat" >$null 2>&1
Add-ToolsHelper $tool
Add-ToProfile $current_profile $tool "New-Alias $tool $bin_dir\$tool.bat" >$null 2>&1
$tool_version = Get-ToolVersion $tool $ver_param
Add-Log $tick $tool "Added $tool $tool_version"
} else {
@ -373,7 +461,6 @@ $current_profile = "$env:TEMP\setup-php.ps1"
$ProgressPreference = 'SilentlyContinue'
$jit_versions = '8.[0-9]'
$nightly_versions = '8.[1-9]'
$cert_source='CurrentUser'
$enable_extensions = ('openssl', 'curl', 'mbstring')
$arch = 'x64'
@ -389,9 +476,8 @@ if($env:RUNNER -eq 'self-hosted') {
$bin_dir = 'C:\tools\bin'
$php_dir = "$php_dir$version"
$ext_dir = "$php_dir\ext"
$cert_source='Curl'
Get-CleanPSProfile >$null 2>&1
New-Item $bin_dir -Type Directory 2>&1 | Out-Null
New-Item $bin_dir -Type Directory -Force > $null 2>&1
Add-Path -PathItem $bin_dir
if($version -lt 5.6) {
Add-Log $cross "PHP" "PHP $version is not supported on self-hosted runner"
@ -401,7 +487,7 @@ if($env:RUNNER -eq 'self-hosted') {
if ((Get-InstalledModule).Name -notcontains 'VcRedist') {
Install-Module -Name VcRedist -Force
}
New-Item $php_dir -Type Directory 2>&1 | Out-Null
New-Item $php_dir -Type Directory -Force > $null 2>&1
Add-Path -PathItem $php_dir
setx PHPROOT $php_dir >$null 2>&1
} else {
@ -426,6 +512,7 @@ if (Test-Path -LiteralPath $php_dir -PathType Container) {
} catch { }
}
$status = "Installed"
$extra_version = ""
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-PSPackage VcRedist VcRedist-main\VcRedist\VcRedist "$github/aaronparker/VcRedist/archive/main.zip" Get-VcList >$null 2>&1
@ -433,12 +520,16 @@ if ($null -eq $installed -or -not("$($installed.Version).".StartsWith(($version
try {
if ($version -match $nightly_versions) {
Invoke-WebRequest -UseBasicParsing -Uri $php_builder/releases/latest/download/Get-PhpNightly.ps1 -OutFile $php_dir\Get-PhpNightly.ps1 > $null 2>&1
& $php_dir\Get-PhpNightly.ps1 -Architecture $arch -ThreadSafe $ts -Path $php_dir > $null 2>&1
& $php_dir\Get-PhpNightly.ps1 -Architecture $arch -ThreadSafe $ts -Path $php_dir -Version $version > $null 2>&1
if(Test-Path $php_dir\COMMIT) {
$extra_version = " ($( Get-Content $php_dir\COMMIT ))"
}
} else {
Install-Php -Version $version -Architecture $arch -ThreadSafe $ts -InstallVC -Path $php_dir -TimeZone UTC -InitialPhpIni Production -Force > $null 2>&1
}
} catch { }
} else {
Set-PhpIniKey -Key 'extension_dir' -Value $ext_dir -Path $php_dir
if($version -match $jit_versions) {
('opcache.enable=1', 'opcache.jit_buffer_size=256M', 'opcache.jit=1235') | ForEach-Object { $p=$_.split('='); Set-PhpIniKey -Key $p[0] -Value $p[1] -Path $php_dir }
}
@ -462,7 +553,8 @@ if($version -lt "5.5") {
$enable_extensions += ('opcache')
}
Enable-PhpExtension -Extension $enable_extensions -Path $php_dir
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)"
Add-PhpCAInfo
Copy-Item -Path $dist\..\src\configs\pm\*.json -Destination $env:RUNNER_TOOL_CACHE
New-Item -ItemType Directory -Path $composer_bin -Force > $null 2>&1
Write-Output "::set-output name=php-version::$($installed.FullVersion)"
Add-Log $tick "PHP" "$status PHP $($installed.FullVersion)$extra_version"

View File

@ -1,247 +1,101 @@
import * as utils from './utils';
type RS = Record<string, string>;
type RSRS = Record<string, RS>;
interface IRef {
ref: string;
node_id: string;
url: string;
object: RS;
}
/**
* Function to get version in semver format.
*
* @param data
*/
export async function getSemverVersion(data: RS): Promise<string> {
const search: string = data['version_prefix'] + data['version'];
const url = `https://api.github.com/repos/${data['repository']}/git/matching-refs/tags%2F${search}.`;
const token: string = await utils.readEnv('COMPOSER_TOKEN');
const response: RS = await utils.fetch(url, token);
if (response.error || response.data === '[]') {
data['error'] = response.error ?? `No version found with prefix ${search}.`;
return data['version'];
} else {
const refs = JSON.parse(response['data']).reverse();
const ref = refs.find((i: IRef) => /.*\d+.\d+.\d+$/.test(i['ref']));
const tag: string = (ref || refs[0])['ref'].split('/').pop();
return tag.replace(/^v(\d)/, '$1');
}
}
/**
* Function to get latest version from releases.atom
*
* @param data
*/
export async function getLatestVersion(data: RS): Promise<string> {
if (!data['version'] && data['fetch_latest'] === 'false') {
return 'latest';
}
const resp: Record<string, string> = await utils.fetch(
`${data['github']}/${data['repository']}/releases.atom`
);
const releases: string[] = [
...resp['data'].matchAll(/releases\/tag\/([a-zA-Z]*)?(\d+.\d+.\d+)"/g)
].map(match => match[2]);
return (
releases
.sort((a: string, b: string) =>
a.localeCompare(b, undefined, {numeric: true})
)
.pop() || 'latest'
);
}
/**
* Function to get tool version
*
* @param version
* @param data
*/
export async function getToolVersion(version: string): Promise<string> {
export async function getVersion(version: string, data: RS): Promise<string> {
// semver_regex - https://semver.org/
const semver_regex =
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
const composer_regex = /^stable$|^preview$|^snapshot$|^v?[1|2]$/;
version = version.replace(/[><=^]*/, '');
const composer_regex = /^composer:(stable|preview|snapshot|[1|2])$/;
const constraint_regex = /[><=^~]+.*/;
const major_minor_regex = /^\d+(\.\d+)?$/;
data['version'] = version.replace(/v?(\d)/, '$1').replace(/\.x/, '');
switch (true) {
case version.charAt(0) == 'v':
return version.replace('v', '');
case composer_regex.test(version):
case semver_regex.test(version):
return version;
case composer_regex.test(data['release']):
case semver_regex.test(data['version']):
case constraint_regex.test(data['version']) && data['type'] === 'composer':
return data['version'];
case major_minor_regex.test(data['version']) && data['type'] === 'composer':
data['release'] = `${data['tool']}:${data['version']}.*`;
return `${data['version']}.*`;
case data['repository'] && major_minor_regex.test(data['version']):
return await getSemverVersion(data);
default:
return 'latest';
return data['version'].replace(/[><=^~]*/, '');
}
}
/**
* Function to parse tool:version
* Function to parse the release tool:version
*
* @param release
* @param data
*/
export async function parseTool(
release: string
): Promise<{name: string; version: string}> {
const parts: string[] = release.split(':');
const tool: string = parts[0];
const version: string | undefined = parts[1];
switch (true) {
case version === undefined:
return {
name: tool,
version: 'latest'
};
case /^[\w.-]+\/[\w.-]+$/.test(tool):
return {
name: tool,
version: version
};
default:
return {
name: tool,
version: await getToolVersion(parts[1])
};
}
}
/**
* Function to get the url of tool with the given version
*
* @param tool
* @param extension
* @param version
* @param prefix
* @param version_prefix
* @param verb
*/
export async function getUri(
tool: string,
extension: string,
version: string,
prefix: string,
version_prefix: string,
verb: string
): Promise<string> {
switch (version) {
case 'latest':
return [prefix, version, verb, tool + extension]
.filter(Boolean)
.join('/');
default:
return [prefix, verb, version_prefix + version, tool + extension]
.filter(Boolean)
.join('/');
}
}
/**
* Helper function to get script to setup phive
*
* @param version
* @param php_version
* @param os_version
*/
export async function addPhive(
version: string,
php_version: string,
os_version: string
): Promise<string> {
switch (true) {
case /5\.[3-5]/.test(php_version):
return await utils.addLog(
'$cross',
'phive',
'Phive is not supported on PHP ' + php_version,
os_version
);
case /5\.6|7\.0/.test(php_version):
version = version.replace('latest', '0.12.1');
break;
case /7\.1/.test(php_version):
version = version.replace('latest', '0.13.5');
break;
}
switch (version) {
case 'latest':
return (
(await utils.getCommand(os_version, 'tool')) +
'https://phar.io/releases/phive.phar phive status'
);
default:
return (
(await utils.getCommand(os_version, 'tool')) +
'https://github.com/phar-io/phive/releases/download/' +
version +
'/phive-' +
version +
'.phar phive status'
);
}
}
/**
* Function to get the phar url in domain/tool-version.phar format
*
* @param domain
* @param tool
* @param prefix
* @param version
*/
export async function getPharUrl(
domain: string,
tool: string,
prefix: string,
version: string
): Promise<string> {
switch (version) {
case 'latest':
return domain + '/' + tool + '.phar';
default:
return domain + '/' + tool + '-' + prefix + version + '.phar';
}
}
/**
* 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<string> {
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
*
* @param version
*/
export async function getDeployerUrl(version: string): Promise<string> {
const deployer = 'https://deployer.org';
switch (version) {
case 'latest':
return deployer + '/deployer.phar';
default:
return deployer + '/releases/v' + version + '/deployer.phar';
}
}
/**
* Function to get the Deployer url
*
* @param version
* @param os_version
*/
export async function getSymfonyUri(
version: string,
os_version: string
): Promise<string> {
let filename = '';
switch (os_version) {
case 'linux':
case 'darwin':
filename = 'symfony_' + os_version + '_amd64';
break;
case 'win32':
filename = 'symfony_windows_amd64.exe';
break;
default:
return await utils.log(
'Platform ' + os_version + ' is not supported',
os_version,
'error'
);
}
switch (version) {
case 'latest':
return 'releases/latest/download/' + filename;
default:
return 'releases/download/v' + version + '/' + filename;
}
}
/**
* Function to get the WP-CLI url
*
* @param version
*/
export async function getWpCliUrl(version: string): Promise<string> {
switch (version) {
case 'latest':
return 'wp-cli/builds/blob/gh-pages/phar/wp-cli.phar?raw=true';
default:
return await getUri(
'wp-cli',
'-' + version + '.phar',
version,
'wp-cli/wp-cli/releases',
'v',
'download'
);
}
export async function getRelease(release: string, data: RS): Promise<string> {
release = release.includes('/') ? release.split('/')[1] : release;
return release.includes(':')
? [data['tool'], release.split(':')[1]].join(':')
: data['tool'];
}
/**
@ -249,10 +103,10 @@ export async function getWpCliUrl(version: string): Promise<string> {
*
* @param tools_list
*/
export async function addComposer(tools_list: string[]): Promise<string[]> {
export async function filterList(tools_list: string[]): Promise<string[]> {
const regex_any = /^composer($|:.*)/;
const regex_valid =
/^composer:?($|preview$|snapshot$|v?[1-2]$|v?\d+\.\d+\.\d+[\w-]*$)/;
/^composer:?($|preview$|snapshot$|v?\d+(\.\d+)?$|v?\d+\.\d+\.\d+[\w-]*$)/;
const matches: string[] = tools_list.filter(tool => regex_valid.test(tool));
let composer = 'composer';
tools_list = tools_list.filter(tool => !regex_any.test(tool));
@ -268,96 +122,356 @@ export async function addComposer(tools_list: string[]): Promise<string[]> {
}
/**
* Function to get composer URL for a given version
* Function to get the url of tool with the given version
*
* @param version
* @param data
*/
export async function getComposerUrl(version: string): Promise<string> {
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:
return `${cache_url},https://getcomposer.org/composer-stable.phar`;
export async function getUrl(data: RS): Promise<string> {
if (data['version'] === 'latest') {
return [
data['domain'],
data['repository'],
data['prefix'],
data['version'],
data['verb'],
data['tool'] + data['extension']
]
.filter(Boolean)
.join('/');
} else {
return [
data['domain'],
data['repository'],
data['prefix'],
data['verb'],
data['version_prefix'] + data['version'],
data['tool'] + data['extension']
]
.filter(Boolean)
.join('/');
}
}
/**
* Function to get the phar url in domain/tool-version.phar format
*
* @param data
*/
export async function getPharUrl(data: RS): Promise<string> {
if (data['version'] === 'latest') {
return data['domain'] + '/' + data['tool'] + '.phar';
} else {
return (
data['domain'] +
'/' +
data['tool'] +
'-' +
data['version_prefix'] +
data['version'] +
'.phar'
);
}
}
/**
* Helper function to get script to setup a tool using a phar url
*
* @param tool
* @param url
* @param os_version
* @param ver_param
* @param data
*/
export async function addArchive(
tool: string,
url: string,
os_version: string,
ver_param: string
): Promise<string> {
export async function addArchive(data: RS): Promise<string> {
return (
(await utils.getCommand(os_version, 'tool')) +
(await utils.joins(url, tool, ver_param))
(await utils.getCommand(data['os_version'], 'tool')) +
(await utils.joins(data['url'], data['tool'], data['version_parameter']))
);
}
/**
* Function to get the script to setup php-config and phpize
* Helper function to get script to setup a tool using composer
*
* @param tool
* @param os_version
* @param data
*/
export async function addDevTools(
tool: string,
os_version: string
): Promise<string> {
switch (os_version) {
export async function addPackage(data: RS): Promise<string> {
const command = await utils.getCommand(data['os_version'], 'composertool');
const parts: string[] = data['repository'].split('/');
return command + parts[1] + ' ' + data['release'] + ' ' + parts[0] + '/';
}
/**
* Function to add blackfire-player
*
* @param data
*/
export async function addBlackfirePlayer(data: RS): Promise<string> {
if (
/5\.[5-6]|7\.0/.test(data['php_version']) &&
data['version'] == 'latest'
) {
data['version'] = '1.9.3';
}
data['url'] = await getPharUrl(data);
return addArchive(data);
}
/**
* Function to add composer
*
* @param data
*/
export async function addComposer(data: RS): Promise<string> {
const github = data['github'];
const getcomposer = data['domain'];
let cache_url = `${github}/shivammathur/composer-cache/releases/latest/download/composer-${data[
'version'
].replace('latest', 'stable')}.phar`;
let source_url = `${getcomposer}/composer.phar`;
switch (true) {
case /^snapshot$/.test(data['version']):
break;
case /^preview$|^[1-2]$/.test(data['version']):
source_url = `${getcomposer}/composer-${data['version']}.phar`;
break;
case /^\d+\.\d+\.\d+[\w-]*$/.test(data['version']):
cache_url = `${github}/${data['repository']}/releases/download/${data['version']}/composer.phar`;
source_url = `${getcomposer}/composer-${data['version']}.phar`;
break;
default:
source_url = `${getcomposer}/composer-stable.phar`;
}
const use_cache: boolean = (await utils.readEnv('NO_TOOLS_CACHE')) !== 'true';
data['url'] = use_cache ? `${cache_url},${source_url}` : source_url;
data['version_parameter'] = data['version'];
return await addArchive(data);
}
/**
* Function to add Deployer
*
* @param data
*/
export async function addDeployer(data: RS): Promise<string> {
if (data['version'] === 'latest') {
data['url'] = data['domain'] + '/deployer.phar';
} else {
data['url'] =
data['domain'] + '/releases/v' + data['version'] + '/deployer.phar';
}
return await addArchive(data);
}
/**
* Function to add php-config and phpize
*
* @param data
*/
export async function addDevTools(data: RS): Promise<string> {
switch (data['os_version']) {
case 'linux':
case 'darwin':
return 'add_devtools ' + tool;
return 'add_devtools ' + data['tool'];
case 'win32':
return await utils.addLog(
'$tick',
tool,
tool + ' is not a windows tool',
data['tool'],
data['tool'] + ' is not a windows tool',
'win32'
);
default:
return await utils.log(
'Platform ' + os_version + ' is not supported',
os_version,
'Platform ' + data['os_version'] + ' is not supported',
data['os_version'],
'error'
);
}
}
/**
* Helper function to get script to setup a tool using composer
* Function to add PECL
*
* @param data
*/
export async function addPECL(data: RS): Promise<string> {
return await utils.getCommand(data['os_version'], 'pecl');
}
/**
* Function to add Phing
*
* @param data
*/
export async function addPhing(data: RS): Promise<string> {
data['url'] =
data['domain'] + '/get/phing-' + data['version'] + data['extension'];
return await addArchive(data);
}
/**
* Helper function to add Phive
*
* @param data
*/
export async function addPhive(data: RS): Promise<string> {
switch (true) {
case /5\.[3-5]/.test(data['php_version']):
return await utils.addLog(
'$cross',
'phive',
'Phive is not supported on PHP ' + data['php_version'],
data['os_version']
);
case /5\.6|7\.0/.test(data['php_version']):
data['version'] = data['version'].replace('latest', '0.12.1');
break;
case /7\.1/.test(data['php_version']):
data['version'] = data['version'].replace('latest', '0.13.5');
break;
case /7\.2/.test(data['php_version']):
data['version'] = data['version'].replace('latest', '0.14.5');
break;
}
if (data['version'] === 'latest') {
data['domain'] = data['domain'] + '/releases';
} else {
data['domain'] = [
data['github'],
data['repository'],
'releases/download',
data['version']
].join('/');
}
data['url'] = await getPharUrl(data);
return await addArchive(data);
}
/**
* Function to add PHPUnit and related tools
*
* @param data
*/
export async function addPHPUnitTools(data: RS): Promise<string> {
data['url'] = await getPharUrl(data);
return await addArchive(data);
}
/**
* Function to add Symfony
*
* @param data
*/
export async function addSymfony(data: RS): Promise<string> {
let filename: string;
switch (data['os_version']) {
case 'linux':
case 'darwin':
filename = 'symfony_' + data['os_version'] + '_amd64';
break;
case 'win32':
filename = 'symfony_windows_amd64.exe';
break;
default:
return await utils.log(
'Platform ' + data['os_version'] + ' is not supported',
data['os_version'],
'error'
);
}
if (data['version'] === 'latest') {
data['uri'] = ['releases/latest/download', filename].join('/');
} else {
data['uri'] = ['releases/download', 'v' + data['version'], filename].join(
'/'
);
}
data['url'] = [data['domain'], data['repository'], data['uri']].join('/');
return await addArchive(data);
}
/**
* Function to add WP-CLI
*
* @param data
*/
export async function addWPCLI(data: RS): Promise<string> {
if (data['version'] === 'latest') {
data['uri'] = 'wp-cli/builds/blob/gh-pages/phar/wp-cli.phar?raw=true';
data['url'] = [data['domain'], data['uri']].join('/');
} else {
data['extension'] = '-' + data['version'] + data['extension'];
data['url'] = await getUrl(data);
}
return await addArchive(data);
}
/**
* Function to get information about a tool
*
* @param tool
* @param release
* @param prefix
* @param php_version
* @param os_version
*/
export async function addPackage(
tool: string,
export async function getData(
release: string,
prefix: string,
php_version: string,
os_version: string
): Promise<string> {
const tool_command = await utils.getCommand(os_version, 'composertool');
return tool_command + tool + ' ' + release + ' ' + prefix;
): Promise<RS> {
const json_file: string = await utils.readFile('tools.json', 'src/configs');
const json_objects: RSRS = JSON.parse(json_file);
release = release.replace(/\s+/g, '');
const parts: string[] = release.split(':');
const tool = parts[0];
const version = parts[1];
let data: RS;
if (Object.keys(json_objects).includes(tool)) {
data = json_objects[tool];
data['tool'] = tool;
} else {
const key: string | undefined = Object.keys(json_objects).find(
(key: string) => {
return json_objects[key]['alias'] == tool;
}
);
if (key) {
data = json_objects[key];
data['tool'] = key;
} else {
data = {
tool: tool.split('/')[1],
repository: tool,
type: 'composer'
};
data = !tool.includes('/') ? {tool: tool} : data;
}
}
data['github'] = 'https://github.com';
data['domain'] ??= data['github'];
data['extension'] ??= '.phar';
data['os_version'] = os_version;
data['php_version'] = php_version;
data['prefix'] = data['github'] === data['domain'] ? 'releases' : '';
data['verb'] = data['github'] === data['domain'] ? 'download' : '';
data['fetch_latest'] ??= 'false';
data['version_parameter'] = JSON.stringify(data['version_parameter']) || '';
data['version_prefix'] ??= '';
data['release'] = await getRelease(release, data);
data['version'] = version
? await getVersion(version, data)
: await getLatestVersion(data);
return data;
}
export const functionRecord: Record<string, (data: RS) => Promise<string>> = {
composer: addComposer,
deployer: addDeployer,
dev_tools: addDevTools,
phive: addPhive,
blackfire_player: addBlackfirePlayer,
pecl: addPECL,
phing: addPhing,
phpunit: addPHPUnitTools,
phpcpd: addPHPUnitTools,
symfony: addSymfony,
wp_cli: addWPCLI
};
/**
* Setup tools
*
@ -376,166 +490,45 @@ export async function addTools(
} else {
script += await utils.stepLog('Setup Tools', os_version);
}
const tools_list = await addComposer(await utils.CSVArray(tools_csv));
const tools_list = await filterList(await utils.CSVArray(tools_csv));
await utils.asyncForEach(tools_list, async function (release: string) {
const tool_data: {name: string; version: string} = await parseTool(release);
const tool: string = tool_data.name;
const version: string = tool_data.version;
const github = 'https://github.com/';
let uri: string = await getUri(
tool,
'.phar',
version,
'releases',
'',
'download'
);
const data: RS = await getData(release, php_version, os_version);
script += '\n';
let url = '';
switch (true) {
case /^blackfire(-agent)?$/.test(tool):
case data['error'] !== undefined:
script += await utils.addLog(
'$cross',
data['tool'],
data['error'],
data['os_version']
);
break;
case 'phar' === data['type']:
data['url'] = await getUrl(data);
script += await addArchive(data);
break;
case 'composer' === data['type']:
script += await addPackage(data);
break;
case 'custom-package' === data['type']:
script += await utils.customPackage(
'blackfire',
data['tool'].split('-')[0],
'tools',
version,
os_version
data['version'],
data['os_version']
);
break;
case /^grpc_php_plugin$|^protoc$/.test(tool):
script += await utils.customPackage(tool, 'tools', version, os_version);
case 'custom-function' === data['type']:
script += await functionRecord[data['function']](data);
break;
case /^behat$|^codeception$|^phpspec$/.test(tool):
script += await addPackage(tool, release, tool + '/', os_version);
break;
case /^blackfire-player$/.test(tool):
url = await getBlackfirePlayerUrl(version, php_version);
script += await addArchive(tool, url, os_version, '"-V"');
break;
case /^composer$/.test(tool):
url = await getComposerUrl(version);
script += await addArchive('composer', url, os_version, version);
break;
case /^composer-normalize$/.test(tool):
uri = await getUri(tool, '.phar', version, 'releases', '', 'download');
url = github + 'ergebnis/composer-normalize/' + uri;
script += await addArchive(tool, url, os_version, '"-V"');
break;
case /^composer-prefetcher$/.test(tool):
script += await addPackage(
'automatic-' + tool,
release,
'narrowspark/',
os_version
);
break;
case /^composer-require-checker$/.test(tool):
uri = await getUri(tool, '.phar', version, 'releases', '', 'download');
url = github + 'maglnet/ComposerRequireChecker/' + uri;
script += await addArchive(tool, url, os_version, '"-V"');
break;
case /^composer-unused$/.test(tool):
script += await addPackage(tool, release, 'icanhazstring/', os_version);
break;
case /^cs2pr$/.test(tool):
uri = await getUri(tool, '', version, 'releases', '', 'download');
url = github + 'staabm/annotate-pull-request-from-checkstyle/' + uri;
script += await addArchive(tool, url, os_version, '"-V"');
break;
case /^deployer$/.test(tool):
url = await getDeployerUrl(version);
script += await addArchive(tool, url, os_version, '"-V"');
break;
case /^flex$/.test(tool):
script += await addPackage(tool, release, 'symfony/', os_version);
break;
case /^infection$/.test(tool):
url = github + 'infection/infection/' + uri;
script += await addArchive(tool, url, os_version, '"-V"');
break;
case /^pecl/.test(tool):
script += await utils.getCommand(os_version, 'pecl');
break;
case /^phan$/.test(tool):
url = github + 'phan/phan/' + uri;
script += await addArchive(tool, url, os_version, '"-v"');
break;
case /^phing$/.test(tool):
url = 'https://www.phing.info/get/phing-' + version + '.phar';
script += await addArchive(tool, url, os_version, '"-v"');
break;
case /^phinx$/.test(tool):
script += await addPackage(tool, release, 'robmorgan/', os_version);
break;
case /^phive$/.test(tool):
script += await addPhive(version, php_version, os_version);
break;
case /^php(-config|ize)$/.test(tool):
script += await addDevTools(tool, os_version);
break;
case /^php-cs-fixer$/.test(tool):
uri = await getUri(tool, '.phar', version, 'releases', 'v', 'download');
url = github + 'FriendsOfPHP/PHP-CS-Fixer/' + uri;
script += await addArchive(tool, url, os_version, '"-V"');
break;
case /^php(cbf|cs)$/.test(tool):
url = github + 'squizlabs/PHP_CodeSniffer/' + uri;
script += await addArchive(tool, url, os_version, '"--version"');
break;
case /^php(cpd|unit)$/.test(tool):
url = await getPharUrl('https://phar.phpunit.de', tool, '', version);
script += await addArchive(tool, url, os_version, '"--version"');
break;
case /^phplint$/.test(tool):
script += await addPackage(tool, release, 'overtrue/', os_version);
break;
case /^phpmd$/.test(tool):
url = github + 'phpmd/phpmd/' + uri;
script += await addArchive(tool, url, os_version, '"--version"');
break;
case /^phpstan$/.test(tool):
url = github + 'phpstan/phpstan/' + uri;
script += await addArchive(tool, url, os_version, '"-V"');
break;
case /^prestissimo$/.test(tool):
script += await addPackage(tool, release, 'hirak/', os_version);
break;
case /^psalm$/.test(tool):
url = github + 'vimeo/psalm/' + uri;
script += await addArchive(tool, url, os_version, '"-v"');
break;
case /^symfony(-cli)?$/.test(tool):
uri = await getSymfonyUri(version, os_version);
url = github + 'symfony/cli/' + uri;
script += await addArchive('symfony', url, os_version, 'version');
break;
case /^vapor(-cli)?$/.test(tool):
script += await addPackage(
'vapor-cli',
release,
'laravel/',
os_version
);
break;
case /^wp(-cli)?$/.test(tool):
url = github + (await getWpCliUrl(version));
script += await addArchive('wp-cli', url, os_version, '"--version"');
break;
case /^none$/.test(tool):
break;
case /^[\w.-]+\/[\w.-]+$/.test(tool):
script += await addPackage(
tool.split('/')[1],
release.split('/')[1].replace(/\s+/, ''),
tool.split('/')[0] + '/',
os_version
);
case /^none$/.test(data['tool']):
break;
default:
script += await utils.addLog(
'$cross',
tool,
'Tool ' + tool + ' is not supported',
os_version
data['tool'],
'Tool ' + data['tool'] + ' is not supported',
data['os_version']
);
break;
}

View File

@ -1,7 +1,8 @@
import {IncomingMessage} from 'http';
import {IncomingMessage, OutgoingHttpHeaders} from 'http';
import * as fs from 'fs';
import * as https from 'https';
import * as path from 'path';
import * as url from 'url';
import * as core from '@actions/core';
/**
@ -10,13 +11,16 @@ import * as core from '@actions/core';
* @param property
*/
export async function readEnv(property: string): Promise<string> {
const value = process.env[property];
switch (value) {
case undefined:
return '';
default:
return value;
}
const property_lc: string = property.toLowerCase();
const property_uc: string = property.toUpperCase();
return (
process.env[property] ||
process.env[property_lc] ||
process.env[property_uc] ||
process.env[property_lc.replace('_', '-')] ||
process.env[property_uc.replace('_', '-')] ||
''
);
}
/**
@ -46,32 +50,60 @@ export async function getInput(
/**
* Function to fetch an URL
*
* @param url
* @param input_url
* @param auth_token
*/
export async function fetch(url: string): Promise<string> {
const fetch_promise: Promise<string> = new Promise(resolve => {
const req = https.get(url, (res: IncomingMessage) => {
res.setEncoding('utf8');
let body = '';
res.on('data', chunk => (body += chunk));
res.on('end', () => resolve(body));
});
req.end();
});
export async function fetch(
input_url: string,
auth_token?: string
): Promise<Record<string, string>> {
const fetch_promise: Promise<Record<string, string>> = new Promise(
resolve => {
const url_object: url.UrlObject = new url.URL(input_url);
const headers: OutgoingHttpHeaders = {
'User-Agent': `Mozilla/5.0 (${process.platform} ${process.arch}) setup-php`
};
if (auth_token) {
headers.authorization = 'Bearer ' + auth_token;
}
const options: https.RequestOptions = {
hostname: url_object.hostname,
path: url_object.pathname,
headers: headers
};
const req = https.get(options, (res: IncomingMessage) => {
if (res.statusCode != 200) {
resolve({error: `${res.statusCode}: ${res.statusMessage}`});
} else {
let body = '';
res.setEncoding('utf8');
res.on('data', chunk => (body += chunk));
res.on('end', () => resolve({data: `${body}`}));
}
});
req.end();
}
);
return await fetch_promise;
}
/** Function to get manifest URL
*
*/
export async function getManifestURL(): Promise<string> {
return 'https://raw.githubusercontent.com/shivammathur/setup-php/develop/src/configs/php-versions.json';
}
/**
* Function to parse PHP version.
*
* @param version
*/
export async function parseVersion(version: string): Promise<string> {
const manifest =
'https://raw.githubusercontent.com/shivammathur/setup-php/develop/src/configs/php-versions.json';
const manifest = await getManifestURL();
switch (true) {
case /^(latest|\d+\.x)$/.test(version):
return JSON.parse(await fetch(manifest))[version];
case /^(latest|nightly|\d+\.x)$/.test(version):
return JSON.parse((await fetch(manifest))['data'])[version];
default:
switch (true) {
case version.length > 1:
@ -207,10 +239,14 @@ export async function addLog(
* Read the scripts
*
* @param filename
* @param directory
*/
export async function readScript(filename: string): Promise<string> {
export async function readFile(
filename: string,
directory: string
): Promise<string> {
return fs.readFileSync(
path.join(__dirname, '../src/scripts/' + filename),
path.join(__dirname, '../' + directory, filename),
'utf8'
);
}
@ -244,18 +280,21 @@ export async function extensionArray(
case ' ':
return [];
default:
return extension_csv
.split(',')
.map(function (extension: string) {
if (/.+-.+\/.+@.+/.test(extension)) {
return extension;
}
return extension
.trim()
.toLowerCase()
.replace(/^php[-_]/, '');
})
.filter(Boolean);
return [
extension_csv.match(/(^|,\s?)none(\s?,|$)/) ? 'none' : '',
...extension_csv
.split(',')
.map(function (extension: string) {
if (/.+-.+\/.+@.+/.test(extension)) {
return extension;
}
return extension
.trim()
.toLowerCase()
.replace(/^(:)?(php[-_]|none|zend )/, '$1');
})
].filter(Boolean);
}
}

View File

@ -1,8 +1,9 @@
{
"compilerOptions": {
"declaration": true,
"esModuleInterop": true,
"lib": [
"ESNext"
"ES2020"
],
"module": "commonjs",
"moduleResolution": "node",
@ -12,7 +13,7 @@
"rootDir": "./src",
"sourceMap": true,
"strict": true,
"target": "ESNext"
"target": "ES2019"
},
"exclude": ["__tests__", "lib", "node_modules"]
}