From 4fc417668582a11dd7f9e9df8a8333c791c3a862 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Thu, 29 Jun 2023 10:18:01 +0200 Subject: [PATCH 1/2] Add composer scripts --- CONTRIBUTING.md | 36 ++++++++++++++++++++++-------------- RELEASING.md | 12 ++++++------ composer.json | 17 ++++++++++++++++- 3 files changed, 44 insertions(+), 21 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b54dab2fd..328c5bce4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -26,8 +26,8 @@ Composer. The test suite may be executed with: -``` -$ vendor/bin/simple-phpunit +```console +$ composer run test ``` The `phpunit.xml.dist` file is used as the default configuration file for the @@ -47,7 +47,7 @@ By default, the `simple-phpunit` binary chooses the correct PHPUnit version for the PHP version you are running. To run tests against a specific PHPUnit version, use the `SYMFONY_PHPUNIT_VERSION` environment variable: -``` +```console $ SYMFONY_PHPUNIT_VERSION=7.5 vendor/bin/simple-phpunit ``` @@ -108,38 +108,46 @@ The following environment variables are used for [CSFLE testing](https://github. * `KMS_TLS_CA_FILE` * `KMS_TLS_CERTIFICATE_KEY_FILE` -## Checking coding standards +## Code quality + +Before submitting a pull request, please ensure that your code adheres to the +coding standards and passes static analysis checks. + +```console +$ composer run checks +``` + +### Coding standards The library's code is checked using [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer), which is installed as a development dependency by Composer. To check the code for style errors, run the `phpcs` binary: - -``` +```console $ vendor/bin/phpcs ``` To automatically fix all fixable errors, use the `phpcbf` binary: -``` +```console $ vendor/bin/phpcbf ``` -## Running static analysis +### Static analysis The library uses [psalm](https://psalm.dev) to run static analysis on the code and ensure an additional level of type safety. New code is expected to adhere to level 1, with a baseline covering existing issues. To run static analysis checks, run the `psalm` binary: -``` +```console $ vendor/bin/psalm ``` To remove fixed errors from the baseline, you can use the `update-baseline` command-line argument: -``` +```console $ vendor/bin/psalm --update-baseline ``` @@ -147,16 +155,16 @@ Note that this will not add new errors to the baseline. New errors should be fixed instead of being added to the technical debt, but in case this isn't possible it can be added to the baseline using `set-baseline`: -``` +```console $ vendor/bin/psalm --set-baseline=psalm-baseline.xml ``` -## Automatic code refactoring +### Refactoring The library uses [rector](https://getrector.com/) to refactor the code for new features. To run automatic refactoring, use the `rector` command: -``` +```console $ vendor/bin/rector ``` @@ -178,7 +186,7 @@ repository: repository. * Create and activate Python 2.7 virtual environment if necessary. - ``` + ```console $ virtualenv -p python2.7 venv $ source venv/bin/activate ``` diff --git a/RELEASING.md b/RELEASING.md index 61424a35e..b73d6f9df 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -76,7 +76,7 @@ the Evergreen configuration should be updated: Commit and push any changes: -``` +```console $ git commit -m "Update composer.json and CI matrices for X.Y.Z" composer.json .evergreen/config.yml $ git push mongodb ``` @@ -85,7 +85,7 @@ $ git push mongodb Create a tag for the release and push: -``` +```console $ git tag -a -m "Release X.Y.Z" X.Y.Z $ git push mongodb --tags ``` @@ -119,7 +119,7 @@ The above would be changed to: Commit this change: -``` +```console $ git commit -m "Master is now 1.10-dev" composer.json ``` @@ -128,7 +128,7 @@ $ git commit -m "Master is now 1.10-dev" composer.json After a new minor version is released (i.e. `master` was tagged), a maintenance branch should be created for future patch releases: -``` +```console $ git checkout -b vX.Y $ git push mongodb vX.Y ``` @@ -146,7 +146,7 @@ Update the master branch alias in `composer.json`: Commit and push this change: -``` +```console $ git commit -m "Master is now X.Y-dev" composer.json $ git push mongodb ``` @@ -155,7 +155,7 @@ $ git push mongodb If this was a patch release, the maintenance branch must be merged up to master: -``` +```console $ git checkout master $ git pull mongodb master $ git merge vX.Y --strategy=ours diff --git a/composer.json b/composer.json index 67149ed8d..480cf7067 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,8 @@ "license": "Apache-2.0", "authors": [ { "name": "Andreas Braun", "email": "andreas.braun@mongodb.com" }, - { "name": "Jeremy Mikola", "email": "jmikola@gmail.com" } + { "name": "Jeremy Mikola", "email": "jmikola@gmail.com" }, + { "name": "Jérôme Tamarelle", "email": "jerome.tamarelle@mongodb.com" } ], "require": { "php": "^7.2 || ^8.0", @@ -33,6 +34,20 @@ "psr-4": { "MongoDB\\Tests\\": "tests/" }, "files": [ "tests/PHPUnit/Functions.php" ] }, + "scripts": { + "checks": [ + "@check:cs", + "@check:psalm", + "@check:rector" + ], + "check:cs": "phpcs", + "check:psalm": "psalm", + "check:rector": "rector --ansi --dry-run", + "fix:cs": "phpcbf", + "fix:psalm:baseline": "psalm --set-baseline=psalm-baseline.xml", + "fix:rector": "rector process --ansi", + "test": "simple-phpunit" + }, "extra": { "branch-alias": { "dev-master": "1.17.x-dev" From 99a8589f74d4b91c77ee3f25df74fd1f374dc9e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Thu, 29 Jun 2023 22:45:25 +0200 Subject: [PATCH 2/2] Update low phpunit version example --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 328c5bce4..a794a00c1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -48,7 +48,7 @@ the PHP version you are running. To run tests against a specific PHPUnit version, use the `SYMFONY_PHPUNIT_VERSION` environment variable: ```console -$ SYMFONY_PHPUNIT_VERSION=7.5 vendor/bin/simple-phpunit +$ SYMFONY_PHPUNIT_VERSION=8.5 vendor/bin/simple-phpunit ``` ### Environment Variables