Skip to content

Commit 6902b29

Browse files
author
Andy Stiller
committed
Merge branch 'dev'
2 parents 0de3fe8 + 2e4fd6c commit 6902b29

232 files changed

Lines changed: 3049 additions & 585 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitlab-ci.yml

Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
################
2+
# Drupal GitLabCI template
3+
#
4+
# Based off GitlabCI templates project: https://git.drupalcode.org/project/gitlab_templates
5+
# Guide: https://www.drupal.org/docs/develop/git/using-gitlab-to-contribute-to-drupal/gitlab-ci
6+
#
7+
# With thanks to:
8+
# - The GitLab Acceleration Initiative participants
9+
# - DrupalSpoons
10+
################
11+
12+
################
13+
# Workflow
14+
#
15+
# Define conditions for when the pipeline will run.
16+
# For example:
17+
# * On commit
18+
# * On merge request
19+
# * On manual trigger
20+
# * etc.
21+
# https://docs.gitlab.com/ee/ci/jobs/job_control.html#specify-when-jobs-run-with-rules
22+
#
23+
# Pipelines can also be configured to run on a schedule,though they still must meet the conditions defined in Workflow and Rules. This can be used, for example, to do nightly regression testing:
24+
# https://gitlab.com/help/ci/pipelines/schedules
25+
################
26+
27+
workflow:
28+
rules:
29+
# These 3 rules from https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Workflows/MergeRequest-Pipelines.gitlab-ci.yml
30+
# Run on merge requests
31+
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
32+
# Run when called from an upstream pipeline https://docs.gitlab.com/ee/ci/pipelines/downstream_pipelines.html?tab=Multi-project+pipeline#use-rules-to-control-downstream-pipeline-jobs
33+
- if: $CI_PIPELINE_SOURCE == 'pipeline'
34+
# Run on commits.
35+
- if: $CI_PIPELINE_SOURCE == "push" && $CI_PROJECT_ROOT_NAMESPACE == "project"
36+
# The last rule above blocks manual and scheduled pipelines on non-default branch. The rule below allows them:
37+
- if: $CI_PIPELINE_SOURCE == "schedule" && $CI_PROJECT_ROOT_NAMESPACE == "project"
38+
# Run if triggered from Web using 'Run Pipelines'
39+
- if: $CI_PIPELINE_SOURCE == "web"
40+
# Run if triggered from WebIDE
41+
- if: $CI_PIPELINE_SOURCE == "webide"
42+
43+
################
44+
# Variables
45+
#
46+
# Overriding variables
47+
# - To override one or more of these variables, simply declare your own
48+
# variables keyword.
49+
# - Keywords declared directly in .gitlab-ci.yml take precedence over include
50+
# files.
51+
# - Documentation: https://docs.gitlab.com/ee/ci/variables/
52+
# - Predefined variables: https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
53+
#
54+
################
55+
56+
variables:
57+
_CONFIG_DOCKERHUB_ROOT: "drupalci"
58+
_TARGET_PHP: "8.1"
59+
CONCURRENCY: 15
60+
GIT_DEPTH: "3"
61+
COMPOSER_ALLOW_SUPERUSER: 1
62+
63+
################
64+
# Stages
65+
#
66+
# Each job is assigned to a stage, defining the order in which the jobs are executed.
67+
# Jobs in the same stage run in parallel.
68+
#
69+
# If all jobs in a stage succeed, the pipeline will proceed to the next stage.
70+
# If any job in the stage fails, the pipeline will exit early.
71+
################
72+
73+
stages:
74+
################
75+
# Code quality checks
76+
#
77+
# This stage includes any codebase validation that we want to perform
78+
# before running functional tests.
79+
################
80+
- 🪄 Lint
81+
82+
################
83+
# Test
84+
#
85+
# The test phase actually executes the tests, as well as gathering results
86+
# and artifacts.
87+
################
88+
- 🗜️ Test
89+
90+
#############
91+
# Templates #
92+
#############
93+
94+
.run-on-mr: &run-on-mr
95+
if: $CI_PIPELINE_SOURCE == "merge_request_event"
96+
97+
.run-on-mr-manual: &run-on-mr-manual
98+
if: $CI_PIPELINE_SOURCE == "merge_request_event"
99+
when: manual
100+
allow_failure: true
101+
102+
.run-on-commit: &run-on-commit
103+
if: $CI_PIPELINE_SOURCE == "push" && $CI_PROJECT_ROOT_NAMESPACE == "project"
104+
105+
.run-daily: &run-daily
106+
if: $CI_PIPELINE_SOURCE == "schedule" && $CI_PROJECT_ROOT_NAMESPACE == "project"
107+
108+
.default-stage: &default-stage
109+
stage: 🗜️ Test
110+
trigger:
111+
# Rely on the status of the child pipeline.
112+
strategy: depend
113+
include:
114+
- local: .gitlab-ci/pipeline.yml
115+
rules:
116+
- <<: *run-on-commit
117+
- <<: *run-on-mr-manual
118+
119+
################
120+
# Jobs
121+
#
122+
# Jobs define what scripts are actually executed in each stage.
123+
################
124+
125+
'🧹 PHP Compatibility checks (PHPCS)':
126+
stage: 🪄 Lint
127+
variables:
128+
PHPCS_PHP_VERSION: "5.6"
129+
KUBERNETES_CPU_REQUEST: "16"
130+
interruptible: true
131+
allow_failure: true
132+
retry:
133+
max: 2
134+
when:
135+
- unknown_failure
136+
- api_failure
137+
- stuck_or_timeout_failure
138+
- runner_system_failure
139+
- scheduler_failure
140+
image:
141+
name: $_CONFIG_DOCKERHUB_ROOT/php-$_TARGET_PHP-apache:production
142+
artifacts:
143+
expire_in: 6 mos
144+
paths:
145+
- phpcs-quality-report.json
146+
reports:
147+
codequality: phpcs-quality-report.json
148+
rules:
149+
- <<: *run-on-mr
150+
before_script:
151+
- echo "{}" > composer.json
152+
- composer config allow-plugins true -n
153+
- composer require --dev drupal/coder:^8.2@stable micheh/phpcs-gitlab phpcompatibility/php-compatibility dealerdirect/phpcodesniffer-composer-installer
154+
- export TARGET_BRANCH=${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}${CI_COMMIT_BRANCH}
155+
script:
156+
- git fetch -vn --depth=$GIT_DEPTH origin "+refs/heads/$TARGET_BRANCH:refs/heads/$TARGET_BRANCH"
157+
- export MODIFIED=`git diff --name-only refs/heads/$TARGET_BRANCH|while read r;do echo "$CI_PROJECT_DIR/$r";done|tr "\n" " "`
158+
- echo -e "$MODIFIED" | tr " " "\n"
159+
- echo "If this list contains more files than what you changed, then you need to rebase your branch."
160+
- vendor/bin/phpcs --basepath=$CI_PROJECT_DIR --report-\\Micheh\\PhpCodeSniffer\\Report\\Gitlab=phpcs-quality-report.json --report-full --report-summary --standard=PHPCompatibility --runtime-set testVersion $PHPCS_PHP_VERSION --extensions=php,module,inc,install,test,profile,theme $MODIFIED
161+
162+
# Default job.
163+
'PHP 8.1 MySQL 5.7':
164+
<<: *default-stage
165+
variables:
166+
_TARGET_PHP: "8.1"
167+
_TARGET_DB: "mysql-5.7"
168+
rules:
169+
- <<: *run-on-commit
170+
- <<: *run-on-mr
171+
172+
'PHP 5.6 MySQL 5.5':
173+
<<: *default-stage
174+
variables:
175+
_TARGET_PHP: "5.6"
176+
_TARGET_DB: "mysql-5.5"
177+
178+
'PHP 7.2 MySQL 5.7':
179+
<<: *default-stage
180+
variables:
181+
_TARGET_PHP: "7.2"
182+
_TARGET_DB: "mysql-5.7"
183+
184+
'PHP 7.4 MySQL 5.7':
185+
<<: *default-stage
186+
variables:
187+
_TARGET_PHP: "7.4"
188+
_TARGET_DB: "mysql-5.7"
189+
190+
'PHP 8.0 MySQL 5.7':
191+
<<: *default-stage
192+
variables:
193+
_TARGET_PHP: "8.0"
194+
_TARGET_DB: "mysql-5.7"
195+
196+
'PHP 8.2 MySQL 8':
197+
<<: *default-stage
198+
variables:
199+
_TARGET_PHP: "8.2"
200+
_TARGET_DB: "mysql-8"
201+
202+
'PHP 7.4 PostgreSQL 9.5':
203+
<<: *default-stage
204+
variables:
205+
_TARGET_PHP: "7.4"
206+
_TARGET_DB: "pgsql-9.5"
207+
208+
'PHP 8.1 PostgreSQL 14.1':
209+
<<: *default-stage
210+
variables:
211+
_TARGET_PHP: "8.1"
212+
_TARGET_DB: "pgsql-14.1"
213+
214+
'PHP 7.4 SQLite 3.27.0':
215+
<<: *default-stage
216+
variables:
217+
_TARGET_PHP: "7.4"
218+
_TARGET_DB: "sqlite-3"
219+
220+
'PHP 8.1 MariaDB 10.3.22':
221+
<<: *default-stage
222+
variables:
223+
_TARGET_PHP: "8.1"
224+
_TARGET_DB: "mariadb-10.3.22"

.gitlab-ci/.htaccess-parent

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Redirect everything via the subdirectory.
2+
3+
RewriteEngine on
4+
RewriteRule (.*) subdirectory/$1 [L]

.gitlab-ci/pipeline.yml

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
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 --account-mail=admin@example.com
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 origin "+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

Comments
 (0)