openeuropa / code-review
OpenEuropa code review component.
Installs: 93 431
Dependents: 55
Suggesters: 0
Security: 0
Stars: 2
Watchers: 23
Forks: 4
Open Issues: 4
Requires
- php: >=8.0
- amphp/parallel: ^1.4.1
- drupal/coder: ^8.3.16
- phpmd/phpmd: ^2.12
- phpro/grumphp: ^1.1
- squizlabs/php_codesniffer: ^3.6
Requires (Dev)
- phpunit/phpunit: ^9.5.5
- 3.x-dev
- 2.x-dev
- 2.0.0-alpha6
- 2.0.0-alpha5
- 2.0.0-alpha4
- 2.0.0-alpha3
- 2.0.0-alpha2
- 2.0.0-alpha1
- 1.x-dev
- 1.7.0
- 1.6.0
- 1.5.0
- 1.4.0
- 1.3.0
- 1.2.0
- 1.1.0
- 1.0.0
- 1.0.0-beta4
- 1.0.0-beta3
- 1.0.0-beta2
- 1.0.0-beta1
- 1.0.0-alpha5
- 1.0.0-alpha4
- 1.0.0-alpha3
- 1.0.0-alpha2
- 1.0.0-alpha1
- 0.x-dev
- 0.3.0
- 0.2.0
- 0.1.1
- 0.1.0
- 0.0.2
- 0.0.1
- dev-dronetest
- dev-update-2.x
- dev-EWPP-1778
- dev-EWPP-1406
- dev-EWPP-1387
- dev-EWPP-929
- dev-master
- dev-OPENEUROPA-2258-test-php72
- dev-73-add-composer-task
This package is auto-updated.
Last update: 2024-11-06 13:00:32 UTC
README
Make automatic conventions checking on each commit via GrumPHP.
Installation
Install the code review component via Composer:
composer require --dev openeuropa/code-review
In your project root create the following grumphp.yml.dist
:
imports: - { resource: vendor/openeuropa/code-review/dist/library-conventions.yml }
For Drupal projects, drupal-conventions.yml
should be imported instead.
Using Docker Compose
Alternatively, you can build a development setup using Docker and Docker Compose with the provided configuration.
Docker provides the necessary services and tools such as a web server and a database server to get the site running, regardless of your local host configuration.
Requirements:
Configuration
By default, Docker Compose reads two files, a docker-compose.yml
and an optional docker-compose.override.yml
file.
By convention, the docker-compose.yml
contains your base configuration and it's provided by default.
The override file, as its name implies, can contain configuration overrides for existing services or entirely new
services.
If a service is defined in both files, Docker Compose merges the configurations.
Find more information on Docker Compose extension mechanism on the official Docker Compose documentation.
Usage
To start, run:
docker-compose up
It's advised to not daemonize docker-compose
so you can turn it off (CTRL+C
) quickly when you're done working.
However, if you'd like to daemonize it, you have to add the flag -d
:
docker-compose up -d
Then:
docker-compose exec web composer install
Running the tests
To run the grumphp checks:
docker-compose exec web ./vendor/bin/grumphp run
To run the phpunit tests:
docker-compose exec web ./vendor/bin/phpunit
Step debugging
To enable step debugging from the command line, pass the XDEBUG_SESSION
environment variable with any value to
the container:
docker-compose exec -e XDEBUG_SESSION=1 web <your command>
Please note that, starting from XDebug 3, a connection error message will be outputted in the console if the variable is set but your client is not listening for debugging connections. The error message will cause false negatives for PHPUnit tests.
To initiate step debugging from the browser, set the correct cookie using a browser extension or a bookmarklet like the ones generated at https://www.jetbrains.com/phpstorm/marklets/.
Customization
This component offers a variety of ready conventions that all projects need to follow. This list of default conventions can be found in CONVENTIONS.md.
Since GrumPHP uses the Symfony Dependency Injection component
you can override specific parameters in your project's grumphp.yml.dist
file as follows:
imports: - { resource: vendor/openeuropa/code-review/dist/library-conventions.yml } parameters: tasks.git_commit_message.matchers: ['/^JIRA-\d+: [A-Z].+\./']
Below the list of task parameters can that be overridden on a per-project basis:
tasks.phpcs.standard
tasks.phpcs.ignore_patterns
tasks.phpcs.triggered_by
tasks.phpcs.whitelist_patterns
tasks.phpcs.warning_severity
tasks.phpmd.exclude
tasks.phpmd.ruleset
tasks.phpmd.triggered_by
tasks.git_commit_message.matchers
More on how to import and override configuration files here.
It is also possible to extend the list of tasks to be run by loading the extra tasks extension and adding tasks under
the extra_tasks:
parameter as shown below:
imports: - { resource: vendor/openeuropa/code-review/dist/library-conventions.yml } parameters: extra_tasks: phpparser: ~ extensions: - OpenEuropa\CodeReview\ExtraTasksExtension
GrumPHP already has a series of tasks that can be used out of the box, you can find the complete list in the GrumPHP tasks page.
It is also possible to create your own tasks as explained in the GrumPHP extensions page.
Usage
GrumPHP tasks will be ran at every commit, if you with to run them without performing a commit use the following command:
./vendor/bin/grumphp run
If you want to simulate the tasks that will be run when creating a new commit:
./vendor/bin/grumphp git:pre-commit
Check GrumPHP documentation for more.
Changelog
The changelog is generated using a local docker installation which installs muccg/docker-github-changelog-generator
This reads the Github API for the required repository and writes the CHANGELOG.md to the root of the repository.
Prerequisites
- Local Docker machine running.
- A Github Access Token should be generated and exported (or written to ~/.gitconfig) as
CHANGELOG_GITHUB_TOKEN=<YOUR TOKEN HERE>
Before tagging a new release export the following:
export CHANGELOG_GITHUB_TOKEN=<YOUR TOKEN HERE> export CHANGELOG_FUTURE_RELEASE=0.1.0
The changelog can then be generated by running:
composer run-script changelog
Troubleshooting
GrumPHP not fired on new commits
With Git 2.9+ (June 2016) you have a new option for centralizing hooks: core.hooksPath
. In case GrumPHP is not
fired on new commits check for core.hooksPath
global option by running:
git config --global --list
To unset that option run:
git config --global --unset core.hooksPath
Generate Changelog on Mac
- Best results were gained using the Docker app
- The local repo folder should be shared under Docker -> Preferences -> File sharing to enable the file to be written locally.