Move automated tests to GitLab CI

Created on 19 January 2024, 5 months ago
Updated 7 February 2024, 5 months ago

Problem/Motivation

All Drupal modules are encouraged to move their automated testing to GitLab.

Proposed resolution

  1. Add .gitlab-ci.yml following the instructions at GitLab CI β†’ .
  2. Add phpcs.xml and phpstan.neon so that static analysis follows Drupal standards.
  3. Add two dev requirements to composer.json so that PHPStan has access to them.
  4. Fix most coding standards violations with phpcbf.

Remaining tasks

User interface changes

None

API changes

None

Data model changes

None

πŸ“Œ Task
Status

Fixed

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States benjifisher Boston area

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

Merge Requests

Comments & Activities

  • Issue created by @benjifisher
  • Merge request !11Configure GitLab CI β†’ (Merged) created by benjifisher
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.x + Environment: PHP 8.2 & MySQL 8
    last update 5 months ago
    4 pass
  • Pipeline finished with Success
    5 months ago
    #79621
  • Status changed to Needs review 5 months ago
  • πŸ‡ΊπŸ‡ΈUnited States benjifisher Boston area

    You can confirm that the CI is running tests. See the results at https://git.drupalcode.org/project/rest_views/-/merge_requests/11/pipelines

    When MR !11 is merged, you (the maintainer) can go to https://www.drupal.org/node/2858988/qa β†’ and disable testing on the legacy DrupalCI, at least for the 3.0.x branch. I copied the link in the issue summary, GitLab CI β†’ , from that page.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.x + Environment: PHP 8.2 & MySQL 8
    last update 5 months ago
    4 pass
  • Pipeline finished with Success
    5 months ago
    #79628
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.x + Environment: PHP 8.2 & MySQL 8
    54:50
    54:06
    Running
  • Pipeline finished with Success
    5 months ago
    #79640
  • Issue was unassigned.
  • πŸ‡ΊπŸ‡ΈUnited States benjifisher Boston area

    I do not like failing tests, so I added some commits to keep phpcs and phpstan happy. I will add details to the issue summary.

  • First commit to issue fork.
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.x + Environment: PHP 8.2 & MySQL 8
    last update 5 months ago
    4 pass
  • Status changed to Needs work 5 months ago
  • πŸ‡ΊπŸ‡ΈUnited States nicxvan

    Thank you for this!

    I fixed a t() warning I still need to test.

    I also added four // phpcs:ignore comments because they are overriding core views methods so I'm not sure why those are throwing a warning still.

    The main issue is now that phpcs is passing stylelint is failing because it can't find a css file.

    Can we disable stylelint since this project has no css libraries?

  • πŸ‡ΊπŸ‡ΈUnited States benjifisher Boston area

    I think this explains why phpcs does not flag those violations in the core views module: from core/phpcs.xml.dist:

      <!-- Only include specific sniffs that pass. This ensures that, if new sniffs are added, HEAD does not fail.-->
    
      <!-- Drupal sniffs -->
      <rule ref="Drupal.Arrays.Array">
        <!-- Sniff for these errors: ArrayClosingIndentation, ArrayIndentation, CommaLastItem -->
        <exclude name="Drupal.Arrays.Array.LongLineDeclaration"/>
      </rule>
    ...
    
  • πŸ‡ΊπŸ‡ΈUnited States benjifisher Boston area

    It looks as though there are only three places where EXPORT_OPTIONS is used:

    class ListExportFormatter extends FormatterBase {
      const VALUE_LABEL    = 'value_label';
      const KEY_VALUE      = 'key_value';
      const EXPORT_OPTIONS = [
        self::VALUE_LABEL => 'Export label and value separately',
        self::KEY_VALUE   => 'Export as key/value',
      ];
    // ...
        $elements['export_format'] = [
          '#type'          => 'radios',
          '#title'         => $this->t('Export format'),
          '#default_value' => $this->getSetting('export_format'),
          '#options'       => array_map([$this, 't'], self::EXPORT_OPTIONS),
        ];
    // ...
        $summary[] = $this->t('@options', ['@options' => self::EXPORT_OPTIONS[$export_format]]);
    

    Really it should be done like this:

    class ListExportFormatter extends FormatterBase {
      const VALUE_LABEL    = 'value_label';
      const KEY_VALUE      = 'key_value';
      const EXPORT_OPTIONS = [
        self::VALUE_LABEL => $this->t('Export label and value separately'),
        self::KEY_VALUE   => $this->t('Export as key/value'),
      ];
    // ...
        $elements['export_format'] = [
          '#type'          => 'radios',
          '#title'         => $this->t('Export format'),
          '#default_value' => $this->getSetting('export_format'),
          '#options'       => self::EXPORT_OPTIONS,
        ];
    // ...
        $summary[] = self::EXPORT_OPTIONS[$export_format];
    

    The only problem is that I do not think you can use $this->t() in a const definition. You should be able to do it in a constructor, after calling the parent constructor. That is, use a class property (maybe a static one) instead of a const.

  • πŸ‡ΊπŸ‡ΈUnited States benjifisher Boston area

    The main issue is now that phpcs is passing stylelint is failing because it can't find a css file.

    Where do you see that? Or did you already do something to fix it?

  • Status changed to Needs review 5 months ago
  • πŸ‡ΊπŸ‡ΈUnited States benjifisher Boston area
  • πŸ‡ΊπŸ‡ΈUnited States nicxvan

    I'm using this: https://www.drupal.org/docs/develop/git/using-gitlab-to-contribute-to-dr... β†’

    When I run it I get this message:
    PASS composer
    PASS composer-lint
    PASS phpcs
    PASS phpstan
    PASS eslint
    PASS phpunit
    FAIL stylelint
    > at standalone (/gcl-builds/web/core/node_modules/stylelint/lib/standalone.js:261:43)
    > Error: No files matching the pattern "../modules/custom/**/*.css" were found.
    > at standalone (/gcl-builds/web/core/node_modules/stylelint/lib/standalone.js:261:43)
    pipeline finished in 1.35 min

    Although the actual tests are not failing so I can work on resolving that locally.

    I'll take a look at your other comments.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.x + Environment: PHP 8.2 & MySQL 8
    last update 5 months ago
    4 pass
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.x + Environment: PHP 8.2 & MySQL 8
    last update 5 months ago
    4 pass
  • πŸ‡ΊπŸ‡ΈUnited States benjifisher Boston area

    @nicxvan:

    Yes, using a function like that looks good to me. You are correctly using $this->t() on literal strings, and I expect the overhead of a function call is just microseconds. If I am wrong about that, then you can use the familiar pattern

    function getExportOptions() {
      if (empty($this->exportOptions)) {
        $this->exportOptions = ...
      }
      return $this->exportOptions;
    }
    

    But I would not bother with that unless it is actually a problem.

    One little complaint: the Coding standards β†’ say,

    Variables should be named using lowercase, and words should be separated either with uppercase characters (example: $lowerCamelCase) or with an underscore (example: <code>$snake_case). Be consistent; do not mix camelCase and snake_case variable naming inside a file.

    The file already uses snake_case for some variables ($export_format and $form_state) and now it uses lowerCamelCase for others ($exportFormat and $exportOptions).

    I cannot mark this issue RTBC, since I made the changes before the last two commits. But those two commits LGTM.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.x + Environment: PHP 8.2 & MySQL 8
    last update 5 months ago
    4 pass
  • Status changed to Fixed 5 months ago
  • πŸ‡ΊπŸ‡ΈUnited States nicxvan

    Good point, I usually leave items like form_state from core snake case, I've updated everything to camelCase.

    I merged this in, thanks for your contribution!

  • Status changed to Needs review 5 months ago
  • πŸ‡ΊπŸ‡ΈUnited States benjifisher Boston area

    That's the sort of change you make when you decide that the module is really your own. ;)

  • Status changed to Fixed 5 months ago
  • πŸ‡ΊπŸ‡ΈUnited States benjifisher Boston area

    Oops, I did not mean to move this issue back to NR.

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

Production build 0.69.0 2024