ci: install phpcs + Drupal coding standard before unit tests#53
ci: install phpcs + Drupal coding standard before unit tests#53
Conversation
Co-authored-by: darrenoh <2293701+darrenoh@users.noreply.github.com>
.github/workflows/tests.yml
Outdated
|
|
||
| - name: Install PHP CodeSniffer with Drupal coding standard | ||
| run: | | ||
| composer global require "squizlabs/php_codesniffer=^4.0" "drupal/coder=^9.0" |
There was a problem hiding this comment.
Let's not lock versions. We always want to require the latest version.
There was a problem hiding this comment.
Done — updated to use =* for both packages in 0694631.
Co-authored-by: darrenoh <2293701+darrenoh@users.noreply.github.com>
darrenoh
left a comment
There was a problem hiding this comment.
The failing job is due to the following Composer error:
dealerdirect/phpcodesniffer-composer-installer (installed globally) contains a Composer plugin which is blocked by your allow-plugins config. You may add it to the list if you consider it safe.
You can run "composer global config --no-plugins allow-plugins.dealerdirect/phpcodesniffer-composer-installer [true|false]" to enable it (true) or disable it explicitly and suppress this exception (false)
See https://getcomposer.org/allow-plugins
Solution:
Add the plugin to Composer’s allow-plugins configuration before running composer global require in your workflow. Update your install step in .github/workflows/tests.yml as follows:
- name: Install PHP CodeSniffer with Drupal coding standard
run: |
composer global config --no-interaction allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
composer global require "squizlabs/php_codesniffer=*" "drupal/coder=*"
# Register the Drupal coding standard with phpcs
"$(composer global config bin-dir --absolute --quiet)/phpcs" \
--config-set installed_paths \
"$(composer global config home --quiet)/vendor/drupal/coder/coder_sniffer"
# Make phpcs available system-wide
sudo ln -sf "$(composer global config bin-dir --absolute --quiet)/phpcs" /usr/local/bin/phpcs
env:
COMPOSER_ALLOW_SUPERUSER: '1'This ensures the Composer plugin is explicitly allowed, fixing the error and unblocking the installation step.
There was a problem hiding this comment.
Pull request overview
This PR updates the CI unit-tests job to ensure PHP CodeSniffer (phpcs) and the Drupal coding standard are installed before the shell-based unit test suite runs, preventing tests/test-phpcs.sh from failing due to missing tooling.
Changes:
- Add a workflow step to install
squizlabs/php_codesnifferanddrupal/coderviacomposer global require - Configure
phpcsto recognize Drupal’s sniffs via--config-set installed_paths - Symlink
phpcsinto/usr/local/binso it’s available onPATHduring tests
You can also share your feedback on Copilot code review. Take the survey.
Co-authored-by: darrenoh <2293701+darrenoh@users.noreply.github.com>
Fixed in 261ef71 — added |
darrenoh
left a comment
There was a problem hiding this comment.
The job failed during the "test-phpcs" stage due to missing PHP_CodeSniffer sniffs from the Slevomat Coding Standard. The log reports errors such as:
- ERROR: Referenced sniff "SlevomatCodingStandard.Classes.BackedEnumTypeSpacing" does not exist.
- Several other SlevomatCodingStandard sniffs are also reported missing.
This indicates that the required Slevomat Coding Standard is not installed or is not available to PHP_CodeSniffer in your workflow.
Solution:
You need to ensure the Slevomat Coding Standard for PHP_CodeSniffer is installed and accessible before running phpcs. Typically, this is managed via Composer.
Code Fix
In your workflow definition (likely in .github/workflows/tests.yml), add or update the step that installs coding standards, for example:
- name: Install Slevomat Coding Standard
run: |
composer require --dev slevomat/coding-standard
./vendor/bin/phpcs --config-set installed_paths vendor/slevomat/coding-standardYou should place this step before running phpcs in your workflow. This ensures the Slevomat coding standard and all its referenced sniffs are available for phpcs runs.
Summary:
Install Slevomat Coding Standard via Composer and ensure it's registered with PHP_CodeSniffer. This will resolve the "sniff does not exist" errors and allow phpcs to apply your coding standards correctly.
… phpcs Co-authored-by: darrenoh <2293701+darrenoh@users.noreply.github.com>
Fixed in ea9cfb2 — removed the manual |
dealerdirect/phpcodesniffer-composer-installerplugin before requiring packagessquizlabs/php_codesniffer=*anddrupal/coder=*via Composer global (always latest)dealerdirectplugin auto-register all coding standards (drupal/coder + slevomat) — fixes missing SlevomatCodingStandard sniffs$GITHUB_PATHinstead of using a sudo symlink💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.