├── Dockerfile ├── LICENSE ├── README.md ├── action.yml ├── app ├── entrypoint.sh └── problem-matcher.json └── resources └── images └── phpcs-drupal-action.png /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM php:8.4.0RC3-cli-alpine 2 | ENV PATH=${PATH}:/root/.composer/vendor/bin 3 | RUN apk add --no-cache \ 4 | git && \ 5 | curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer && \ 6 | composer global config --no-plugins allow-plugins.dealerdirect/phpcodesniffer-composer-installer true && \ 7 | composer global require drupal/coder squizlabs/php_codesniffer && \ 8 | phpcs --config-set default_standard Drupal,DrupalPractice 9 | COPY app /app 10 | RUN chmod +x /app/entrypoint.sh 11 | WORKDIR /app 12 | ENTRYPOINT ["/app/entrypoint.sh"] -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020-2024 Guillaume Duveau 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Fast & inexpensive GitHub Action to check Drupal PHP coding standards with annotations 2 | 3 | ![PHPCS Drupal action](./resources/images/phpcs-drupal-action.png) 4 | 5 | This GitHub Action allows to **check your code against the Drupal PHP coding standards**. 6 | 7 | It has **GitHub Annotations** working out-of-the box. It's **fast** and **inexpensive** (in terms of GitHub Action minutes) compared to most others. This is because it doesn't install composer dependencies. The downside is that all components versions are fixed by the version of the action you are using, and not by your code base. 8 | 9 | The Docker image used by this action is automatically built from this repository on https://quay.io/repository/guix77/phpcs-drupal-action 10 | 11 | ## Requirements 12 | 13 | + A Drupal project following the https://github.com/drupal-composer/drupal-project structure; 14 | + A GitHub repository of course. 15 | 16 | ## Installation 17 | 18 | In the root of your Drupal project, create ````phpcs.xml````: 19 | 20 | ```` 21 | 22 | 23 | PHP CodeSniffer configuration for Drupal coding standards. 24 | ./web/modules/custom 25 | ./web/themes/custom 26 | 27 | 28 | 29 | 30 | 31 | ```` 32 | 33 | In the root of your Drupal project, create ````.github/workflows/drupalCodingStandards.yml````: 34 | 35 | ```` 36 | name: Drupal coding standards 37 | 38 | on: [pull_request] 39 | 40 | jobs: 41 | phpcs-drupal: 42 | name: Drupal coding standards 43 | runs-on: ubuntu-latest 44 | steps: 45 | - uses: actions/checkout@v4 46 | - uses: guix77/phpcs-drupal-action@php8.4RC3 47 | ```` 48 | 49 | You can customize the trigger of course (\\\\on: [pull_request]\\\\). 50 | 51 | That's it. 52 | 53 | ## Memory limit 54 | 55 | Optionally you could define the memory limit to use when executing phpcs. By default it is set to 128M. 56 | 57 | ```` 58 | uses: guix77/phpcs-drupal-action@php8.4RC3 59 | with: 60 | memory_limit: 512M 61 | ```` 62 | 63 | Define this if you get an error like: `Fatal error: Allowed memory size of...`. 64 | 65 | ## Credits 66 | 67 | Inspired by https://github.com/chekalsky/phpcs-action 68 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: 'PHPCS Drupal check with Annotations' 2 | description: 'PHPCS Drupal checker with auto annotations out of the box' 3 | author: 'Guillaume Duveau' 4 | inputs: 5 | memory_limit: 6 | description: 'Define the memory limit to use. Default: 128M.' 7 | required: false 8 | default: '128M' 9 | runs: 10 | using: 'docker' 11 | image: 'docker://quay.io/guix77/phpcs-drupal-action:php8.4RC3' 12 | branding: 13 | icon: 'code' 14 | color: 'blue' 15 | -------------------------------------------------------------------------------- /app/entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cp /app/problem-matcher.json /github/workflow/problem-matcher.json 4 | 5 | echo "::add-matcher::${RUNNER_TEMP}/_github_workflow/problem-matcher.json" 6 | 7 | phpcs -d memory_limit=${INPUT_MEMORY_LIMIT} --report=checkstyle 8 | 9 | status=$? 10 | 11 | echo "::remove-matcher owner=phpcs::" 12 | 13 | exit $status 14 | -------------------------------------------------------------------------------- /app/problem-matcher.json: -------------------------------------------------------------------------------- 1 | { 2 | "problemMatcher": [ 3 | { 4 | "owner": "phpcs", 5 | "severity": "error", 6 | "pattern": [ 7 | { 8 | "regexp": "^$", 9 | "file": 1 10 | }, 11 | { 12 | "regexp": "+)$", 13 | "line": 1, 14 | "column": 2, 15 | "severity": 3, 16 | "message": 4, 17 | "code": 5, 18 | "loop": true 19 | } 20 | ] 21 | } 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /resources/images/phpcs-drupal-action.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guix77/phpcs-drupal-action/9739e99b558fd8caebfe181c9d72eb18b99f4407/resources/images/phpcs-drupal-action.png --------------------------------------------------------------------------------