|
| 1 | +stages: |
| 2 | + ################ |
| 3 | + # Test |
| 4 | + # |
| 5 | + # The test phase actually executes the tests, as well as gathering results |
| 6 | + # and artifacts. |
| 7 | + ################ |
| 8 | + - 🗜️ Test |
| 9 | + |
| 10 | +############# |
| 11 | +# Templates # |
| 12 | +############# |
| 13 | + |
| 14 | +.default-job-settings: &default-job-settings |
| 15 | + interruptible: true |
| 16 | + allow_failure: false |
| 17 | + retry: |
| 18 | + max: 2 |
| 19 | + when: |
| 20 | + - unknown_failure |
| 21 | + - api_failure |
| 22 | + - stuck_or_timeout_failure |
| 23 | + - runner_system_failure |
| 24 | + - scheduler_failure |
| 25 | + image: |
| 26 | + name: $_CONFIG_DOCKERHUB_ROOT/php-$_TARGET_PHP-apache:production |
| 27 | + rules: |
| 28 | + - if: $CI_PIPELINE_SOURCE == "parent_pipeline" |
| 29 | + |
| 30 | +.test-variables: &test-variables |
| 31 | + FF_NETWORK_PER_BUILD: 1 |
| 32 | + SIMPLETEST_BASE_URL: http://localhost/subdirectory |
| 33 | + DB_DRIVER: mysql |
| 34 | + MYSQL_ROOT_PASSWORD: root |
| 35 | + MYSQL_DATABASE: drupal |
| 36 | + MYSQL_USER: drupaltestbot |
| 37 | + MYSQL_PASSWORD: drupaltestbotpw |
| 38 | + POSTGRES_DB: drupaltestbot |
| 39 | + POSTGRES_USER: drupaltestbot |
| 40 | + POSTGRES_PASSWORD: drupaltestbotpw |
| 41 | + CI_PARALLEL_NODE_INDEX: $CI_NODE_INDEX |
| 42 | + CI_PARALLEL_NODE_TOTAL: $CI_NODE_TOTAL |
| 43 | + |
| 44 | +.with-database: &with-database |
| 45 | + name: $_CONFIG_DOCKERHUB_ROOT/$_TARGET_DB:production |
| 46 | + alias: database |
| 47 | + |
| 48 | +.with-chrome: &with-chrome |
| 49 | + name: $_CONFIG_DOCKERHUB_ROOT/chromedriver:production |
| 50 | + alias: chrome |
| 51 | + entrypoint: |
| 52 | + - chromedriver |
| 53 | + - "--no-sandbox" |
| 54 | + - "--log-path=/tmp/chromedriver.log" |
| 55 | + - "--verbose" |
| 56 | + - "--whitelisted-ips=" |
| 57 | + |
| 58 | +.phpunit-artifacts: &phpunit-artifacts |
| 59 | + artifacts: |
| 60 | + when: always |
| 61 | + expire_in: 6 mos |
| 62 | + reports: |
| 63 | + junit: ./sites/default/files/simpletest/*.xml |
| 64 | + paths: |
| 65 | + - ./sites/default/files/simpletest |
| 66 | + |
| 67 | +.setup-webroot: &setup-webserver |
| 68 | + before_script: |
| 69 | + - ln -s $CI_PROJECT_DIR /var/www/html/subdirectory |
| 70 | + - cp $CI_PROJECT_DIR/.gitlab-ci/.htaccess-parent /var/www/html/.htaccess |
| 71 | + - sudo service apache2 start |
| 72 | + |
| 73 | +.get-simpletest-db: &get-simpletest-db |
| 74 | + - | |
| 75 | + # Assume SQLite unless we have another known target. |
| 76 | + export SIMPLETEST_DB=sqlite://localhost/$CI_PROJECT_DIR/sites/default/files/db.sqlite |
| 77 | + [[ $_TARGET_DB == mysql* ]] && export SIMPLETEST_DB=mysql://$MYSQL_USER:$MYSQL_PASSWORD@database/$MYSQL_DATABASE |
| 78 | + [[ $_TARGET_DB == mariadb* ]] && export SIMPLETEST_DB=mysql://$MYSQL_USER:$MYSQL_PASSWORD@database/$MYSQL_DATABASE |
| 79 | + [[ $_TARGET_DB == pgsql* ]] && export SIMPLETEST_DB=pgsql://$POSTGRES_USER:$POSTGRES_PASSWORD@database/$POSTGRES_DB |
| 80 | + - echo "SIMPLETEST_DB = $SIMPLETEST_DB" |
| 81 | + |
| 82 | +.prepare-dirs: &prepare-dirs |
| 83 | + - mkdir -p ./sites/default/files ./sites/default/files/simpletest ./build/logs/junit |
| 84 | + - chown -R www-data:www-data ./sites ./build/logs/junit /var/www/ |
| 85 | + - sudo -u www-data git config --global --add safe.directory $CI_PROJECT_DIR |
| 86 | + |
| 87 | +.install-drupal: &install-drupal |
| 88 | + - sudo -u www-data /usr/local/bin/drush si -y --db-url=$SIMPLETEST_DB --clean-url=0 --account-name=admin --account-pass=drupal [email protected] |
| 89 | + - sudo -u www-data /usr/local/bin/drush vset simpletest_clear_results '0' |
| 90 | + - sudo -u www-data /usr/local/bin/drush vset simpletest_verbose '1' |
| 91 | + - sudo -u www-data /usr/local/bin/drush en -y simpletest |
| 92 | + |
| 93 | +.run-tests: &run-tests |
| 94 | + script: |
| 95 | + - *get-simpletest-db |
| 96 | + - *prepare-dirs |
| 97 | + - *install-drupal |
| 98 | + # We need to pass this along directly even though it's set in the environment parameters. |
| 99 | + - sudo -u www-data php ./scripts/run-tests.sh --color --concurrency "$CONCURRENCY" --url "$SIMPLETEST_BASE_URL" --verbose --fail-only --all --xml "$CI_PROJECT_DIR/sites/default/files/simpletest" --ci-parallel-node-index $CI_PARALLEL_NODE_INDEX --ci-parallel-node-total $CI_PARALLEL_NODE_TOTAL |
| 100 | + |
| 101 | +.run-test-only-tests: &run-test-only-tests |
| 102 | + script: |
| 103 | + - *get-simpletest-db |
| 104 | + - *prepare-dirs |
| 105 | + - *install-drupal |
| 106 | + - export TARGET_BRANCH=${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}${CI_COMMIT_BRANCH} |
| 107 | + - git fetch -vn --depth=50 "$CI_MERGE_REQUEST_PROJECT_URL" "+refs/heads/$TARGET_BRANCH:refs/heads/$TARGET_BRANCH" |
| 108 | + - | |
| 109 | + echo "ℹ️ Changes from ${TARGET_BRANCH}" |
| 110 | + git diff ${CI_MERGE_REQUEST_DIFF_BASE_SHA} --name-only |
| 111 | + echo "1️⃣ Reverting non test changes" |
| 112 | + if [[ $(git diff ${CI_MERGE_REQUEST_DIFF_BASE_SHA} --diff-filter=DM --name-only|grep -Ev '.test$'|grep -v .gitlab-ci|grep -v scripts/run-tests.sh) ]]; then |
| 113 | + git diff ${CI_MERGE_REQUEST_DIFF_BASE_SHA} --diff-filter=DM --name-only|grep -Ev '.test$'|grep -v .gitlab-ci|grep -v scripts/run-tests.sh|while read file;do |
| 114 | + echo "↩️ Reverting $file" |
| 115 | + git checkout refs/heads/${TARGET_BRANCH} -- $file; |
| 116 | + done |
| 117 | + fi |
| 118 | + echo "2️⃣ Deleting new files" |
| 119 | + if [[ $(git diff ${CI_MERGE_REQUEST_DIFF_BASE_SHA} --diff-filter=A --name-only|grep -Ev '.test$'|grep -v .gitlab-ci|grep -v scripts/run-tests.sh) ]]; then |
| 120 | + git diff ${CI_MERGE_REQUEST_DIFF_BASE_SHA} --diff-filter=A --name-only|grep -Ev '.test$'|grep -v .gitlab-ci|grep -v scripts/run-tests.sh|while read file;do |
| 121 | + echo "🗑️️ Deleting $file" |
| 122 | + git rm $file |
| 123 | + done |
| 124 | + fi |
| 125 | + echo "3️⃣ Running test changes for this branch" |
| 126 | + if [[ $(git diff ${CI_MERGE_REQUEST_DIFF_BASE_SHA} --name-only|grep -E '.test$') ]]; then |
| 127 | + git diff ${CI_MERGE_REQUEST_DIFF_BASE_SHA} --name-only|grep -E ".test$"|while read file;do |
| 128 | + sudo -u www-data php ./scripts/run-tests.sh --color --concurrency "$CONCURRENCY" --url "$SIMPLETEST_BASE_URL" --verbose --fail-only --xml "$CI_PROJECT_DIR/sites/default/files/simpletest/test-only" --file "$file" |
| 129 | + done |
| 130 | + fi |
| 131 | +
|
| 132 | +################ |
| 133 | +# Jobs |
| 134 | +# |
| 135 | +# Jobs define what scripts are actually executed in each stage. |
| 136 | +################ |
| 137 | + |
| 138 | +'⚡️ PHPUnit Unit': |
| 139 | + <<: [ *phpunit-artifacts, *setup-webserver, *run-tests, *default-job-settings ] |
| 140 | + stage: 🗜️ Test |
| 141 | + parallel: 3 |
| 142 | + services: |
| 143 | + - <<: *with-database |
| 144 | + - <<: *with-chrome |
| 145 | + variables: |
| 146 | + <<: *test-variables |
| 147 | + CONCURRENCY: "$CONCURRENCY" |
| 148 | + KUBERNETES_CPU_REQUEST: "16" |
| 149 | + |
| 150 | +'🩹 Test-only changes': |
| 151 | + <<: [ *phpunit-artifacts, *setup-webserver, *run-test-only-tests, *default-job-settings ] |
| 152 | + stage: 🗜️ Test |
| 153 | + when: manual |
| 154 | + interruptible: true |
| 155 | + allow_failure: true |
| 156 | + variables: |
| 157 | + <<: *test-variables |
| 158 | + services: |
| 159 | + - <<: *with-database |
| 160 | + - <<: *with-chrome |
0 commit comments