Make it possible for contrib modules to reuse core's commit-code-check.sh

Created on 7 October 2022, about 2 years ago
Updated 24 May 2023, over 1 year ago

Problem/Motivation

Once upon a time, in the ckeditor5 contrib module, commit-code-check.sh was used to do core-quality code checks on Drupal CI. This necessitated a bunch of awkward sed calls and other very hacky dance moves.

Automatic Updates does the same thing. I'm sure it would help Project Browser too. Or anything else that is developed first in contrib, for eventual inclusion in core.

Proposed resolution

Make it possible for commit-code-check.sh to run against a particular directory.

This will enable any Drupal contrib module to add this to their drupalci.yml:

      container_command.commit-checks:
        commands:
          - ../../../core/scripts/dev/commit-code-check.sh --drupalci
        halt-on-fail: true

… and get the same exact checks as core does:

This would allow every contrib module that chooses to do so, to follow the lead of continuously matching core's evolving best practices.

Remaining tasks

Implement this in a merge request and manually test it. Then, RTBC and merge it, and rejoice! Standard procedure.

User interface changes

TBD; I'm not sure commit-code-check.sh counts as a user interface.

API changes

TBD; I'm not sure it counts as an API either.

Data model changes

None.

Release notes snippet

TBD, but this being an internal development script, I doubt it will need one.

✨ Feature request
Status

Needs work

Version

11.0 πŸ”₯

Component
OtherΒ  β†’

