How to use custom PHP_CodeSniffer ruleset within reusable github actions workflow?

We have each of our custom modules in separate GitHub repositories that are managed via composer and would like to use PHP_CodeSniffer on the files within. We have also created a separate GitHub repository for reusable workflows that the module workflows will call.

The phpcs-ruleset.xml file that we want to use is located in the root of our workflows repository. At this point, PHP_CodeSniffer is running through the files of the module correctly and shows the errors that it finds but is not respecting the rules I’ve changed in the phpcs-ruleset.xml file, specifically the Generic.WhiteSpace.ScopeIndent properties I changed.

This is the reusable workflow currently:

name: Test versions of Drupal core and PHP on:   workflow_call:     inputs:       module-name:         required: true         type: string       dependencies:         required: false         type: string jobs:   testing:     name: Drupal ${{ matrix.drupal-core }} - PHP ${{ matrix.php-versions }}     runs-on: ubuntu-latest     strategy:       fail-fast: false       matrix:         drupal-core: ['9.2.x', '9.3.x']         php-versions: ['7.4', '8.0']     steps:       - name: Checkout Drupal core         uses: actions/checkout@v2         with:           repository: drupal/drupal           ref: ${{ matrix.drupal-core }}        - name: Checkout module         uses: actions/checkout@v2         with:           path: modules/${{ inputs.module-name }}        - name: Setup PHP, with composer and extensions         uses: shivammathur/setup-php@v2         with:           php-version: ${{ matrix.php-versions }}           coverage: none        - name: Get composer cache directory         id: composercache         run: echo "::set-output name=dir::$(composer config cache-files-dir)"        - name: Cache composer dependencies         uses: actions/cache@v2         with:           path: ${{ steps.composercache.outputs.dir }}           key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}           restore-keys: ${{ runner.os }}-composer-        - name: Install Drupal core dependencies         run: |           composer --no-interaction --no-progress --prefer-dist --optimize-autoloader install        - name: Install module dependencies         if: ${{ inputs.dependencies != '' }}         run: |           composer --no-interaction --no-progress require              ${{ inputs.dependencies }}        - name: Install Coder module         run: |           composer --dev --no-interaction --no-progress require              drupal/coder:8.3.15        - name: Check coding standards         run: |           ./vendor/bin/phpcs -p modules/${{ inputs.module-name }} 

This is the workflow in one of our custom module repositories that calls the reusable workflow:

name: Test versions of Drupal core and PHP on:   push:     branches: [ main ]   pull_request:     branches: [ main ] jobs:   test-drupal-and-php-versions-workflow:     uses: MyOrg/workflows/.github/workflows/drupal-php-test.yml@main     with:       module-name: ${{ github.event.repository.name }} 

and this is the custom PHP_CodeSniffer ruleset that I’m wanting to use, it doesn’t have many rules as of yet because I’m just trying to get it to work currently:

<?xml version="1.0" encoding="UTF-8"?> <ruleset name="phpcs-standard">   <description>Codestyle ruleset for Drupal</description>    <!-- Specify standards. -->   <rule ref="Drupal"/>   <rule ref="DrupalPractice"/>    <rule ref="Generic.WhiteSpace.ScopeIndent">     <properties>         <property name="indent" value="2" />         <property name="exact" value="true" />     </properties>   </rule>    <!-- Include path with the Drupal and DrupalPractice rules. -->   <config name="installed_paths" value="vendor/drupal/coder/coder_sniffer"/>    <!-- Set ignore extensions. -->   <arg name="ignore" value="*.css,*.md,*.txt"/>    <!-- Check all files in the current directory and below. -->   <file>.</file> </ruleset> 
This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

How to use custom PHP_CodeSniffer ruleset within reusable github actions workflow?

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.