forked from Vincit/wordpress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
141 lines (117 loc) · 4.57 KB
/
.gitlab-ci.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
image: edbizarro/gitlab-ci-pipeline-php:7.3-alpine
services:
- mysql:5.7
# Fill in ssh username, hosts, ports and theme slug ie. directory name
variables:
WP_TEST_URL: "http://localhost:12000"
WP_TEST_USER: "test"
WP_TEST_USER_PASS: "test"
WP_ENV: "ci"
MYSQL_DATABASE: "wp_test"
MYSQL_HOST: "mysql"
MYSQL_ROOT_PASSWORD: "root"
DB_NAME: "wp_test"
DB_USER: "root"
DB_PASSWORD: "root"
DB_HOST: "mysql"
SSH_USERNAME: "username"
PROD_HOST: "example.com"
STAGING_HOST: "staging.example.com"
PROD_SSH_PORT: "11111"
STAGING_SSH_PORT: "11222"
THEME_SLUG: "theme_dir"
stages:
- install
- build
- test
- deploy
cache:
key: project-deps
paths:
- composer-cache/
before_script:
- sudo apk add mysql-client sshpass pkgconfig autoconf automake libtool nasm build-base zlib-dev
# Install router so that we don't need nginx/php-fpm
- curl -s https://raw.githubusercontent.com/Seravo/wordpress-test-template/master/lib/router.php > htdocs/router.php
# Start php server on background
- cd htdocs && php -S 0.0.0.0:12000 router.php & sleep 2
install:
stage: install
script:
# Install Composer deps
- COMPOSER_CACHE_DIR=composer-cache composer install --no-dev --no-interaction
# Install WordPress with wp-cli
- curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
- php wp-cli.phar core install --url=$WP_TEST_URL --title='Test' --admin_user=$WP_TEST_USER --admin_password=$WP_TEST_USER_PASS --admin_email="$WP_TEST_USER@wordpress.dev" --skip-email --path=htdocs/wordpress
artifacts:
untracked: true
only:
- master
- staging
- production
build:
stage: build
script:
# Change to theme dir
- cd htdocs/wp-content/themes/$THEME_SLUG
# Install Composer deps
- composer install --no-dev --no-interaction
# Install NPM packages and build using production confs
- npm install
artifacts:
untracked: true
cache:
key: theme-deps
paths:
- htdocs/wp-content/themes/$THEME_SLUG/vendor/
- htdocs/wp-content/themes/$THEME_SLUG/node_modules/
only:
- master
- staging
- production
test:
stage: test
script:
- echo "Running test"
# Get the database
- sshpass -e ssh -q -o StrictHostKeyChecking=no $SSH_USERNAME@$PROD_HOST -p $PROD_SSH_PORT 'wp db export - --single-transaction' > database.sql
- php wp-cli.phar db import database.sql --path=htdocs/wordpress
- rm database.sql
# Activate all plugins
- php wp-cli.phar plugin activate --all --path=htdocs/wordpress
# Test webserver
- curl -i http://localhost:12000
# Syntax check all php files and fail for any error text in STDERR
- '! find . -type f -name "*.php" -exec php -d error_reporting=32767 -l {} \; 2>&1 >&- | grep "^"'
# @TODO: Run a more extensive test using the above real WordPress installation
only:
- master
- staging
- production
# deploy_staging:
# stage: deploy
# script:
# # Set permissions correctly because GitLab sets them to 666/777 https://gitlab.com/gitlab-org/gitlab-runner/issues/1736
# - sudo find $CI_PROJECT_DIR -type f -exec chmod 644 {} \;
# - sudo find $CI_PROJECT_DIR -type d -exec chmod 755 {} \;
# - echo "Deploy to staging server"
# - sshpass -e rsync -av --progress --exclude='.git' --exclude='composer-cache' --exclude='node_modules' --exclude='*/wp-content/uploads/*' --exclude='*/wp-content/db.php' --delete -e "ssh -T -o Compression=no -o StrictHostKeyChecking=no -p $STAGING_SSH_PORT" $CI_PROJECT_DIR/ $SSH_USERNAME@$STAGING_HOST:/data/wordpress
# - sshpass -e ssh -q -o StrictHostKeyChecking=no $SSH_USERNAME@$STAGING_HOST -p $STAGING_SSH_PORT 'wp-restart-nginx && wp-flush-cache && wp-fix-languages'
# environment:
# name: staging
# url: https://$STAGING_HOST
# only:
# - staging
# deploy_production:
# stage: deploy
# script:
# - sudo find $CI_PROJECT_DIR -type f -exec chmod 644 {} \;
# - sudo find $CI_PROJECT_DIR -type d -exec chmod 755 {} \;
# - echo "Deploy to production server"
# - sshpass -e rsync -av --progress --exclude='.git' --exclude='composer-cache' --exclude='node_modules' --exclude='*/wp-content/uploads/*' --exclude='*/wp-content/db.php' --delete -e "ssh -T -o Compression=no -o StrictHostKeyChecking=no -p $PROD_SSH_PORT" $CI_PROJECT_DIR/ $SSH_USERNAME@$PROD_HOST:/data/wordpress
#. - sshpass -e ssh -q -o StrictHostKeyChecking=no $SSH_USERNAME@$PROD_HOST -p $PROD_SSH_PORT 'wp-restart-nginx && wp-flush-cache && wp-fix-languages'
# environment:
# name: production
# url: https://$PROD_HOST
# only:
# - production