-
Notifications
You must be signed in to change notification settings - Fork 3
250 lines (214 loc) · 12.6 KB
/
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
name: Run Tests
# When to run tests.
on:
pull_request:
types:
- opened
- synchronize
push:
branches:
- main
jobs:
tests:
# Name.
name: ${{ matrix.test-groups }} / WordPress ${{ matrix.wp-versions }} / PHP ${{ matrix.php-versions }}
# Virtual Environment to use.
# @see: https://github.com/actions/virtual-environments
runs-on: ubuntu-20.04
# Environment Variables.
# Accessible by using ${{ env.NAME }}
# Use ${{ secrets.NAME }} to include any GitHub Secrets in ${{ env.NAME }}
# The base folder will always be /home/runner/work/github-repo-name/github-repo-name
env:
ROOT_DIR: /home/runner/work/convertkit-woocommerce/convertkit-woocommerce/wordpress
PLUGIN_DIR: /home/runner/work/convertkit-woocommerce/convertkit-woocommerce/wordpress/wp-content/plugins/convertkit-woocommerce
DB_NAME: test
DB_USER: root
DB_PASS: root
DB_HOST: localhost
INSTALL_PLUGINS: "custom-order-numbers-for-woocommerce woocommerce woocommerce-gateway-stripe" # Don't include this repository's Plugin here.
STRIPE_TEST_PUBLISHABLE_KEY: ${{ secrets.STRIPE_TEST_PUBLISHABLE_KEY }} # Stripe Test API Publishable Key, stored in the repository's Settings > Secrets
STRIPE_TEST_SECRET_KEY: ${{ secrets.STRIPE_TEST_SECRET_KEY }} # Stripe Test API Secret Key, stored in the repository's Settings > Secrets
CONVERTKIT_API_KEY: ${{ secrets.CONVERTKIT_API_KEY }} # ConvertKit API Key, stored in the repository's Settings > Secrets
CONVERTKIT_API_SECRET: ${{ secrets.CONVERTKIT_API_SECRET }} # ConvertKit API Secret, stored in the repository's Settings > Secrets
CONVERTKIT_API_KEY_NO_DATA: ${{ secrets.CONVERTKIT_API_KEY_NO_DATA }} # ConvertKit API Key for ConvertKit account with no data, stored in the repository's Settings > Secrets
CONVERTKIT_API_SECRET_NO_DATA: ${{ secrets.CONVERTKIT_API_SECRET_NO_DATA }} # ConvertKit API Secret for ConvertKit account with no data, stored in the repository's Settings > Secrets
CONVERTKIT_OAUTH_ACCESS_TOKEN: ${{ secrets.CONVERTKIT_OAUTH_ACCESS_TOKEN }}
CONVERTKIT_OAUTH_REFRESH_TOKEN: ${{ secrets.CONVERTKIT_OAUTH_REFRESH_TOKEN }}
CONVERTKIT_OAUTH_ACCESS_TOKEN_NO_DATA: ${{ secrets.CONVERTKIT_OAUTH_ACCESS_TOKEN_NO_DATA }}
CONVERTKIT_OAUTH_REFRESH_TOKEN_NO_DATA: ${{ secrets.CONVERTKIT_OAUTH_REFRESH_TOKEN_NO_DATA }}
CONVERTKIT_OAUTH_CLIENT_ID: ${{ secrets.CONVERTKIT_OAUTH_CLIENT_ID }}
CONVERTKIT_OAUTH_REDIRECT_URI: ${{ secrets.CONVERTKIT_OAUTH_REDIRECT_URI }}
KIT_OAUTH_REDIRECT_URI: ${{ secrets.KIT_OAUTH_REDIRECT_URI }}
# Defines the WordPress and PHP Versions matrix to run tests on
# WooCommerce 5.9.0 requires WordPress 5.6 or greater, so we do not test on earlier versions
# If testing older WordPress versions, ensure they are e.g. 5.7.4, 5.6.6 that have the X3 SSL fix: https://core.trac.wordpress.org/ticket/54207
# For PHP, make sure that an nginx configuration file exists for the required PHP version in this repository at tests/nginx/php-x.x.conf
strategy:
fail-fast: false
matrix:
wp-versions: [ 'latest' ] #[ '6.1.1', 'latest' ]
php-versions: [ '7.4', '8.0', '8.1', '8.2', '8.3' ] #[ '7.4', '8.0', '8.1' ]
# Folder names within the 'tests' folder to run tests in parallel.
test-groups: [
'acceptance/general',
'acceptance/integrations',
'acceptance/purchase-data',
'acceptance/settings',
'acceptance/subscribe',
'acceptance/sync-past-orders'
]
# Steps to install, configure and run tests
steps:
- name: Define Test Group Name
id: test-group
uses: mad9000/actions-find-and-replace-string@5
with:
source: ${{ matrix.test-groups }}
find: '/'
replace: '-'
replaceAll: true
- name: Start MySQL
run: sudo systemctl start mysql.service
- name: Create MySQL Database
run: |
mysql -e 'CREATE DATABASE test;' -u${{ env.DB_USER }} -p${{ env.DB_PASS }}
mysql -e 'SHOW DATABASES;' -u${{ env.DB_USER }} -p${{ env.DB_PASS }}
# WordPress won't be able to connect to the DB if we don't perform this step.
- name: Permit MySQL Password Auth for MySQL 8.0
run: mysql -e "ALTER USER '${{ env.DB_USER }}'@'${{ env.DB_HOST }}' IDENTIFIED WITH mysql_native_password BY '${{ env.DB_PASS }}';" -u${{ env.DB_USER }} -p${{ env.DB_PASS }}
# Some workflows checkout WordPress from GitHub, but that seems to bring a bunch of uncompiled files with it.
# Instead download from wordpress.org stable.
- name: Download WordPress
run: wget https://wordpress.org/wordpress-${{ matrix.wp-versions }}.tar.gz
- name: Extract WordPress
run: tar xfz wordpress-${{ matrix.wp-versions }}.tar.gz
# Checkout (copy) this repository's Plugin to this VM.
- name: Checkout Plugin
uses: actions/checkout@v4
with:
path: ${{ env.PLUGIN_DIR }}
# We install WP-CLI, as it provides useful commands to setup and install WordPress through the command line.
- name: Install WP-CLI
run: |
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp-cli
- name: Setup wp-config.php
working-directory: ${{ env.ROOT_DIR }}
run: wp-cli config create --dbname=${{ env.DB_NAME }} --dbuser=${{ env.DB_USER }} --dbpass=${{ env.DB_PASS }} --dbhost=${{ env.DB_HOST }} --locale=en_DB
- name: Install WordPress
working-directory: ${{ env.ROOT_DIR }}
run: wp-cli core install --url=127.0.0.1 --title=ConvertKit --admin_user=admin --admin_password=password [email protected]
# env.INSTALL_PLUGINS is a list of Plugin slugs, space separated e.g. contact-form-7 woocommerce.
# We activate the Plugins so that any directories they create are added now, before we later set
# directory permissions in this action.
# These Plugins won't be active when Codeception's acceptance tests run, as Codeception copies
# the tests/_data/dump.sql, which has no active Plugins specified.
- name: Install Free Third Party WordPress Plugins
working-directory: ${{ env.ROOT_DIR }}
run: wp-cli plugin install ${{ env.INSTALL_PLUGINS }} --activate
# These should be stored as a separated list of URLs in the repository Settings > Secrets > Repository Secret > CONVERTKIT_PAID_PLUGIN_URLS.
# We cannot include the URLs in this file, as they're not Plugins we are permitted to distribute.
- name: Install Paid Third Party WordPress Plugins
working-directory: ${{ env.ROOT_DIR }}
run: wp-cli plugin install ${{ secrets.CONVERTKIT_PAID_PLUGIN_URLS }}
# WP_DEBUG = true is required so all PHP errors are output and caught by tests (E_ALL).
# WP_DEBUG = false for PHP 8.1+, otherwise E_DEPRECATED is output due to WooCommerce.
- name: Enable WP_DEBUG
if: ${{ matrix.php-versions != '8.1' && matrix.php-versions != '8.2' && matrix.php-versions != '8.3' }}
working-directory: ${{ env.ROOT_DIR }}
run: |
wp-cli config set WP_DEBUG true --raw
# FS_METHOD = direct is required for WP_Filesystem to operate without suppressed PHP fopen() errors that trip up tests.
- name: Enable FS_METHOD
working-directory: ${{ env.ROOT_DIR }}
run: |
wp-cli config set FS_METHOD direct
# This step is deliberately after WordPress installation and configuration, as enabling PHP 8.x before using WP-CLI results
# in the workflow failing due to incompatibilities between WP-CLI and PHP 8.x.
# By installing PHP at this stage, we can still run our tests against e.g. PHP 8.x.
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: xdebug
# Make sure that an nginx configuration file exists in this repository at tests/nginx/php-x.x.conf.
# Refer to an existing .conf file in this repository if you need to create a new one e.g. for a new PHP version.
- name: Copy nginx configuration file
run: sudo cp ${{ env.PLUGIN_DIR }}/tests/nginx/php-${{ matrix.php-versions }}.conf /etc/nginx/conf.d/php-${{ matrix.php-versions }}.conf
- name: Test nginx
run: sudo nginx -t
- name: Start nginx
run: sudo systemctl start nginx.service
- name: Install chromedriver
uses: nanasess/setup-chromedriver@master
- name: Start chromedriver
run: |
export DISPLAY=:99
chromedriver --port=9515 --url-base=/wd/hub &
sudo Xvfb -ac :99 -screen 0 1920x1080x24 > /dev/null 2>&1 & # optional
# Write any secrets, such as API keys, to the .env.dist.testing file now.
# Make sure your committed .env.dist.testing file ends with a newline.
# The formatting of the contents to include a blank newline is deliberate.
- name: Define GitHub Secrets in .env.dist.testing
uses: DamianReeves/[email protected]
with:
path: ${{ env.PLUGIN_DIR }}/.env.dist.testing
contents: |
STRIPE_TEST_PUBLISHABLE_KEY=${{ env.STRIPE_TEST_PUBLISHABLE_KEY }}
STRIPE_TEST_SECRET_KEY=${{ env.STRIPE_TEST_SECRET_KEY }}
CONVERTKIT_API_KEY=${{ env.CONVERTKIT_API_KEY }}
CONVERTKIT_API_SECRET=${{ env.CONVERTKIT_API_SECRET }}
CONVERTKIT_API_KEY_NO_DATA=${{ env.CONVERTKIT_API_KEY_NO_DATA }}
CONVERTKIT_API_SECRET_NO_DATA=${{ env.CONVERTKIT_API_SECRET_NO_DATA }}
CONVERTKIT_OAUTH_ACCESS_TOKEN=${{ env.CONVERTKIT_OAUTH_ACCESS_TOKEN }}
CONVERTKIT_OAUTH_REFRESH_TOKEN=${{ env.CONVERTKIT_OAUTH_REFRESH_TOKEN }}
CONVERTKIT_OAUTH_ACCESS_TOKEN_NO_DATA=${{ env.CONVERTKIT_OAUTH_ACCESS_TOKEN_NO_DATA }}
CONVERTKIT_OAUTH_REFRESH_TOKEN_NO_DATA=${{ env.CONVERTKIT_OAUTH_REFRESH_TOKEN_NO_DATA }}
CONVERTKIT_OAUTH_CLIENT_ID=${{ env.CONVERTKIT_OAUTH_CLIENT_ID }}
CONVERTKIT_OAUTH_REDIRECT_URI=${{ env.CONVERTKIT_OAUTH_REDIRECT_URI }}
KIT_OAUTH_REDIRECT_URI=${{ env.KIT_OAUTH_REDIRECT_URI }}
write-mode: append
# Installs wp-browser, Codeception, PHP CodeSniffer and anything else needed to run tests.
- name: Run Composer
working-directory: ${{ env.PLUGIN_DIR }}
run: composer update
- name: Build PHP Autoloader
working-directory: ${{ env.PLUGIN_DIR }}
run: composer dump-autoload
# This ensures the Plugin's log file can be written to.
# We don't recursively do this, as it'll prevent Codeception from writing to the /tests/_output directory.
- name: Set Permissions for Plugin Directory
run: |
sudo chmod g+w ${{ env.PLUGIN_DIR }}
sudo chown www-data:www-data ${{ env.PLUGIN_DIR }}
# This ensures WooCommerce log files can be written to.
- name: Set Permissions for WooCommerce Logs Directory
run: |
sudo mkdir ${{ env.ROOT_DIR }}/wp-content/uploads/wc-logs
sudo chmod g+w ${{ env.ROOT_DIR }}/wp-content/uploads/wc-logs
sudo chown www-data:www-data ${{ env.ROOT_DIR }}/wp-content/uploads/wc-logs
# Build Codeception Tests.
- name: Build Tests
working-directory: ${{ env.PLUGIN_DIR }}
run: php vendor/bin/codecept build
# Run Codeception WPUnit Tests on the PHP 7.4 instance before the acceptance/general acceptance tests.
# We run these once to avoid hitting API rate limits.
- name: Run tests/wpunit
if: ${{ matrix.php-versions == '7.4' && matrix.test-groups == 'acceptance/general' }}
working-directory: ${{ env.PLUGIN_DIR }}
run: php vendor/bin/codecept run tests/wpunit --fail-fast
# Run Codeception Acceptance Tests.
- name: Run tests/${{ matrix.test-groups }}
working-directory: ${{ env.PLUGIN_DIR }}
run: php vendor/bin/codecept run tests/${{ matrix.test-groups }} --fail-fast
# Artifacts are data generated by this workflow that we want to access, such as log files, screenshots, HTML output.
# The if: failure() directive means that this will run when the workflow fails e.g. if a test fails, which is needed
# because we want to see why a test failed.
- name: Upload Test Results to Artifact
if: failure()
uses: actions/upload-artifact@v4
with:
name: test-results-${{ steps.test-group.outputs.value }}-${{ matrix.php-versions }}
path: ${{ env.PLUGIN_DIR }}/tests/_output/