|
| 1 | +name: CS |
| 2 | + |
| 3 | +on: |
| 4 | + # Run on all pushes and on all pull requests. |
| 5 | + # Prevent the build from running when there are only irrelevant changes. |
| 6 | + push: |
| 7 | + paths-ignore: |
| 8 | + - '**.md' |
| 9 | + - 'docs/**' |
| 10 | + pull_request: |
| 11 | + paths-ignore: |
| 12 | + - '**.md' |
| 13 | + - 'docs/**' |
| 14 | + |
| 15 | +jobs: |
| 16 | + checkcs: |
| 17 | + name: 'Basic CS and QA checks' |
| 18 | + runs-on: ubuntu-latest |
| 19 | + |
| 20 | + env: |
| 21 | + XMLLINT_INDENT: ' ' |
| 22 | + # - COMPOSER_ROOT_VERSION is needed to get round the recursive dependency when using CI. |
| 23 | + COMPOSER_ROOT_VERSION: '1.99.99' |
| 24 | + |
| 25 | + steps: |
| 26 | + - name: Checkout code |
| 27 | + uses: actions/checkout@v2 |
| 28 | + |
| 29 | + - name: Install PHP |
| 30 | + uses: shivammathur/setup-php@v2 |
| 31 | + with: |
| 32 | + php-version: '7.4' |
| 33 | + coverage: none |
| 34 | + |
| 35 | + - name: 'Composer: adjust dependencies' |
| 36 | + run: | |
| 37 | + # The sniff stage doesn't run the unit tests, so no need for PHPUnit. |
| 38 | + composer remove --no-update --dev phpunit/phpunit --no-scripts |
| 39 | + # Using PHPCS `master` as an early detection system for bugs upstream. |
| 40 | + composer require --no-update squizlabs/php_codesniffer:"dev-master" |
| 41 | + # Add PHPCSDevCS - this is the CS ruleset we use. |
| 42 | + # This is not in the composer.json as it has different minimum PHPCS reqs and would conflict. |
| 43 | + composer require --no-update --dev phpcsstandards/phpcsdevcs:"^1.1.2" |
| 44 | +
|
| 45 | + # Install dependencies and handle caching in one go. |
| 46 | + # @link https://github.com/marketplace/actions/install-composer-dependencies |
| 47 | + - name: Install Composer dependencies |
| 48 | + uses: "ramsey/composer-install@v1" |
| 49 | + |
| 50 | + - name: Install xmllint |
| 51 | + run: sudo apt-get install --no-install-recommends -y libxml2-utils |
| 52 | + |
| 53 | + # Show XML violations inline in the file diff. |
| 54 | + # @link https://github.com/marketplace/actions/xmllint-problem-matcher |
| 55 | + - uses: korelstar/xmllint-problem-matcher@v1 |
| 56 | + |
| 57 | + # Validate the XML file. |
| 58 | + # @link http://xmlsoft.org/xmllint.html |
| 59 | + - name: Validate rulesets against schema |
| 60 | + run: xmllint --noout --schema vendor/squizlabs/php_codesniffer/phpcs.xsd ./*/ruleset.xml |
| 61 | + |
| 62 | + # Check the code-style consistency of the XML file. |
| 63 | + - name: Check XML code style |
| 64 | + run: | |
| 65 | + diff -B ./PHPCSUtils/ruleset.xml <(xmllint --format "./PHPCSUtils/ruleset.xml") |
| 66 | + diff -B ./PHPCS23Utils/ruleset.xml <(xmllint --format "./PHPCS23Utils/ruleset.xml") |
| 67 | +
|
| 68 | + # Check the code-style consistency of the PHP files. |
| 69 | + - name: Check PHP code style |
| 70 | + run: vendor/bin/phpcs |
| 71 | + |
| 72 | + # Validate the composer.json file. |
| 73 | + # @link https://getcomposer.org/doc/03-cli.md#validate |
| 74 | + - name: Validate Composer installation |
| 75 | + run: composer validate --no-check-all --strict |
0 commit comments