-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
171 lines (155 loc) · 4.39 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
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
# Our base image
image: wpquark/wptest-php-nodejs-grunt:latest
# mysql service
services:
- mysql
# Select what we should cache
cache:
paths:
- vendor/
- node_modules/
- bower_components/
# Our stages
stages:
- test
- sonarqube
- build
- deploy
variables:
# Configure mysql service (https://hub.docker.com/_/mysql/)
MYSQL_DATABASE: wordpress_tests
MYSQL_ROOT_PASSWORD: mysql
WP_MULTISITE: "0"
# We test on php7
# default job to run on every commit, everywhere
test:
stage: test
tags:
- wordpress
before_script:
# Install npm to get grunt and other stuff
- npm install
# Install all dependencies
- grunt install
# Create the build files (js/css) so that we can test them
- grunt prep
# Check the PHP Version
- php -v
# Install WordPress PHPUnit Test
- bash bin/install-wp-tests.sh wordpress_test root mysql mysql $WP_VERSION
script:
- grunt test
artifacts:
paths:
- build/
expire_in: 1 week
# SonarQube Preview running everywhere except on master branch and schedules
sonarqube-preview:
stage: sonarqube
cache:
paths:
tags:
- sonar
before_script:
# Increase sonar memory
- export SONAR_RUNNER_OPTS="-Xmx3072m"
script:
- /opt/sonar-scanner/bin/sonar-scanner -Dsonar.login=$SONAR_TOKEN -Dsonar.analysis.mode=preview -Dsonar.gitlab.project_id=$CI_PROJECT_PATH -Dsonar.gitlab.commit_sha=$CI_COMMIT_SHA -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME -Dsonar.gitlab.only_issue_from_commit_file=true -Dsonar.gitlab.only_issue_from_commit_line=true
dependencies:
- test
except:
- master
- schedules
- web
# SonarQube Publish running on master of this repo and during schedules
sonarqube-publish:
stage: sonarqube
cache:
paths:
tags:
- sonar
before_script:
# Increase sonar memory
- export SONAR_RUNNER_OPTS="-Xmx3072m"
script:
- /opt/sonar-scanner/bin/sonar-scanner -Dsonar.login=$SONAR_TOKEN
dependencies:
- test
environment:
name: sonarqube
url: https://cq.wpquark.io/dashboard?id=cq.wpquark%3Awpupdate
only:
- master@wpq-server/wpq-wp-update
- schedules
- web
# Now comes our actual CI
# We work on the develop branch
# So we test there which is covered by the test job
# Now we build on merging to master
build:
stage: build
cache:
paths:
- vendor/
- node_modules/
- bower_components/
policy: pull
tags:
- wordpress
before_script:
# Install npm to get grunt and other stuff
- npm install
# Install all dependencies
- grunt install
script:
- grunt release
artifacts:
paths:
- build/package
expire_in: 1 week
only:
- master@wpq-server/wpq-wp-update
# release job on tag
# It basically creates an installable zip file and attaches to the artifact
deploy-distribution:
stage: deploy
cache:
paths:
- vendor/
- node_modules/
- bower_components/
policy: pull
tags:
- wordpress
variables:
CMD_CREATE_DIR: 'rm -rf '
before_script:
# Install npm to get grunt and other stuff
- npm install
# Install all dependencies
- grunt install
# Setup Environment variables to access keys & ssh agent
- eval $(ssh-agent -s)
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
# Make the build package if not found, because artifacts expire
- '[[ ! -f build/package/wpq-wp-update.zip ]] && echo "Distribution Package not found. Making now..." && grunt release || echo "Found Distribution Package. Using from artifacts"'
script:
# Make sure we add the Staging Key so that we can SSH
- ssh-add <(echo "$WPQ_DISTRIBUTION_KEY")
# Delete and recreate the temporary directory for copying
- ssh -p22800 wpqdist@gliese.itg-vps.com "rm -rf ~/tmp_wpq_wp_update && mkdir -p ~/tmp_wpq_wp_update"
# Copy the distribution ZIP
- scp -P22800 build/package/wpq-wp-update.zip wpqdist@gliese.itg-vps.com:~/tmp_wpq_wp_update
# Unzip over the existing one
- ssh -p22800 wpqdist@gliese.itg-vps.com "rm -rf ~/public_html/wp-content/plugins/wpq-wp-update && unzip ~/tmp_wpq_wp_update/wpq-wp-update.zip -d ~/public_html/wp-content/plugins"
artifacts:
name: 'wpq-wp-update'
paths:
- build/package/wpq-wp-update.zip
environment:
name: production/distribution
url: https://dist.wpquark.io/wp-admin/
dependencies:
- build
only:
- master@wpq-server/wpq-wp-update