-
Notifications
You must be signed in to change notification settings - Fork 12
215 lines (183 loc) · 7.72 KB
/
smoke-test.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
name: Smoke Test
on:
pull_request:
types: [ labeled ]
workflow_dispatch:
inputs:
ref:
description: 'The branch to run the smoke test on'
required: false
default: 'master'
workflow_run:
workflows: [ Release Plugin ]
types:
- completed
schedule:
- cron: '0 3 * * 0/2'
env:
# Must match the env variables in .dist.env file
TEST_SITE_DB_HOST: localhost
WP_ROOT_FOLDER: /tmp/wordpress
TEST_SITE_DB_NAME: test_acceptance
TEST_SITE_DB_USER: root
TEST_SITE_DB_PASSWORD: root
TEST_SITE_TABLE_PREFIX: wp_
TEST_SITE_ADMIN_USERNAME: admin
TEST_SITE_ADMIN_PASSWORD: password
TEST_SITE_WP_ADMIN_PATH: /wp-admin
TEST_SITE_WP_URL: http://localhost:8888
TEST_SITE_WP_DOMAIN: localhost:8888
TEST_SITE_ADMIN_EMAIL: [email protected]
jobs:
smoke_test:
# If the event is label added, check if the label is 'run: smoke tests' otherwise run the smoke test
if: |
github.event_name == 'pull_request' && contains(github.event.label.name, 'run: smoke tests') ||
github.event_name == 'workflow_dispatch' ||
github.event_name == 'push' && github.ref == 'refs/heads/master' ||
github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success' ||
github.event_name == 'schedule'
name: Smoke Test
runs-on: ubuntu-latest
strategy:
fail-fast: true
max-parallel: 2
matrix:
php: [ 7.4, 8.0 ]
WP_VERSION: [ latest ]
WC_VERSION: [ latest ]
include:
- php: 7.4
WP_VERSION: latest
WC_VERSION: latest
- php: 8.1
WP_VERSION: latest
WC_VERSION: latest
services:
mariadb:
image: mariadb:latest
ports:
- 3306
env:
MYSQL_DATABASE: test_acceptance
MYSQL_ROOT_PASSWORD: root
options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3
steps:
- uses: actions/checkout@v3
- name: Setup proper PHP version
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
ini-values: output_buffering=off
extensions: mbstring, intl, pdo_mysql
- name: Setup github token
run: composer config -g github-oauth.github.com ${{ secrets.ACCESS_TOKEN }}
- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install Dependencies
run: |
composer install --no-interaction --prefer-dist --no-progress
- name: Set database connection env globals
env:
DB_PORT: ${{ job.services.mariadb.ports[3306] }}
run: |
echo "TEST_SITE_DB_HOST=127.0.0.1:$DB_PORT" >> $GITHUB_ENV
echo "TEST_SITE_DB_DSN=mysql:host=127.0.0.1:$DB_PORT;dbname=$TEST_SITE_DB_NAME" >> $GITHUB_ENV
- name: Verify MariaDB connection and database list
env:
DB_PORT: ${{ job.services.mariadb.ports[3306] }}
run: |
while ! mysqladmin ping -h"127.0.0.1" -P"$DB_PORT" --silent; do
sleep 1
done
mysql -u $TEST_SITE_DB_USER -p"$TEST_SITE_DB_PASSWORD" -h"127.0.0.1" -P"$DB_PORT" -e "SHOW DATABASES;"
- name: Setup WP CLI tools
run: |
mkdir -p $WP_ROOT_FOLDER
mkdir $GITHUB_WORKSPACE/tools
wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar -P $GITHUB_WORKSPACE/tools/
chmod +x $GITHUB_WORKSPACE/tools/wp-cli.phar && mv $GITHUB_WORKSPACE/tools/wp-cli.phar $GITHUB_WORKSPACE/tools/wp
echo "$GITHUB_WORKSPACE/tools/" >> $GITHUB_PATH
- name: Prepare environment
run: |
# Install WP
wp core download --version=${{ matrix.WP_VERSION }} || exit 1
wp config create --dbname="$TEST_SITE_DB_NAME" --dbuser="$TEST_SITE_DB_USER" --dbpass="$TEST_SITE_DB_PASSWORD" --dbhost="$TEST_SITE_DB_HOST" --dbprefix="$TEST_SITE_TABLE_PREFIX" || exit 1
wp config set WP_DEBUG true --raw || exit 1
wp config set WP_DEBUG_LOG true --raw || exit 1
wp core install --url="$TEST_SITE_WP_URL" --title="Test" --admin_user="$TEST_SITE_ADMIN_USERNAME" --admin_password="$TEST_SITE_ADMIN_PASSWORD" --admin_email="$TEST_SITE_ADMIN_EMAIL" --skip-email || exit 1
wp rewrite structure '/%postname%/' --hard || exit 1
wp core update-db || exit 1
# Uninstall all plugins
wp plugin uninstall --all || exit 1
# Install WooCommerce
if [[ ${{ matrix.WC_VERSION }} == 'latest' ]]; then
wp plugin install woocommerce --activate || exit 1
else
wp plugin install woocommerce --version=${{ matrix.WC_VERSION }} --activate || exit 1
fi
# Import dummy data
wp wc tool run install_pages --user=$TEST_SITE_ADMIN_USERNAME || exit 1
wp plugin install wordpress-importer --activate || exit 1
wp import $WP_ROOT_FOLDER/wp-content/plugins/woocommerce/sample-data/sample_products.xml --authors=create >> /dev/null || exit 1
# Deactivate WooCommerce and importer plugin
wp plugin deactivate wordpress-importer --uninstall || exit 1
wp plugin deactivate woocommerce || exit 1
# Install plugin
# wp plugin install $GITHUB_WORKSPACE --activate || exit 1
# Export the database
wp db export $GITHUB_WORKSPACE/tests/_data/dump.sql || exit 1
# Create codeception.yml file
cp $GITHUB_WORKSPACE/codeception.dist.yml $GITHUB_WORKSPACE/codeception.yml || exit 1
env:
DB_PORT: ${{ job.services.mariadb.ports[3306] }}
working-directory: ${{ env.WP_ROOT_FOLDER }}
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '11'
- name: Run Selenium
run: nohup java -jar $SELENIUM_JAR_PATH standalone --port 4444 &
- name: Run chromedriver
run: nohup $CHROMEWEBDRIVER/chromedriver --url-base=/wd/hub /dev/null 2>&1 &
- name: Start a web server
run: php -S "$TEST_SITE_WP_DOMAIN" -t "$WP_ROOT_FOLDER" >/dev/null 2>&1 &
- name: Log versions
run: |
echo "Tested on PHP ${{ matrix.php }} and WordPress ${{ matrix.WP_VERSION }} and WooCommerce ${{ matrix.WC_VERSION }}"
echo "PHP version: $(php -v)"
echo "Composer version: $(composer --version)"
echo "Node version: $(node -v)"
echo "NPM version: $(npm -v)"
echo "Yarn version: $(yarn -v)"
- name: Run Codeception acceptance tests
run: composer run-script test:acceptance
- name: Run Codeception functional tests
run: composer run-script test:functional
# - name: Run Codeception WP unit tests
# run: composer run-script test:wpunit
- name: Maybe Upload Tests Output
if: ${{ failure() }}
uses: actions/upload-artifact@v2
with:
name: tests-output-${{ matrix.php }}-${{ matrix.WP_VERSION }}-${{ matrix.WC_VERSION }}
path: ./tests/_output/
- name: Maybe Upload Database Dump
if: ${{ failure() }}
uses: actions/upload-artifact@v2
with:
name: database-dump-${{ matrix.php }}-${{ matrix.WP_VERSION }}-${{ matrix.WC_VERSION }}
path: ./tests/_data/
- name: Upload Debug Log
if: ${{ always() }}
uses: actions/upload-artifact@v2
with:
name: debug-log-${{ matrix.php }}-${{ matrix.WP_VERSION }}-${{ matrix.WC_VERSION }}
path: ${{ env.WP_ROOT_FOLDER }}/wp-content/debug.log