Problem/Motivation

Problem occurs on version 1.7.1 of gitlab-ci - https://www.drupal.org/project/gitlab_templates/issues/3503613#comment-1...

Issue with PHPCs and PHPStan during pipeline execution:

For example:

Issue fork droopler-3503626

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

damian.skiba created an issue. See original summary.

damian.skiba’s picture

Issue summary: View changes

jonathan1055 made their first commit to this issue’s fork.

jonathan1055’s picture

Thanks for opening this issue. I have used it to test out some ideas about how to make phpcs ignore certain folders in a project's own directory structure. I created a phpcs.xml.dist file in the project top folder, but it also required some customization in the actual phpcs: script: part of the pipeline. Here is a summary of the results, which shows in principle that this works:

Added one phpcs fault. Added verbose -v flag to show which files are now being checked. When the 'web' folder is correctly ignored there are just 16 files which are considered to contain php code. The log shows:

Registering sniffs in the droopler standard... DONE (131 sniffs registered)
Creating file list... DONE (16 files in queue)

https://git.drupalcode.org/issue/droopler-3503626/-/jobs/4209476

Without -v verbose output
https://git.drupalcode.org/issue/droopler-3503626/-/jobs/4209827

Removed the forced error, all clean green
https://git.drupalcode.org/issue/droopler-3503626/-/jobs/4209839

MR18 is not ready for committing, because the customizations should really be done in Gitlab Templates, see #3380694: Add basepath parameter to PHP Code Sniffer so that paths are relative. When that issue is ready I will use this MR to test it.

jonathan1055’s picture

Status: Active » Needs review

I have found a simpler way for you to fix the phpcs and phpstan problems, and not have to pin your Gitlab Templates version to 1.6.14 but allow you to return to using the default version. The recursion problems in PHPStan were due to this project having a /web/ folder at the top of the project repository. This is a perfectly valid thing to do, and you do not need to change it. The problem is that the pipeline build process also creates a 'web' folder at top level. The name of this folder is arbitrary and we already provide a variable _WEB_ROOT to hold the value, which defaults to 'web'. But if you specify a different name in your .gitlab-ci.yml file then the problems do not occur.

MR18 now demonstrates this - see the pipeline https://git.drupalcode.org/issue/droopler-3503626/-/pipelines/413632
The phpstan job runs and passes green.
The phpcs job now validly checks your project's 'web' folder, and we see

Registering sniffs in the drupal-project standard... DONE (131 sniffs registered)
Creating file list... DONE (24 files in queue)
FILE: web/profiles/droopler/src/Form/RecipesForm.php
-------------------------------------------------------------------------
FOUND 7 ERRORS AND 1 WARNING AFFECTING 8 LINES

These are valid phpcs errors and warnings, they were not being reported previously because the "web" folder was being ignored (regardless of whether a project had their own or not). That problem was fixed in gitlab templates issue #3497525: Only symlink to the project's own files which is what exposed the problem you reported.

I have removed the testing changes, so MR18 is now ready for review

damian.skiba’s picture

Status: Needs review » Fixed

Thank you, Jonathan1055 and Fjgarlin, for your help with resolving the issue.

damian.skiba’s picture

Status: Fixed » Closed (fixed)
jonathan1055’s picture

Title: [Gitlab] Pipeline task fails » [Gitlab] Pipeline task fails - change $_WEB_ROOT

You are welcome, and thank you for bringing the problem to our attention. We are working on a solution to detect when the project has a directory matching _$WEB_ROOT and give an informative message in the log.

grzegorz.bartman’s picture