|
| 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" |
0 commit comments