-
Notifications
You must be signed in to change notification settings - Fork 4
/
config.yml
200 lines (185 loc) · 7.7 KB
/
config.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# PHP CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-php/ for more details
#
version: 2
jobs:
build:
docker:
# You can easily switch containers and versions here.
# @see https://circleci.com/docs/2.0/circleci-images/#php
# The following container already comes with Apache, Node.js and
# chromedriver and geckodriver preinstalled.
- image: circleci/php:7.4-apache-node-browsers
- image: circleci/mariadb:latest
environment:
- MYSQL_ROOT_HOST=%
working_directory: ~/drupal-circleci-behat
steps:
- checkout
# Setup Apache.
# For convenience the site will be accessible internally under a
# *.localhost TLD. Which also is used in the behat.yml.
- run:
name: Setup Apache
command: |
sudo cp .circleci/env/drupal-circleci-behat.conf /etc/apache2/sites-available/drupal-circleci-behat.conf
sudo a2ensite drupal-circleci-behat
sudo service apache2 start
echo 127.0.0.1 drupal-circleci-behat.localhost | sudo tee -a /etc/hosts
- run:
name: Setup tools
command: |
sudo apt-get -qq update && sudo apt-get -qqy upgrade
sudo apt-get -yqq install libpng-dev libonig-dev mariadb-client nano xvfb
sudo docker-php-ext-install gd mbstring mysqli pdo pdo_mysql
sudo service apache2 restart
# Xvfb enables you to run graphical applications for browser tests
# headlessly (on a CI server without a display) while also having the
# ability to take screenshots.
- run:
name: Start Xvfb
command: |
sudo Xvfb :7055
export DISPLAY=:7055
background: true
- run:
name: Download Selenium
command: |
curl -O http://selenium-release.storage.googleapis.com/3.141/selenium-server-standalone-3.141.5.jar
- run:
name: Start Selenium
command: |
mkdir -p /tmp/selenium
java -jar selenium-server-standalone-3.141.5.jar -log /tmp/selenium/selenium.log
background: true
# Restore cache.
# Cache gets invalidated automatically as soon as the composer.lock has
# changed between two builds.
# You can easily invalidate the cache manually by incrementing its key:
# v2-..., v3-... and so on.
- restore_cache:
keys:
- v1-dependencies-{{ checksum "composer.lock" }}
# Fallback to use the latest cache if no exact match is found.
- v1-dependencies-
# Install dependencies and add the bin dir to the global $PATH to use its
# commands without needing to reference their location:
# Now you can use `drush` instead of `cd web && ../bin/drush` for example.
- run:
name: Composer Install
command: |
composer install -n --prefer-dist
echo 'export PATH=$HOME/drupal-circleci-behat/vendor/bin:$PATH' >> $BASH_ENV
source /home/circleci/.bashrc
# Save the dependencies.
# This step as all other steps can also get implemented multiple times.
# Imagine what else you can cache then:
# - theme dependencies
# - database dumps (importing an existing database before `drush cim`
# will dramatically improve build time when the project gets larger)
# - ...
- save_cache:
paths:
- ./vendor
key: v1-dependencies-{{ checksum "composer.lock" }}
# A minimal profile Drupal created locally using the following command:
# - drush -y site:install minimal --site-name='Hello World' --site-mail=info@drupal-circleci-behat.localhost --account-name=admin --account-pass=admin
# - drush -y cex
# But you could also simply create a standard profile Drupal, set UUID to be the same as in system.site.yml and then import existing config:
# - drush -y site:install
# - drush -y ev '\Drupal::entityManager()->getStorage("shortcut_set")->load("default")->delete();'
# - drush -y config-set "system.site" uuid "c6e1475a-d30b-4dac-9cba-7dc12de37090"
# - drush -y cim
# As soon as your project grows you may want to rewrite this step:
# - drush sqlc < circleci-cached-database-dump.sql
# - drush updb
# - drush cim
# - ...
- run:
name: Setup Drupal
command: |
cp .circleci/env/.htaccess web/.htaccess
cp .circleci/env/settings.local.php web/sites/default/settings.local.php
cd web
drush -y site:install --existing-config
# Run tests and store the results to get a nice looking test summary.
# @see https://circleci.com/docs/2.0/configuration-reference/#store_test_results
- run:
name: Tests
command: |
mkdir -p tests/behat/test-results/junit
cd tests/behat
behat --no-snippets -f pretty -o std -f junit -o test-results/junit/junit.xml
- store_test_results:
path: tests/behat/test-results
# When we started Selenium we told it to log into that directory. Let's
# store the logs for better debuggability, to maybe have a look at them
# later from the CircleCI UI.
- store_artifacts:
path: /tmp/selenium
# Above commands all belong to the build step. Now comes the deploy step.
# Which only gets reached when all tests passed.
#
# This step absolutely depends on your deployment tactic:
# - maybe you will SSH upload the build to your servers
# - maybe you will SSH trigger some deploy script to do the work
# - ...
#
# In this example CircleCI branch-wise SSH into the dev or live server and
# calls a Bash script which then may run:
# - bin/drush state:set system.maintenance_mode 1 -y
# - git pull
# - composer install
# - bin/drush updb -y
# - bin/drush cim -y
# - ...
deploy:
machine:
enabled: true
working_directory: ~/drupal-circleci-behat
steps:
- checkout
# - run:
# name: Fix ssh Could not resolve hostname
# command: |
# ssh-keyscan "${LIVE_IP}" >> ~/.ssh/known_hosts
# ssh-keyscan "${DEV_IP}" >> ~/.ssh/known_hosts
#
# - add_ssh_keys: # add private SSH key from CircleCI account based on fingerprint
# fingerprints:
# - "14:09:a1:b2:b3:c4:d5:e6:f7:g8:h9:81:"
#
# - run:
# name: Deploy main
# command: if [ "${CIRCLE_BRANCH}" == "main" ]; then ssh -p "${LIVE_PORT}" "${LIVE_USER}"@"${LIVE_IP}" "cd /var/www/wordpress-circleci-behat/scripts/deployment && . deploy.sh ${CIRCLE_SHA1}"; else echo "Skipped"; fi
# - run:
# name: Deploy dev
# command: if [ "${CIRCLE_BRANCH}" == "develop" ]; then ssh -p "${DEV_PORT}" "${DEV_USER}"@"${DEV_IP}" "cd /var/www/wordpress-circleci-behat/scripts/deployment && . deploy.sh ${CIRCLE_SHA1}"; else echo "Skipped"; fi
- run: echo "${CIRCLE_BRANCH}"; echo "${CIRCLE_SHA1}";
# In this example the whole workflow which consists of a build step and a
# deploy step only gets triggered on pushes to the develop branch and the
# main branch.
# Simply remove the filters to have it triggered in every branch (which raises
# the risk that you hit the maximum 1.500 build minutes/month when you only have
# a free plan).
workflows:
version: 2
build-and-deploy:
jobs:
- build
# - build:
# filters:
# branches:
# only:
# - develop
# - main
- deploy:
requires:
- build
# You could limit the CI to only be triggered for develop and main branches.
# filters:
# branches:
# only:
# - develop
# - main