Compare commits

..

26 Commits
1.8.0 ... 2.0.0

Author SHA1 Message Date
383a511d0e Merge pull request #177 from shivammathur/develop
2.0.0
2020-02-17 04:40:05 +05:30
cc55dbcaa8 Remove support for deprecated inputs 2020-02-17 02:35:18 +05:30
e644692ccf Update test workflow 2020-02-17 01:15:15 +05:30
96d5358317 Bump version to 2.0.0 2020-02-17 01:14:18 +05:30
3a473c9a22 Add support for unstable versions 2020-02-16 07:04:15 +05:30
40944de129 Fix phalcon caching on darwin 2020-02-15 23:46:26 +05:30
f9202d6b64 Support existing PHP on darwin 2020-02-14 16:52:33 +05:30
d99c8732ba Fix extension_version on windows 2020-02-14 15:48:43 +05:30
2c559eae3d Update documentation for v2 2020-02-14 13:35:04 +05:30
3a2ca44a8a Add problem matcher for PHP native errors 2020-02-14 12:55:54 +05:30
17241e2689 Add support for update and extension versions 2020-02-14 12:55:04 +05:30
ca33d01e9f Add support for old PHP versions on linux 2020-02-13 10:31:48 +05:30
3c6644f237 Add support for old PHP versions on windows 2020-02-06 05:54:20 +05:30
326dfd1e76 Add support for old PHP versions on darwin 2020-02-06 05:53:28 +05:30
d9cf6f5ad6 Merge pull request #173 from shivammathur/develop
1.8.2
2020-02-03 04:26:49 +05:30
ea50c7c0a2 Bump version to 1.8.2 2020-02-03 04:07:28 +05:30
6ca549dcaa Update readme 2020-02-03 03:48:07 +05:30
d3760be2cc Add support for cs2pr and refactor tools code 2020-02-03 02:28:00 +05:30
3454287b87 Improve phalcon scripts 2020-02-02 18:29:12 +05:30
88c7757dc8 Add dependencies when enabling extensions in linux 2020-02-02 12:58:32 +05:30
48cfea3f3e Add script to help cache extensions 2020-02-02 04:30:01 +05:30
43cfa2b1a8 Refactor scripts 2020-02-02 03:26:15 +05:30
76cecacc5e Merge pull request #168 from shivammathur/develop
1.8.1
2020-01-27 22:39:10 +05:30
d6e173ffc6 Fix pecl command in linux 2020-01-27 21:32:49 +05:30
26701f2ec8 Bump version to 1.8.1 2020-01-27 21:24:08 +05:30
e934fe28b8 Fix PECL config 2020-01-27 21:09:51 +05:30
44 changed files with 2436 additions and 2847 deletions

View File

@ -27,6 +27,9 @@ jobs:
matrix: matrix:
operating-system: [ubuntu-latest, windows-latest, macos-latest] operating-system: [ubuntu-latest, windows-latest, macos-latest]
php-versions: ['8.0'] php-versions: ['8.0']
env:
extensions: xml, opcache, xdebug, pcov
key: cache-v1
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
@ -53,12 +56,27 @@ jobs:
timeout-minutes: 1 timeout-minutes: 1
run: curl -s https://codecov.io/bash | bash -s -- -t ${{secrets.CODECOV_TOKEN}} -f coverage/clover.xml -n github-actions-codecov-${{ matrix.operating-system }}-php${{ matrix.php-versions }} run: curl -s https://codecov.io/bash | bash -s -- -t ${{secrets.CODECOV_TOKEN}} -f coverage/clover.xml -n github-actions-codecov-${{ matrix.operating-system }}-php${{ matrix.php-versions }}
- name: Setup cache environment
id: cache-env
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.php-versions }}
extensions: ${{ env.extensions }}
key: ${{ env.key }}
- name: Cache extensions
uses: actions/cache@v1
with:
path: ${{ steps.cache-env.outputs.dir }}
key: ${{ steps.cache-env.outputs.key }}
restore-keys: ${{ steps.cache-env.outputs.key }}
- name: Setup PHP with extensions and custom config - name: Setup PHP with extensions and custom config
run: node dist/index.js run: node dist/index.js
env: env:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: xml, opcache, xdebug, pcov #optional extensions: ${{ env.extensions }}
ini-values: post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata #optional ini-values: post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata
coverage: pcov coverage: pcov
- name: Testing PHP version - name: Testing PHP version

View File

@ -24,7 +24,10 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
operating-system: [ubuntu-latest, windows-latest, macos-latest] operating-system: [ubuntu-latest, windows-latest, macos-latest]
php-versions: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4'] php-versions: ['5.3', '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4']
env:
extensions: xml, opcache, xdebug, pcov
key: cache-v1
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
@ -51,12 +54,27 @@ jobs:
timeout-minutes: 1 timeout-minutes: 1
run: curl -s https://codecov.io/bash | bash -s -- -t ${{secrets.CODECOV_TOKEN}} -f coverage/clover.xml -n github-actions-codecov-${{ matrix.operating-system }}-php${{ matrix.php-versions }} run: curl -s https://codecov.io/bash | bash -s -- -t ${{secrets.CODECOV_TOKEN}} -f coverage/clover.xml -n github-actions-codecov-${{ matrix.operating-system }}-php${{ matrix.php-versions }}
- name: Setup cache environment
id: cache-env
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.php-versions }}
extensions: ${{ env.extensions }}
key: ${{ env.key }}
- name: Cache extensions
uses: actions/cache@v1
with:
path: ${{ steps.cache-env.outputs.dir }}
key: ${{ steps.cache-env.outputs.key }}
restore-keys: ${{ steps.cache-env.outputs.key }}
- name: Setup PHP with extensions and custom config - name: Setup PHP with extensions and custom config
run: node dist/index.js run: node dist/index.js
env: env:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: xml, opcache, xdebug, pcov #optional extensions: ${{ env.extensions }}
ini-values: post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata #optional ini-values: post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata
- name: Testing PHP version - name: Testing PHP version
run: | run: |

256
README.md
View File

