Commit a307d661 authored by Adam G-H's avatar Adam G-H Committed by Brad Jones
Browse files

Issue #3326143 by phenaproxima, bradjones1: Switch GitLab CI configuration to...

Issue #3326143 by phenaproxima, bradjones1: Switch GitLab CI configuration to the template developed by the DA
parent 99cae6ec
Loading
Loading
Loading
Loading
Loading
+320 −1
Original line number Diff line number Diff line
################
# DrupalCI GitLabCI template
#
# Gitlab-ci.yml to replicate DrupalCI testing for Contrib
#
# This is hestenet's test template
# Source: https://gitlab.com/drupal-infrastructure/gitlab-acceleration/gitlabci/file-templates/-/blob/main/gitlab-ci/template.gitlab-ci.yml
#
# With thanks to:
#   * The GitLab Acceleration Initiative participants
#   * DrupalSpoons
################

################
# Guidelines
#
# This template is designed to give any Contrib maintainer everything they need to test, without requiring modification. It is also designed to keep up to date with Core Development automatically through the use of include files that can be centrally maintained.
#
# However, you can modify this template if you have additional needs for your project.
################

################
# Includes
#
# Additional configuration can be provided through includes.
# One advantage of include files is that if they are updated upstream, the changes affect all pipelines using that include.
#
# Includes can be overriden by re-declaring anything provided in an include, here in gitlab-ci.yml
# https://docs.gitlab.com/ee/ci/yaml/includes.html#override-included-configuration-values
################

include:
  remote: 'https://gitlab.com/drupalspoons/composer-plugin/-/raw/master/templates/.gitlab-ci.yml'
  ################
  # DrupalCI includes:
  # include.drupalci.main.yml - This parent include contains nested includes for all DrupalCI test features. As long as you include this, any future includes added by the Drupal Association will be accessible to your pipelies automatically.
  # View this file to see what nested includes are provided.
  ################
  remote: 'https://git.drupalcode.org/project/gitlab_templates/-/raw/1.0.x/includes/include.drupalci.main.yml'

################
# Variables
#
# The include file include.drupalci.main.yml in this template includes a include.drupalci.variables.yml
#   - These variables provide 'Semantic Labels' to help you automatically track the current supported and development versions of Drupal, as well as the current min/max system requirements for PHP, database, etc.
#   - If this file is updated, your testing configuration will automatically follow these changes.
#
# Overriding variables
#   - To override one or more of these variables, simply declare your own variables keyword.
#   - Keywords declared directly in .gitlab-ci.yml take precedence over include files.
#   - Documentation:  https://docs.gitlab.com/ee/ci/variables/
#     - Predefined variables: https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
#
################

################
# Workflow
#
# The include file include.drupalci.main.yml in this template includes a include.drupalci.worfklows.yml
#   - This will test on commit, on merge request, and on any scheduled defined in the GitLab UI for your project.
#   - If this file is updated, your testing configuration will automatically follow these changes.
#
# Overriding workflows
#   - To override these workflows, simply declare your own workflow keyword.
#   - Keywords declared directly in .gitlab-ci.yml take precedence over include files.
#   - Documentation: https://docs.gitlab.com/ee/ci/yaml/workflow.html
#
################

################
# Stages
#
# Each job is assigned to a stage, defining the order in which the jobs are executed.
# Jobs in the same stage run in parallel.
#
# If all jobs in a stage succeed, the pipeline will proceed to the next stage.
# If any job in the stage fails, the pipeline will exit early.
################

stages:
  ################
  # Build
  #
  # In the Build stage we are assembling our test environment:
  #   * Selecting the core version to test against
  #   * Selecting php version
  #   * Selectig the database, and configuring it
  #   * Plus any additional build steps, like composer runs, etc
  # Wherever possible, we use variables defined in: include.druaplci.variables.yml so that the configuration can stay up to date with current Drupal Core development.
  #
  # Documentation: https://docs.gitlab.com/ee/ci/yaml/#stages
  ################
  - build

  ################
  # Validate
  #
  # The validate stage includes any codebase validation that we want to perform before running functional tests. These are items we may want to fail-fast on, before doing a full test-run.
  ################
  - validate

  ################
  # Test
  #
  # The test phase actually executes the functional tests, as well as gathering results and artifacts.
  ################
  - test

