Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding PHP 8.1 support and related changes #236

Merged
merged 50 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
f4aef07
Adding PHP 8.1 testing
gudmdharalds Jan 25, 2022
15fc308
Updating commands
gudmdharalds Jan 25, 2022
eb2f094
Fix path
gudmdharalds Jan 25, 2022
33889ed
Run PHPCompatibility tests
gudmdharalds Jan 25, 2022
56a04d9
Use PHP 7.4 for PHP linting
gudmdharalds Jan 25, 2022
96bd72e
Removing symlink creation
gudmdharalds Jan 25, 2022
2a3199f
Using ~/project
gudmdharalds Jan 25, 2022
f15a2e3
Update with PHP 8 recommendation
gudmdharalds Jan 27, 2022
e6f02c3
Merge branch 'main' into update-php-8
gudmdharalds Jan 31, 2022
65145f7
Merge branch 'update-php-8' of github.com:Automattic/vip-go-ci into u…
gudmdharalds Feb 1, 2022
6dae1e2
PHP 8 fix for getopt()
gudmdharalds Feb 1, 2022
6097d47
Merge branch 'main' into update-php-8
gudmdharalds Feb 9, 2022
76b5664
Renaming option --php-path to --lint-php-path
gudmdharalds Feb 9, 2022
12daff3
Moving --lint-php-path around in help message.
gudmdharalds Feb 9, 2022
54badc8
Make help message more detailed.
gudmdharalds Feb 9, 2022
a13d3ca
Add lint-php-path parameter, slight formatting changes.
gudmdharalds Feb 10, 2022
19803a4
Use --svg-php-path option when scanning.
gudmdharalds Feb 10, 2022
21eb1a4
Add --svg-php-path option, update --phpcs-php-path and --lint-php-path.
gudmdharalds Feb 10, 2022
48bc9a8
Add --phpcs-php-path and --lint-php-path
gudmdharalds Feb 10, 2022
440a567
Adding PHPDoc
gudmdharalds Feb 10, 2022
370a321
Adding svg-php-path option
gudmdharalds Feb 10, 2022
6408d5f
Adding phpcs-php-path option
gudmdharalds Feb 10, 2022
fa2c969
Setting expected lint-php-path option to null
gudmdharalds Feb 10, 2022
b0fcb8b
Setting svg-php-path option to null.
gudmdharalds Feb 10, 2022
18de83d
Adding phpcs-php-path option
gudmdharalds Feb 10, 2022
0db2d59
Adding --svg-php-path option
gudmdharalds Feb 11, 2022
ca031d1
Adding/updating --phpcs-php-path, --phpcs-severity and --phpcs-runtim…
gudmdharalds Feb 11, 2022
d9d97a3
Adding --phpcs-php-path option
gudmdharalds Feb 11, 2022
14147f9
Adding --phpcs-php-path option
gudmdharalds Feb 11, 2022
ad7c348
Adding/updating --phpcs-php-path, --phpcs-runtime-set, --phpcs-severi…
gudmdharalds Feb 11, 2022
47bf19c
Adding/updating --phpcs-php-path, --phpcs-runtime-set options.
gudmdharalds Feb 11, 2022
7afa36b
Adding --svg-php-path option.
gudmdharalds Feb 11, 2022
f06ac48
Adding --svg-php-path option.
gudmdharalds Feb 11, 2022
f0ef2a0
Add --phpcs-php-path, apply WordPress coding standard.
gudmdharalds Feb 11, 2022
00202ab
Use different PHP versions for different types of scanning. Remove PH…
gudmdharalds Feb 11, 2022
59512d7
Apply WordPress coding standard.
gudmdharalds Feb 11, 2022
8552d31
Update unit-tests
gudmdharalds Feb 11, 2022
02f5de9
Apply WordPress coding standard.
gudmdharalds Feb 11, 2022
e43085b
Apply WordPress coding standard.
gudmdharalds Feb 14, 2022
68bbb43
Apply WordPress coding standard.
gudmdharalds Feb 14, 2022
4b45e0f
New section, path to PHP
gudmdharalds Feb 14, 2022
007111c
Update README.md
gudmdharalds Feb 14, 2022
46812d1
Update README.md
gudmdharalds Feb 14, 2022
b3059e3
Update README.md
gudmdharalds Feb 14, 2022
8a4250d
Update README.md
gudmdharalds Feb 14, 2022
589378f
Update README.md
gudmdharalds Feb 14, 2022
469807c
Updating README.md
gudmdharalds Feb 14, 2022
6125f47
Updating README.md
gudmdharalds Feb 14, 2022
bac486c
Adding section on different PHP versions in tests.
gudmdharalds Feb 14, 2022
a08e1c5
Merge branch 'main' into update-php-8
gudmdharalds Feb 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,50 @@ commands:
- run: php -v
# Update software and install a few things
- run: sudo apt update
- run: sudo docker-php-ext-install zip pcntl
- run: sudo apt install -y zip unzip gzip tar
- run: composer require --dev phpunit/phpunit ^9
# By default, php is not available in /usr/bin, fix that
- run: sudo ln -s /usr/local/bin/php /usr/bin/php
# Ensure we always have access to PHP 7.4, PHP 8.0 and PHP 8.1.
# Different versions are used for PHP linting, PHPCS scanning and SVG scanning.
# Note: This uses a third-party package, should be safe as no secrets are used during this build.
- run: sudo add-apt-repository -y ppa:ondrej/php
- run: sudo apt install -y php7.4 php7.4-dom php7.4-curl php7.4-mbstring
- run: sudo apt install -y php8.0 php8.0-dom php8.0-curl php8.0-mbstring
- run: sudo apt install -y php8.1 php8.1-dom php8.1-curl php8.1-mbstring
# Install all the tools vip-go-ci needs, remove vip-go-ci itself though
- run: bash ~/project/tools-init.sh
- run: rm -rf ~/vip-go-ci-tools/vip-go-ci
# Change path to vital tools needed
- run: sed 's/\/home\/phpunit\//\/home\/circleci\//' < ~/project/unittests.ini.dist > ~/project/unittests.ini
# Change paths to vital tools needed, ensure we use different
# PHP versions for different types of scanning.
- run: cat ~/project/unittests.ini.dist | sed 's/\/home\/phpunit\//\/home\/circleci\//' | sed 's/lint-php-path=\/usr\/bin\/php/lint-php-path=\/usr\/bin\/php8.0/g' | sed 's/phpcs-php-path=\/usr\/bin\/php/phpcs-php-path=\/usr\/bin\/php7.4/g' | sed 's/svg-php-path=\/usr\/bin\/php/svg-php-path=\/usr\/bin\/php8.1/g' > ~/project/unittests.ini
# No secrets available for unit-tests
- run: touch ~/project/unittests-secrets.ini
# Prepare phpunit configuration file
- run: sed 's/PROJECT_DIR/\/home\/circleci\/project/g' ~/project/phpunit.xml.dist > ~/project/phpunit.xml
# Move to project directory
- run: cd ~/project
# Run unit tests
- run: ./vendor/bin/phpunit --testsuite=unit-tests -vv
# Run integration tests
- run: ./vendor/bin/phpunit --testsuite=integration-tests -vv
# Run PHPCS, check for PHP compatibility issues
- run: ~/vip-go-ci-tools/phpcs/bin/phpcs --runtime-set 'testVersion' '7.4-' --standard=PHPCompatibility,PHPCompatibilityParagonieRandomCompat,PHPCompatibilityParagonieSodiumCompat --ignore="vendor/*" ~/project
- run: ~/vip-go-ci-tools/phpcs/bin/phpcs --runtime-set 'testVersion' '8.1-' --standard=PHPCompatibility,PHPCompatibilityParagonieRandomCompat,PHPCompatibilityParagonieSodiumCompat --ignore="vendor/*" ~/project