@ -10,7 +10,7 @@
<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://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://codecov.io/gh/shivammathur/setup-php/branch/master/graph/badge.svg"></a> <a href="https://codecov.io/gh/shivammathur/setup-php" title="Code coverage"><img alt="Codecov Code Coverage" src="https://codecov.io/gh/shivammathur/setup-php/branch/master/graph/badge.svg"></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"></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"></a>
<a href="#tada-php-support" title="PHP Versions Supported"><img alt="PHP Versions Supported" src="https://img.shields.io/badge/php-%3E%3D%205.6-8892BF.svg"></a> <a href="#tada-php-support" title="PHP Versions Supported"><img alt="PHP Versions Supported" src="https://img.shields.io/badge/php-%3E%3D%205.3-8892BF.svg"></a>
</p> </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 setup 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. 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 setup 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.
@ -24,25 +24,32 @@ Setup PHP with required extensions, php.ini configuration, code-coverage support
- [Coverage support](#signal_strength-coverage-support) - [Coverage support](#signal_strength-coverage-support)
- [Xdebug](#xdebug) - [Xdebug](#xdebug)
- [PCOV](#pcov) - [PCOV](#pcov)
- [Disable coverage](#disable-coverage) - [Disable Coverage](#disable-coverage)
- [Usage](#memo-usage) - [Usage](#memo-usage)
- [Inputs](#inputs)
- [Basic Setup](#basic-setup) - [Basic Setup](#basic-setup)
- [Matrix Setup](#matrix-setup) - [Matrix Setup](#matrix-setup)
- [Experimental Setup](#experimental-setup) - [Experimental Setup](#experimental-setup)
- [Thread Safe Setup](#thread-safe-setup) - [Thread Safe Setup](#thread-safe-setup)
- [Cache dependencies](#cache-dependencies) - [Force Update](#force-update)
- [Verbose Setup](#verbose-setup)
- [Cache Extensions](#cache-extensions)
- [Cache Composer Dependencies](#cache-composer-dependencies)
- [Problem Matchers](#problem-matchers) - [Problem Matchers](#problem-matchers)
- [Examples](#examples) - [Examples](#examples)
- [License](#scroll-license) - [License](#scroll-license)
- [Contributions](#1-contributions) - [Contributions](#1-contributions)
- [Support this project](#sparkling_heart-support-this-project) - [Support This Project](#sparkling_heart-support-this-project)
- [This action uses the following works](#bookmark-this-action-uses-the-following-works) - [Dependencies](#bookmark-dependencies)
- [Further Reading](#bookmark_tabs-further-reading) - [Further Reading](#bookmark_tabs-further-reading)
## :tada: PHP Support ## :tada: PHP Support
|PHP Version|Stability|Release Support| |PHP Version|Stability|Release Support|
|--- |--- |--- | |--- |--- |--- |
|5.3|`Stable`|`End of life`|
|5.4|`Stable`|`End of life`|
|5.5|`Stable`|`End of life`|
|5.6|`Stable`|`End of life`| |5.6|`Stable`|`End of life`|
|7.0|`Stable`|`End of life`| |7.0|`Stable`|`End of life`|
|7.1|`Stable`|`End of life`| |7.1|`Stable`|`End of life`|
@ -64,20 +71,51 @@ Setup PHP with required extensions, php.ini configuration, code-coverage support
## :heavy_plus_sign: PHP Extension Support ## :heavy_plus_sign: PHP Extension Support
- On `ubuntu` by default extensions which are available as a package can be installed. If the extension is not available as a package but it is on `PECL`, it can be installed by specifying `pecl` in the tools input. - On `ubuntu` by default extensions which are available as a package can be installed. If the extension is not available as a package but it is on `PECL`, it can be installed by specifying `pecl` in the tools input.
```yaml
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
tools: pecl
extensions: swoole
```
- On `windows` extensions which have `windows` binary on `PECL` can be installed. - On `windows` extensions which have `windows` binary on `PECL` can be installed.
- On `macOS` extensions which are on `PECL` can be installed. - On `macOS` extensions which are on `PECL` can be installed.
- Extensions which are installed along with PHP if specified are enabled. - Extensions which are installed along with PHP if specified are enabled.
- Extensions on `PECL` which do not have a latest stable version, their pre-release versions can be installed by suffixing the extension with its state i.e `alpha`, `beta`, `devel` or `snapshot` separated by a `-` like `msgpack-beta`.
- Specific versions of PECL extensions can be installed by suffixing the extension with the version. This is useful for installing old versions of extensions which support end of life PHP versions.
```yaml
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
tools: pecl
extensions: pcov-1.0.6
```
- Pre-release versions of PECL extensions can be installed by suffixing the extension with its state i.e `alpha`, `beta`, `devel` or `snapshot`.
```yaml
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
tools: pecl
extensions: xdebug-beta
```
- Extensions which cannot be installed gracefully leave an error message in the logs, the action is not interrupted. - Extensions which cannot be installed gracefully leave an error message in the logs, the action is not interrupted.
## :wrench: Tools Support ## :wrench: Tools Support
These tools can be setup globally using the `tools` input. These tools can be setup globally using the `tools` input.
`codeception`, `composer`, `composer-prefetcher`, `deployer`, `pecl`, `phinx`, `phive`, `phpcbf`, `phpcpd`, `php-config`, `php-cs-fixer`, `phpcs`, `phpize`, `phpmd`, `phpstan`, `phpunit`, `prestissimo`, `psalm`, `symfony` `codeception`, `composer`, `composer-prefetcher`, `cs2pr`, `deployer`, `pecl`, `phinx`, `phive`, `phpcbf`, `phpcpd`, `php-config`, `php-cs-fixer`, `phpcs`, `phpize`, `phpmd`, `phpstan`, `phpunit`, `prestissimo`, `psalm`, `symfony`
```yaml ```yaml
uses: shivammathur/setup-php@v1 uses: shivammathur/setup-php@v2
with: with:
php-version: '7.4' php-version: '7.4'
tools: php-cs-fixer, phpunit tools: php-cs-fixer, phpunit
@ -87,7 +125,7 @@ To setup a particular version of a tool, specify it in the form `tool:version`.
Version should be in semver format and a valid release of the tool. Version should be in semver format and a valid release of the tool.
```yaml ```yaml
uses: shivammathur/setup-php@v1 uses: shivammathur/setup-php@v2
with: with:
php-version: '7.4' php-version: '7.4'
tools: php-cs-fixer:2.15.5, phpunit:8.5.1 tools: php-cs-fixer:2.15.5, phpunit:8.5.1
@ -95,7 +133,7 @@ with:
**Note** **Note**
- `composer` is setup by default. - `composer` is setup by default.
- Specifying version for `composer` and `pecl` has no effect, latest version of both tools will be setup. - Specifying version for `composer` and `pecl` has no effect, latest versions of both tools which are compatible with the PHP version will be setup.
- If the version specified for the tool is not in semver format, latest version of the tool will be setup. - If the version specified for the tool is not in semver format, latest version of the tool will be setup.
- Tools which cannot be installed gracefully leave an error message in the logs, the action is not interrupted. - Tools which cannot be installed gracefully leave an error message in the logs, the action is not interrupted.
@ -107,7 +145,7 @@ Specify `coverage: xdebug` to use `Xdebug`.
Runs on all [PHP versions supported](#tada-php-support "List of PHP versions supported on this GitHub Action") except `8.0`. Runs on all [PHP versions supported](#tada-php-support "List of PHP versions supported on this GitHub Action") except `8.0`.
```yaml ```yaml
uses: shivammathur/setup-php@v1 uses: shivammathur/setup-php@v2
with: with:
php-version: '7.4' php-version: '7.4'
coverage: xdebug coverage: xdebug
@ -115,23 +153,22 @@ with:
### PCOV ### PCOV
Specify `coverage: pcov` to use `PCOV`. Specify `coverage: pcov` to use `PCOV` and disable `Xdebug`.
It is much faster than `Xdebug`. It is much faster than `Xdebug`.
`PCOV` needs `PHP >= 7.1`. `PCOV` needs `PHP >= 7.1`.
If your source code directory is other than `src`, `lib` or, `app`, specify `pcov.directory` using the `ini-values` input. If your source code directory is other than `src`, `lib` or, `app`, specify `pcov.directory` using the `ini-values` input.
```yaml ```yaml
uses: shivammathur/setup-php@v1 uses: shivammathur/setup-php@v2
with: with:
php-version: '7.4' php-version: '7.4'
ini-values: pcov.directory=api #optional, see above for usage. ini-values: pcov.directory=api #optional, see above for usage.
coverage: pcov coverage: pcov
``` ```
### Disable coverage ### Disable Coverage
Specify `coverage: none` to disable both `Xdebug` and `PCOV`. Specify `coverage: none` to remove both `Xdebug` and `PCOV`.
Consider disabling the coverage using this PHP action for these reasons. Consider disabling the coverage using this PHP action for these reasons.
- You are not generating coverage reports while testing. - You are not generating coverage reports while testing.
@ -139,7 +176,7 @@ Consider disabling the coverage using this PHP action for these reasons.
- You are using `phpdbg` for running your tests. - You are using `phpdbg` for running your tests.
```yaml ```yaml
uses: shivammathur/setup-php@v1 uses: shivammathur/setup-php@v2
with: with:
php-version: '7.4' php-version: '7.4'
coverage: none coverage: none
@ -147,15 +184,38 @@ with:
## :memo: Usage ## :memo: Usage
Inputs supported by this GitHub Action. ### Inputs
- php-version `required` #### `php-version` (required)
- extensions `optional`
- ini-values `optional`
- coverage `optional`
- tools `optional`
See [action.yml](action.yml "Metadata for this GitHub Action") and usage below for more info. - Specify the PHP version you want to setup.
- Accepts a `string`. For example `'7.4'`.
- See [PHP support](#tada-php-support) for supported PHP versions.
#### `extensions` (optional)
- Specify the extensions you want to setup.
- Accepts a `string` in csv-format. For example `mbstring, zip`.
- See [PHP extension support](#heavy_plus_sign-php-extension-support) for more info.
#### `ini-values` (optional)
- Specify the values you want to add to `php.ini`.
- Accepts a `string` in csv-format. For example `post_max_size=256M, short_open_tag=On`.
#### `coverage` (optional)
- Specify the code coverage driver you want to setup.
- Accepts `xdebug`, `pcov` or `none`.
- See [coverage support](#signal_strength-coverage-support) for more info.
#### `tools` (optional)
- Specify the tools you want to setup.
- Accepts a `string` in csv-format. For example `phpunit, phpcs`
- See [tools Support](#wrench-tools-support) for tools supported.
See below for more info.
### Basic Setup ### Basic Setup
@ -167,13 +227,13 @@ steps:
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@v1 uses: shivammathur/setup-php@v2
with: with:
php-version: '7.4' php-version: '7.4'
extensions: mbstring, intl #optional, setup extensions extensions: mbstring, intl
ini-values: post_max_size=256M, short_open_tag=On #optional, setup php.ini configuration ini-values: post_max_size=256M, short_open_tag=On
coverage: xdebug #optional, setup coverage driver coverage: xdebug
tools: php-cs-fixer, phpunit #optional, setup tools globally tools: php-cs-fixer, phpunit
``` ```
### Matrix Setup ### Matrix Setup
@ -194,13 +254,13 @@ jobs:
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@v1 uses: shivammathur/setup-php@v2
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: mbstring, intl #optional, setup extensions extensions: mbstring, intl
ini-values: post_max_size=256M, short_open_tag=On #optional, setup php.ini configuration ini-values: post_max_size=256M, short_open_tag=On
coverage: xdebug #optional, setup coverage driver coverage: xdebug
tools: php-cs-fixer, phpunit #optional, setup tools globally tools: php-cs-fixer, phpunit
``` ```
### Experimental Setup ### Experimental Setup
@ -219,13 +279,13 @@ steps:
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@v1 uses: shivammathur/setup-php@v2
with: with:
php-version: '8.0' php-version: '8.0'
extensions: mbstring #optional, setup extensions extensions: mbstring
ini-values: opcache.jit_buffer_size=256M, opcache.jit=1235, pcre.jit=1 #optional, setup php.ini configuration ini-values: opcache.jit_buffer_size=256M, opcache.jit=1235, pcre.jit=1
coverage: pcov #optional, setup PCOV, Xdebug does not support this version yet. coverage: pcov
tools: php-cs-fixer, phpunit #optional, setup tools globally tools: php-cs-fixer, phpunit
``` ```
### Thread Safe Setup ### Thread Safe Setup
@ -244,14 +304,79 @@ jobs:
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@v1 uses: shivammathur/setup-php@v2
with: with:
php-version: '7.4' php-version: '7.4'
env: env:
PHPTS: ts # specify ts or nts PHPTS: ts # specify ts or nts
``` ```
### Cache dependencies ### Force Update
- PHP versions which are pre-installed on the GitHub Actions runner are not updated to their latest patch release by default.
- You can specify the `update` environment variable to `true` to force update to the latest release.
```yaml
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
env:
update: true # specify true or false
```
### Verbose Setup
- To debug any issues, you can use the `verbose` tag instead of `v2`.
```yaml
- name: Setup PHP
uses: shivammathur/setup-php@verbose
with:
php-version: '7.4'
```
### Cache Extensions
You can persist PHP extensions you setup using the [`shivammathur/cache-extensions`](https://github.com/shivammathur/cache-extensions "GitHub Action to cache php extensions") and [`action/cache`](https://github.com/actions/cache "GitHub Action to cache files") GitHub Actions. Extensions which take very long to setup if cached are available in the next workflow run and enabled directly which reduces the workflow execution time.
```yaml
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ubuntu-latest, windows-latest, macos-latest]
php-versions: ['7.2', '7.3', '7.4']
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}
env:
extensions: intl, pcov
key: cache-v1 # can be any string, change to clear the extension cache.
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup cache environment
id: cache-env
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.php-versions }}
extensions: ${{ env.extensions }}
key: ${{ env.key }}
- name: Cache extensions
uses: actions/cache@v1
with:
path: ${{ steps.cache-env.outputs.dir }}
key: ${{ steps.cache-env.outputs.key }}
restore-keys: ${{ steps.cache-env.outputs.key }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: ${{ env.extensions }}
```
### Cache Composer Dependencies
You can persist composer's internal cache directory using the [`action/cache`](https://github.com/actions/cache "GitHub Action to cache files") GitHub Action. Dependencies cached are loaded directly instead of downloading them while installation. The files cached are available across check-runs and will reduce the workflow execution time. You can persist composer's internal cache directory using the [`action/cache`](https://github.com/actions/cache "GitHub Action to cache files") GitHub Action. Dependencies cached are loaded directly instead of downloading them while installation. The files cached are available across check-runs and will reduce the workflow execution time.
@ -281,13 +406,42 @@ key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
### Problem Matchers ### Problem Matchers
You can setup problem matchers for your `PHPUnit` output by adding this step after the `setup-php` step. This will scan the logs for failing tests and surface that information prominently in the GitHub Actions UI by creating annotations and log file decorations. #### PHP
Setup problem matchers for your `PHP` output by adding this step after the `setup-php` step. This will scan the logs for PHP errors and warnings, and surface them prominently in the GitHub Actions UI by creating annotations and log file decorations.
```yaml
- name: Setup Problem Matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
```
#### PHPUnit
Setup problem matchers for your `PHPUnit` output by adding this step after the `setup-php` step. This will scan the logs for failing tests and surface that information prominently in the GitHub Actions UI by creating annotations and log file decorations.
```yaml ```yaml
- name: Setup Problem Matchers for PHPUnit - name: Setup Problem Matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
``` ```
#### Other Tools
For tools that support `checkstyle` reporting like `phpstan`, `psalm`, `php-cs-fixer` and `phpcs` you can use `cs2pr` to annotate your code.
For examples refer to [cs2pr documentation](https://github.com/staabm/annotate-pull-request-from-checkstyle).
> Here is an example with `phpstan`.
```yaml
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
tools: cs2pr, phpstan
- name: PHPStan
run: phpstan analyse src --error-format=checkstyle | cs2pr
```
### Examples ### Examples
Examples for setting up this GitHub Action with different PHP Frameworks/Packages. Examples for setting up this GitHub Action with different PHP Frameworks/Packages.
@ -318,13 +472,13 @@ Examples for setting up this GitHub Action with different PHP Frameworks/Package
## :scroll: License ## :scroll: License
The scripts and documentation in this project are released under the [MIT License](LICENSE "License for shivammathur/setup-php"). This project has multiple [dependencies](https://github.com/shivammathur/setup-php/network/dependencies "Dependencies for this PHP Action") and uses [various works](#bookmark-this-action-uses-the-following-works "Tools used by this action"). Their licenses can be found in their respective repositories. The scripts and documentation in this project are released under the [MIT License](LICENSE "License for shivammathur/setup-php"). This project has multiple [dependencies](#dependencies "Dependencies for this PHP Action"). Their licenses can be found in their respective repositories.
## :+1: Contributions ## :+1: Contributions
Contributions are welcome! See [Contributor's Guide](.github/CONTRIBUTING.md "shivammathur/setup-php contribution guide"). If you face any issues while using this or want to suggest a feature/improvement, create an issue [here](https://github.com/shivammathur/setup-php/issues "Issues reported"). Contributions are welcome! See [Contributor's Guide](.github/CONTRIBUTING.md "shivammathur/setup-php contribution guide"). If you face any issues while using this or want to suggest a feature/improvement, create an issue [here](https://github.com/shivammathur/setup-php/issues "Issues reported").
## :sparkling_heart: Support this project ## :sparkling_heart: Support This Project
If this action helped you. If this action helped you.
@ -333,12 +487,16 @@ If this action helped you.
- I maintain this in my free time, please support me with a [Patreon](https://www.patreon.com/shivammathur "Shivam Mathur Patreon") subscription or a one time contribution using [Paypal](https://www.paypal.me/shivammathur "Shivam Mathur PayPal"). - I maintain this in my free time, please support me with a [Patreon](https://www.patreon.com/shivammathur "Shivam Mathur Patreon") subscription or a one time contribution using [Paypal](https://www.paypal.me/shivammathur "Shivam Mathur PayPal").
- If you need any help using this, please contact me using [Codementor](https://www.codementor.io/shivammathur "Shivam Mathur Codementor") - If you need any help using this, please contact me using [Codementor](https://www.codementor.io/shivammathur "Shivam Mathur Codementor")
## :bookmark: This action uses the following works ## :bookmark: Dependencies
- [ppa:ondrej/php](https://launchpad.net/~ondrej/+archive/ubuntu/php "Pre-compiled ubuntu packages") - [Node.js dependencies](https://github.com/shivammathur/setup-php/network/dependencies "Node.js dependencies")
- [shivammathur/php-builder](https://github.com/shivammathur/php-builder "Pre-compiled nightly PHP builds") - [gplessis/dotdeb-php](https://github.com/gplessis/dotdeb-php "Packaging for end of life PHP versions")
- [mlocati/powershell-phpmanager](https://github.com/mlocati/powershell-phpmanager "Package to handle PHP on windows") - [mlocati/powershell-phpmanager](https://github.com/mlocati/powershell-phpmanager "Package to handle PHP on windows")
- [ppa:ondrej/php](https://launchpad.net/~ondrej/+archive/ubuntu/php "Packaging active PHP packages")
- [shivammathur/cache-extensions](https://github.com/shivammathur/cache-extensions "GitHub action to help with caching PHP extensions")
- [shivammathur/homebrew-php](https://github.com/shivammathur/homebrew-php "Tap for PHP builds for MacOS") - [shivammathur/homebrew-php](https://github.com/shivammathur/homebrew-php "Tap for PHP builds for MacOS")
- [shivammathur/php-builder](https://github.com/shivammathur/php-builder "Nightly PHP package")
- [shivammathur/php5-ubuntu](https://github.com/shivammathur/php5-ubuntu "Scripts to setup PHP5 versions")
## :bookmark_tabs: Further Reading ## :bookmark_tabs: Further Reading

View File

@ -3,7 +3,7 @@ import * as extensions from '../src/extensions';
describe('Extension tests', () => { describe('Extension tests', () => {
it('checking addExtensionOnWindows', async () => { it('checking addExtensionOnWindows', async () => {
let win32: string = await extensions.addExtension( let win32: string = await extensions.addExtension(
'xdebug, pcov, phalcon4, ast-beta', 'xdebug, pcov, phalcon4, ast-beta, grpc-1.2.3, inotify-1.2.3alpha2',
'7.4', '7.4',
'win32' 'win32'
); );
@ -11,6 +11,8 @@ describe('Extension tests', () => {
expect(win32).toContain('Add-Extension pcov'); expect(win32).toContain('Add-Extension pcov');
expect(win32).toContain('phalcon.ps1 phalcon4'); expect(win32).toContain('phalcon.ps1 phalcon4');
expect(win32).toContain('Add-Extension ast beta'); 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');
win32 = await extensions.addExtension( win32 = await extensions.addExtension(
'phalcon3, does_not_exist', 'phalcon3, does_not_exist',
@ -27,16 +29,19 @@ describe('Extension tests', () => {
it('checking addExtensionOnLinux', async () => { it('checking addExtensionOnLinux', async () => {
let linux: string = await extensions.addExtension( let linux: string = await extensions.addExtension(
'xdebug, pcov, ast-beta', 'xdebug, pcov, ast-beta, xdebug-alpha, grpc-1.2.3',
'7.4', '7.4',
'linux' 'linux'
); );
expect(linux).toContain('update_extension xdebug 2.9.0'); expect(linux).toContain('update_extension xdebug 2.9.1');
expect(linux).toContain( expect(linux).toContain(
'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php7.4-pcov' 'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php7.4-pcov'
); );
expect(linux).toContain('pecl install -f pcov'); expect(linux).toContain('add_unstable_extension ast beta extension');
expect(linux).toContain('install_extension ast-beta'); expect(linux).toContain('add_pecl_extension grpc 1.2.3');
expect(linux).toContain(
'add_unstable_extension xdebug alpha zend_extension'
);
linux = await extensions.addExtension('gearman', '7.0', 'linux'); linux = await extensions.addExtension('gearman', '7.0', 'linux');
expect(linux).toContain('gearman.sh 7.0'); expect(linux).toContain('gearman.sh 7.0');
@ -62,13 +67,14 @@ describe('Extension tests', () => {
it('checking addExtensionOnDarwin', async () => { it('checking addExtensionOnDarwin', async () => {
let darwin: string = await extensions.addExtension( let darwin: string = await extensions.addExtension(
'xdebug, pcov, ast-beta', 'xdebug, pcov, ast-beta, grpc-1.2.3',
'7.2', '7.2',
'darwin' 'darwin'
); );
expect(darwin).toContain('sudo pecl install -f xdebug'); expect(darwin).toContain('sudo pecl install -f xdebug');
expect(darwin).toContain('sudo pecl install -f pcov'); expect(darwin).toContain('sudo pecl install -f pcov');
expect(darwin).toContain('install_extension ast-beta'); expect(darwin).toContain('add_unstable_extension ast beta extension');
expect(darwin).toContain('sudo pecl install -f grpc-1.2.3');
darwin = await extensions.addExtension('phalcon3', '7.0', 'darwin'); darwin = await extensions.addExtension('phalcon3', '7.0', 'darwin');
expect(darwin).toContain('phalcon_darwin.sh phalcon3 7.0'); expect(darwin).toContain('phalcon_darwin.sh phalcon3 7.0');
@ -82,6 +88,15 @@ describe('Extension tests', () => {
darwin = await extensions.addExtension('pcov', '7.2', 'darwin'); darwin = await extensions.addExtension('pcov', '7.2', 'darwin');
expect(darwin).toContain('sudo pecl install -f pcov'); expect(darwin).toContain('sudo pecl install -f pcov');
darwin = await extensions.addExtension('xdebug', '5.3', 'darwin');
expect(darwin).toContain('sudo pecl install -f xdebug-2.2.7');
darwin = await extensions.addExtension('xdebug', '5.4', 'darwin');
expect(darwin).toContain('sudo pecl install -f xdebug-2.4.1');
darwin = await extensions.addExtension('xdebug', '5.5', 'darwin');
expect(darwin).toContain('sudo pecl install -f xdebug-2.5.5');
darwin = await extensions.addExtension('xdebug', '5.6', 'darwin'); darwin = await extensions.addExtension('xdebug', '5.6', 'darwin');
expect(darwin).toContain('sudo pecl install -f xdebug-2.5.5'); expect(darwin).toContain('sudo pecl install -f xdebug-2.5.5');

View File

@ -46,7 +46,7 @@ jest.mock('../src/install', () => ({
case 'darwin': case 'darwin':
case 'linux': case 'linux':
script = await install.build(os_version + '.sh', version, os_version); script = await install.build(os_version + '.sh', version, os_version);
script += 'sh script.sh ' + version + ' ' + __dirname; script += 'bash script.sh ' + version + ' ' + __dirname;
break; break;
case 'win32': case 'win32':
script = await install.build(os_version + '.sh', version, os_version); script = await install.build(os_version + '.sh', version, os_version);
@ -117,7 +117,7 @@ describe('Install', () => {
// @ts-ignore // @ts-ignore
let script: string = await install.run(); let script: string = await install.run();
expect(script).toContain('initial script'); expect(script).toContain('initial script');
expect(script).toContain('sh script.sh 7.3 '); expect(script).toContain('bash script.sh 7.3 ');
setEnv('7.3', 'linux', 'a, b', 'a=b', 'x', 'phpunit', 'true'); setEnv('7.3', 'linux', 'a, b', 'a=b', 'x', 'phpunit', 'true');
// @ts-ignore // @ts-ignore
@ -126,7 +126,7 @@ describe('Install', () => {
expect(script).toContain('install extensions'); expect(script).toContain('install extensions');
expect(script).toContain('edit php.ini'); expect(script).toContain('edit php.ini');
expect(script).toContain('set coverage driver'); expect(script).toContain('set coverage driver');
expect(script).toContain('sh script.sh 7.3'); expect(script).toContain('bash script.sh 7.3');
expect(script).toContain('add_tool'); expect(script).toContain('add_tool');
setEnv('7.3', 'linux', 'a, b', 'a=b', 'x', 'phpunit', ''); setEnv('7.3', 'linux', 'a, b', 'a=b', 'x', 'phpunit', '');
@ -136,7 +136,7 @@ describe('Install', () => {
expect(script).toContain('install extensions'); expect(script).toContain('install extensions');
expect(script).toContain('edit php.ini'); expect(script).toContain('edit php.ini');
expect(script).toContain('set coverage driver'); expect(script).toContain('set coverage driver');
expect(script).toContain('sh script.sh 7.3'); expect(script).toContain('bash script.sh 7.3');
expect(script).toContain('add_tool'); expect(script).toContain('add_tool');
}); });
@ -145,7 +145,7 @@ describe('Install', () => {
// @ts-ignore // @ts-ignore
let script: string = await install.run(); let script: string = await install.run();
expect(script).toContain('initial script'); expect(script).toContain('initial script');
expect(script).toContain('sh script.sh 7.3 ' + __dirname); expect(script).toContain('bash script.sh 7.3 ' + __dirname);
setEnv('7.3', 'darwin', 'a, b', 'a=b', 'x', '', ''); setEnv('7.3', 'darwin', 'a, b', 'a=b', 'x', '', '');
// @ts-ignore // @ts-ignore
@ -154,7 +154,7 @@ describe('Install', () => {
expect(script).toContain('install extensions'); expect(script).toContain('install extensions');
expect(script).toContain('edit php.ini'); expect(script).toContain('edit php.ini');
expect(script).toContain('set coverage driver'); expect(script).toContain('set coverage driver');
expect(script).toContain('sh script.sh 7.3 ' + __dirname); expect(script).toContain('bash script.sh 7.3 ' + __dirname);
}); });
it('Test malformed version inputs', async () => { it('Test malformed version inputs', async () => {
@ -162,18 +162,18 @@ describe('Install', () => {
// @ts-ignore // @ts-ignore
let script: string = await install.run(); let script: string = await install.run();
expect(script).toContain('initial script'); expect(script).toContain('initial script');
expect(script).toContain('sh script.sh 7.4 ' + __dirname); expect(script).toContain('bash script.sh 7.4 ' + __dirname);
setEnv(8.0, 'darwin', '', '', '', '', ''); setEnv(8.0, 'darwin', '', '', '', '', '');
// @ts-ignore // @ts-ignore
script = await install.run(); script = await install.run();
expect(script).toContain('initial script'); expect(script).toContain('initial script');
expect(script).toContain('sh script.sh 8.0 ' + __dirname); expect(script).toContain('bash script.sh 8.0 ' + __dirname);
setEnv(8, 'darwin', '', '', '', '', ''); setEnv(8, 'darwin', '', '', '', '', '');
// @ts-ignore // @ts-ignore
script = await install.run(); script = await install.run();
expect(script).toContain('initial script'); expect(script).toContain('initial script');
expect(script).toContain('sh script.sh 8.0 ' + __dirname); expect(script).toContain('bash script.sh 8.0 ' + __dirname);
}); });
}); });

View File

@ -18,10 +18,10 @@ describe('Matchers', () => {
process.env['RUNNER_TOOL_CACHE'] = __dirname; process.env['RUNNER_TOOL_CACHE'] = __dirname;
await matchers.addMatchers(); await matchers.addMatchers();
const spy = jest.spyOn(io, 'cp'); const spy = jest.spyOn(io, 'cp');
expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledTimes(2);
}); });
it('Test Regex', async () => { it('Test PHPUnit Regex', async () => {
const regex1 = /^\d+\)\s.*$/; const regex1 = /^\d+\)\s.*$/;
const regex2 = /^(.*Failed\sasserting\sthat.*)$/; const regex2 = /^(.*Failed\sasserting\sthat.*)$/;
const regex3 = /^\s*$/; const regex3 = /^\s*$/;
@ -31,4 +31,21 @@ describe('Matchers', () => {
expect(regex3.test('\n')).toBe(true); expect(regex3.test('\n')).toBe(true);
expect(regex4.test('/path/to/file.php:42')).toBe(true); expect(regex4.test('/path/to/file.php:42')).toBe(true);
}); });
it('Test PHP Regex', async () => {
const regex1 = /^(.*error):\s+\s+(.+) in (.+) on line (\d+)$/;
const regex2 = /^(.*Warning|.*Deprecated|.*Notice):\s+\s+(.+) in (.+) on line (\d+)$/;
expect(
regex1.test('PHP Parse error: error_message in file.php on line 10')
).toBe(true);
expect(
regex2.test('PHP Notice: info_message in file.php on line 10')
).toBe(true);
expect(
regex2.test('PHP Warning: warning_message in file.php on line 10')
).toBe(true);
expect(
regex2.test('PHP Deprecated: deprecated_message in file.php on line 10')
).toBe(true);
});
}); });

View File

@ -96,33 +96,24 @@ describe('Tools tests', () => {
it('checking getUri', async () => { it('checking getUri', async () => {
expect( expect(
await tools.getUri('tool', 'latest', 'releases', '', 'download') await tools.getUri('tool', '.phar', 'latest', 'releases', '', 'download')
).toBe('releases/latest/download/tool.phar'); ).toBe('releases/latest/download/tool.phar');
expect( expect(
await tools.getUri('tool', '1.2.3', 'releases', '', 'download') await tools.getUri('tool', '.phar', '1.2.3', 'releases', '', 'download')
).toBe('releases/download/1.2.3/tool.phar'); ).toBe('releases/download/1.2.3/tool.phar');
expect( expect(
await tools.getUri('tool', '1.2.3', 'releases', 'v', 'download') await tools.getUri('tool', '.phar', '1.2.3', 'releases', 'v', 'download')
).toBe('releases/download/v1.2.3/tool.phar'); ).toBe('releases/download/v1.2.3/tool.phar');
}); });
it('checking getCodeceptionUriBuilder', async () => { it('checking getCodeceptionUriBuilder', async () => {
expect(await tools.getCodeceptionUriBuilder('3.2.1', '5.6', 'php56')).toBe( expect(await tools.getCodeceptionUriBuilder('3.2.1', 'php56')).toBe(
'releases/3.2.1/php56/codecept.phar' 'releases/3.2.1/php56/codecept.phar'
); );
expect(await tools.getCodeceptionUriBuilder('3.2.1', '7.0', 'php54')).toBe( expect(await tools.getCodeceptionUriBuilder('3.2.1', 'php54')).toBe(
'releases/3.2.1/php54/codecept.phar' 'releases/3.2.1/php54/codecept.phar'
); );
expect(await tools.getCodeceptionUriBuilder('3.2.1', '7.1', 'php56')).toBe( expect(await tools.getCodeceptionUriBuilder('3.2.1', '')).toBe(
'releases/3.2.1/php56/codecept.phar'
);
expect(await tools.getCodeceptionUriBuilder('3.2.1', '7.2', 'php56')).toBe(
'releases/3.2.1/codecept.phar'
);
expect(await tools.getCodeceptionUriBuilder('3.2.1', '7.3', 'php56')).toBe(
'releases/3.2.1/codecept.phar'
);
expect(await tools.getCodeceptionUriBuilder('3.2.1', '7.4', 'php56')).toBe(
'releases/3.2.1/codecept.phar' 'releases/3.2.1/codecept.phar'
); );
}); });
@ -146,17 +137,59 @@ describe('Tools tests', () => {
expect(await tools.getCodeceptionUri('latest', '7.4')).toBe( expect(await tools.getCodeceptionUri('latest', '7.4')).toBe(
'codecept.phar' 'codecept.phar'
); );
expect(await tools.getCodeceptionUri('3.2.1', '5.6')).toBe( expect(await tools.getCodeceptionUri('4.0.0', '7.4')).toBe(
'releases/3.2.1/php54/codecept.phar' 'releases/4.0.0/codecept.phar'
); );
expect(await tools.getCodeceptionUri('4.3.2', '5.6')).toBe( expect(await tools.getCodeceptionUri('4.0.0', '5.6')).toBe(
'releases/4.3.2/php56/codecept.phar' 'releases/4.0.0/php56/codecept.phar'
); );
expect(await tools.getCodeceptionUri('3.2.1', '7.4')).toBe( expect(await tools.getCodeceptionUri('4.0.0', '7.1')).toBe(
'releases/3.2.1/codecept.phar' 'releases/4.0.0/php56/codecept.phar'
); );
expect(await tools.getCodeceptionUri('4.3.2', '7.4')).toBe( expect(await tools.getCodeceptionUri('3.1.0', '7.4')).toBe(
'releases/4.3.2/codecept.phar' 'releases/3.1.0/codecept.phar'
);
expect(await tools.getCodeceptionUri('3.1.0', '5.6')).toBe(
'releases/3.1.0/php54/codecept.phar'
);
expect(await tools.getCodeceptionUri('2.5.4', '7.4')).toBe(
'releases/2.5.4/codecept.phar'
);
expect(await tools.getCodeceptionUri('2.5.4', '5.6')).toBe(
'releases/2.5.4/php54/codecept.phar'
);
expect(await tools.getCodeceptionUri('2.3.4', '7.4')).toBe(
'releases/2.3.4/codecept.phar'
);
expect(await tools.getCodeceptionUri('2.3.4', '5.4')).toBe(
'releases/2.3.4/php54/codecept.phar'
);
expect(await tools.getCodeceptionUri('2.2.4', '5.6')).toBe(
'releases/2.2.4/codecept.phar'
);
expect(await tools.getCodeceptionUri('2.2.4', '7.4')).toBe(
'releases/2.2.4/codecept.phar'
);
expect(await tools.getCodeceptionUri('2.2.4', '5.4')).toBe(
'releases/2.2.4/php54/codecept.phar'
);
expect(await tools.getCodeceptionUri('2.1.7', '5.6')).toBe(
'releases/2.1.7/codecept.phar'
);
expect(await tools.getCodeceptionUri('2.1.7', '5.4')).toBe(
'releases/2.1.7/php54/codecept.phar'
);
expect(await tools.getCodeceptionUri('2.1.5', '5.4')).toBe(
'releases/2.1.5/codecept.phar'
);
expect(await tools.getCodeceptionUri('2.1.5', '7.4')).toBe(
'releases/2.1.5/codecept.phar'
);
expect(await tools.getCodeceptionUri('1.6.9', '7.4')).toBe(
'releases/1.6.9/codecept.phar'
);
expect(await tools.getCodeceptionUri('1.5.0', '7.4')).toBe(
'releases/1.5.0/codecept.phar'
); );
}); });
@ -325,13 +358,16 @@ describe('Tools tests', () => {
it('checking addTools on linux', async () => { it('checking addTools on linux', async () => {
const script: string = await tools.addTools( const script: string = await tools.addTools(
'php-cs-fixer, phpstan, phpunit, pecl, phinx, phinx:1.2.3, phive, php-config, phpize, symfony', 'cs2pr, php-cs-fixer, phpstan, phpunit, pecl, phinx, phinx:1.2.3, phive, php-config, phpize, symfony',
'7.4', '7.4',
'linux' 'linux'
); );
expect(script).toContain( expect(script).toContain(
'add_tool https://github.com/composer/composer/releases/latest/download/composer.phar composer' 'add_tool https://github.com/composer/composer/releases/latest/download/composer.phar composer'
); );
expect(script).toContain(
'add_tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/latest/download/cs2pr cs2pr'
);
expect(script).toContain( expect(script).toContain(
'add_tool https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/latest/download/php-cs-fixer.phar php-cs-fixer' 'add_tool https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/latest/download/php-cs-fixer.phar php-cs-fixer'
); );
@ -356,13 +392,16 @@ describe('Tools tests', () => {
}); });
it('checking addTools on darwin', async () => { it('checking addTools on darwin', async () => {
const script: string = await tools.addTools( const script: string = await tools.addTools(
'phpcs, phpcbf, phpcpd, phpmd, psalm, phinx, phive:1.2.3, composer-prefetcher:1.2.3, phpize, php-config, symfony, symfony:1.2.3', 'phpcs, phpcbf, phpcpd, phpmd, psalm, phinx, phive:1.2.3, cs2pr:1.2.3, composer-prefetcher:1.2.3, phpize, php-config, symfony, symfony:1.2.3',
'7.4', '7.4',
'darwin' 'darwin'
); );
expect(script).toContain( expect(script).toContain(
'add_tool https://github.com/composer/composer/releases/latest/download/composer.phar composer' 'add_tool https://github.com/composer/composer/releases/latest/download/composer.phar composer'
); );
expect(script).toContain(
'add_tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/download/1.2.3/cs2pr cs2pr'
);
expect(script).toContain( expect(script).toContain(
'add_tool https://github.com/squizlabs/PHP_CodeSniffer/releases/latest/download/phpcs.phar phpcs' 'add_tool https://github.com/squizlabs/PHP_CodeSniffer/releases/latest/download/phpcs.phar phpcs'
); );
@ -396,13 +435,16 @@ describe('Tools tests', () => {
}); });
it('checking addTools on windows', async () => { it('checking addTools on windows', async () => {
const script: string = await tools.addTools( const script: string = await tools.addTools(
'codeception, deployer, prestissimo, phpmd, phinx, phive:0.13.2, php-config, phpize, symfony, does_not_exit', 'codeception, cs2pr, deployer, prestissimo, phpmd, phinx, phive:0.13.2, php-config, phpize, symfony, does_not_exit',
'7.4', '7.4',
'win32' 'win32'
); );
expect(script).toContain( expect(script).toContain(
'Add-Tool https://github.com/composer/composer/releases/latest/download/composer.phar composer' 'Add-Tool https://github.com/composer/composer/releases/latest/download/composer.phar composer'
); );
expect(script).toContain(
'Add-Tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/latest/download/cs2pr cs2pr'
);
expect(script).toContain( expect(script).toContain(
'Add-Tool https://deployer.org/deployer.phar deployer' 'Add-Tool https://deployer.org/deployer.phar deployer'
); );

View File

@ -20,18 +20,8 @@ inputs:
tools: tools:
description: 'Setup popular tools globally.' description: 'Setup popular tools globally.'
required: false required: false
# Deprecated options, do not use. Will not be supported in v2 which will be released around February 1, 2020. update:
extension-csv: description: 'Update PHP if already installed.'
description: 'Deprecated! Use extensions instead.'
deprecationMessage: 'The extension-csv property will not be supported in v2. Use extensions instead.'
required: false
ini-values-csv:
description: 'Deprecated! Use ini-values instead.'
deprecationMessage: 'The ini-values-csv property will not be supported in v2. Use ini-values instead.'
required: false
pecl:
description: 'Deprecated! Use tools instead to setup PECL.'
deprecationMessage: 'The pecl property will not be supported in v2. Specify pecl in tools instead.'
required: false required: false
runs: runs:
using: 'node12' using: 'node12'

168
dist/index.js vendored
View File

@ -964,9 +964,10 @@ const io = __importStar(__webpack_require__(1));
*/ */
function addMatchers() { function addMatchers() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const config_path = path.join(__dirname, '..', 'src', 'configs', 'phpunit.json'); const config_path = path.join(__dirname, '..', 'src', 'configs');
const runner_dir = yield utils.getInput('RUNNER_TOOL_CACHE', false); const runner_dir = yield utils.getInput('RUNNER_TOOL_CACHE', false);
yield io.cp(config_path, runner_dir); yield io.cp(path.join(config_path, 'phpunit.json'), runner_dir);
yield io.cp(path.join(config_path, 'php.json'), runner_dir);
}); });
} }
exports.addMatchers = addMatchers; exports.addMatchers = addMatchers;
@ -1684,13 +1685,15 @@ exports.parseTool = parseTool;
* @param version_prefix * @param version_prefix
* @param verb * @param verb
*/ */
function getUri(tool, version, prefix, version_prefix, verb) { function getUri(tool, extension, version, prefix, version_prefix, verb) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
switch (version) { switch (version) {
case 'latest': case 'latest':
return [prefix, version, verb, tool + '.phar'].filter(Boolean).join('/'); return [prefix, version, verb, tool + extension]
.filter(Boolean)
.join('/');
default: default:
return [prefix, verb, version_prefix + version, tool + '.phar'] return [prefix, verb, version_prefix + version, tool + extension]
.filter(Boolean) .filter(Boolean)
.join('/'); .join('/');
} }
@ -1701,20 +1704,13 @@ exports.getUri = getUri;
* Helper function to get the codeception url * Helper function to get the codeception url
* *
* @param version * @param version
* @param php_version
* @param suffix * @param suffix
*/ */
function getCodeceptionUriBuilder(version, php_version, suffix) { function getCodeceptionUriBuilder(version, suffix) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
switch (true) { return ['releases', version, suffix, 'codecept.phar']
case /^5\.6$|^7\.[0|1]$/.test(php_version): .filter(Boolean)
return ['releases', version, suffix, 'codecept.phar'] .join('/');
.filter(Boolean)
.join('/');
case /^7\.[2-4]$/.test(php_version):
default:
return ['releases', version, 'codecept.phar'].filter(Boolean).join('/');
}
}); });
} }
exports.getCodeceptionUriBuilder = getCodeceptionUriBuilder; exports.getCodeceptionUriBuilder = getCodeceptionUriBuilder;
@ -1726,19 +1722,55 @@ exports.getCodeceptionUriBuilder = getCodeceptionUriBuilder;
*/ */
function getCodeceptionUri(version, php_version) { function getCodeceptionUri(version, php_version) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const codecept = yield getCodeceptionUriBuilder(version, '');
const codecept54 = yield getCodeceptionUriBuilder(version, 'php54');
const codecept56 = yield getCodeceptionUriBuilder(version, 'php56');
// Refer to https://codeception.com/builds
switch (true) { switch (true) {
case /latest/.test(version): case /latest/.test(version):
switch (true) { switch (true) {
case /^5\.6$|^7\.[0|1]$/.test(php_version): case /5\.6|7\.[0|1]/.test(php_version):
return 'php56/codecept.phar'; return 'php56/codecept.phar';
case /^7\.[2-4]$/.test(php_version): case /7\.[2-4]/.test(php_version):
default: default:
return 'codecept.phar'; return 'codecept.phar';
} }
case /([4-9]|\d{2,})\..*/.test(version): case /(^[4-9]|\d{2,})\..*/.test(version):
return yield getCodeceptionUriBuilder(version, php_version, 'php56'); switch (true) {
case /5\.6|7\.[0|1]/.test(php_version):
return codecept56;
case /7\.[2-4]/.test(php_version):
default:
return codecept;
}
case /(^2\.[4-5]\.\d+|^3\.[0-1]\.\d+).*/.test(version):
switch (true) {
case /5\.6/.test(php_version):
return codecept54;
case /7\.[0-4]/.test(php_version):
default:
return codecept;
}
case /^2\.3\.\d+.*/.test(version):
switch (true) {
case /5\.[4-6]/.test(php_version):
return codecept54;
case /^7\.[0-4]$/.test(php_version):
default:
return codecept;
}
case /(^2\.(1\.([6-9]|\d{2,}))|^2\.2\.\d+).*/.test(version):
switch (true) {
case /5\.[4-5]/.test(php_version):
return codecept54;
case /5.6|7\.[0-4]/.test(php_version):
default:
return codecept;
}
case /(^2\.(1\.[0-5]|0\.\d+)|^1\.[6-8]\.\d+).*/.test(version):
return codecept;
default: default:
return yield getCodeceptionUriBuilder(version, php_version, 'php54'); return yield codecept;
} }
}); });
} }
@ -1940,12 +1972,17 @@ function addTools(tools_csv, php_version, os_version) {
const tool = tool_data.name; const tool = tool_data.name;
const version = tool_data.version; const version = tool_data.version;
const github = 'https://github.com/'; const github = 'https://github.com/';
let uri = yield getUri(tool, version, 'releases', '', 'download'); let uri = yield getUri(tool, '.phar', version, 'releases', '', 'download');
script += '\n'; script += '\n';
let url = ''; let url = '';
switch (tool) { switch (tool) {
case 'cs2pr':
uri = yield getUri(tool, '', version, 'releases', '', 'download');
url = github + 'staabm/annotate-pull-request-from-checkstyle/' + uri;
script += yield addArchive(tool, version, url, os_version);
break;
case 'php-cs-fixer': case 'php-cs-fixer':
uri = yield getUri(tool, version, 'releases', 'v', 'download'); uri = yield getUri(tool, '.phar', version, 'releases', 'v', 'download');
url = github + 'FriendsOfPHP/PHP-CS-Fixer/' + uri; url = github + 'FriendsOfPHP/PHP-CS-Fixer/' + uri;
script += yield addArchive(tool, version, url, os_version); script += yield addArchive(tool, version, url, os_version);
break; break;
@ -2097,7 +2134,7 @@ exports.addCoverageXdebug = addCoverageXdebug;
function addCoveragePCOV(version, os_version, pipe) { function addCoveragePCOV(version, os_version, pipe) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
let script = '\n'; let script = '\n';
switch (version) { switch (true) {
default: default:
script += script +=
(yield extensions.addExtension('pcov', version, os_version, true)) + (yield extensions.addExtension('pcov', version, os_version, true)) +
@ -2119,8 +2156,7 @@ function addCoveragePCOV(version, os_version, pipe) {
script += yield utils.addLog('$tick', 'coverage: pcov', 'PCOV enabled as coverage driver', os_version); script += yield utils.addLog('$tick', 'coverage: pcov', 'PCOV enabled as coverage driver', os_version);
// version is not supported // version is not supported
break; break;
case '5.6': case /5\.[3-6]|7\.0/.test(version):
case '7.0':
script += yield utils.addLog('$cross', 'pcov', 'PHP 7.1 or newer is required', os_version); script += yield utils.addLog('$cross', 'pcov', 'PHP 7.1 or newer is required', os_version);
break; break;
} }
@ -2325,15 +2361,14 @@ function build(filename, version, os_version) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
// taking inputs // taking inputs
const extension_csv = (yield utils.getInput('extensions', false)) || const extension_csv = (yield utils.getInput('extensions', false)) ||
(yield utils.getInput('extension', false)) || (yield utils.getInput('extension', false));
(yield utils.getInput('extension-csv', false)); const ini_values_csv = yield utils.getInput('ini-values', false);
const ini_values_csv = (yield utils.getInput('ini-values', false)) ||
(yield utils.getInput('ini-values-csv', false));
const coverage_driver = yield utils.getInput('coverage', false); const coverage_driver = yield utils.getInput('coverage', false);
const pecl = yield utils.getInput('pecl', false); const pecl = yield utils.getInput('pecl', false);
let tools_csv = yield utils.getInput('tools', false); let tools_csv = yield utils.getInput('tools', false);
if (pecl == 'true' || if (pecl == 'true' ||
/.*-(beta|alpha|devel|snapshot).*/.test(extension_csv)) { /.*-(beta|alpha|devel|snapshot).*/.test(extension_csv) ||
/.*-(\d+\.\d+\.\d+).*/.test(extension_csv)) {
tools_csv = 'pecl, ' + tools_csv; tools_csv = 'pecl, ' + tools_csv;
} }
let script = yield utils.readScript(filename, version, os_version); let script = yield utils.readScript(filename, version, os_version);
@ -2357,16 +2392,16 @@ exports.build = build;
function run() { function run() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try { try {
const os_version = process.platform;
let version = yield utils.getInput('php-version', true); let version = yield utils.getInput('php-version', true);
version = version.length > 1 ? version.slice(0, 3) : version + '.0'; version = version.length > 1 ? version.slice(0, 3) : version + '.0';
const os_version = process.platform;
// check the os version and run the respective script // check the os version and run the respective script
let script_path = ''; let script_path = '';
switch (os_version) { switch (os_version) {
case 'darwin': case 'darwin':
case 'linux': case 'linux':
script_path = yield build(os_version + '.sh', version, os_version); script_path = yield build(os_version + '.sh', version, os_version);
yield exec_1.exec('sh ' + script_path + ' ' + version + ' ' + __dirname); yield exec_1.exec('bash ' + script_path + ' ' + version + ' ' + __dirname);
break; break;
case 'win32': case 'win32':
script_path = yield build('win32.ps1', version, os_version); script_path = yield build('win32.ps1', version, os_version);
@ -2642,13 +2677,27 @@ function addExtensionDarwin(extension_csv, version, pipe) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
extension = extension.toLowerCase(); extension = extension.toLowerCase();
const version_extension = version + extension; const version_extension = version + extension;
const [ext_name, ext_version] = extension.split('-');
const prefix = yield utils.getExtensionPrefix(ext_name);
let install_command = ''; let install_command = '';
switch (true) { switch (true) {
// match pre-release versions // match pre-release versions
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension): case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
install_command = 'install_extension ' + extension + pipe; script +=
'\nadd_unstable_extension ' +
ext_name +
' ' +
ext_version +
' ' +
prefix;
return;
case /5\.3xdebug/.test(version_extension):
install_command = 'sudo pecl install -f xdebug-2.2.7' + pipe;
break; break;
case /5\.6xdebug/.test(version_extension): case /5\.4xdebug/.test(version_extension):
install_command = 'sudo pecl install -f xdebug-2.4.1' + pipe;
break;
case /5\.[5-6]xdebug/.test(version_extension):
install_command = 'sudo pecl install -f xdebug-2.5.5' + pipe; install_command = 'sudo pecl install -f xdebug-2.5.5' + pipe;
break; break;
case /7\.0xdebug/.test(version_extension): case /7\.0xdebug/.test(version_extension):
@ -2665,15 +2714,14 @@ function addExtensionDarwin(extension_csv, version, pipe) {
pipe; pipe;
break; break;
case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension):
install_command = script +=
'sh ' + 'sh ' +
path.join(__dirname, '../src/scripts/ext/phalcon_darwin.sh') + path.join(__dirname, '../src/scripts/ext/phalcon_darwin.sh') +
' ' + ' ' +
extension + extension +
' ' + ' ' +
version + version;
pipe; return;
break;
default: default:
install_command = 'sudo pecl install -f ' + extension + pipe; install_command = 'sudo pecl install -f ' + extension + pipe;
break; break;
@ -2705,13 +2753,23 @@ function addExtensionWindows(extension_csv, version, pipe) {
yield utils.asyncForEach(extensions, function (extension) { yield utils.asyncForEach(extensions, function (extension) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
extension = extension.toLowerCase(); extension = extension.toLowerCase();
const [extension_name, stability] = extension.split('-'); const [ext_name, ext_version] = extension.split('-');
const version_extension = version + extension; const version_extension = version + extension;
let matches;
switch (true) { switch (true) {
// match pre-release versions // match pre-release versions
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension): case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
script += '\nAdd-Extension ' + extension_name + ' ' + stability; script += '\nAdd-Extension ' + ext_name + ' ' + ext_version;
break; break;
// match exact versions
case /.*-\d+\.\d+\.\d+$/.test(version_extension):
script += '\nAdd-Extension ' + ext_name + ' stable ' + ext_version;
return;
case /.*-(\d+\.\d+\.\d)+(beta|alpha|devel|snapshot)\d*/.test(version_extension):
matches = /.*-(\d+\.\d+\.\d)+(beta|alpha|devel|snapshot)\d*/.exec(version_extension);
script +=
'\nAdd-Extension ' + ext_name + ' ' + matches[2] + ' ' + matches[1];
return;
// match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4 // match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4
case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension):
script += script +=
@ -2748,12 +2806,24 @@ function addExtensionLinux(extension_csv, version, pipe) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
extension = extension.toLowerCase(); extension = extension.toLowerCase();
const version_extension = version + extension; const version_extension = version + extension;
const [ext_name, ext_version] = extension.split('-');
const prefix = yield utils.getExtensionPrefix(ext_name);
let install_command = ''; let install_command = '';
switch (true) { switch (true) {
// match pre-release versions // match pre-release versions
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension): case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
install_command = 'install_extension ' + extension + pipe; script +=
break; '\nadd_unstable_extension ' +
ext_name +
' ' +
ext_version +
' ' +
prefix;
return;
// match exact versions
case /.*-\d+\.\d+\.\d+.*/.test(version_extension):
script += '\nadd_pecl_extension ' + ext_name + ' ' + ext_version;
return;
// match 5.6gearman..7.4gearman // match 5.6gearman..7.4gearman
case /^((5\.6)|(7\.[0-4]))gearman$/.test(version_extension): case /^((5\.6)|(7\.[0-4]))gearman$/.test(version_extension):
install_command = install_command =
@ -2776,7 +2846,7 @@ function addExtensionLinux(extension_csv, version, pipe) {
// match 7.0xdebug..7.4xdebug // match 7.0xdebug..7.4xdebug
case /^7\.[0-4]xdebug$/.test(version_extension): case /^7\.[0-4]xdebug$/.test(version_extension):
script += script +=
'\nupdate_extension xdebug 2.9.0' + '\nupdate_extension xdebug 2.9.1' +
pipe + pipe +
'\n' + '\n' +
(yield utils.addLog('$tick', 'xdebug', 'Enabled', 'linux')); (yield utils.addLog('$tick', 'xdebug', 'Enabled', 'linux'));
@ -2787,19 +2857,11 @@ function addExtensionLinux(extension_csv, version, pipe) {
version + version +
'-' + '-' +
extension.replace('pdo_', '').replace('pdo-', '') + extension.replace('pdo_', '').replace('pdo-', '') +
pipe +
' || sudo pecl install -f ' +
extension +
pipe; pipe;
break; break;
} }
script += script +=
'\nadd_extension ' + '\nadd_extension ' + extension + ' "' + install_command + '" ' + prefix;
extension +
' "' +
install_command +
'" ' +
(yield utils.getExtensionPrefix(extension));
}); });
}); });
return script; return script;

View File

@ -13,7 +13,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP, with composer and extensions - name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
- name: Get composer cache directory - name: Get composer cache directory

View File

@ -27,7 +27,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@v1 uses: shivammathur/setup-php@v2
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
# You can also use ext-apcu or ext-memcached instead of ext-redis # You can also use ext-apcu or ext-memcached instead of ext-redis
@ -63,7 +63,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@v1 uses: shivammathur/setup-php@v2
with: with:
php-version: '7.3' php-version: '7.3'
extensions: mbstring, intl extensions: mbstring, intl
@ -90,7 +90,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@v1 uses: shivammathur/setup-php@v2
with: with:
php-version: '7.3' php-version: '7.3'
extensions: mbstring, intl extensions: mbstring, intl

View File

@ -27,7 +27,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@v1 uses: shivammathur/setup-php@v2
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
# You can also use ext-apcu or ext-memcached instead of ext-redis # You can also use ext-apcu or ext-memcached instead of ext-redis
@ -63,7 +63,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@v1 uses: shivammathur/setup-php@v2
with: with:
php-version: '7.3' php-version: '7.3'
extensions: mbstring, intl extensions: mbstring, intl
@ -90,7 +90,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@v1 uses: shivammathur/setup-php@v2
with: with:
php-version: '7.3' php-version: '7.3'
extensions: mbstring, intl extensions: mbstring, intl

View File

@ -13,7 +13,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: mbstring, intl, pdo_sqlite, pdo_mysql extensions: mbstring, intl, pdo_sqlite, pdo_mysql
@ -43,7 +43,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@v1 uses: shivammathur/setup-php@v2
with: with:
php-version: '7.3' php-version: '7.3'
extensions: mbstring, intl extensions: mbstring, intl
@ -70,7 +70,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@v1 uses: shivammathur/setup-php@v2
with: with:
php-version: '7.3' php-version: '7.3'
extensions: mbstring, intl extensions: mbstring, intl

View File

@ -12,7 +12,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP, with composer and extensions - name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: mbstring, intl, curl, dom extensions: mbstring, intl, curl, dom

View File

@ -36,7 +36,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP, with composer and extensions - name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: mbstring, dom, fileinfo, mysql extensions: mbstring, dom, fileinfo, mysql

View File

@ -38,7 +38,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP, with composer and extensions - name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: mbstring, dom, fileinfo, pgsql extensions: mbstring, dom, fileinfo, pgsql

View File

@ -14,7 +14,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP, with composer and extensions - name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: mbstring, dom, fileinfo extensions: mbstring, dom, fileinfo

View File

@ -36,7 +36,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP, with composer and extensions - name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: mbstring, dom, fileinfo, mysql extensions: mbstring, dom, fileinfo, mysql

View File

@ -38,7 +38,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP, with composer and extensions - name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: mbstring, dom, fileinfo, pgsql extensions: mbstring, dom, fileinfo, pgsql

View File

@ -14,7 +14,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP, with composer and extensions - name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: mbstring, dom, fileinfo, mysql extensions: mbstring, dom, fileinfo, mysql

View File

@ -36,7 +36,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP, with composer and extensions - name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: mbstring, dom, zip, phalcon4, mysql #use phalcon3 for the phalcon 3.x. extensions: mbstring, dom, zip, phalcon4, mysql #use phalcon3 for the phalcon 3.x.

View File

@ -37,7 +37,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP, with composer and extensions - name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: mbstring, dom, zip, phalcon4, pgsql #use phalcon3 for the phalcon 3.x extensions: mbstring, dom, zip, phalcon4, pgsql #use phalcon3 for the phalcon 3.x

View File

@ -18,7 +18,7 @@ jobs:
with: with:
node-version: ${{ matrix.node-versions }} node-version: ${{ matrix.node-versions }}
- name: Setup PHP, with composer and extensions - name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: mbstring extensions: mbstring

View File

@ -12,7 +12,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP, with composer and extensions - name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: mbstring, simplexml, dom extensions: mbstring, simplexml, dom

View File

@ -23,7 +23,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP, with composer and extensions - name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, mysql extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, mysql

View File

@ -23,7 +23,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP, with composer and extensions - name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, pgsql extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, pgsql

View File

@ -14,7 +14,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP, with composer and extensions - name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite

View File

@ -33,7 +33,7 @@ jobs:
with: with:
node-version: 10.x node-version: 10.x
- name: Setup PHP, with composer and extensions - name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: mbstring, intl, gd, imagick, zip, dom, mysql extensions: mbstring, intl, gd, imagick, zip, dom, mysql

View File

@ -33,7 +33,7 @@ jobs:
with: with:
node-version: 10.x node-version: 10.x
- name: Setup PHP, with composer and extensions - name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: mbstring, intl, gd, imagick, zip, dom, pgsql extensions: mbstring, intl, gd, imagick, zip, dom, pgsql

View File

@ -12,7 +12,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP, with composer and extensions - name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: mbstring, bcmath, curl, intl extensions: mbstring, bcmath, curl, intl

3804
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "setup-php", "name": "setup-php",
"version": "1.8.0", "version": "2.0.0",
"private": false, "private": false,
"description": "Setup PHP for use with GitHub Actions", "description": "Setup PHP for use with GitHub Actions",
"main": "dist/index.js", "main": "dist/index.js",
@ -24,28 +24,28 @@
"author": "shivammathur", "author": "shivammathur",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/core": "^1.2.0", "@actions/core": "^1.2.2",
"@actions/exec": "^1.0.2", "@actions/exec": "^1.0.3",
"@actions/io": "^1.0.1", "@actions/io": "^1.0.2",
"fs": "0.0.1-security" "fs": "0.0.1-security"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^24.0.21", "@types/jest": "^25.1.2",
"@types/node": "^12.12.16", "@types/node": "^13.7.1",
"@typescript-eslint/eslint-plugin": "^2.11.0", "@typescript-eslint/eslint-plugin": "^2.19.2",
"@typescript-eslint/parser": "^2.11.0", "@typescript-eslint/parser": "^2.19.2",
"@zeit/ncc": "^0.21.0", "@zeit/ncc": "^0.21.1",
"eslint": "^6.6.0", "eslint": "^6.8.0",
"eslint-config-prettier": "^6.5.0", "eslint-config-prettier": "^6.10.0",
"eslint-plugin-import": "^2.19.1", "eslint-plugin-import": "^2.20.1",
"eslint-plugin-jest": "^23.0.3", "eslint-plugin-jest": "^23.7.0",
"eslint-plugin-prettier": "^3.1.1", "eslint-plugin-prettier": "^3.1.2",
"husky": "^3.0.9", "husky": "^4.2.3",
"jest": "^24.9.0", "jest": "^25.1.0",
"jest-circus": "^24.9.0", "jest-circus": "^25.1.0",
"prettier": "^1.17.1", "prettier": "^1.19.1",
"ts-jest": "^24.1.0", "ts-jest": "^25.2.0",
"typescript": "^3.7.3" "typescript": "^3.7.5"
}, },
"husky": { "husky": {
"skipCI": true, "skipCI": true,

29
src/configs/php.json Normal file
View File

@ -0,0 +1,29 @@
{
"problemMatcher": [
{
"owner": "php_native_error",
"severity": "error",
"pattern": [
{
"regexp": "^(.*error):\\s+\\s+(.+) in (.+) on line (\\d+)$",
"code": 1,
"message": 2,
"file": 3,
"line": 4
}
]
}, {
"owner": "php_native_warning",
"severity": "warning",
"pattern": [
{
"regexp": "^(.*Warning|.*Deprecated|.*Notice):\\s+\\s+(.+) in (.+) on line (\\d+)$",
"code": 1,
"message": 2,
"file": 3,
"line": 4
}
]
}
]
}

View File

@ -54,7 +54,7 @@ export async function addCoveragePCOV(
pipe: string pipe: string
): Promise<string> { ): Promise<string> {
let script = '\n'; let script = '\n';
switch (version) { switch (true) {
default: default:
script += script +=
(await extensions.addExtension('pcov', version, os_version, true)) + (await extensions.addExtension('pcov', version, os_version, true)) +
@ -83,8 +83,8 @@ export async function addCoveragePCOV(
); );
// version is not supported // version is not supported
break; break;
case '5.6':
case '7.0': case /5\.[3-6]|7\.0/.test(version):
script += await utils.addLog( script += await utils.addLog(
'$cross', '$cross',
'pcov', 'pcov',

View File

@ -18,13 +18,27 @@ export async function addExtensionDarwin(
await utils.asyncForEach(extensions, async function(extension: string) { await utils.asyncForEach(extensions, async function(extension: string) {
extension = extension.toLowerCase(); extension = extension.toLowerCase();
const version_extension: string = version + extension; const version_extension: string = version + extension;
const [ext_name, ext_version]: string[] = extension.split('-');
const prefix = await utils.getExtensionPrefix(ext_name);
let install_command = ''; let install_command = '';
switch (true) { switch (true) {
// match pre-release versions // match pre-release versions
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension): case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
install_command = 'install_extension ' + extension + pipe; script +=
'\nadd_unstable_extension ' +
ext_name +
' ' +
ext_version +
' ' +
prefix;
return;
case /5\.3xdebug/.test(version_extension):
install_command = 'sudo pecl install -f xdebug-2.2.7' + pipe;
break; break;
case /5\.6xdebug/.test(version_extension): case /5\.4xdebug/.test(version_extension):
install_command = 'sudo pecl install -f xdebug-2.4.1' + pipe;
break;
case /5\.[5-6]xdebug/.test(version_extension):
install_command = 'sudo pecl install -f xdebug-2.5.5' + pipe; install_command = 'sudo pecl install -f xdebug-2.5.5' + pipe;
break; break;
case /7\.0xdebug/.test(version_extension): case /7\.0xdebug/.test(version_extension):
@ -41,15 +55,14 @@ export async function addExtensionDarwin(
pipe; pipe;
break; break;
case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension):
install_command = script +=
'sh ' + 'sh ' +
path.join(__dirname, '../src/scripts/ext/phalcon_darwin.sh') + path.join(__dirname, '../src/scripts/ext/phalcon_darwin.sh') +
' ' + ' ' +
extension + extension +
' ' + ' ' +
version + version;
pipe; return;
break;
default: default:
install_command = 'sudo pecl install -f ' + extension + pipe; install_command = 'sudo pecl install -f ' + extension + pipe;
break; break;
@ -81,13 +94,27 @@ export async function addExtensionWindows(
let script = '\n'; let script = '\n';
await utils.asyncForEach(extensions, async function(extension: string) { await utils.asyncForEach(extensions, async function(extension: string) {
extension = extension.toLowerCase(); extension = extension.toLowerCase();
const [extension_name, stability]: string[] = extension.split('-'); const [ext_name, ext_version]: string[] = extension.split('-');
const version_extension: string = version + extension; const version_extension: string = version + extension;
let matches: RegExpExecArray;
switch (true) { switch (true) {
// match pre-release versions // match pre-release versions
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension): case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
script += '\nAdd-Extension ' + extension_name + ' ' + stability; script += '\nAdd-Extension ' + ext_name + ' ' + ext_version;
break; break;
// match exact versions
case /.*-\d+\.\d+\.\d+$/.test(version_extension):
script += '\nAdd-Extension ' + ext_name + ' stable ' + ext_version;
return;
case /.*-(\d+\.\d+\.\d)+(beta|alpha|devel|snapshot)\d*/.test(
version_extension
):
matches = /.*-(\d+\.\d+\.\d)+(beta|alpha|devel|snapshot)\d*/.exec(
version_extension
) as RegExpExecArray;
script +=
'\nAdd-Extension ' + ext_name + ' ' + matches[2] + ' ' + matches[1];
return;
// match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4 // match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4
case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension):
script += script +=
@ -124,12 +151,24 @@ export async function addExtensionLinux(
await utils.asyncForEach(extensions, async function(extension: string) { await utils.asyncForEach(extensions, async function(extension: string) {
extension = extension.toLowerCase(); extension = extension.toLowerCase();
const version_extension: string = version + extension; const version_extension: string = version + extension;
const [ext_name, ext_version]: string[] = extension.split('-');
const prefix = await utils.getExtensionPrefix(ext_name);
let install_command = ''; let install_command = '';
switch (true) { switch (true) {
// match pre-release versions // match pre-release versions
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension): case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
install_command = 'install_extension ' + extension + pipe; script +=
break; '\nadd_unstable_extension ' +
ext_name +
' ' +
ext_version +
' ' +
prefix;
return;
// match exact versions
case /.*-\d+\.\d+\.\d+.*/.test(version_extension):
script += '\nadd_pecl_extension ' + ext_name + ' ' + ext_version;
return;
// match 5.6gearman..7.4gearman // match 5.6gearman..7.4gearman
case /^((5\.6)|(7\.[0-4]))gearman$/.test(version_extension): case /^((5\.6)|(7\.[0-4]))gearman$/.test(version_extension):
install_command = install_command =
@ -152,7 +191,7 @@ export async function addExtensionLinux(
// match 7.0xdebug..7.4xdebug // match 7.0xdebug..7.4xdebug
case /^7\.[0-4]xdebug$/.test(version_extension): case /^7\.[0-4]xdebug$/.test(version_extension):
script += script +=
'\nupdate_extension xdebug 2.9.0' + '\nupdate_extension xdebug 2.9.1' +
pipe + pipe +
'\n' + '\n' +
(await utils.addLog('$tick', 'xdebug', 'Enabled', 'linux')); (await utils.addLog('$tick', 'xdebug', 'Enabled', 'linux'));
@ -163,19 +202,11 @@ export async function addExtensionLinux(
version + version +
'-' + '-' +
extension.replace('pdo_', '').replace('pdo-', '') + extension.replace('pdo_', '').replace('pdo-', '') +
pipe +
' || sudo pecl install -f ' +
extension +
pipe; pipe;
break; break;
} }
script += script +=
'\nadd_extension ' + '\nadd_extension ' + extension + ' "' + install_command + '" ' + prefix;
extension +
' "' +
install_command +
'" ' +
(await utils.getExtensionPrefix(extension));
}); });
return script; return script;
} }

View File

@ -22,17 +22,15 @@ export async function build(
// taking inputs // taking inputs
const extension_csv: string = const extension_csv: string =
(await utils.getInput('extensions', false)) || (await utils.getInput('extensions', false)) ||
(await utils.getInput('extension', false)) || (await utils.getInput('extension', false));
(await utils.getInput('extension-csv', false)); const ini_values_csv: string = await utils.getInput('ini-values', false);
const ini_values_csv: string =
(await utils.getInput('ini-values', false)) ||
(await utils.getInput('ini-values-csv', false));
const coverage_driver: string = await utils.getInput('coverage', false); const coverage_driver: string = await utils.getInput('coverage', false);
const pecl: string = await utils.getInput('pecl', false); const pecl: string = await utils.getInput('pecl', false);
let tools_csv: string = await utils.getInput('tools', false); let tools_csv: string = await utils.getInput('tools', false);
if ( if (
pecl == 'true' || pecl == 'true' ||
/.*-(beta|alpha|devel|snapshot).*/.test(extension_csv) /.*-(beta|alpha|devel|snapshot).*/.test(extension_csv) ||
/.*-(\d+\.\d+\.\d+).*/.test(extension_csv)
) { ) {
tools_csv = 'pecl, ' + tools_csv; tools_csv = 'pecl, ' + tools_csv;
} }
@ -58,16 +56,17 @@ export async function build(
*/ */
export async function run(): Promise<void> { export async function run(): Promise<void> {
try { try {
const os_version: string = process.platform;
let version: string = await utils.getInput('php-version', true); let version: string = await utils.getInput('php-version', true);
version = version.length > 1 ? version.slice(0, 3) : version + '.0'; version = version.length > 1 ? version.slice(0, 3) : version + '.0';
const os_version: string = process.platform;
// check the os version and run the respective script // check the os version and run the respective script
let script_path = ''; let script_path = '';
switch (os_version) { switch (os_version) {
case 'darwin': case 'darwin':
case 'linux': case 'linux':
script_path = await build(os_version + '.sh', version, os_version); script_path = await build(os_version + '.sh', version, os_version);
await exec('sh ' + script_path + ' ' + version + ' ' + __dirname); await exec('bash ' + script_path + ' ' + version + ' ' + __dirname);
break; break;
case 'win32': case 'win32':
script_path = await build('win32.ps1', version, os_version); script_path = await build('win32.ps1', version, os_version);

View File

@ -6,13 +6,8 @@ import * as io from '@actions/io';
* Cache json files for problem matchers * Cache json files for problem matchers
*/ */
export async function addMatchers(): Promise<void> { export async function addMatchers(): Promise<void> {
const config_path = path.join( const config_path = path.join(__dirname, '..', 'src', 'configs');
__dirname,
'..',
'src',
'configs',
'phpunit.json'
);
const runner_dir: string = await utils.getInput('RUNNER_TOOL_CACHE', false); const runner_dir: string = await utils.getInput('RUNNER_TOOL_CACHE', false);
await io.cp(config_path, runner_dir); await io.cp(path.join(config_path, 'phpunit.json'), runner_dir);
await io.cp(path.join(config_path, 'php.json'), runner_dir);
} }

View File

@ -16,36 +16,72 @@ add_log() {
fi fi
} }
# Function to remove extensions
remove_extension() {
extension=$1
sudo sed -i '' "/$extension/d" "$ini_file"
sudo rm -rf "$ext_dir"/"$extension".so >/dev/null 2>&1
}
# Function to setup extensions # Function to setup extensions
add_extension() { add_extension() {
extension=$1 extension=$1
install_command=$2 install_command=$2
prefix=$3 prefix=$3
if ! php -m | grep -i -q -w "$extension" && [ -e "$ext_dir/$extension.so" ]; then if ! php -m | grep -i -q -w "$extension" && [ -e "$ext_dir/$extension.so" ]; then
echo "$prefix=$extension" >>"$ini_file" && add_log "$tick" "$extension" "Enabled" echo "$prefix=$ext_dir/$extension.so" >>"$ini_file" && add_log "$tick" "$extension" "Enabled"
elif php -m | grep -i -q -w "$extension"; then elif php -m | grep -i -q -w "$extension"; then
add_log "$tick" "$extension" "Enabled" add_log "$tick" "$extension" "Enabled"
elif ! php -m | grep -i -q -w "$extension"; then elif ! php -m | grep -i -q -w "$extension"; then
(eval "$install_command" && add_log "$tick" "$extension" "Installed and enabled") || if [[ "$version" =~ $old_versions ]]; then
add_log "$cross" "$extension" "Could not install $extension on PHP $semver" (sudo port install php"$nodot_version"-"$extension" >/dev/null 2>&1 && add_log "$tick" "$extension" "Installed and enabled") ||
(eval "$install_command" >/dev/null 2>&1 && echo "$prefix=$ext_dir/$extension.so" >>"$ini_file" && add_log "$tick" "$extension" "Installed and enabled") ||
add_log "$cross" "$extension" "Could not install $extension on PHP $semver"
else
(eval "$install_command" >/dev/null 2>&1 && add_log "$tick" "$extension" "Installed and enabled") ||
add_log "$cross" "$extension" "Could not install $extension on PHP $semver"
fi
fi fi
} }
# Function to force install extensions using PECL # Fuction to get the PECL version
install_extension() { get_pecl_version() {
extension=$1 extension=$1
extension_name="$(echo "$extension" | cut -d'-' -f 1)" stability=$2
sudo sed -i "/$extension_name/d" "$ini_file" pecl_rest='https://pecl.php.net/rest/r/'
sudo rm -rf /etc/php/"$version"/cli/conf.d/*"$extension_name"* >/dev/null 2>&1 response=$(curl -q -sSL "$pecl_rest$extension"/allreleases.xml)
sudo rm -rf "$ext_dir"/"$extension_name".so >/dev/null 2>&1 pecl_version=$(echo "$response" | grep -m 1 -Eo "(\d*\.\d*\.\d*$stability\d*)")
sudo pecl install -f "$extension" >/dev/null 2>&1 if [ ! "$pecl_version" ]; then
pecl_version=$(echo "$response" | grep -m 1 -Eo "(\d*\.\d*\.\d*)")
fi
echo "$pecl_version"
} }
# Function to remove extensions # Function to pre-release extensions using PECL
remove_extension() { add_unstable_extension() {
extension=$1 extension=$1
sudo sed -i '' "/$1/d" "$ini_file" stability=$2
sudo rm -rf "$ext_dir"/"$1".so >/dev/null 2>&1 prefix=$3
pecl_version=$(get_pecl_version "$extension" "$stability")
if ! php -m | grep -i -q -w "$extension" && [ -e "$ext_dir/$extension.so" ]; then
extension_version=$(php -d="$prefix=$extension" -r "echo phpversion('$extension');")
if [ "$extension_version" = "$pecl_version" ]; then
echo "$prefix=$extension" >>"$ini_file" && add_log "$tick" "$extension" "Enabled"
else
remove_extension "$extension"
add_extension "$extension" "sudo pecl install -f $extension-$pecl_version" "$prefix"
fi
elif php -m | grep -i -q -w "$extension"; then
extension_version=$(php -r "echo phpversion('$extension');")
if [ "$extension_version" = "$pecl_version" ]; then
add_log "$tick" "$extension" "Enabled"
else
remove_extension "$extension"
add_extension "$extension" "sudo pecl install -f $extension-$pecl_version" "$prefix"
fi
else
add_extension "$extension" "sudo pecl install -f $extension-$pecl_version" "$prefix"
fi
} }
# Function to setup a remote tool # Function to setup a remote tool
@ -57,63 +93,133 @@ add_tool() {
composer -q global config process-timeout 0 composer -q global config process-timeout 0
add_log "$tick" "$tool" "Added" add_log "$tick" "$tool" "Added"
else else
if [ ! -e /usr/local/bin/"$tool" ]; then tool_path=/usr/local/bin/"$tool"
rm -rf /usr/local/bin/"${tool:?}" if [ ! -e "$tool_path" ]; then
rm -rf "$tool_path"
fi fi
status_code=$(sudo curl -s -w "%{http_code}" -o /usr/local/bin/"$tool" -L "$url")
status_code=$(sudo curl -s -w "%{http_code}" -o "$tool_path" -L "$url")
if [ "$status_code" = "200" ]; then if [ "$status_code" = "200" ]; then
sudo chmod a+x /usr/local/bin/"$tool" sudo chmod a+x "$tool_path"
if [ "$tool" = "phive" ]; then
add_extension curl "sudo pecl install -f curl" extension >/dev/null 2>&1
add_extension mbstring "sudo pecl install -f mbstring" extension >/dev/null 2>&1
add_extension xml "sudo pecl install -f xml" extension >/dev/null 2>&1
elif [ "$tool" = "cs2pr" ]; then
sudo sed -i '' 's/exit(9)/exit(0)/' "$tool_path"
tr -d '\r' < "$tool_path" | sudo tee "$tool_path.tmp" >/dev/null 2>&1 && sudo mv "$tool_path.tmp" "$tool_path"
sudo chmod a+x "$tool_path"
fi
add_log "$tick" "$tool" "Added" add_log "$tick" "$tool" "Added"
else else
add_log "$cross" "$tool" "Could not setup $tool" add_log "$cross" "$tool" "Could not setup $tool"
fi fi
fi fi
if [ "$tool" = "phive" ]; then
add_extension curl >/dev/null 2>&1
add_extension mbstring >/dev/null 2>&1
add_extension xml >/dev/null 2>&1
fi
} }
# Function to add a tool using composer
add_composer_tool() { add_composer_tool() {
tool=$1 tool=$1
release=$2 release=$2
prefix=$3 prefix=$3
( (
composer global require "$prefix$release" >/dev/null 2>&1 && \ composer global require "$prefix$release" >/dev/null 2>&1 &&
sudo ln -sf "$(composer -q global config home)"/vendor/bin/"$tool" /usr/local/bin/"$tool" && \ sudo ln -sf "$(composer -q global config home)"/vendor/bin/"$tool" /usr/local/bin/"$tool" &&
add_log "$tick" "$tool" "Added" add_log "$tick" "$tool" "Added"
) || add_log "$cross" "$tool" "Could not setup $tool" ) || add_log "$cross" "$tool" "Could not setup $tool"
} }
# Function to configure PECL
configure_pecl() {
if [[ ! "$version" =~ $old_versions ]]; then
for tool in pear pecl; do
sudo "$tool" config-set php_ini "$ini_file" >/dev/null 2>&1
sudo "$tool" config-set auto_discover 1 >/dev/null 2>&1
sudo "$tool" channel-update "$tool".php.net >/dev/null 2>&1
done
fi
}
# Function to log PECL, it is installed along with PHP
add_pecl() { add_pecl() {
sudo pear config-set php_ini "$ini_file" >/dev/null 2>&1
sudo pear config-set auto_discover 1 >/dev/null 2>&1
sudo pear channel-update pear.php.net >/dev/null 2>&1
sudo pecl channel-update pecl.php.net >/dev/null 2>&1
add_log "$tick" "PECL" "Added" add_log "$tick" "PECL" "Added"
} }
# Function to setup PHP and composer # Function to add PECL when macports is used
setup_php_and_composer() { add_pecl_old() {
export HOMEBREW_NO_INSTALL_CLEANUP=TRUE pecl_version='master'
brew tap shivammathur/homebrew-php >/dev/null 2>&1 if [ "$1" = "53" ]; then
brew install shivammathur/php/php@"$version" >/dev/null 2>&1 pecl_version='v1.9.5'
brew link --force --overwrite php@"$version" >/dev/null 2>&1 fi
curl -o pear.phar -sSL https://github.com/pear/pearweb_phars/raw/$pecl_version/install-pear-nozlib.phar
sudo php pear.phar -d /opt/local/lib/php$1 -b /usr/local/bin && rm -rf pear.phar
}
add_macports() {
uri=$(curl -sSL https://github.com/macports/macports-base/releases | grep -Eo "(\/.*Catalina.pkg)" | head -n 1)
curl -o port.pkg -sSL https://github.com"$uri"
sudo installer -pkg port.pkg -target / && rm -rf port.pkg
}
sync_macports() {
while true; do
status=0
sudo port sync || status=$?
if [[ "$status" -eq 0 ]]; then
break
fi
sleep 2
done
}
port_setup_php() {
sudo port install php$1 php$1-curl php$1-mbstring php$1-xmlrpc php$1-openssl php$1-opcache
sudo cp /opt/local/etc/php$1/php.ini-development /opt/local/etc/php$1/php.ini
sudo port select --set php php$1
sudo ln -sf /opt/local/bin/* /usr/local/bin
add_pecl_old "$1"
} }
# Variables # Variables
tick="✓" tick="✓"
cross="✗" cross="✗"
version=$1 version=$1
nodot_version=${1/./}
old_versions="5.[3-5]"
existing_version=$(php-config --version | cut -c 1-3)
[[ -z "${update}" ]] && update='false' || update="${update}"
# Setup PHP and composer # Setup PHP
step_log "Setup PHP" step_log "Setup PHP"
setup_php_and_composer if [[ "$version" =~ $old_versions ]]; then
export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
export TERM=xterm
step_log "Setup Macports"
add_macports >/dev/null 2>&1
add_log "$tick" "Macports" "Installed"
sync_macports >/dev/null 2>&1
add_log "$tick" "Macports" "Synced"
step_log "Setup PHP"
port_setup_php $nodot_version >/dev/null 2>&1
status="Installed"
elif [ "$existing_version" != "$version" ] || [ "$update" = "true" ]; then
export HOMEBREW_NO_INSTALL_CLEANUP=TRUE >/dev/null 2>&1
brew tap shivammathur/homebrew-php >/dev/null 2>&1
brew install shivammathur/php/php@"$version" >/dev/null 2>&1
brew link --force --overwrite php@"$version" >/dev/null 2>&1
if [ "$update" = "true" ]; then
status="Updated to"
else
status="Installed"
fi
else
status="Found"
fi
ini_file=$(php -d "date.timezone=UTC" --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g") ini_file=$(php -d "date.timezone=UTC" --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g")
echo "date.timezone=UTC" >>"$ini_file"
ext_dir=$(php -i | grep "extension_dir => /usr" | sed -e "s|.*=> s*||")
sudo chmod 777 "$ini_file" sudo chmod 777 "$ini_file"
mkdir -p "$(pecl config-get ext_dir)" echo "date.timezone=UTC" >>"$ini_file"
ext_dir=$(php -i | grep -Ei "extension_dir => /(usr|opt)" | sed -e "s|.*=> s*||")
sudo mkdir -p "$ext_dir"
semver=$(php -v | head -n 1 | cut -f 2 -d ' ') semver=$(php -v | head -n 1 | cut -f 2 -d ' ')
add_log "$tick" "PHP" "Installed PHP $semver" configure_pecl
add_log "$tick" "PHP" "$status PHP $semver"

View File

@ -22,7 +22,7 @@ Function Install-Phalcon() {
$zip_file = $match.Matches[0].Groups[1].Value $zip_file = $match.Matches[0].Groups[1].Value
Invoke-WebRequest -UseBasicParsing -Uri $domain/$zip_file -OutFile $ENV:RUNNER_TOOL_CACHE\phalcon.zip > $null 2>&1 Invoke-WebRequest -UseBasicParsing -Uri $domain/$zip_file -OutFile $ENV:RUNNER_TOOL_CACHE\phalcon.zip > $null 2>&1
Expand-Archive -Path $ENV:RUNNER_TOOL_CACHE\phalcon.zip -DestinationPath $ENV:RUNNER_TOOL_CACHE\phalcon -Force > $null 2>&1 Expand-Archive -Path $ENV:RUNNER_TOOL_CACHE\phalcon.zip -DestinationPath $ENV:RUNNER_TOOL_CACHE\phalcon -Force > $null 2>&1
New-Item -ItemType SymbolicLink -Path $ext_dir\php_phalcon.dll -Target $ENV:RUNNER_TOOL_CACHE\phalcon\php_phalcon.dll > $null 2>&1 Copy-Item -Path "$ENV:RUNNER_TOOL_CACHE\phalcon\php_phalcon.dll" -Destination "$ext_dir\php_phalcon.dll"
Enable-PhpExtension -Extension phalcon -Path $php_dir Enable-PhpExtension -Extension phalcon -Path $php_dir
} }
printf "\033[%s;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "32" $tick $extension "Installed and enabled" printf "\033[%s;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "32" $tick $extension "Installed and enabled"

View File

@ -27,14 +27,7 @@ install_phalcon() {
add_log "$cross" "$extension" "Could not install $extension on PHP $semver" add_log "$cross" "$extension" "Could not install $extension on PHP $semver"
} }
# Function to remove an extensions ini_file="/etc/php/$2/cli/conf.d/50-phalcon.ini"
remove_extension() {
extension=$1
sudo sed -i "/$extension/d" "$ini_file"
rm -rf "$ext_dir/$extension.so"
}
ini_file=$(php --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g")
ext_dir=$(php -i | grep "extension_dir => /usr" | sed -e "s|.*=> s*||") ext_dir=$(php -i | grep "extension_dir => /usr" | sed -e "s|.*=> s*||")
semver=$(php -v | head -n 1 | cut -f 2 -d ' ' | cut -f 1 -d '-') semver=$(php -v | head -n 1 | cut -f 2 -d ' ' | cut -f 1 -d '-')
extension_major_version=$(echo "$1" | grep -i -Po '\d') extension_major_version=$(echo "$1" | grep -i -Po '\d')
@ -44,18 +37,16 @@ cross="✗"
if [ "$extension_major_version" = "4" ]; then if [ "$extension_major_version" = "4" ]; then
if [ -e "$ext_dir/psr.so" ]; then if [ -e "$ext_dir/psr.so" ]; then
echo "extension=psr" >>"$ini_file" echo "extension=psr.so" | sudo tee -a "$ini_file" >/dev/null 2>&1
fi fi
if [ -e "$ext_dir/phalcon.so" ]; then if [ -e "$ext_dir/phalcon.so" ]; then
if php -m | grep -i -q -w psr; then if php -m | grep -i -q -w psr; then
echo "extension=phalcon" >>"$ini_file" phalcon_version=$(php -d="extension=phalcon" -r "echo phpversion('phalcon');" | cut -d'.' -f 1)
phalcon_version=$(php -r "echo phpversion('phalcon');" | cut -d'.' -f 1)
if [ "$phalcon_version" != "$extension_major_version" ]; then if [ "$phalcon_version" != "$extension_major_version" ]; then
remove_extension "psr" >/dev/null 2>&1
remove_extension "phalcon" >/dev/null 2>&1
install_phalcon "$1" "$2" install_phalcon "$1" "$2"
else else
echo "extension=phalcon.so" | sudo tee -a "$ini_file" >/dev/null 2>&1
add_log "$tick" "$1" "Enabled" add_log "$tick" "$1" "Enabled"
fi fi
else else
@ -68,12 +59,11 @@ fi
if [ "$extension_major_version" = "3" ]; then if [ "$extension_major_version" = "3" ]; then
if [ -e "$ext_dir/phalcon.so" ]; then if [ -e "$ext_dir/phalcon.so" ]; then
echo "extension=phalcon" >>"$ini_file" phalcon_version=$(php -d="extension=phalcon.so" -r "echo phpversion('phalcon');" | cut -d'.' -f 1)
phalcon_version=$(php -r "echo phpversion('phalcon');" | cut -d'.' -f 1)
if [ "$phalcon_version" != "$extension_major_version" ]; then if [ "$phalcon_version" != "$extension_major_version" ]; then
remove_extension "phalcon" >/dev/null 2>&1
install_phalcon "$1" "$2" install_phalcon "$1" "$2"
else else
echo "extension=phalcon.so" | sudo tee -a "$ini_file" >/dev/null 2>&1
add_log "$tick" "$1" "Enabled" add_log "$tick" "$1" "Enabled"
fi fi
else else

View File

@ -1,22 +1,43 @@
# Function to log result of a operation
add_log() {
mark=$1
subject=$2
message=$3
if [ "$mark" = "$tick" ]; then
printf "\033[32;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message"
else
printf "\033[31;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message"
fi
}
# Function to install phalcon
install_phalcon() {
(
brew tap shivammathur/homebrew-phalcon >/dev/null 2>&1
brew install phalcon@"$php_version"_"$extension_major" >/dev/null 2>&1
sudo cp /usr/local/opt/psr@"$php_version"/psr.so "$ext_dir" >/dev/null 2>&1
sudo cp /usr/local/opt/phalcon@"$php_version"_"$extension_major"/phalcon.so "$ext_dir" >/dev/null 2>&1
add_log "$tick" "$extension" "Installed and enabled"
) || add_log "$cross" "$extension" "Could not install $extension on PHP $semver"
}
tick="✓"
cross="✗"
extension=$1 extension=$1
extension_major=${extension: -1} extension_major=${extension: -1}
php_version=$2 php_version=$2
semver=$(php -v | head -n 1 | cut -f 2 -d ' ')
ini_file=$(php -d "date.timezone=UTC" --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g") ini_file=$(php -d "date.timezone=UTC" --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g")
ext_dir=$(php -i | grep "extension_dir => /usr" | sed -e "s|.*=> s*||") ext_dir=$(php -i | grep "extension_dir => /usr" | sed -e "s|.*=> s*||")
if [ -e "$ext_dir/psr.so" ] && [ -e "$ext_dir/phalcon.so" ]; then if [ -e "$ext_dir/psr.so" ] && [ -e "$ext_dir/phalcon.so" ]; then
echo "extension=psr" >>"$ini_file" phalcon_version=$(php -d="extension=psr.so" -d="extension=phalcon.so" -r "echo phpversion('phalcon');" | cut -d'.' -f 1)
echo "extension=phalcon" >>"$ini_file"
phalcon_semver=$(php -r "echo phpversion('phalcon');")
phalcon_version=$(echo "$phalcon_semver" | cut -d'.' -f 1)
if [ "$phalcon_version" != "$extension_major" ]; then if [ "$phalcon_version" != "$extension_major" ]; then
sudo sed -i '' "/psr/d" "$ini_file" install_phalcon
sudo sed -i '' "/phalcon/d" "$ini_file" else
rm -rf "$ext_dir"/psr.so echo "extension=psr.so" >>"$ini_file"
rm -rf "$ext_dir"/phalcon.so echo "extension=phalcon.so" >>"$ini_file"
brew tap shivammathur/homebrew-phalcon add_log "$tick" "$extension" "Enabled"
brew install phalcon@"$php_version"_"$extension_major"
fi fi
else else
brew tap shivammathur/homebrew-phalcon install_phalcon
brew install phalcon@"$php_version"_"$extension_major" fi
fi

View File

@ -19,47 +19,116 @@ add_log() {
# Function to update php ppa # Function to update php ppa
update_ppa() { update_ppa() {
if [ "$ppa_updated" = "false" ]; then if [ "$ppa_updated" = "false" ]; then
find /etc/apt/sources.list.d -type f -name 'ondrej-ubuntu-php*.list' -exec sudo DEBIAN_FRONTEND=noninteractive apt-fast update -o Dir::Etc::sourcelist="{}" ';' >/dev/null 2>&1 if [[ "$version" =~ $old_versions ]]; then
ppa_updated="true" ppa="dotdeb-ubuntu-php*.list"
else
ppa="ondrej-ubuntu-php*.list"
fi
find /etc/apt/sources.list.d -type f -name "$ppa" -exec sudo "$debconf_fix" apt-fast update -o Dir::Etc::sourcelist="{}" ';' >/dev/null 2>&1
echo "true"
fi fi
} }
# Function to configure PECL
configure_pecl() {
if [ "$pecl_config" = "false" ] && [ -e /usr/bin/pecl ]; then
for tool in pear pecl; do
sudo "$tool" config-set php_ini "$ini_file" >/dev/null 2>&1
sudo "$tool" config-set auto_discover 1 >/dev/null 2>&1
sudo "$tool" channel-update "$tool".php.net >/dev/null 2>&1
done
pecl_config="true"
fi
}
# Fuction to get the PECL version
get_pecl_version() {
extension=$1
stability=$2
pecl_rest='https://pecl.php.net/rest/r/'
response=$(curl -q -sSL "$pecl_rest$extension"/allreleases.xml)
pecl_version=$(echo "$response" | grep -m 1 -Po "(\d*\.\d*\.\d*$stability\d*)")
if [ ! "$pecl_version" ]; then
pecl_version=$(echo "$response" | grep -m 1 -Po "(\d*\.\d*\.\d*)")
fi
echo "$pecl_version"
}
# Function to setup extensions # Function to setup extensions
add_extension() { add_extension() {
extension=$1 extension=$1
install_command=$2 install_command=$2
prefix=$3 prefix=$3
if [[ "$version" =~ $old_versions ]]; then
install_command="ppa_updated=$(update_ppa) && ${install_command/5\.[4-5]-$extension/5-$extension=$release_version}"
fi
if ! php -m | grep -i -q -w "$extension" && [ -e "$ext_dir/$extension.so" ]; then if ! php -m | grep -i -q -w "$extension" && [ -e "$ext_dir/$extension.so" ]; then
echo "$prefix=$extension" >>"$ini_file" && add_log "$tick" "$extension" "Enabled" # shellcheck disable=SC2046
$apt_install $(apt-cache depends php"$version"-"$extension" 2>/dev/null | awk '/Depends:/{print$2}') >/dev/null 2>&1
echo "$prefix=$extension.so" >>"$ini_file" && add_log "$tick" "$extension" "Enabled"
elif php -m | grep -i -q -w "$extension"; then elif php -m | grep -i -q -w "$extension"; then
add_log "$tick" "$extension" "Enabled" add_log "$tick" "$extension" "Enabled"
elif ! php -m | grep -i -q -w "$extension"; then elif ! php -m | grep -i -q -w "$extension"; then
(eval "$install_command" && add_log "$tick" "$extension" "Installed and enabled") || (eval "$install_command" >/dev/null 2>&1 && add_log "$tick" "$extension" "Installed and enabled") ||
(update_ppa && eval "$install_command" && add_log "$tick" "$extension" "Installed and enabled") || (ppa_updated=$(update_ppa) && eval "$install_command" >/dev/null 2>&1 && add_log "$tick" "$extension" "Installed and enabled") ||
(sudo pecl install -f "$extension" >/dev/null 2>&1 && add_log "$tick" "$extension" "Installed and enabled") ||
add_log "$cross" "$extension" "Could not install $extension on PHP $semver" add_log "$cross" "$extension" "Could not install $extension on PHP $semver"
fi fi
sudo chmod 777 "$ini_file" sudo chmod 777 "$ini_file"
} }
# Function to force install extensions using PECL # Function to delete extensions
install_extension() { delete_extension() {
extension=$1 extension=$1
extension_name="$(echo "$extension" | cut -d'-' -f 1)" sudo sed -i "/$extension/d" "$ini_file"
sudo sed -i "/$extension_name/d" "$ini_file" sudo rm -rf "$scan_dir"/*"$extension"* >/dev/null 2>&1
sudo rm -rf /etc/php/"$version"/cli/conf.d/*"$extension_name"* >/dev/null 2>&1 sudo rm -rf "$ext_dir"/"$extension".so >/dev/null 2>&1
sudo rm -rf "$ext_dir"/"$extension_name".so >/dev/null 2>&1
sudo pecl install -f "$extension" >/dev/null 2>&1
} }
# Function to remove extensions # Function to disable and delete extensions
remove_extension() { remove_extension() {
extension=$1 extension=$1
if [ -e /etc/php/"$version"/mods-available/"$extension".ini ]; then if [ -e /etc/php/"$version"/mods-available/"$extension".ini ]; then
sudo phpdismod -v "$version" "$extension" sudo phpdismod -v "$version" "$extension"
fi fi
sudo sed -i "/$extension/d" "$ini_file" delete_extension "$extension"
sudo rm -rf /etc/php/"$version"/cli/conf.d/*"$extension"* >/dev/null 2>&1 }
sudo rm -rf "$ext_dir"/"$extension".so >/dev/null 2>&1
# Function to install a PECL version
add_pecl_extension() {
extension=$1
pecl_version=$2
delete_extension "$extension"
(sudo pecl install -f "$extension-$pecl_version" >/dev/null 2>&1 &&
add_log "$tick" "$extension" "Installed and enabled") ||
add_log "$cross" "$extension" "Could not install $extension-$pecl_version on PHP $semver"
}
# Function to pre-release extensions using PECL
add_unstable_extension() {
extension=$1
stability=$2
prefix=$3
pecl_version=$(get_pecl_version "$extension" "$stability")
if ! php -m | grep -i -q -w "$extension" && [ -e "$ext_dir/$extension.so" ]; then
extension_version=$(php -d="$prefix=$extension" -r "echo phpversion('$extension');")
if [ "$extension_version" = "$pecl_version" ]; then
echo "$prefix=$extension.so" >>"$ini_file" && add_log "$tick" "$extension" "Enabled"
else
delete_extension "$extension"
add_pecl_extension "$extension" "$pecl_version"
fi
elif php -m | grep -i -q -w "$extension"; then
extension_version=$(php -r "echo phpversion('$extension');")
if [ "$extension_version" = "$pecl_version" ]; then
add_log "$tick" "$extension" "Enabled"
else
delete_extension "$extension"
add_pecl_extension "$extension" "$pecl_version"
fi
else
add_pecl_extension "$extension" "$pecl_version"
fi
} }
# Function to update extension # Function to update extension
@ -71,7 +140,7 @@ update_extension() {
if [ "$final_version" != "$current_version" ]; then if [ "$final_version" != "$current_version" ]; then
version_exists=$(apt-cache policy -- *"$extension" | grep "$final_version") version_exists=$(apt-cache policy -- *"$extension" | grep "$final_version")
if [ -z "$version_exists" ]; then if [ -z "$version_exists" ]; then
update_ppa ppa_updated=$(update_ppa)
fi fi
$apt_install php"$version"-"$extension" $apt_install php"$version"-"$extension"
fi fi
@ -81,34 +150,37 @@ update_extension() {
add_tool() { add_tool() {
url=$1 url=$1
tool=$2 tool=$2
if [ ! -e /usr/local/bin/"$tool" ]; then tool_path=/usr/local/bin/"$tool"
rm -rf /usr/local/bin/"${tool:?}" if [ ! -e "$tool_path" ]; then
rm -rf "$tool_path"
fi fi
status_code=$(sudo curl -s -w "%{http_code}" -o /usr/local/bin/"$tool" -L "$url") status_code=$(sudo curl -s -w "%{http_code}" -o "$tool_path" -L "$url")
if [ "$status_code" = "200" ]; then if [ "$status_code" = "200" ]; then
sudo chmod a+x /usr/local/bin/"$tool" sudo chmod a+x "$tool_path"
if [ "$tool" = "composer" ]; then
composer -q global config process-timeout 0
elif [ "$tool" = "cs2pr" ]; then
sudo sed -i 's/\r$//; s/exit(9)/exit(0)/' "$tool_path"
elif [ "$tool" = "phive" ]; then
add_extension curl "$apt_install php$version-curl" extension >/dev/null 2>&1
add_extension mbstring "$apt_install php$version-mbstring" extension >/dev/null 2>&1
add_extension xml "$apt_install php$version-xml" extension >/dev/null 2>&1
fi
add_log "$tick" "$tool" "Added" add_log "$tick" "$tool" "Added"
else else
add_log "$cross" "$tool" "Could not setup $tool" add_log "$cross" "$tool" "Could not setup $tool"
fi fi
if [ "$tool" = "composer" ]; then
composer -q global config process-timeout 0
fi
if [ "$tool" = "phive" ]; then
add_extension curl >/dev/null 2>&1
add_extension mbstring >/dev/null 2>&1
add_extension xml >/dev/null 2>&1
fi
} }
# Function to setup a tool using composer
add_composer_tool() { add_composer_tool() {
tool=$1 tool=$1
release=$2 release=$2
prefix=$3 prefix=$3
( (
composer global require "$prefix$release" >/dev/null 2>&1 && \ composer global require "$prefix$release" >/dev/null 2>&1 &&
sudo ln -sf "$(composer -q global config home)"/vendor/bin/"$tool" /usr/local/bin/"$tool" && \ sudo ln -sf "$(composer -q global config home)"/vendor/bin/"$tool" /usr/local/bin/"$tool" &&
add_log "$tick" "$tool" "Added" add_log "$tick" "$tool" "Added"
) || add_log "$cross" "$tool" "Could not setup $tool" ) || add_log "$cross" "$tool" "Could not setup $tool"
} }
@ -119,6 +191,7 @@ add_devtools() {
fi fi
sudo update-alternatives --set php-config /usr/bin/php-config"$version" >/dev/null 2>&1 sudo update-alternatives --set php-config /usr/bin/php-config"$version" >/dev/null 2>&1
sudo update-alternatives --set phpize /usr/bin/phpize"$version" >/dev/null 2>&1 sudo update-alternatives --set phpize /usr/bin/phpize"$version" >/dev/null 2>&1
configure_pecl
} }
# Function to setup the nightly build from master branch # Function to setup the nightly build from master branch
@ -127,21 +200,36 @@ setup_master() {
install_dir=~/php/"$version" install_dir=~/php/"$version"
sudo mkdir -m 777 -p ~/php sudo mkdir -m 777 -p ~/php
$apt_install libicu-dev >/dev/null 2>&1 $apt_install libicu-dev >/dev/null 2>&1
curl -o "$tar_file" -L https://bintray.com/shivammathur/php/download_file?file_path="$tar_file" >/dev/null 2>&1 curl -SLO https://dl.bintray.com/shivammathur/php/"$tar_file" >/dev/null 2>&1
sudo tar xf "$tar_file" -C ~/php >/dev/null 2>&1 sudo tar xf "$tar_file" -C ~/php >/dev/null 2>&1
rm -rf "$tar_file" rm -rf "$tar_file"
sudo ln -sf -S "$version" "$install_dir"/bin/* /usr/bin/ sudo ln -sf -S "$version" "$install_dir"/bin/* /usr/bin/
sudo ln -sf "$install_dir"/etc/php.ini /etc/php.ini sudo ln -sf "$install_dir"/etc/php.ini /etc/php.ini
} }
# Function to setup PHP 5.3, PHP 5.4 and PHP 5.5
setup_old_versions() {
(
cd /tmp || exit
curl -SLO https://dl.bintray.com/shivammathur/php/php-"$version".tar.xz >/dev/null 2>&1
sudo tar xf php-"$version".tar.xz >/dev/null 2>&1
cd php-"$version" || exit
sudo chmod a+x ./*.sh
./install.sh >/dev/null 2>&1
./post-install.sh >/dev/null 2>&1
)
sudo rm -rf /tmp/php-"$version"
configure_pecl
release_version=$(php -v | head -n 1 | cut -d' ' -f 2)
}
# Function to setup PECL # Function to setup PECL
add_pecl() { add_pecl() {
add_devtools add_devtools
$apt_install php-pear >/dev/null 2>&1 if [ ! -e /usr/bin/pecl ]; then
sudo pear config-set php_ini "$ini_file" >/dev/null 2>&1 $apt_install php-pear >/dev/null 2>&1
sudo pear config-set auto_discover 1 >/dev/null 2>&1 fi
sudo pear channel-update pear.php.net >/dev/null 2>&1 configure_pecl
sudo pecl channel-update pecl.php.net >/dev/null 2>&1
add_log "$tick" "PECL" "Added" add_log "$tick" "PECL" "Added"
} }
@ -158,49 +246,62 @@ switch_version() {
tick="✓" tick="✓"
cross="✗" cross="✗"
ppa_updated="false" ppa_updated="false"
pecl_config="false"
version=$1 version=$1
apt_install="sudo DEBIAN_FRONTEND=noninteractive apt-fast install -y" old_versions="5.[4-5]"
debconf_fix="DEBIAN_FRONTEND=noninteractive"
apt_install="sudo $debconf_fix apt-fast install -y"
existing_version=$(php-config --version | cut -c 1-3) existing_version=$(php-config --version | cut -c 1-3)
semver=$(php -v | head -n 1 | cut -f 2 -d ' ' | cut -f 1 -d '-') [[ -z "${update}" ]] && update='false' || update="${update}"
# Setup PHP # Setup PHP
step_log "Setup PHP" step_log "Setup PHP"
sudo mkdir -p /var/run sudo mkdir -p /var/run /run/php
sudo mkdir -p /run/php
if [ "$existing_version" != "$version" ]; then if [ "$existing_version" != "$version" ]; then
if [ ! -e "/usr/bin/php$version" ]; then if [ ! -e "/usr/bin/php$version" ]; then
update_ppa if [ "$version" = "8.0" ]; then
ppa_updated=1
if [ "$version" = "7.4" ]; then
$apt_install php"$version" php"$version"-curl php"$version"-mbstring php"$version"-xml php"$version"-phpdbg >/dev/null 2>&1
elif [ "$version" = "8.0" ]; then
setup_master setup_master
elif [[ "$version" =~ $old_versions ]] || [ "$version" = "5.3" ]; then
setup_old_versions
else else
version_exists=$(apt-cache policy -- php"$version" | grep "$version")
if [ -z "$version_exists" ]; then
ppa_updated=$(update_ppa)
fi
$apt_install php"$version" php"$version"-curl php"$version"-mbstring php"$version"-xml >/dev/null 2>&1 $apt_install php"$version" php"$version"-curl php"$version"-mbstring php"$version"-xml >/dev/null 2>&1
fi fi
status="installed" status="Installed"
else else
status="switched" if [ "$update" = "true" ]; then
$apt_install php"$version" >/dev/null 2>&1
status="Updated to"
else
status="Switched to"
fi
fi fi
switch_version # PHP 5.3 is switched by install script, for rest switch_version
if [ "$version" != "5.3" ]; then
semver=$(php -v | head -n 1 | cut -f 2 -d ' ' | cut -f 1 -d '-') switch_version
if [ "$version" = "8.0" ]; then
semver=$(php -v | head -n 1 | cut -f 2 -d ' ')
fi fi
if [ "$status" != "switched" ]; then
status="Installed PHP $semver"
else
status="Switched to PHP $semver"
fi
else else
status="PHP $semver Found" if [ "$update" = "true" ]; then
$apt_install php"$version" >/dev/null 2>&1
status="Updated to"
else
status="Found"
fi
fi
semver=$(php -v | head -n 1 | cut -f 2 -d ' ')
if [ ! "$version" = "8.0" ]; then
semver=$(echo "$semver" | cut -f 1 -d '-')
fi fi
ini_file=$(php --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g") ini_file=$(php --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g")
ext_dir=$(php -i | grep "extension_dir => /usr" | sed -e "s|.*=> s*||") ext_dir=$(php -i | grep "extension_dir => /" | sed -e "s|.*=> s*||")
scan_dir=$(php --ini | grep additional | sed -e "s|.*: s*||")
sudo chmod 777 "$ini_file" sudo chmod 777 "$ini_file"
add_log "$tick" "PHP" "$status" add_log "$tick" "PHP" "$status PHP $semver"

View File

@ -31,11 +31,16 @@ Function Add-Extension {
[ValidateNotNull()] [ValidateNotNull()]
[ValidateSet('stable', 'beta', 'alpha', 'devel', 'snapshot')] [ValidateSet('stable', 'beta', 'alpha', 'devel', 'snapshot')]
[string] [string]
$mininum_stability = 'stable' $mininum_stability = 'stable',
[Parameter(Position = 2, Mandatory = $false)]
[ValidateNotNull()]
[ValidatePattern('^\d+(\.\d+){0,2}$')]
[string]
$extension_version = ''
) )
try { try {
$extension_info = Get-PhpExtension -Path $php_dir | Where-Object { $_.Name -eq $extension -or $_.Handle -eq $extension } $extension_info = Get-PhpExtension -Path $php_dir | Where-Object { $_.Name -eq $extension -or $_.Handle -eq $extension }
if ($null -ne $extension_info -and $mininum_stability -eq 'stable') { if ($null -ne $extension_info) {
switch ($extension_info.State) { switch ($extension_info.State) {
'Builtin' { 'Builtin' {
Add-Log $tick $extension "Enabled" Add-Log $tick $extension "Enabled"
@ -50,12 +55,13 @@ Function Add-Extension {
} }
} }
else { else {
Install-PhpExtension -Extension $extension -MinimumStability $mininum_stability -Path $php_dir if($extension_version -ne '') {
if($mininum_stability -ne 'stable') { Install-PhpExtension -Extension $extension -Version $extension_version -MinimumStability $mininum_stability -Path $php_dir
Add-Log $tick "$extension-$mininum_stability" "Installed and enabled"
} else { } else {
Add-Log $tick $extension "Installed and enabled" Install-PhpExtension -Extension $extension -MinimumStability $mininum_stability -Path $php_dir
} }
Add-Log $tick $extension "Installed and enabled"
} }
} }
catch { catch {
@ -95,10 +101,7 @@ Function Add-Tool() {
if (Test-Path $php_dir\$tool) { if (Test-Path $php_dir\$tool) {
Remove-Item $php_dir\$tool Remove-Item $php_dir\$tool
} }
if ($tool -eq "composer") { if ($tool -eq "symfony") {
Install-Composer -Scope System -Path $php_dir -PhpPath $php_dir
composer -q global config process-timeout 0
} elseif ($tool -eq "symfony") {
Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $php_dir\$tool.exe Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $php_dir\$tool.exe
Add-Content -Path $PsHome\profile.ps1 -Value "New-Alias $tool $php_dir\$tool.exe" > $null 2>&1 Add-Content -Path $PsHome\profile.ps1 -Value "New-Alias $tool $php_dir\$tool.exe" > $null 2>&1
} else { } else {
@ -117,6 +120,10 @@ Function Add-Tool() {
Add-Extension curl >$null 2>&1 Add-Extension curl >$null 2>&1
Add-Extension mbstring >$null 2>&1 Add-Extension mbstring >$null 2>&1
Add-Extension xml >$null 2>&1 Add-Extension xml >$null 2>&1
} elseif($tool -eq "cs2pr") {
(Get-Content $php_dir/cs2pr).replace('exit(9)', 'exit(0)') | Set-Content $php_dir/cs2pr
} elseif($tool -eq "composer") {
composer -q global config process-timeout 0
} }
if (((Get-ChildItem -Path $php_dir/* | Where-Object Name -Match "^$tool(.exe|.phar)*$").Count -gt 0)) { if (((Get-ChildItem -Path $php_dir/* | Where-Object Name -Match "^$tool(.exe|.phar)*$").Count -gt 0)) {
Add-Log $tick $tool "Added" Add-Log $tick $tool "Added"
@ -195,15 +202,22 @@ if ($null -eq $installed -or -not("$($installed.Version).".StartsWith(($version
Install-Php -Version $version -Architecture $arch -ThreadSafe $ts -InstallVC -Path $php_dir -TimeZone UTC -InitialPhpIni Production -Force >$null 2>&1 Install-Php -Version $version -Architecture $arch -ThreadSafe $ts -InstallVC -Path $php_dir -TimeZone UTC -InitialPhpIni Production -Force >$null 2>&1
} else { } else {
$updated = Update-Php $php_dir >$null 2>&1 if((Test-Path env:update) -and $env:update -eq 'true') {
if($updated -eq $False) { Update-Php $php_dir > $null 2>&1
$status = "Updated to"
} else {
$status = "Found" $status = "Found"
} }
} }
$installed = Get-Php -Path $php_dir $installed = Get-Php -Path $php_dir
Set-PhpIniKey -Key 'date.timezone' -Value 'UTC' -Path $php_dir Set-PhpIniKey -Key 'date.timezone' -Value 'UTC' -Path $php_dir
Enable-PhpExtension -Extension openssl, curl, opcache -Path $php_dir if($version -lt "5.5") {
Add-Extension openssl >$null 2>&1
Add-Extension curl >$null 2>&1
} else {
Enable-PhpExtension -Extension openssl, curl, opcache -Path $php_dir
}
Update-PhpCAInfo -Path $php_dir -Source CurrentUser Update-PhpCAInfo -Path $php_dir -Source CurrentUser
if ($version -eq 'master') { if ($version -eq 'master') {
if($installed.ThreadSafe) { if($installed.ThreadSafe) {

View File

@ -116,6 +116,7 @@ export async function parseTool(
*/ */
export async function getUri( export async function getUri(
tool: string, tool: string,
extension: string,
version: string, version: string,
prefix: string, prefix: string,
version_prefix: string, version_prefix: string,
@ -123,9 +124,11 @@ export async function getUri(
): Promise<string> { ): Promise<string> {
switch (version) { switch (version) {
case 'latest': case 'latest':
return [prefix, version, verb, tool + '.phar'].filter(Boolean).join('/'); return [prefix, version, verb, tool + extension]
.filter(Boolean)
.join('/');
default: default:
return [prefix, verb, version_prefix + version, tool + '.phar'] return [prefix, verb, version_prefix + version, tool + extension]
.filter(Boolean) .filter(Boolean)
.join('/'); .join('/');
} }
@ -135,23 +138,15 @@ export async function getUri(
* Helper function to get the codeception url * Helper function to get the codeception url
* *
* @param version * @param version
* @param php_version
* @param suffix * @param suffix
*/ */
export async function getCodeceptionUriBuilder( export async function getCodeceptionUriBuilder(
version: string, version: string,
php_version: string,
suffix: string suffix: string
): Promise<string> { ): Promise<string> {
switch (true) { return ['releases', version, suffix, 'codecept.phar']
case /^5\.6$|^7\.[0|1]$/.test(php_version): .filter(Boolean)
return ['releases', version, suffix, 'codecept.phar'] .join('/');
.filter(Boolean)
.join('/');
case /^7\.[2-4]$/.test(php_version):
default:
return ['releases', version, 'codecept.phar'].filter(Boolean).join('/');
}
} }
/** /**
@ -164,19 +159,55 @@ export async function getCodeceptionUri(
version: string, version: string,
php_version: string php_version: string
): Promise<string> { ): Promise<string> {
const codecept: string = await getCodeceptionUriBuilder(version, '');
const codecept54: string = await getCodeceptionUriBuilder(version, 'php54');
const codecept56: string = await getCodeceptionUriBuilder(version, 'php56');
// Refer to https://codeception.com/builds
switch (true) { switch (true) {
case /latest/.test(version): case /latest/.test(version):
switch (true) { switch (true) {
case /^5\.6$|^7\.[0|1]$/.test(php_version): case /5\.6|7\.[0|1]/.test(php_version):
return 'php56/codecept.phar'; return 'php56/codecept.phar';
case /^7\.[2-4]$/.test(php_version): case /7\.[2-4]/.test(php_version):
default: default:
return 'codecept.phar'; return 'codecept.phar';
} }
case /([4-9]|\d{2,})\..*/.test(version): case /(^[4-9]|\d{2,})\..*/.test(version):
return await getCodeceptionUriBuilder(version, php_version, 'php56'); switch (true) {
case /5\.6|7\.[0|1]/.test(php_version):
return codecept56;
case /7\.[2-4]/.test(php_version):
default:
return codecept;
}
case /(^2\.[4-5]\.\d+|^3\.[0-1]\.\d+).*/.test(version):
switch (true) {
case /5\.6/.test(php_version):
return codecept54;
case /7\.[0-4]/.test(php_version):
default:
return codecept;
}
case /^2\.3\.\d+.*/.test(version):
switch (true) {
case /5\.[4-6]/.test(php_version):
return codecept54;
case /^7\.[0-4]$/.test(php_version):
default:
return codecept;
}
case /(^2\.(1\.([6-9]|\d{2,}))|^2\.2\.\d+).*/.test(version):
switch (true) {
case /5\.[4-5]/.test(php_version):
return codecept54;
case /5.6|7\.[0-4]/.test(php_version):
default:
return codecept;
}
case /(^2\.(1\.[0-5]|0\.\d+)|^1\.[6-8]\.\d+).*/.test(version):
return codecept;
default: default:
return await getCodeceptionUriBuilder(version, php_version, 'php54'); return await codecept;
} }
} }
@ -404,12 +435,24 @@ export async function addTools(
const tool: string = tool_data.name; const tool: string = tool_data.name;
const version: string = tool_data.version; const version: string = tool_data.version;
const github = 'https://github.com/'; const github = 'https://github.com/';
let uri: string = await getUri(tool, version, 'releases', '', 'download'); let uri: string = await getUri(
tool,
'.phar',
version,
'releases',
'',
'download'
);
script += '\n'; script += '\n';
let url = ''; let url = '';
switch (tool) { switch (tool) {
case 'cs2pr':
uri = await getUri(tool, '', version, 'releases', '', 'download');
url = github + 'staabm/annotate-pull-request-from-checkstyle/' + uri;
script += await addArchive(tool, version, url, os_version);
break;
case 'php-cs-fixer': case 'php-cs-fixer':
uri = await getUri(tool, version, 'releases', 'v', 'download'); uri = await getUri(tool, '.phar', version, 'releases', 'v', 'download');
url = github + 'FriendsOfPHP/PHP-CS-Fixer/' + uri; url = github + 'FriendsOfPHP/PHP-CS-Fixer/' + uri;
script += await addArchive(tool, version, url, os_version); script += await addArchive(tool, version, url, os_version);
break; break;