################
# Jobs
#
# Jobs define what scripts are actually executed in each stage.
#
# The 'rules' keyword can also be used to define conditions for each job.
# # @TODO: Use rules to define core version to test against, allow overriding default on manual run with variables. (Perhaps with 'variables in variables')
#
# Documentation: https://docs.gitlab.com/ee/ci/jobs/
################

################
# Build Jobs
################

variable-checks:       # This job runs in the build stage, which runs first.
  stage: build
  script:
    - echo "Checking variables"
    - echo $_TARGET_CORE
    - echo $_TARGET_PHP
    - echo $_TARGET_DB_TYPE
    - echo $_TARGET_DB_VERSION
    - echo $_WEB_ROOT
    - echo $_COMPOSER_JSON

# @TODO - work in progress to adapt the composer build step from DrupalSpoons examples
composer:
  stage: build
  variables:
    # Used the bin/setup script.
    NONINTERACTIVE: 1
  # Use artifacts to copy codebase to subsequent jobs.
  # See https://lorisleiva.com/laravel-deployment-using-gitlab-pipelines/.
  artifacts:
    expire_in: 1 week
    expose_as: 'web-vendor'
    paths: # @todo - where we want to store artifacts?
      - vendor/
      - $_WEB_ROOT
      - .composer-plugin.env
      - composer.spoons.json
      - composer.spoons.lock\
  script: #this script is configuring composer, including options for local Dev - can we simplify?
      - export
      - composer config platform.ext-sodium $PHP_VERSION --file=composer.json
      - bash <(curl -s $_COMPOSER_SETUP)

################
# Validate Jobs
################

composer-lint:
  stage: validate
  script:
    - composer validate
    - composer lint

#phpcs:
#  stage: validate
#  script:
#    # Do we need: vendor/drupalspoons/composer-plugin/templates/phpcs.xml.dist ?
#    #- cp -u vendor/drupalspoons/composer-plugin/templates/phpcs.xml.dist $_WEB_ROOT/modules/custom
#    - composer phpcs -- --report-junit=junit.xml --report-full --report-summary
#  allow_failure: true
#  artifacts:
#    expose_as: junit
#    expire_in: 6 mos
#    paths:
#      - junit.xml
#    reports:
#      junit: junit.xml

#stylelint:
#  stage: validate
#  script:
#    # Installs all core javascript dependencies.
#    - yarn --cwd $_WEB_ROOT/core add stylelint-junit-formatter
#    - composer stylelint -- --color || true
#    - composer stylelint -- --color --custom-formatter node_modules/stylelint-junit-formatter > junit.xml || true
#  allow_failure: true
#  artifacts:
#    expose_as: junit
#    expire_in: 6 mos
#    paths:
#      - junit.xml
#    reports:
#      junit: junit.xml

#eslint:
#  stage: validate
#  script:
#    # Installs all core javascript dependencies.
#    - yarn --cwd $_WEB_ROOT/core add stylelint-junit-formatter
#    - composer eslint -- --format junit --output-file junit.xml || true
#  allow_failure: true
#  artifacts:
#    expose_as: junit
#    expire_in: 6 mos
#    paths:
#      - junit.xml
#    reports:
#      junit: junit.xml

################
# Test Jobs
################
# @TODO: Multiple environment handling
# Do we want to offer a default example of matrix testing, perhaps commented out? Or linked to in documentation?
# Or do we want to stick to single environment for cost control, and rely on advanced maintainers to figure it out?
################

#Set default php image
default:
  image:
    name: $_CONFIG_DOCKERHUB_ROOT/php-$_TARGET_PHP-apache:production

