Skip to content
Snippets Groups Projects

Proof of concept

Compare and
3 files
+ 475
225
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 377
0
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 # Build third party dependencies etc
################
# 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.
################
- 🪄 Lint # Code quality checks
################
# Test
#
# The test phase actually executes the tests, as well as gathering results and artifacts.
################
- 🗜️ Test
#############
# Templates #
#############
#Set default php image
.default_php_image: &default_php_image
image:
name: $_CONFIG_DOCKERHUB_ROOT/php-$_TARGET_PHP-apache:production
# Default rules.
.default_rules: &default_rules
rules:
- if: $CI_PIPELINE_SOURCE == "parent_pipeline"
.composer_code: &composer_code
paths:
- ./vendor
.composer-cache: &composer_cache
key:
files:
- ./composer.json
- ./composer.lock
<<: *composer_code
.yarn-code: &yarn_code
paths:
- ./core/node_modules
.yarn-cache: &yarn_cache
key:
files:
- ./core/package.json
- ./core/yarn.lock
<<: *yarn_code
.pull-composer-cache: &pull-composer-cache
cache:
policy: pull
<<: *composer_cache
dependencies:
- '📦️ Composer'
.with-composer-cache: &with-composer-cache
needs:
- '📦️ Composer'
<<: *pull-composer-cache
.interruptible: &interruptible
interruptible: true
allow_failure: false
.with-yarn-cache: &with-yarn-cache
dependencies:
- '📦️ Yarn'
needs:
- '📦️ Yarn'
cache:
policy: pull
<<: *yarn_cache
.junit-artifacts: &junit-artifacts
artifacts:
expose_as: junit
expire_in: 6 mos
paths:
- junit.xml
reports:
junit: junit.xml
.with-linting: &with-linting
needs:
- '📦️ Composer'
- '🧹 PHP Static Analysis (phpstan)'
- '🧹 PHP Coding standards (PHPCS)'
- '🧹 Compilation check'
- '📦️ Yarn'
- '📔 Spell-checking'
- '🧹 JavaScript linting (eslint)'
- '🧹 CSS linting (stylelint)'
<<: *pull-composer-cache
.with-unit-tests: &with-unit-tests
needs:
- '⚡️ PHPUnit Unit'
- '📦️ Composer'
<<: *pull-composer-cache
.with-composer-and-yarn: &with-composer-and-yarn
needs:
- '📦️ Composer'
- '⚡️ PHPUnit Unit'
- '📦️ Yarn'
dependencies:
- '📦️ Yarn'
- '📦️ Composer'
.test-variables: &test-variables
FF_NETWORK_PER_BUILD: 1
SIMPLETEST_BASE_URL: http://localhost/subdirectory
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
MINK_DRIVER_ARGS_WEBDRIVER: '["chrome", {"browserName":"chrome","chromeOptions":{"args":["--disable-dev-shm-usage","--disable-gpu","--headless"]}}, "http://localhost:9515"]'
.with-database: &with-database
name: $_CONFIG_DOCKERHUB_ROOT/$_TARGET_DB_TYPE-$_TARGET_DB_VERSION:production
alias: database
.with-chrome: &with-chrome
name: $_CONFIG_DOCKERHUB_ROOT/chromedriver:production
alias: chrome
entrypoint:
- chromedriver
- "--no-sandbox"
- "--log-path=/tmp/chromedriver.log"
- "--verbose"
- "--whitelisted-ips="
.phpunit-artifacts: &phpunit-artifacts
artifacts:
when: always
expire_in: 6 mos
reports:
junit: ./sites/default/files/simpletest/phpunit-*.xml
paths:
- ./sites/default/files/simpletest/phpunit-*.xml
- ./sites/simpletest/browser_output
.setup-webroot: &setup-webserver
before_script:
- ln -s `pwd` /var/www/html/subdirectory
- sudo service apache2 start
.run-tests: &run-tests
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 -p ./sites/simpletest ./build/logs/junit /var/www/.composer
- chown -R www-data:www-data ./sites ./build/logs/junit ./vendor /var/www/
- sudo -u www-data git config --global --add safe.directory `pwd`
# We need to pass this along directly even though it's set in the environment parameters.
- sudo MINK_DRIVER_ARGS_WEBDRIVER="$MINK_DRIVER_ARGS_WEBDRIVER" -u www-data php ./core/scripts/run-tests.sh --color --keep-results --types "$TESTSUITE" --concurrency "$CONCURRENCY" --repeat "1" --sqlite "./sites/default/files/.sqlite" --dburl $SIMPLETEST_DB --url $SIMPLETEST_BASE_URL --all --verbose --non-html
################
# Jobs
#
# Jobs define what scripts are actually executed in each stage.
#
# The 'rules' keyword can also be used to define conditions for each job.
#
# Documentation: https://docs.gitlab.com/ee/ci/jobs/
################
################
# Build Jobs
################
'ℹ️ Output build parameters': # This job runs in the build stage, which runs first.
<<: *default_php_image
stage: 🏗️ Build
interruptible: true
script:
- echo "Checking variables"
- echo $_TARGET_PHP
- echo $_TARGET_DB_TYPE
- echo $_TARGET_DB_VERSION
'📦️ Composer':
<<: [ *default_php_image, *default_rules ]
stage: 🏗️ Build
<<: *interruptible
cache:
<<: *composer_cache
artifacts:
expire_in: 1 week
expose_as: 'web-vendor'
paths:
- vendor/
script:
- export
- composer validate
- composer install
'📦️ Yarn':
<<: [ *default_php_image, *default_rules ]
stage: 🏗️ Build
interruptible: true
cache:
<<: *yarn_cache
artifacts:
expire_in: 1 week
expose_as: 'yarn-vendor'
paths:
- core/node_modules/
script:
# Installs all core javascript dependencies and adds junit formatter.
- yarn --cwd ./core add stylelint-junit-formatter
################
# Lint Jobs
################
'🧹 PHP Coding standards (PHPCS)':
<<: [ *with-composer-cache, *interruptible, *junit-artifacts, *default_php_image, *default_rules ]
stage: 🪄 Lint
script:
- composer phpcs -- --report-junit=junit.xml --report-full --report-summary
'🧹 PHP Static Analysis (phpstan)':
<<: [ *with-composer-cache, *interruptible, *junit-artifacts, *default_php_image, *default_rules ]
stage: 🪄 Lint
script:
# Turn off apc to avoid corrupt composer cache.
- php -d apc.enabled=0 -d apc.enable_cli=0 vendor/bin/phpstan analyze --no-progress --configuration=./core/phpstan.neon.dist --error-format=junit > junit.xml
'🧹 CSS linting (stylelint)':
<<: [ *with-yarn-cache, *interruptible, *junit-artifacts, *default_php_image, *default_rules ]
stage: 🪄 Lint
script:
- yarn run --cwd=./core lint:css --color --custom-formatter node_modules/stylelint-junit-formatter > junit.xml
'🧹 Compilation check':
<<: [ *with-yarn-cache, *interruptible, *default_php_image, *default_rules ]
stage: 🪄 Lint
script:
- yarn run --cwd=./core build:css --check
- cd core && yarn run -s check:ckeditor5
'🧹 JavaScript linting (eslint)':
<<: [ *with-yarn-cache, *interruptible, *junit-artifacts, *default_php_image, *default_rules ]
stage: 🪄 Lint
script:
- yarn --cwd=./core run -s lint:core-js-passing --format junit > junit.xml
'📔 Spell-checking':
<<: [ *with-yarn-cache, *interruptible, *default_php_image, *default_rules ]
stage: 🪄 Lint
script:
- git fetch origin
- export MODIFIED=`git diff --name-only origin/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}|while read r;do echo "$PWD/$r";done|tr "\n" " "`
- yarn --cwd=./core run -s spellcheck --no-must-find-files -c ./.cspell.json check $MODIFIED
################
# Test Jobs
################
'⚡️ PHPUnit Unit':
<<: [ *with-linting, *interruptible, *phpunit-artifacts, *setup-webserver, *run-tests, *default_php_image, *default_rules ]
stage: 🗜️ Test
services:
# There are some unit tests that need a database.
- <<: *with-database
variables:
<<: *test-variables
TESTSUITE: PHPUnit-Unit
CONCURRENCY: "$DEFAULT_CONCURRENCY"
'⚙️️ PHPUnit Kernel':
<<: [ *with-unit-tests, *interruptible, *phpunit-artifacts, *setup-webserver, *run-tests, *default_php_image, *default_rules ]
stage: 🗜️ Test
variables:
<<: *test-variables
TESTSUITE: PHPUnit-Kernel
CONCURRENCY: "$DEFAULT_CONCURRENCY"
services:
- <<: *with-database
'🌐️️ PHPUnit Functional':
<<: [ *with-unit-tests, *interruptible, *phpunit-artifacts, *setup-webserver, *run-tests, *default_php_image, *default_rules ]
stage: 🗜️ Test
timeout: 2 hours
variables:
<<: *test-variables
TESTSUITE: PHPUnit-Functional
CONCURRENCY: "$DEFAULT_CONCURRENCY"
services:
- <<: *with-database
'👷️️️ PHPUnit Build':
<<: [ *with-unit-tests, *interruptible, *phpunit-artifacts, *setup-webserver, *run-tests, *default_php_image, *default_rules ]
stage: 🗜️ Test
variables:
<<: *test-variables
TESTSUITE: PHPUnit-Build
CONCURRENCY: "$DEFAULT_CONCURRENCY"
services:
- <<: *with-database
'🖱️️️ PHPUnit Functional Javascript':
<<: [ *with-unit-tests, *interruptible, *phpunit-artifacts, *setup-webserver, *run-tests, *default_php_image, *default_rules ]
stage: 🗜️ Test
variables:
<<: *test-variables
TESTSUITE: PHPUnit-FunctionalJavascript
CONCURRENCY: 15
services:
- <<: *with-database
- <<: *with-chrome
'🦉️️️ Nightwatch':
<<: [ *with-composer-and-yarn, *interruptible, *setup-webserver, *default_php_image, *default_rules ]
stage: 🗜️ Test
variables:
<<: *test-variables
services:
- <<: *with-database
- <<: *with-chrome
script:
# Determine DB driver.
- |
[[ $_TARGET_DB_TYPE == "sqlite" ]] && export DRUPAL_TEST_DB_URL=sqlite://localhost/sites/default/files/.sqlite
[[ $_TARGET_DB_TYPE == "mysql" ]] && export DRUPAL_TEST_DB_URL=mysql://$MYSQL_USER:$MYSQL_PASSWORD@database/$MYSQL_DATABASE
[[ $_TARGET_DB_TYPE == "pgsql" ]] && export DRUPAL_TEST_DB_URL=pgsql://$POSTGRES_USER:$POSTGRES_PASSWORD@database/$POSTGRES_DB
- export
- cp ./core/.env.example ./core/.env
# dotenv-safe/config does not support environment variables
# @see https://github.com/rolodato/dotenv-safe/issues/126
# @todo move this to `variables` when the above is resolved
- echo "DRUPAL_TEST_BASE_URL='http://localhost/subdirectory'" >> ./core/.env
- echo "DRUPAL_TEST_CHROMEDRIVER_AUTOSTART=false" >> ./core/.env
- echo "DRUPAL_TEST_DB_URL='${DRUPAL_TEST_DB_URL}'" >> ./core/.env
- echo "DRUPAL_TEST_WEBDRIVER_HOSTNAME='localhost'" >> ./core/.env
- echo "DRUPAL_TEST_WEBDRIVER_CHROME_ARGS='--disable-dev-shm-usage --disable-gpu --headless'" >> ./core/.env
- echo "DRUPAL_TEST_WEBDRIVER_PORT='9515'" >> ./core/.env
- echo "DRUPAL_NIGHTWATCH_OUTPUT='"nightwatch_output"'" >> ./core/.env
- cat ./core/.env
- mkdir -p ./sites/simpletest /var/www/.cache/yarn /var/www/.yarn ./nightwatch_output
- chown -R www-data:www-data ./sites/simpletest /var/www/.cache/yarn /var/www/.yarn ./nightwatch_output ./core/.env
- sudo BABEL_DISABLE_CACHE=1 -u www-data yarn --cwd ./core test:nightwatch
artifacts:
when: always
expire_in: 6 mos
reports:
junit: ./nightwatch_output/*.xml
paths:
- ./nightwatch_output
Loading