Last updated about 9 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    This came up again, because of πŸ› Fix PHPStan violations (happened because PHPStan code checks stopped running…) Fixed . Let's make this happen πŸ™

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    I've fixed πŸ“Œ Fix cspell use: specify globRoot and always pass --root to cspell Fixed . Please review, so we can move forward here :)

  • Status changed to Needs work over 1 year ago
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί
  • @xjm opened merge request.
  • First commit to issue fork.
  • Status changed to Needs review over 1 year ago
  • last update over 1 year ago
    29,367 pass, 2 fail
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    Rather than recreating this MR to target 11.x, I'm just uploading it as a patch. (Also, the conflict that πŸ“Œ Fix cspell use: specify globRoot and always pass --root to cspell Fixed caused was not resolved correctly in the existing MR. πŸ˜… But it's tricky!)

    Also because creating a new branch endlessly tells me πŸ€ͺ😬😬

    This patch correctly resolves the conflict: πŸ“Œ Fix cspell use: specify globRoot and always pass --root to cspell Fixed already did everything we needed! 😊

  • last update over 1 year ago
    29,390 pass
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί
    +++ b/core/scripts/dev/commit-code-check.sh
    @@ -109,6 +109,8 @@
    +DRUPAL_ROOT=${DRUPAL_ROOT:="$TOP_LEVEL"}
    

    We can do better than this I think.

    This means that you would have to first cd into the contrib module and then specify the Drupal root manually:

    cd modules/contrib/cdn
    DRUPAL_ROOT=<SOMETHING> sh ../../../core/scripts/dev/commit-code-check.sh
    

    … but the script is already in Drupal core. So why don't we use that to determine the Drupal root? πŸ€“

  • Assigned to wim leers
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    #13 works fine:

    $ sh ../../../core/scripts/dev/commit-code-check.sh 
    /Users/wim.leers/core/modules/contrib/automatic_updates
     1/13 /Users/wim.leers/core/modules/contrib/automatic_updates/3347584-2.patch 170.51ms
     2/13 /Users/wim.leers/core/modules/contrib/automatic_updates/3350457-2.patch 4.88ms
     3/13 /Users/wim.leers/core/modules/contrib/automatic_updates/3350568-10.patch 5.31ms
     4/13 /Users/wim.leers/core/modules/contrib/automatic_updates/3350568-11.patch 5.46ms
     5/13 /Users/wim.leers/core/modules/contrib/automatic_updates/3350568-18.patch 14.84ms
     6/13 /Users/wim.leers/core/modules/contrib/automatic_updates/3350568.patch 3.15ms
     7/13 /Users/wim.leers/core/modules/contrib/automatic_updates/3351895-41-update-core-MR-converter-do-not-test.patch 2.38ms
     8/13 /Users/wim.leers/core/modules/contrib/automatic_updates/3351895-41-update-core-MR-converter.patch 1.85ms
     9/13 /Users/wim.leers/core/modules/contrib/automatic_updates/3354914-5.patch 5.33ms
    10/13 /Users/wim.leers/core/modules/contrib/automatic_updates/drupalci.yml 4.82ms
    11/13 /Users/wim.leers/core/modules/contrib/automatic_updates/f 2.96ms
    12/13 /Users/wim.leers/core/modules/contrib/automatic_updates/mirror.patch 10.13ms
    13/13 /Users/wim.leers/core/modules/contrib/automatic_updates/next 1.95ms
    CSpell: Files checked: 13, Issues found: 0 in 0 files
    
    CSpell: passed
    

    Note that cSpell automatically picked up the .cspell.json in that module (i.e. the current working directory)!

    Contrast that with:

    $ sh ../../../core/scripts/dev/commit-code-check.sh 
     1/22 /Users/wim.leers/core/modules/contrib/cdn/.phpcs-cache 279.23ms X
    /Users/wim.leers/core/modules/contrib/cdn/.phpcs-cache:1:9746 - Unknown word (Validatable)
    /Users/wim.leers/core/modules/contrib/cdn/.phpcs-cache:1:415639 - Unknown word (Farfuture)
    /Users/wim.leers/core/modules/contrib/cdn/.phpcs-cache:1:440137 - Unknown word (Farfuture)
    …
    /Users/wim.leers/core/modules/contrib/cdn/tests/src/Functional/CdnIntegrationTest.php:207:55 - Unknown word (Farfuture)
    /Users/wim.leers/core/modules/contrib/cdn/tests/src/Functional/CdnIntegrationTest.php:220:27 - Unknown word (Farfuture)
    CSpell: Files checked: 22, Issues found: 95 in 17 files
    
    CSpell: failed
    

    That module does not have a .cspell.json πŸ‘

    Next up: phpstan.

  • last update over 1 year ago
    Build Successful
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    First let's stop running all tests, we only want the commit checks. Let's save some DrupalCI cycles 😊

  • last update over 1 year ago
    188 pass
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    Apparently we need some test results for it to succeed.

  • last update over 1 year ago
    188 pass
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    Now also works for phpstan:

    $ sh ../../../core/scripts/dev/commit-code-check.sh 
     1/14 /Users/wim.leers/core/modules/contrib/automatic_updates/3347584-2.patch 173.93ms
     2/14 /Users/wim.leers/core/modules/contrib/automatic_updates/3350457-2.patch 4.57ms
     3/14 /Users/wim.leers/core/modules/contrib/automatic_updates/3350568-10.patch 5.71ms
     4/14 /Users/wim.leers/core/modules/contrib/automatic_updates/3350568-11.patch 5.59ms
     5/14 /Users/wim.leers/core/modules/contrib/automatic_updates/3350568-18.patch 15.23ms
     6/14 /Users/wim.leers/core/modules/contrib/automatic_updates/3350568.patch 3.29ms
     7/14 /Users/wim.leers/core/modules/contrib/automatic_updates/3351895-41-update-core-MR-converter-do-not-test.patch 2.75ms
     8/14 /Users/wim.leers/core/modules/contrib/automatic_updates/3351895-41-update-core-MR-converter.patch 1.87ms
     9/14 /Users/wim.leers/core/modules/contrib/automatic_updates/3354914-5.patch 3.47ms
    10/14 /Users/wim.leers/core/modules/contrib/automatic_updates/drupalci.yml 9.52ms
    11/14 /Users/wim.leers/core/modules/contrib/automatic_updates/f 2.94ms
    12/14 /Users/wim.leers/core/modules/contrib/automatic_updates/mirror.patch 6.17ms
    13/14 /Users/wim.leers/core/modules/contrib/automatic_updates/next 2.00ms
    14/14 /Users/wim.leers/core/modules/contrib/automatic_updates/package_manager/tests/src/Kernel/PackageManagerKernelTestBase.php 48.94ms
    CSpell: Files checked: 14, Issues found: 0 in 0 files
    
    CSpell: passed
    
    ----------------------------------------------------------------------------------------------------
    
    Running PHPStan on *all* files.
    
                                                                                                                            
     [OK] No errors                                                                                                         
                                                                                                                            
    
    
    PHPStan: passed
    

    πŸ‘† This means it works, because if it were using core's phpstan.neon.dist, it would fail: there's additional ignoreErrors entries! πŸ₯³

  • Issue was unassigned.
  • last update over 1 year ago
    Custom Commands Failed
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    And now everything else:

    1. phpcs
    2. And under for FILE in $FILES; do, running:
      1. stat permissions checks
      2. phpcs on YAML
      3. eslint
      4. PCSS β†’ CSS compiling

    πŸ‘

    Specifically skipped for non-core projects, because they're highly specific to Drupal core:

    1. yarn run -s lint:core-js-passing
    2. yarn run -s lint:css
    3. yarn run -s check:ckeditor5
    4. yarn run build:css --check

    And under for FILE in $FILES; do, skipped these:

    1. # Don't commit changes to vendor.
    2. # Don't commit changes to core/node_modules.
    3. phpcs on PHP files/code> β†’ because we've already scanned <em>everything</em> above, so no more need to scan one-by-one!</li>
      </ol>
      
      Resulting output:
      <code>
      $ sh ../../../core/scripts/dev/commit-code-check.sh
      1/3 /Users/wim.leers/core/modules/contrib/automatic_updates/drupalci.yml 175.53ms
      2/3 /Users/wim.leers/core/modules/contrib/automatic_updates/next 4.37ms
      3/3 /Users/wim.leers/core/modules/contrib/automatic_updates/package_manager/tests/src/Kernel/PackageManagerKernelTestBase.php 55.63ms
      CSpell: Files checked: 3, Issues found: 0 in 0 files
      
      CSpell: passed
      
      ----------------------------------------------------------------------------------------------------
      
      Running PHPStan on *all* files.
      
                                                                                                                              
       [OK] No errors                                                                                                         
                                                                                                                              
      
      
      PHPStan: passed
      
      ----------------------------------------------------------------------------------------------------
      ............................................................  60 / 332 (18%)
      ............................................................ 120 / 332 (36%)
      .....S...................................................... 180 / 332 (54%)
      ............................................................ 240 / 332 (72%)
      ............................................................ 300 / 332 (90%)
      ................................                             332 / 332 (100%)
      
      
      Time: 2.81 secs; Memory: 20MB
      
      
      PHPCS: passed
      
      ----------------------------------------------------------------------------------------------------
      Checking next
      
      next passed
      
      ----------------------------------------------------------------------------------------------------
      Checking drupalci.yml
      
      ESLint: drupalci.yml passed
      drupalci.yml passed
      
      ----------------------------------------------------------------------------------------------------
      Checking package_manager/tests/src/Kernel/PackageManagerKernelTestBase.php
      
      package_manager/tests/src/Kernel/PackageManagerKernelTestBase.php passed
      
      ----------------------------------------------------------------------------------------------------
      

      πŸ‘† this means that modules/contrib/automatic_updates/drupalci.yml could use:

            container_command.commit-checks:
              commands:
                - ../../../core/scripts/dev/commit-code-check.sh --drupalci
              halt-on-fail: true
      

      … and that's all it would take for a contrib module to adopt this!

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    While the original title was accurate, I think this title better reflects the ecosystem impact this is aiming at! 😊

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    Adding a second and third example to the issue summary.

  • last update over 1 year ago
    Custom Commands Failed
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    I got something wrong in the PHPStan one.

  • Status changed to Needs work over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    Tests not passing...?

Production build 0.71.5 2024