# List of images at: https://circleci.com/docs/2.0/circleci-images/
# List of images at: https://circleci.com/developer/images/image/cimg/php#image-tags
jobs:
testphp74:
testphp80:
docker:
- image: circleci/php:7.4.14-cli
- image: cimg/php:8.0.15
steps:
- build-cmd

testphp80:
testphp81:
docker:
- image: circleci/php:8.0.1-cli
- image: cimg/php:8.1.2
steps:
- build-cmd

- build-cmd

workflows:
vipgocitests:
jobs:
- testphp74
- testphp80
- testphp81
120 changes: 74 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ If you have a feature request, please read the [file on contributing](CONTRIBUTI

### System requirements

* `vip-go-ci` requires PHP 7.3 or later. PHP 7.4 is preferred.
* `vip-go-ci` requires PHP 8.0 or later. PHP 8.1 is recommended.
* The PHP-based utlities — PHPCS, SVG scanner and PHP Lint — can be run using different PHP versions than `vip-go-ci` itself. See individual sections below on this.
* Linux is recommended as a platform for `vip-go-ci`.
* git version 2.10 or later.
* Working bash shell.
Expand Down Expand Up @@ -96,7 +97,7 @@ While running, `vip-go-ci` will output log of its actions. Here is an example --
"branches-ignore": [],
"autoapprove": true,
"autoapprove-filetypes": [ "css", "txt", "pdf ],
"php-path": "php",
"lint-php-path": "php",
"debug-level": 0,
"dry-run": false
}
Expand Down Expand Up @@ -288,21 +289,7 @@ docker-compose up -d --scale agent=3

Alternatively, if you do not wish to run TeamCity in a Docker-instance, you can download it and set it up manually.


### Exit codes

`vip-go-ci.php` exits with different UNIX exit codes depending on what problems were found and if any system issues were encountered:

* Code `0`: Normal, no errors were found in the code scanned and no fatal system errors were encountered. There could have been warnings found in the code, though.
* Code `220`: Internal error in `vip-go-ci`.
* Code `230`: Commit specified is not associated with any pull request.
* Code `249`: Scanning exceeded maximum time allowed.
* Code `250`: Scanning was completed, but some errors were found in the code.
* Code `251`: Exiting due to a system problem.
* Code `252`: A fatal problem with GitHub was encountered leading to an exit.
* Code `253`: A problem with usage options was detected, leading to an exit.

## Other features
## Features overview

`vip-go-ci` has support for various features not documented above, such as dismissing stale reviews, setting specific options via the repository being scanned and more. These features are configurable via the command-line or the environment, and are documented below.

Expand Down Expand Up @@ -373,6 +360,22 @@ To have a message posted, simply run `vip-go-ci` with a `--informational-msg` pa

The message will be included in any generic pull request comments or pull request reviews submitted.

### PHP Linting configuration

By default, `vip-go-ci` will PHP lint any files modified by the current pull request. PHP linting is performed by running `php -l`.

To use a different PHP interpreter than the system default to perform PHP linting, use the `--lint-php-path` option. This should point to a PHP binary.

The following PHP linting related options can be configured via repository config-file or normal options:

#### Option `--lint-modified-files-only`

The `lint-modified-files-only` option specifies whether `vip-go-ci` should PHP lint only the PHP files modified, or all the PHP files in the base branch. See [here](#configuration-via-repository-config-file) on modifying this option via configuration file.

For example:

> {"lint-modified-files-only":false}

### PHPCS configuration

Support for checking for issues in PHP files by using [PHPCS](https://github.com/squizlabs/PHP_CodeSniffer/) scanning is supported. The behaviour of PHPCS scanning can be configured using several options.
Expand All @@ -383,9 +386,9 @@ An example of how PHPCS can be used:

With these settings, PHPCS is turned on, is expected to be found in the path shown above, should use two PHPCS standards (`WordPress-VIP-Go` and `PHPCompatibilityWP`), while excluding one particular PHPCS sniff and specifically include another one. When executing PHPCS, one runtime option should be set (`testVersion 7.4-`) and severity level should be `1`. Also, users can ask to skip scanning particular pull requests by setting a label named `skip-phpcs-scan`.

Any number of PHPCS standards can be specified, and any number of runtime settings as well. Also, see section above about configuring options via repository file.
Any number of PHPCS standards can be specified, and any number of runtime settings as well. Also, see section above about configuring options via repository file. Should any of the PHPCS sniffs included or excluded be invalid, this is reported in the relevant pull requests.

Should any of the PHPCS sniffs included or excluded be invalid, this is reported in the relevant pull requests.
To use a different PHP interpreter than the system default to run PHPCS, use `--phpcs-php-path`. This should point to a PHP binary.

The following PHPCS-related options can be configured via repository config-file:

Expand All @@ -411,15 +414,7 @@ The `phpcs-sniffs-include` is configured in the same way as the `phpcs-sniffs-ex

Please note that should any of the PHPCS sniffs specified be invalid, a warning will be posted on any pull request scanned. The warning will be removed during next scan and not posted again if the issue is fixed.

#### Options `--lint-modified-files-only`

The ``lint-modified-files-only`` option specifies whether the ``vip-go-ci`` bot should scan all the PHP files in the repository (including already merged files) or files modified by the PR only.

Due to performance concerns, the lint-modified-files-only option is enabled by default. It can be disabled through the ``.vipgoci_options`` configuration file. To disable the ``lint-modified-files-only`` option, ensure the ``.vipgoci_options`` configuration file is created in the git-repository and define the option as false. See the example below:

> {"lint-modified-files-only":false}

### SVG scanning
### SVG scanning configuration

`vip-go-ci` supports scanning SVG files for dangerous tags. The scanning is accomplished by a [SVG scanner](https://github.com/Automattic/vip-go-svg-sanitizer), while `vip-go-ci` takes care of posting the issues found.

Expand All @@ -429,6 +424,8 @@ To make use of this feature, the `--svg-checks` and `--svg-scanner-path` options

With these options, SVG scanning is turned on and a scanner at a particular path location is to be used.

To use a different PHP interpreter than the system default to run the SVG scanner, use `--svg-php-path`. This should point to a PHP binary.

The following SVG-related options can be configured via repository config-file:

#### Option `--svg-checks`
Expand Down Expand Up @@ -667,39 +664,52 @@ export WP_CODING_STANDARDS_SHA1SUM="d35ec268531453cbf2078c57356e38c5f8936e87";

All utilities in `tools-init.sh` follow the same pattern.

## Exit codes

`vip-go-ci.php` exits with different UNIX exit codes depending on what problems were found and if any system issues were encountered:

* Code `0`: Normal, no errors were found in the code scanned and no fatal system errors were encountered. There could have been warnings found in the code, though.
* Code `220`: Internal error in `vip-go-ci`.
* Code `230`: Commit specified is not associated with any pull request.
* Code `249`: Scanning exceeded maximum time allowed.
* Code `250`: Scanning was completed, but some errors were found in the code.
* Code `251`: Exiting due to a system problem.
* Code `252`: A fatal problem with GitHub was encountered leading to an exit.
* Code `253`: A problem with usage options was detected, leading to an exit.

## Tests

To run the tests for `vip-go-ci`, you will need to install `phpunit` and any dependencies needed (this would include `xdebug`).

Note that the test suite sometimes uses the @runTestsInSeparateProcesses and @preserveGlobalState PHPUnit flags to avoid any influence of one test on another.
Note that the test suite uses the @runTestsInSeparateProcesses and @preserveGlobalState PHPUnit flags to avoid any influence of one test on another.

### Setting up test suite

To be able run the test suite, a few steps will need to be taken.

### PHPUnit configuration file:
Run:
1) run the following command:
> mv phpunit.xml.dist phpunit.xml

Replace the string ``PROJECT_DIR`` with your local project directory. E.g.:
2) replace the string `PROJECT_DIR` in `phpunit.xml` with your local project directory.

For example:
> <directory>PROJECT_DIR/tests/integration</directory>
will be:
> <directory>~/Projects/tests/integration</directory>
> <directory>~/Projects/vip-go-ci/tests/integration</directory>

Then run the unit tests using the following command:

### Unit test suite
> phpunit --testsuite=unit-tests -vv
3) This step is only needed if you intend to run the integration tests.

By running this command, you will run the tests that do not depend on external calls.
Start with preparing the `unittests.ini` file:

### Integration test suite
> phpunit --testsuite=integration-tests -vv
> cp unittests.ini.dist unittests.ini

By using this command, you will run the tests of the test-suite which can be run (depending on tokens and other detail), and get feedback on any errors or warnings. Note that when run, requests will be made to the GitHub API, but using anonymous calls (unless configured as shown below). It can happen that the GitHub API returns with an error indicating that the maximum limit of API requests has been reached; the solution is to wait and re-run or use authenticated calls (see below).
Alter any options in the file as needed to match the setup of your system. Note that in some cases, you may have to use different PHP versions for PHPCS or the SVG scanner, than `vip-go-ci` itself.

`vip-go-ci` ships with a default `unittests.ini.dist` file which includes configuration details needed for the unit tests to run. This includes repository to use for testing, pull request IDs and more.
Note that some tests will require a GitHub token to submit POST/PUT requests to GitHub in order to complete, need access to the hashes-to-hashes database, or to a repo-meta API.

Run:
> cp unittests.ini.dist unittests.ini
To skip these tests, simply place an empty `unittests-secrets.ini` file in the root directory of `vip-go-ci` and skip the rest of this section.

Note that by default, some tests will be skipped, as these will require a GitHub token to write to GitHub in order to complete, need access to the hashes-to-hashes database, or to a repo-meta API. To enable the testing of these, you need to set up a `unittests-secrets.ini` file in the root of the repository. It should include the following fields:
To enable the testing of these, you need to set up a `unittests-secrets.ini` file in the root directory of `vip-go-ci`. This file should include the following fields:

```
[auto-approvals-secrets]
Expand All @@ -724,7 +734,25 @@ support-level= ; Name of support level given by meta API
support-level-field-name= ; Support level field name in meta API
```

This file is not included, and needs to be configured manually. When that is complete, the tests can be re-run.
This file is not included, and needs to be configured manually.

### Unit test suite

The unit test suite can be run using the following command:

> phpunit --testsuite=unit-tests -vv

By running this command, you will run the tests that do not depend on external calls.

### Integration test suite

The integration tests can be run using the following command:

> phpunit --testsuite=integration-tests -vv

Integration tests will execute the scanning utilities — PHPCS, SVG scanner and PHP Lint — and so paths to these, and a PHP interpreter, need to be configured. See the `unittests.ini` file.

By using this command, you will run the tests of the test-suite which can be run (depending on tokens and other detail), and get feedback on any errors or warnings. Note that when run, requests will be made to the GitHub API, but using anonymous calls (unless configured as shown above). It can happen that the GitHub API returns with an error indicating that the maximum limit of API requests has been reached; the solution is to wait and re-run or use authenticated calls (see above).

## Setting GitHub Build Status

Expand Down
8 changes: 6 additions & 2 deletions exec.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<?php

/*
/**
* Call vipgoci_run() when not running a
* unit-test.
*
* @package Automattic/vip-go-ci
*/

declare(strict_types=1);

if (
(
( ! defined( 'VIPGOCI_UNIT_TESTING' ) ) ||
Expand Down
Loading