drupal/.gitlab-ci/pipeline.yml

300 lines
12 KiB
YAML
Raw Normal View History

# cspell:ignore drupaltestbot drupaltestbotpw
stages:
- 🗜️ Test
#############
# Templates #
#############
.default-job-settings: &default-job-settings
stage: 🗜️ Test
interruptible: true
allow_failure: false
retry:
max: 2
when:
- unknown_failure
- api_failure
- stuck_or_timeout_failure
- runner_system_failure
- scheduler_failure
image:
name: $_CONFIG_DOCKERHUB_ROOT/php-$_TARGET_PHP-apache:production
rules:
- if: $CI_PIPELINE_SOURCE == "parent_pipeline" && $PERFORMANCE_TEST != "1"
.junit-artifacts: &junit-artifacts
artifacts:
expose_as: junit
expire_in: 6 mos
paths:
- junit.xml
reports:
junit: junit.xml
.with-composer: &with-composer
needs:
- pipeline: $PARENT_PIPELINE_ID
job: '📦️ Composer'
.with-composer-and-yarn: &with-composer-and-yarn
needs:
- pipeline: $PARENT_PIPELINE_ID
job: '📦️ Composer'
- pipeline: $PARENT_PIPELINE_ID
job: '📦️ Yarn'
.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
POSTGRES_DB: drupaltestbot
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"]'
CI_PARALLEL_NODE_INDEX: $CI_NODE_INDEX
CI_PARALLEL_NODE_TOTAL: $CI_NODE_TOTAL
.with-database: &with-database
name: $_CONFIG_DOCKERHUB_ROOT/$_TARGET_DB: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 $CI_PROJECT_DIR /var/www/html/subdirectory
- sudo service apache2 start
.set-simpletest-db: &set-simpletest-db
- |
[[ $_TARGET_DB == sqlite* ]] && export SIMPLETEST_DB=sqlite://localhost/$CI_PROJECT_DIR/sites/default/files/db.sqlite?module=sqlite
[[ $_TARGET_DB == mysql* ]] && export SIMPLETEST_DB=mysql://$MYSQL_USER:$MYSQL_PASSWORD@database/$MYSQL_DATABASE?module=mysql
[[ $_TARGET_DB == mariadb* ]] && export SIMPLETEST_DB=mysql://$MYSQL_USER:$MYSQL_PASSWORD@database/$MYSQL_DATABASE?module=mysql
[[ $_TARGET_DB == pgsql* ]] && export SIMPLETEST_DB=pgsql://$POSTGRES_USER:$POSTGRES_PASSWORD@database/$POSTGRES_DB?module=pgsql
.set-directory-settings: &set-directory-settings
- |
mkdir -p ./sites/simpletest ./sites/default/files ./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 $CI_PROJECT_DIR
.run-tests: &run-tests
script:
- *set-simpletest-db
- *set-directory-settings
# Need to pass this along directly.
- 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/tests.sqlite" --dburl $SIMPLETEST_DB --url $SIMPLETEST_BASE_URL --verbose --non-html --all --ci-parallel-node-index $CI_PARALLEL_NODE_INDEX --ci-parallel-node-total $CI_PARALLEL_NODE_TOTAL
.run-repeat-class-test: &run-repeat-class-test
script:
- *set-simpletest-db
- *set-directory-settings
- echo " Running class ${REPEAT_TEST_CLASS}"
- |
if [[ $REPEAT_TEST_CLASS == "Drupal\Tests\Change\Me" ]]; then
echo '❗ You need to change the REPEAT_TEST_CLASS variable to an existing class before running the job.'
echo ' You just need to click on the job that you want to run (do not press the play button straight away) and then set the following:'
echo ' "Key" to "REPEAT_TEST_CLASS" and "Value" to "Drupal\Tests\ckeditor5\FunctionalJavascript\MediaLinkabilityTest"';
exit 1;
else
sudo MINK_DRIVER_ARGS_WEBDRIVER="$MINK_DRIVER_ARGS_WEBDRIVER" -u www-data php ./core/scripts/run-tests.sh --color --keep-results --concurrency "$CONCURRENCY" --repeat "100" --sqlite "./sites/default/files/tests.sqlite" --dburl $SIMPLETEST_DB --url $SIMPLETEST_BASE_URL --verbose --non-html --class $REPEAT_TEST_CLASS
fi
################
# 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/
################
'🌐️️ PHPUnit Functional':
<<: [ *with-composer, *phpunit-artifacts, *setup-webserver, *run-tests, *default-job-settings ]
parallel: 7
variables:
<<: *test-variables
TESTSUITE: PHPUnit-Functional
CONCURRENCY: "$CONCURRENCY"
KUBERNETES_CPU_REQUEST: "24"
services:
- <<: *with-database
'🩹 Test-only changes':
<<: [ *with-composer, *phpunit-artifacts, *setup-webserver, *default-job-settings ]
when: manual
interruptible: true
allow_failure: true
variables:
<<: *test-variables
services:
- <<: *with-database
- <<: *with-chrome
script:
- *set-simpletest-db
- *set-directory-settings
- export TARGET_BRANCH=${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}${CI_COMMIT_BRANCH}
- git fetch -vn --depth=3 "$CI_MERGE_REQUEST_PROJECT_URL" "+refs/heads/$TARGET_BRANCH:refs/heads/$TARGET_BRANCH"
- |
echo " Changes from ${TARGET_BRANCH}"
git diff refs/heads/${TARGET_BRANCH} --name-only
echo "If this list contains more files than what you changed, then you need to rebase your branch."
echo "1⃣ Reverting non test changes"
if [[ $(git diff refs/heads/${TARGET_BRANCH} --diff-filter=DM --name-only|grep -Ev "Test.php$"|grep -v .gitlab-ci|grep -v scripts/run-tests.sh) ]]; then
git diff refs/heads/${TARGET_BRANCH} --diff-filter=DM --name-only|grep -Ev "Test.php$"|grep -v .gitlab-ci|grep -v scripts/run-tests.sh|while read file;do
echo "↩️ Reverting $file";
git checkout refs/heads/${TARGET_BRANCH} -- $file;
done
fi
if [[ $(git diff refs/heads/${TARGET_BRANCH} --diff-filter=A --name-only|grep -Ev "Test.php$"|grep -v .gitlab-ci|grep -v scripts/run-tests.sh) ]]; then
git diff refs/heads/${TARGET_BRANCH} --diff-filter=A --name-only|grep -Ev "Test.php$"|grep -v .gitlab-ci|grep -v scripts/run-tests.sh|while read file;do
echo "🗑️️ Deleting $file";
git rm $file;
done
fi
echo "2⃣ Running test changes for this branch"
if [[ $(git diff refs/heads/${TARGET_BRANCH} --name-only|grep -E "Test.php$") ]]; then
for test in `git diff refs/heads/${TARGET_BRANCH} --name-only|grep -E "Test.php$"`; do
sudo SIMPLETEST_BASE_URL="$SIMPLETEST_BASE_URL" SIMPLETEST_DB="$SIMPLETEST_DB" MINK_DRIVER_ARGS_WEBDRIVER="$MINK_DRIVER_ARGS_WEBDRIVER" -u www-data ./vendor/bin/phpunit -c core $test --log-junit=./sites/default/files/simpletest/phpunit-`echo $test|sed 's/\//_/g' `.xml;
done;
fi
'⚙️️ PHPUnit Kernel':
<<: [*with-composer, *phpunit-artifacts, *setup-webserver, *run-tests, *default-job-settings ]
parallel: 2
variables:
<<: *test-variables
TESTSUITE: PHPUnit-Kernel
CONCURRENCY: "$CONCURRENCY"
KUBERNETES_CPU_REQUEST: "16"
services:
- <<: *with-database
'🖱️️️ PHPUnit Functional Javascript':
<<: [ *with-composer, *phpunit-artifacts, *setup-webserver, *run-tests, *default-job-settings ]
parallel: 2
variables:
<<: *test-variables
TESTSUITE: PHPUnit-FunctionalJavascript
CONCURRENCY: 15
KUBERNETES_CPU_REQUEST: "8"
services:
- <<: *with-database
- <<: *with-chrome
'👷️️️ PHPUnit Build':
<<: [ *with-composer, *phpunit-artifacts, *setup-webserver, *run-tests, *default-job-settings ]
variables:
<<: *test-variables
TESTSUITE: PHPUnit-Build
CONCURRENCY: "$CONCURRENCY"
KUBERNETES_CPU_REQUEST: "2"
services:
- <<: *with-database
'⚡️ PHPUnit Unit':
<<: [ *with-composer, *phpunit-artifacts, *setup-webserver, *run-tests, *default-job-settings ]
services:
# There are some unit tests that need a database.
# @todo Remove after https://www.drupal.org/project/drupal/issues/3386217
- <<: *with-database
variables:
<<: *test-variables
TESTSUITE: PHPUnit-Unit
CONCURRENCY: "$CONCURRENCY"
KUBERNETES_CPU_REQUEST: "16"
'🦉️️️ Nightwatch':
<<: [ *with-composer-and-yarn, *setup-webserver, *default-job-settings ]
variables:
<<: *test-variables
KUBERNETES_CPU_REQUEST: "3"
services:
- <<: *with-database
- <<: *with-chrome
script:
- *set-simpletest-db
- export DRUPAL_TEST_DB_URL=$SIMPLETEST_DB
- 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 ./sites/default/files /var/www/.cache/yarn /var/www/.yarn ./nightwatch_output
- chown -R www-data:www-data ./sites/simpletest ./sites/default/files /var/www/.cache/yarn /var/www/.yarn ./nightwatch_output ./core/.env
- sudo BABEL_DISABLE_CACHE=1 -u www-data yarn --cwd ./core test:nightwatch --workers=4
artifacts:
when: always
expire_in: 6 mos
reports:
junit: ./nightwatch_output/*.xml
paths:
- ./nightwatch_output
'🔁 Repeat Class Test':
<<: [ *with-composer, *phpunit-artifacts, *setup-webserver, *run-repeat-class-test, *default-job-settings ]
when: manual
interruptible: true
allow_failure: true
variables:
<<: *test-variables
CONCURRENCY: "$CONCURRENCY"
REPEAT_TEST_CLASS: 'Drupal\Tests\Change\Me'
services:
- <<: *with-database
'🚲 Performance tests':
<<: [ *with-composer, *phpunit-artifacts, *setup-webserver, *default-job-settings ]
rules:
- if: $PERFORMANCE_TEST == "1"
variables:
<<: *test-variables
KUBERNETES_CPU_REQUEST: "24"
services:
- <<: *with-database
- <<: *with-chrome
script:
# Determine DB driver.
- |
[[ $_TARGET_DB == sqlite* ]] && export SIMPLETEST_DB=sqlite://localhost/subdirectory/sites/default/files/db.sqlite?module=sqlite
[[ $_TARGET_DB == mysql* ]] && export SIMPLETEST_DB=mysql://$MYSQL_USER:$MYSQL_PASSWORD@database/$MYSQL_DATABASE?module=mysql
[[ $_TARGET_DB == mariadb* ]] && export SIMPLETEST_DB=mysql://$MYSQL_USER:$MYSQL_PASSWORD@database/$MYSQL_DATABASE?module=mysql
[[ $_TARGET_DB == pgsql* ]] && export SIMPLETEST_DB=pgsql://$POSTGRES_USER:$POSTGRES_PASSWORD@database/$POSTGRES_DB?module=pgsql
- export OTEL_COLLECTOR="$OTEL_COLLECTOR"
- mkdir -p ./sites/simpletest ./sites/default/files ./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 $CI_PROJECT_DIR
- for run in {1..3}; do sudo SIMPLETEST_BASE_URL="$SIMPLETEST_BASE_URL" SIMPLETEST_DB="$SIMPLETEST_DB" MINK_DRIVER_ARGS_WEBDRIVER="$MINK_DRIVER_ARGS_WEBDRIVER" OTEL_COLLECTOR="$OTEL_COLLECTOR" -u www-data ./vendor/bin/phpunit -c core --group OpenTelemetry --log-junit=./sites/default/files/simpletest/phpunit-performance.xml; done