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>