Problem/Motivation
In GitLabCI testing now that Drupal 11.1 is the current version, I have started to see this PHPCS failure:
FILE: ...builds/project/ip2country/web/modules/custom/ip2country/recipes/README.txt
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
9 | ERROR | [x] Expected 1 newline at end of file; 2 found
| | (Drupal.Files.EndFileNewline.TooMany)
--------------------------------------------------------------------------------See https://git.drupalcode.org/project/ip2country/-/jobs/3792045
The problem showed up in my weekly scheduled testing as of 21 Dec - this did not happen in the previous test on 14 Dec when the current core version was 11.0.
Note that the recipes/README.txt is not present in my project's repository, so I assume this is something that is added during GitLabCI testing. Regardless, it's not part of my project so I can't fix it in my project.
I think that what is happening is that core/assets/scaffold/files/recipes.README.txt is being copied into my project for testing purposes (why?).
This core README.txt does have the above problem - there's a blank line at the end when there shouldn't be. This was committed in #3447886: Add support for recipes to drupal/recommended-project and drupal/legacy-project, so perhaps someone can look to see how that was put into core with a PHPCS violation?
Here's a patch to fix that file, which hopefully trickles down to fix the issue in my project's testing.
Issue fork drupal-3495586
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:
- 3495586-phpcs-error-in
changes, plain diff MR !10651
Comments
Comment #3
quietone commentedThe PHPCS checks in core do not check
.txtfiles. It runs on these extensions,<arg name="extensions" value="engine,inc,install,module,php,profile,test,theme,yml"/>. Where the module ipcountry is using a custom phpcs.xml that is checking .txt files.I suggest that the custom phpcs.xml be modified to only check files in that module.
Comment #4
tr commentedAh, thank you for noticing that.
But still, why is recipe.README.txt being moved into my module's codebase on GitLabCI if I don't have any recipes in the module and I am not testing recipes?
I think it still makes sense to patch recipe.README.txt so that it complies with coding standards, even if core doesn't about checking .txt files.
Comment #5
quietone commentedI don't know why phpcs for the module is running phpcs on core files, that sounds like a question for the gitlab templates project.
Drupal does not have coding standards for .txt files, so there isn't currently anything to comply with. The standard that does exist about the end of a file is for PHP files. The closest issue I know about is the Coding Standards one for markdown, #2952616: Adopt CommonMark spec for Markdown files.
Comment #6
tr commentedNo, you misread. PHPCS is not running on a core file. The file in question is
FILE: ...builds/project/ip2country/web/modules/custom/ip2country/recipes/README.txt, which is a file inside the ip2country project folder. Presumably it was copied there by the GitLabCI job, because it is not present in the module's codebase.Comment #7
ghost of drupal pastI believe there are two independent problems here:
1. Trivial core fix to delete the spurious newline
2. Figure it out whether the core composer.json or https://git.drupalcode.org/project/gitlab_templates/-/blob/main/scripts/... causes this
Comment #8
tr commentedYes, two independent issues, as you said. The MR addresses #1, but I don't know where to start with #2 because what's happening behind the scenes during GitLabCI deployment doesn't show up in the logs/artifacts.
I can narrow it down a bit because @quietone noted that my phpcs.xml.dist enables phpcs checking of txt files, while the core default does not check txt files.
Upon further examination, I see this exact same phpcs error on
[modulename]/recipes/README.txtin every project I own that does phpcs checks on txt files. If you don't enable phpcs checks on txt files, you will never notice thatrecipes.README.txtfile is getting copied into every project during GitLabCI testing.I had tagged this issue with "Recipe initiative" because I though someone involved with the recipe project might recognize why this file is being copied into a contrib module folder.
Comment #9
tr commentedcore/composer.jsoncontains the following:As you can see, this is explicitly copying
recipes.README.txtinto the[project-root]directory, which is inside the contributed module when testing contributed modules. That it why it is present inside my module in GitLabCI testing, and that is why it is being tested when I run my module tests.This line of code in
core/composer.jsonwas explicitly added by the issue i cited in the OP: #3447886: Add support for recipes to drupal/recommended-project and drupal/legacy-projectSpecifically, it was added in that issue by @thejimbirch in https://git.drupalcode.org/project/drupal/-/merge_requests/8113/diffs?co... (without the extra blank line at the end of the README) then the extra whitespace was explicitly added by @alexpott in https://git.drupalcode.org/project/drupal/-/merge_requests/8113/diffs?co...
This is only done in core 11.1+ and is not present in core 11.0, which explains why this error only just started showing up when core 11.1 was released and GitLabCI started to use that as the default version.
Why is this done? Why does
recipes.README.txtneed to be copied into the tested contributed module's directory structure?As @ghost of drupal past said, this is two issues.
recipes.README.txtinto my project codebase? It is not explained in the original issue, and as far as I can see it only causes problems. Should I re-open that other issue?The objective is to have my tests stop failing because of this file that I don't want or need in my project codebase. The failures are due to actions taken by core in 11.1, and need to be fixed in core.
I added back the "Recipes initiative" tag because this change was made in an issue that also had this tag - this problematic change was clearly part of the recipes initiative.
Comment #10
cilefen commentedThis is RTBC for the newline quick fix.
Based on its contents the new README is meant to be scaffolded into a full Drupal site codebase, not into extension directories. The same must happen with
.gitattributesand.editorconfigbut to date I suppose those have been benign on CI. @tr: Whether we need a separate issue for solving that or if we should just continue here I'll leave to your discretion.Comment #11
tr commentedI'm happy to do it here, I just don't know *why* this is being put in
[project-root]instead of[web-root]. Was it just a mistake? Was it deliberate? I don't know the reason, and the reason wasn't explained in the issue that added it, and I am reluctant to move that file because it might break something I'm not aware of.That's why I'm asking for help here, and tagging it with "Recipes initiative" - to get the attention of someone who might know. I will also post a link to this issue in #3447886: Add support for recipes to drupal/recommended-project and drupal/legacy-project to hopefully get the attention of someone who might know.
Comment #12
thejimbirch commentedRecipes are applied to Drupal, they are not a part of Drupal with the exception of core’s recipes.
That is the reason the file is put in the project root and not the web root.
Comment #13
tr commentedThe question is, why is
recipe/REAME.txtbeing inserted into my contributed module's code base during testing? Why is it needed? Why is it in core composer.json as an asset file that needs to be copied somewhere?My module does not use recipes in any way.
That is not something my contributed module needs or wants, and is unexpected.
And as demonstrated here, it causes test failures when my contributed module is tested. Failures which do not show up in my local environment, because they are solely due to the test environment inserting unknown files into my code base.
They're not part of my contributed module either.
If that's the reason this file doesn't belong in [web-root], then it also doesn't belong in [project-root].
It doesn't belong there.
Comment #14
thejimbirch commentedAs far as I understand, the core recommended composer template is a recommendation on how to start a Drupal project using composer. Recipes are now a part of Drupal core.
While your issue here and the MR that fixes the errant extra line is in the recipes system, I feel like your comments are more about the testing system and why it uses the core recommended template that now includes recipes. That is beyond any of my knowledge, and I feel like it should have an additional issue in whatever issue queue is responsible for that.
Comment #15
tr commentedWhether it is used for deployment or testing, why does
recipe/README.txthave to be copied into a contributed module codebase?Again, unexpected, unneeded, and unwanted - it doesn't add anything to the contributed project. And in this case actually breaks something. It doesn't belong there.
Testing only has value if it is done in the same conditions as deployment. So if
drupal/core-recommendedis what people use to build Drupal sites, then that is *exactly* what should be used in testing.Comment #16
cilefen commented@tr: I think @thejimbirch agrees with you comments about CI but suggests you should open a separate issue for them, possibly in https://www.drupal.org/project/gitlab_templates.
Comment #17
alexpottCommitted and pushed d2e10cddc0b to 11.x and 0ae30d842e8 to 11.1.x. Thanks!
Comment #20
alexpottFWIW this happens because of the super odd way in which the contrib gitlab templates get your code in the correct place. See https://git.drupalcode.org/project/gitlab_templates/-/blob/main/scripts/... - this approach has always been fragile and we should change it. We should not be altering the code under-test in the way that we do. See also https://git.drupalcode.org/project/gitlab_templates/-/blob/main/scripts/... for how the project's composer.json is changed.
Comment #22
alexpottI've created #3501054: Change how the templates link the project into Drupal to address the root cause.