Stop reusing core's commit-code-check.sh in favor of 4 simple commands

Created on 21 February 2023, over 1 year ago
Updated 23 February 2023, over 1 year ago

Problem/Motivation

In drupalci.yml we currently copy and edit core's commit-code-check.sh file and then run it.

This means we can't run this easily locally. So if there is problem with the script we can only know if it fails or if we check the drupalci output. So miss problems like this ๐Ÿ› Fix PHPStan violations (happened because PHPStan code checks stopped runningโ€ฆ) Fixed

Steps to reproduce

Proposed resolution


Stop using commit-code-check.sh in favor of a handful of simple commands that A) are a lot easier to debug on DrupalCI, B) can also be run locally quite easily.

Remaining tasks

User interface changes

API changes

Data model changes

๐Ÿ“Œ Task
Status

Fixed

Version

3.0

Component

Code

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States tedbow Ithaca, NY, USA

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

Comments & Activities

  • Issue created by @tedbow
  • @tedbow opened merge request.
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Well well โ€ฆ as promised during yesterday's meeting, I looked into solving this challenge in core. So I found @phenaproxima's โœจ Make it possible for contrib modules to reuse core's commit-code-check.sh Needs work which is blocked on ๐Ÿ“Œ Fix cspell use: specify globRoot and always pass --root to cspell Fixed . So I spent yesterday solving that.

    In doing so, I discovered Drupal core had not been running PHPStan/cspell/โ€ฆ either!

    I reported that very late in my day yesterday and overnight it was fixed in ๐Ÿ› Fix commit-code-check.sh on DrupalCI Fixed .

    Now that is out of the way, AU's script is failing in a different way:

    00:01:48.682 modules/contrib/automatic_updates/commit-code-check.sh --drupalci
    00:01:48.764 warning: unable to access 'modules/contrib/automatic_updates/.gitignore': Permission denied
    00:01:48.764 warning: could not open directory 'modules/contrib/automatic_updates/tests/': Permission denied
    00:01:48.764 warning: could not open directory 'modules/contrib/automatic_updates/src/': Permission denied
    00:01:48.764 warning: could not open directory 'modules/contrib/automatic_updates/scripts/': Permission denied
    00:01:48.764 warning: could not open directory 'modules/contrib/automatic_updates/package_manager/': Permission denied
    00:01:48.764 warning: could not open directory 'modules/contrib/automatic_updates/css/': Permission denied
    00:01:48.764 warning: could not open directory 'modules/contrib/automatic_updates/config/': Permission denied
    00:01:48.764 warning: could not open directory 'modules/contrib/automatic_updates/automatic_updates_extensions/': Permission denied
    

    @omkar.podey is investigating this at #3341224-14: Always catch \Throwable, not \Exception and always pass the old exception when re-throwing. โ†’ .

  • Status changed to Postponed over 1 year ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ
  • Assigned to Wim Leers
  • Status changed to Postponed: needs info over 1 year ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    I left out the juiciest bit in #4:

    00:01:48.682 modules/contrib/automatic_updates/commit-code-check.sh --drupalci
    00:01:48.764 warning: unable to access 'modules/contrib/automatic_updates/.gitignore': Permission denied
    00:01:48.764 warning: could not open directory 'modules/contrib/automatic_updates/tests/': Permission denied
    00:01:48.764 warning: could not open directory 'modules/contrib/automatic_updates/src/': Permission denied
    00:01:48.764 warning: could not open directory 'modules/contrib/automatic_updates/scripts/': Permission denied
    00:01:48.764 warning: could not open directory 'modules/contrib/automatic_updates/package_manager/': Permission denied
    00:01:48.764 warning: could not open directory 'modules/contrib/automatic_updates/css/': Permission denied
    00:01:48.764 warning: could not open directory 'modules/contrib/automatic_updates/config/': Permission denied
    00:01:48.764 warning: could not open directory 'modules/contrib/automatic_updates/automatic_updates_extensions/': Permission denied
    00:02:06.564 
    1/3 /var/www/html/.gitattributes 680.12ms
    00:02:07.536 
    2/3 /var/www/html/README.md 101.96ms
    00:02:07.639 
    3/3 /var/www/html/composer.json 144.73ms
    00:02:07.785 CSpell: Files checked: 3, Issues found: 0 in 0 files
    00:02:07.812 
    00:02:07.812 CSpell: passed
    00:02:07.812 
    00:02:07.812 ----------------------------------------------------------------------------------------------------
    00:02:07.812 
    00:02:07.812 Running PHPStan on *all* files.
    00:03:29.644 
    00:03:29.650  [OK] No errors                                                                 
    00:03:29.650 
    00:03:29.693 
    00:03:29.693 PHPStan: passed
    00:03:29.693 
    00:03:29.693 ----------------------------------------------------------------------------------------------------
    00:03:36.946 .........W...E........E.EEEEEEEBuild timed out (after 110 minutes). Marking the build as aborted.
    01:50:00.428 Build was aborted
    01:50:00.429 Archiving artifacts
    

    โ†’ the problems in #4 are just the early ones, PHPSTan eventually runs forever and that's really the problem here.

    I don't see yet how ๐Ÿ› Fix commit-code-check.sh on DrupalCI Fixed could cause this.

    Still investigating over at ๐Ÿ“Œ Always catch \Throwable, not \Exception, and pass the old exception when re-throwing. Fixed โ€ฆ

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Update: set -xev helps us understand this:

    00:01:58.137 + DEPENDENCIES_NEED_INSTALLING=0
    00:01:58.137 # Ensure PHP development dependencies are installed.
    00:01:58.137 # @todo https://github.com/composer/composer/issues/4497 Improve this to
    00:01:58.137 #  determine if dependencies in the lock file match the installed versions.
    00:01:58.137 #  Using composer install --dry-run is not valid because it would depend on
    00:01:58.137 #  user-facing strings in Composer.
    00:01:58.137 if ! [[ -f '/var/www/html/vendor/bin/phpcs' ]]; then
    00:01:58.137   printf "Drupal's PHP development dependencies are not installed. Run 'composer install' from the root directory.\n"
    00:01:58.137   DEPENDENCIES_NEED_INSTALLING=1;
    00:01:58.137 fi
    00:01:58.137 + [[ -f /var/www/html/vendor/bin/phpcs ]]
    00:01:58.137 modules/contrib/automatic_updates/commit-code-check.sh: 186: [[: not found
    00:01:58.137 + printf Drupal's PHP development dependencies are not installed. Run 'composer install' from the root directory.\n
    00:01:58.137 + DEPENDENCIES_NEED_INSTALLING=1
    

    โ€” https://dispatcher.drupalci.org/job/drupal8_contrib_patches/145897/console

    โ†’ it appears that phpcs is not installed? That seems odd.

    also: I was wrong in #6: that output shows pretty clearly that phpstan finishes just fine; the next thing to run is phpcs, and that's what fails/runs forever! Somehow ๐Ÿ˜ณ So that could be explained by the above. Although it's then pretty mysterious why the error would have be swallowed prior to the set -xevโ€ฆ

    ๐Ÿ•ต๏ธโ€โ™€๏ธ

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    While breaking my head over this, here's an alternative attempted work-aroundโ€ฆ

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    That worked for phpcs and phpstan, but not yet cspell and eslint. Adding debug outputโ€ฆ

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Ah, so /var/www/html/core is not the core subdirectory of coreโ€ฆ

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    More debug output. This is very confusing.

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Looks like cd results are lost in this context โ€ฆ so let's put it all in a single line instead then.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    In the proposed resolution, we would have committed a copy of commit-code-check.sh that hardcodes DrupalCI's absolute paths, so it still would not have worked locallyโ€ฆ

    Besides, no module is even remotely as big as Drupal core. So the many optimizations in that script to only check the files that have changed is really premature optimization/unjustifiable complexity.

    So โ€ฆ we can make this ๐Ÿ’ฏ times simpler.

  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ
  • Issue was unassigned.
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    #15 works.

    1. It runs phpcs and finds no violations ๐Ÿ‘
    2. It catches all phpstan violations that ๐Ÿ› Fix PHPStan violations (happened because PHPStan code checks stopped runningโ€ฆ) Fixed is fixing. ๐Ÿ‘
    3. It finds spelling violations because I am not yet incorporating our dictionary. ๐Ÿ‘
    4. It finds a weird problem in our drupalci.yml file โ€” this is the sole thing that probably needs double-checking โ€” running the same command locally definitely detects a wrongly formatted routes YAML file!

    Need confirmation that we want to go this direction. Only cspell dictionary and the drupalci.yml problems remain to be solved, other than that this is already ready!

  • Assigned to Wim Leers
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Discussed with @tedbow and @phenaproxima. They're on board! ๐Ÿฅณ

    Let's finish this.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    30 minutes searching for this โ€ฆ ๐Ÿ˜ฌ cspell's DX can be improved quite a bit stillโ€ฆ

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Thanks to https://github.com/streetsidesoftware/cspell/pull/966, we can easily make cspell discover our dictionary ๐Ÿ‘

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ
    1. Stop spellchecking pcre.ini and README.md, neither of which will go into core anyway
    2. Add --no-progress so cspell's output is not ridiculously overwhelming and detailed.
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Moved it all into a script: scripts/commit-code-check.sh. And calling that. So that delivers on @tedbow's original hope/vision ๐Ÿ˜Š

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Make --drupalci flag work and chmod a+x.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Whoops, that $FINAL_STATUS was not yet being respected.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Simplify by introducing a few bash functions, that also allows for much better consistency!

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    #24 looks like this:

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Fix the phpcs violation that landed last night.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Merging in ๐Ÿ› Fix PHPStan violations (happened because PHPStan code checks stopped runningโ€ฆ) Fixed by doing curl https://git.drupalcode.org/project/automatic_updates/-/merge_requests/708.diff | git apply -3v && git ci -nam "Yash's phpstan fixes" and generating a new patch โ€” this should be green ๐Ÿค“

  • Assigned to tedbow
  • Status changed to RTBC over 1 year ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Looks like @yash still has some work cut out for him!

    Please commit #26 first right now, so that @yash.rode can continue in ๐Ÿ› Fix PHPStan violations (happened because PHPStan code checks stopped runningโ€ฆ) Fixed tomorrow :)

    (If you prefer, you could choose to disable the phpstan checking by commenting that one line in there, but I think that's not really helping us.)

    For the committer:

    +++ b/scripts/commit-code-check.sh
    @@ -0,0 +1,120 @@
    +print_title "[1/4] PHPCS"
    +$CORE_DIRECTORY/vendor/bin/phpcs $MODULE_DIRECTORY -ps --standard="$CORE_DIRECTORY/core/phpcs.xml.dist"
    +print_results $? "PHPCS"
    +
    +print_title "[2/4] PHPStan"
    +php -d apc.enabled=0 -d apc.enable_cli=0 $CORE_DIRECTORY/vendor/bin/phpstan analyze --no-progress --configuration="$CORE_DIRECTORY/core/phpstan.neon.dist" $MODULE_DIRECTORY
    +print_results $? "PHPStan"
    +
    +print_title "[3/4] CSpell"
    +cd $CORE_DIRECTORY/core && yarn run -s spellcheck --no-progress --root $MODULE_DIRECTORY -c .cspell.json "**" && cd -
    +print_results $? "CSpell"
    +
    +print_title "[4/4] eslint:yaml"
    +cd $CORE_DIRECTORY/core && yarn eslint --resolve-plugins-relative-to . --ext .yml $MODULE_DIRECTORY && cd -
    +print_results $? "eslint:yaml"
    +print_separator
    

    This is really how we run tests.

    Everything else is for:
    - documentation
    - supporting a --drupalci flag, just like core's script
    - setting up variables for colored output, just like core's script
    - existing the script with a computed "final status" just like the core script
    - discovering the core directory

    โ€ฆ but with far less repetition thanks to print_seprator, print_title and print_results helper functions

  • Status changed to Fixed over 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States tedbow Ithaca, NY, USA

    @Wim Leers ๐Ÿ™๐Ÿ™๐Ÿ™๐Ÿ™๐Ÿ™๐Ÿ™๐Ÿ™๐Ÿ™

    I committed this with the phpstan part commented out but just pushed a change to ๐Ÿ› Fix PHPStan violations (happened because PHPStan code checks stopped runningโ€ฆ) Fixed that uncomments this

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States tedbow Ithaca, NY, USA

    Working on possible follow-up

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    That is one weird follow-up ๐Ÿคฃ Where are you going with that?!

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Extracted some of the key simplifications this has compared to core's script into a core patch: ๐Ÿ“Œ Simplify commit-code-check.sh: reduce repetition Needs work .

  • Issue was unassigned.
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    This was blocking the path to core for sure!

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

Production build 0.69.0 2024