Skip to content

Tools: switch Drupal CI to Gitlab CI

Switch contrib modules on Drupal.org from Drupal CI to Gitlab CI.

https://www.drupal.org/docs/develop/git/using-gitlab-to-contribute-to-drupal/gitlab-ci https://git.drupalcode.org/project/mongodb/-/blob/8.x-2.x/.gitlab-ci.yml?ref_type=heads

OK:

  • Composer validate
  • YAML lint => in Eslint

To do:

  • Composer normalize
  • PHP CS
phpcs:
  script:
    - test -f phpcs.xml.dist || curl -OL https://git.drupalcode.org/$_GITLAB_TEMPLATES_REPO/-/raw/$_GITLAB_TEMPLATES_REF/scripts/phpcs.xml.dist
    - vendor/bin/phpcs -s $_WEB_ROOT/modules/custom --report-junit=junit.xml --report-full --report-summary --report-source

To customise, and import my rules $COMPOSER_EXTRA

  • PHP MD
  • PHP MND
  • PHP Stan
  • Psalm
  • Rector
  • PHP CS Fixer
  • Stylelint
   - exists:
        - "**/*.css"
      when: on_success
    - when: never
  script:
    - yarn --cwd $_WEB_ROOT/core add stylelint-junit-formatter
    # the `|| true` makes sure both steps run https://stackoverflow.com/questions/59180675/how-to-continue-job-even-when-script-fails
    - yarn --silent --cwd $_WEB_ROOT/core stylelint --formatter verbose --config ./.stylelintrc.json ../modules/custom/**/*.css --color || true

test if possible to ignore some files for compiled CSS.

  • ES Lint == JS + YAML
  • rename .es6.js file into JS
  • converts .js into ES6.
  • convertir tout JS en ES6?
  • vérifier si scan différent entre ES6 et non ES6
  • SASS Lint
  • Spellcheck

Draft and notes below.

eslint: - exists: - "/*.js" - "/.yml" when: on_success - when: never script: # Change directory to the project root folder - cd CI_PROJECT_DIR/_WEB_ROOT/modules/custom/$CI_PROJECT_NAME # Configure prettier - test -e .prettierrc.json || ln -s CI_PROJECT_DIR/_WEB_ROOT/core/.prettierrc.json . - test -e .prettierignore || echo '.yml' > .prettierignore # Run twice in order to show output in console log and also in junit file. https://stackoverflow.com/questions/58391647/eslint-output-to-file-and-console-at-the-same-time # The || true makes sure the second call runs even if the first fails. https://stackoverflow.com/questions/59180675/how-to-continue-job-even-when-script-fails - CI_PROJECT_DIR/_WEB_ROOT/core/node_modules/.bin/eslint --no-error-on-unmatched-pattern --ignore-pattern=".es6.js" --resolve-plugins-relative-to=CI_PROJECT_DIR/_WEB_ROOT/core --ext=.js,.yml . || true - CI_PROJECT_DIR/_WEB_ROOT/core/node_modules/.bin/eslint --no-error-on-unmatched-pattern --ignore-pattern=".es6.js" --resolve-plugins-relative-to=CI_PROJECT_DIR/_WEB_ROOT/core --ext=.js,.yml --format=junit --output-file=$CI_PROJECT_DIR/junit.xml .

validate stage

SKIP_VARIABLE_CHECKS:
    value: "0"
    description: "Set to 1 to skip the variable checks CI job"
SKIP_COMPOSER:
    value: "0"
    description: "Set to 1 to skip the composer CI job"
SKIP_COMPOSER_LINT:
    value: "0"
    description: "Set to 1 to skip the composer lint CI job"
SKIP_PHPCS:
    value: "0"
    description: "Set to 1 to skip the phpcs CI job"
SKIP_STYLELINT:
    value: "0"
    description: "Set to 1 to skip the stylelint CI job"
SKIP_ESLINT:
    value: "0"
    description: "Set to 1 to skip the ESLINT CI job"
SKIP_PHPUNIT:
    value: "0"
    description: "Set to 1 to skip the PHPUNIT CI job"
COMPOSER_EXTRA:
    value: ""
    description: "Additional options that are appended to the `composer` job call."

variables:

Disable default phpunit job in favor of the d9/10 variants below.

SKIP_PHPUNIT: 1 _PHPUNIT_EXTRA: --verbose

Convenient, and we have no secrets.

_SHOW_ENVIRONMENT_VARIABLES: 1

composer: extends: .composer-base

.phpunit-local: variables: SKIP_PHPUNIT: 0

include:

This include centralizes our CI "golden path" https://docs.gitlab.com/ee/ci/yaml/#includefile

  • project: 'project/gitlab_templates' ref: $_GITLAB_TEMPLATES_REF file:
    • '/includes/include.drupalci.main.yml'
    • '/includes/include.drupalci.variables.yml'
    • '/includes/include.drupalci.workflows.yml'
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information