phpunit:
  stage: test
  variables:
    # https://docs.gitlab.com/runner/configuration/feature-flags.html#available-feature-flags
    FF_NETWORK_PER_BUILD: 1
    SIMPLETEST_BASE_URL: http://localhost:8888
    DB_DRIVER: mysql
    MYSQL_ROOT_PASSWORD: root
    MYSQL_DATABASE: mysql
    MYSQL_USER: drupaltestbot
    MYSQL_PASSWORD: drupaltestbotpw
    MARIADB_TAG: $_TARGET_DB_VERSION
    POSTGRES_TAG: $_TARGET_DB_VERSION
    POSTGRES_DB: pgsql
    POSTGRES_USER: drupaltestbot
    POSTGRES_PASSWORD: drupaltestbotpw

  services:
    - name: $_CONFIG_DOCKERHUB_ROOT/$_TARGET_DB_TYPE-$_TARGET_DB_VERSION:production
      alias: database
    - name: $_CONFIG_DOCKERHUB_ROOT/chromedriver:production
      alias: chrome
      entrypoint:
        - chromedriver
        - "--no-sandbox"
        - "--log-path=/tmp/chromedriver.log"
        - "--verbose"
        - "--whitelisted-ips="
  script:
    #  Determine DB driver.
    - |
      [[ $_TARGET_DB_TYPE == "sqlite" ]] && export SIMPLETEST_DB=sqlite://localhost/sites/default/files/.sqlite
      [[ $_TARGET_DB_TYPE == "mysql" ]] && export SIMPLETEST_DB=mysql://$MYSQL_USER:$MYSQL_PASSWORD@database/$MYSQL_DATABASE
      [[ $_TARGET_DB_TYPE == "pgsql" ]] && export SIMPLETEST_DB=pgsql://$POSTGRES_USER:$POSTGRES_PASSWORD@database/$POSTGRES_DB
    - export
    - mkdir $_WEB_ROOT/sites/simpletest
    - composer webserver >> webserver.log 2>&1 &
    # Provide some context on the test run.
    - vendor/bin/drush status
    # Finally, execute tests.
    - composer unit -- --log-junit junit.xml
  artifacts:
    expire_in: 6 mos
    expose_as: 'junit-browser_output-webserver_log'
    reports:
      junit: junit.xml
    paths:
      - junit.xml
      - webserver.log
      - $_WEB_ROOT/sites/simpletest/browser_output


###################################################################################
#
#                                        *
#                                       /(
#                                      ((((,
#                                    /(((((((
#                                   ((((((((((*
#                                ,(((((((((((((((
#                              ,(((((((((((((((((((
#                            ((((((((((((((((((((((((*
#                         *(((((((((((((((((((((((((((((
#                       ((((((((((((((((((((((((((((((((((*
#                    *((((((((((((((((((  .((((((((((((((((((
#                  ((((((((((((((((((.       /(((((((((((((((((*
#                /(((((((((((((((((            .(((((((((((((((((,
#             ,((((((((((((((((((                 ((((((((((((((((((
#           .((((((((((((((((((((                   .(((((((((((((((((
#          (((((((((((((((((((((((                     ((((((((((((((((/
#        (((((((((((((((((((((((((((/                    ,(((((((((((((((*
#      .((((((((((((((/  /(((((((((((((.                   ,(((((((((((((((
#     *((((((((((((((      ,(((((((((((((/                   *((((((((((((((.
#    ((((((((((((((,          /(((((((((((((.                  ((((((((((((((,
#   (((((((((((((/              ,(((((((((((((*                 ,(((((((((((((,
#  *(((((((((((((                .(((((((((((((((                ,(((((((((((((
#  ((((((((((((/                /((((((((((((((((((.              ,((((((((((((/
# (((((((((((((              *(((((((((((((((((((((((*             *((((((((((((
# (((((((((((((            ,(((((((((((((..(((((((((((((           *((((((((((((
# ((((((((((((,          /((((((((((((*      /((((((((((((/         ((((((((((((
# (((((((((((((        /((((((((((((/          (((((((((((((*       ((((((((((((
# (((((((((((((/     /((((((((((((               ,((((((((((((,    *((((((((((((
#  ((((((((((((((  *(((((((((((/                   *((((((((((((.  ((((((((((((/
#  *((((((((((((((((((((((((((,                      /(((((((((((((((((((((((((
#   (((((((((((((((((((((((((                         ((((((((((((((((((((((((,
#   .(((((((((((((((((((((((/                         ,(((((((((((((((((((((((
#     ((((((((((((((((((((((/                         ,(((((((((((((((((((((/
#      *(((((((((((((((((((((                         (((((((((((((((((((((,
#       ,(((((((((((((((((((((,                      ((((((((((((((((((((/
#         ,(((((((((((((((((((((*                  /((((((((((((((((((((
#            ((((((((((((((((((((((,           ,/((((((((((((((((((((,
#              ,(((((((((((((((((((((((((((((((((((((((((((((((((((
#                 .(((((((((((((((((((((((((((((((((((((((((((((
#                     .((((((((((((((((((((((((((((((((((((,.
#                          .,(((((((((((((((((((((((((.
#
###################################################################################