Problem/Motivation

Hi,

composer-lint job fails while it says that composer.json is valid: https://git.drupalcode.org/project/sobki_theme_admin/-/jobs/1181958

Proposed resolution

The job fails on projects where there are no files that match .php, .inc, .module or .install
So the job can check for the existence of atleast one of these before running parallel-lint

Update doc page

Here is a view of how the updated doc page will appear
https://git.drupalcode.org/issue/gitlab_templates-3436819/-/blob/3436819...

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

Grimreaper created an issue. See original summary.

jonathan1055’s picture

$ composer validate
./composer.json is valid
$ vendor/bin/parallel-lint --version
PHP Parallel Lint version 1.4.0
$ vendor/bin/parallel-lint --no-progress -e php,module,install,inc $_PARALLEL_LINT_EXTRA --exclude $_WEB_ROOT --exclude ./vendor .
PHP 8.1.27 | 10 parallel jobs
No file found to check.

Is it giving a failiing exit code because there are no files to check? Maybe there is some kind of --no-files-no-failure option to set, like there is on other linting jobs?
Alternatively we test for the existence of one of those types of files, and don't run the parallel-lint call if there are none?

jonathan1055’s picture

One option would be to add

    - exists:
        - "**/*.php"
        - "**/*.module"
        - "**/*.install"
        - "**/*.inc"

to the job, but that would not allow your checking on composer.json, because the job would not get added in the first place. Maybe it's better to check for the files within the script.

jonathan1055’s picture

Untested. No idea if this is going to work. It does display the files locally, so that will need to be tidied up.

jonathan1055’s picture

Status: Active » Needs review

I've worked out a solution, and this is now ready for review. To give some backgroud, using Scheduler as my test module, the current job gives

/builds/project/scheduler
$ vendor/bin/parallel-lint --no-progress -e php,module,install,inc $_PARALLEL_LINT_EXTRA --exclude $_WEB_ROOT --exclude vendor  .
PHP 8.1.27 | 10 parallel jobs
Checked 136 files in 0.3 seconds

I used find to check if there are any files with extensions php,module,install or inc, but this returned all the php in the vendor folders. Then I thought about changing directory to modules/custom/{project} to count the php files there. But running parallel-lint there gives

$ cd $CI_PROJECT_DIR/$_WEB_ROOT/modules/custom/$CI_PROJECT_NAME
$ pwd
/builds/project/scheduler/web/modules/custom/scheduler
$ $CI_PROJECT_DIR/vendor/bin/parallel-lint -e php,module,install,inc --show-deprecated $_PARALLEL_LINT_EXTRA .
PHP 8.1.27 | 10 parallel jobs
Checked 4 files in 0 seconds

Only four files were tested, not 136. After a bit of investigation I realised that these four are the only matching files in the project top-level folder, all the rest are sub-folders src, tests, etc. The parallel-lint command does not follow symlinked files in sub-folders, but it could read the four symlinked files at the top level. To verify this I used

$ find . -type f | grep -E "\.(php|module|install|inc)$"

which finds nothing. But changing -type f to -type l to look for symlinks and we get the four top-level files.

$ find . -type l | grep -E "\.(php|module|install|inc)$" || true
./scheduler.tokens.inc
./scheduler.module
./scheduler.install
./scheduler.api.php

and these four files must have been the only ones tested by parallel-lint. The results of all of the above with extra output can be seen in this test job https://git.drupalcode.org/project/scheduler/-/jobs/1201071

This shows me that we have to run parallel-lint at the root folder /projects/build/{project} - which is where it is done now. Therefore we search/count php files in $CI_PROJECT_DIR/$_WEB_ROOT/modules/custom/$CI_PROJECT_NAME but we do change directory, we run parallel-lint in the same place as now. find -L $_WEB_ROOT/modules/custom/$CI_PROJECT_NAME -type f | grep -E '\.(php|module|install|inc)$' does the checking. The addition of the -L argument is to allow find to follow symlinks, and this gives the correct number of files in the project.

Here's a test running MR168 with the new additions uncustomised.
https://git.drupalcode.org/project/scheduler/-/pipelines/133829

Here is a test showing what happens when no files are found (I just added ZZZ into the patten to ensure no match)
https://git.drupalcode.org/project/scheduler/-/pipelines/133802

jonathan1055’s picture

Title: Composer Lint fail while composer.json valid » Composer-lint fails if there are no php files in the project

I have tested this using sobki_theme_admin, the project for which Grimreaper raised this issue.

The issue is #3436970: Gitlab pipeline testing and MR is https://git.drupalcode.org/project/sobki_theme_admin/-/merge_requests/1

The parallel-lint job now passes not fails, and log says

/builds/issue/sobki_theme_admin-3436970
$ composer --version
Composer version 2.6.6 2023-12-08 18:32:26
$ composer validate
./composer.json is valid
$ vendor/bin/parallel-lint --version
PHP Parallel Lint version 1.4.0
There are no PHP files to validate.

See https://git.drupalcode.org/issue/sobki_theme_admin-3436970/-/jobs/1201439

grimreaper’s picture

Thanks a lot @jonathan1055!

One small comment on my review.

Could be RTBC from what I see on #3436970: Gitlab pipeline testing, but not changing the status as I think it needs a review from another maintainer.

fjgarlin’s picture

Status: Needs review » Reviewed & tested by the community

Happy for the pwd command to stay.

This looks great. Thanks also for the testing on project with and without files to run this parallel-lint job on.
RTBC, will probably commit it later today.

jonathan1055’s picture

Issue summary: View changes

Thanks. I just rebased again (no conflicts).
Are you OK with the added --show-deprecated parameter?

fjgarlin’s picture

Status: Reviewed & tested by the community » Needs work

I'd rather remove it and add it as part of the documentation as it can easily be set via _PARALLEL_LINT_EXTRA.
Moving to Needs work, but once that's removed and the documentation page has been updated it can go back to RTBC (or Needs review and I can give it a final review).

jonathan1055’s picture

Issue summary: View changes
Status: Needs work » Needs review

Yes, ok. I have removed the parameter and updated the docs. Here's the new page. I made a few other additions to it. Is there anything else to add whilst we are on this job?
https://git.drupalcode.org/issue/gitlab_templates-3436819/-/blob/3436819...

fjgarlin’s picture

Status: Needs review » Reviewed & tested by the community

I made a really minor suggestion to the documentation file (mostly wrapping things around backticks as it renders nicely in markdown), but everything is great and ready to be merged.

I can apply that suggestion before merging or you are free to do it if you think it's valid.

RTBC.

fjgarlin’s picture

Status: Reviewed & tested by the community » Fixed

Merged, thanks so much!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.