Skip to content

Commit 0cbac64

Browse files
ci(multisite): Add action for multisite tests
1 parent cbd7f63 commit 0cbac64

File tree

2 files changed

+198
-1
lines changed

2 files changed

+198
-1
lines changed
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
name: End-to-end test suite
2+
on:
3+
push:
4+
branches:
5+
- main
6+
- feat/multisite
7+
paths-ignore:
8+
- '**.md'
9+
workflow_dispatch:
10+
11+
permissions:
12+
contents: read
13+
14+
env:
15+
# Allow ddev get to use a GitHub token to prevent rate limiting by tests
16+
DDEV_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17+
18+
jobs:
19+
end-to-end-test-suite:
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
wp-version: [ "4.9", "6.2" ]
24+
php-version: [ "7.2" ]
25+
subdomain: ["site1", "site2"]
26+
27+
name: End-to-end test suite
28+
runs-on: ubuntu-latest
29+
if: ${{ !contains(github.event.head_commit.message, 'chore(') }}
30+
31+
env:
32+
EXTENSION_NAME: "CrowdSec_Bouncer"
33+
EXTENSION_PATH: "wp-content/plugins/crowdsec"
34+
35+
steps:
36+
37+
- name: Install DDEV
38+
# @see https://ddev.readthedocs.io/en/stable/#installationupgrade-script-linux-and-macos-armarm64-and-amd64-architectures
39+
run: |
40+
curl -fsSL https://apt.fury.io/drud/gpg.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/ddev.gpg > /dev/null
41+
echo "deb [signed-by=/etc/apt/trusted.gpg.d/ddev.gpg] https://apt.fury.io/drud/ * *" | sudo tee /etc/apt/sources.list.d/ddev.list
42+
sudo apt-get -q update
43+
sudo apt-get -q -y install libnss3-tools ddev
44+
mkcert -install
45+
ddev config global --instrumentation-opt-in=false --omit-containers=dba,ddev-ssh-agent
46+
47+
48+
- name: Set WP_VERSION_CODE env
49+
# used in some directory path and conventional file naming
50+
# Example : 5.6.5 => wp565
51+
run: |
52+
echo "WP_VERSION_CODE=$(echo wp${{ matrix.wp-version }} | sed 's/\.//g' )" >> $GITHUB_ENV
53+
54+
- name: Create empty WordPress DDEV project (with Apache)
55+
run: ddev config --project-type=wordpress --project-name=${{ env.WP_VERSION_CODE }} --php-version=${{ matrix.php-version }} --webserver-type=apache-fpm --additional-hostnames=site1.${{ env.WP_VERSION_CODE }},site2.${{ env.WP_VERSION_CODE }}
56+
57+
- name: Add Redis, Memcached, Crowdsec and Playwright
58+
run: |
59+
ddev get ddev/ddev-redis
60+
ddev get ddev/ddev-memcached
61+
ddev get julienloizelet/ddev-playwright
62+
# override redis.conf
63+
ddev get julienloizelet/ddev-tools
64+
ddev get julienloizelet/ddev-crowdsec-php
65+
66+
- name: Start DDEV
67+
run: ddev start
68+
69+
- name: Download WordPress
70+
run: ddev wp core download --version=${{ matrix.wp-version }}
71+
72+
- name: Setup WordPress ${{ matrix.wp-version }} with PHP ${{ matrix.php-version }}
73+
run: |
74+
ddev wp core multisite-install --url='https://${{ env.WP_VERSION_CODE }}.ddev.site' --title='WordPress' --admin_user='admin' --admin_password='admin123' --admin_email='admin@admin.com' --subdomains=true
75+
76+
- name: Copy multisite .htaccess
77+
run: cp .ddev/okaeli-add-on/wordpress/custom_files/.htaccess-multisite-subdomain .htaccess
78+
79+
- name: Prepare multisite config
80+
run: |
81+
sed -i -e 's/#ddev-generated//g' wp-config-ddev.php
82+
sed -i -e 's/REPLACE_SUBDOMAIN_INSTALL/true/g' .ddev/okaeli-add-on/wordpress/custom_files/multisite-config.php
83+
sed -i -e 's/REPLACE_PROJECT_URI/${{ env.WP_VERSION_CODE }}.ddev.site/g' .ddev/okaeli-add-on/wordpress/custom_files/multisite-config.php
84+
sed -i '/DB_HOST/ r .ddev/okaeli-add-on/wordpress/custom_files/multisite-config.php' wp-config-ddev.php
85+
sed -i -e 's/#ddev-generated//g' wp-config-ddev.php
86+
87+
- name: Create sub sites
88+
run: |
89+
ddev wp site create --slug="site1" --title="WordPress Site1"
90+
ddev wp site create --slug="site2" --title="WordPress Site2"
91+
92+
- name: Clone ${{ env.EXTENSION_NAME }} files
93+
uses: actions/checkout@v3
94+
with:
95+
path: ${{ env.EXTENSION_PATH }}
96+
97+
- name: Prepare for playwright test
98+
run: |
99+
mkdir -p crowdsec/tls
100+
mkdir -p crowdsec/geolocation
101+
cp .ddev/okaeli-add-on/wordpress/custom_files/crowdsec/php/cache-actions-from-plugin-folder.php cache-actions.php
102+
cp -r .ddev/okaeli-add-on/custom_files/crowdsec/cfssl/* crowdsec/tls
103+
ddev maxmind-download DEFAULT GeoLite2-City crowdsec/geolocation
104+
ddev maxmind-download DEFAULT GeoLite2-Country crowdsec/geolocation
105+
cd crowdsec/geolocation
106+
sha256sum -c GeoLite2-Country.tar.gz.sha256.txt
107+
sha256sum -c GeoLite2-City.tar.gz.sha256.txt
108+
tar -xf GeoLite2-Country.tar.gz
109+
tar -xf GeoLite2-City.tar.gz
110+
rm GeoLite2-Country.tar.gz GeoLite2-Country.tar.gz.sha256.txt GeoLite2-City.tar.gz GeoLite2-City.tar.gz.sha256.txt
111+
cd ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev/__scripts__
112+
chmod +x test-init.sh
113+
./test-init.sh
114+
chmod +x run-tests.sh
115+
116+
- name: Some DEBUG information
117+
run: |
118+
ddev --version
119+
ddev exec php -v
120+
ddev exec -s crowdsec crowdsec -version
121+
122+
- name: Run Plugin activation tests
123+
uses: ./wp-content/plugins/crowdsec/.github/workflows/end-to-end/run-single-test
124+
with:
125+
test_path: ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev
126+
file_path: 1-activate-plugin.js
127+
subdomain: ${{ matrix.subdomain }}
128+
129+
- name: Configure CrowdSec and Wordpress bouncer plugin
130+
run: |
131+
ddev crowdsec-config
132+
133+
- name: Run Live mode remediation tests
134+
uses: ./wp-content/plugins/crowdsec/.github/workflows/end-to-end/run-single-test
135+
with:
136+
test_path: ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev
137+
file_path: 2-live-mode-remediations.js
138+
subdomain: ${{ matrix.subdomain }}
139+
140+
- name: Run more Live mode remediation tests
141+
uses: ./wp-content/plugins/crowdsec/.github/workflows/end-to-end/run-single-test
142+
with:
143+
test_path: ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev
144+
file_path: 3-live-mode-more.js
145+
subdomain: ${{ matrix.subdomain }}
146+
147+
- name: Run Live mode cache tests
148+
uses: ./wp-content/plugins/crowdsec/.github/workflows/end-to-end/run-single-test
149+
with:
150+
test_path: ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev
151+
file_path: 4-live-mode-cache.js
152+
subdomain: ${{ matrix.subdomain }}
153+
154+
- name: Prepare cron usage
155+
run: |
156+
sed -i 's/fastcgi_finish_request/\/\/fastcgi_finish_request/g' wp-cron.php
157+
158+
- name: Run Stream mode tests
159+
uses: ./wp-content/plugins/crowdsec/.github/workflows/end-to-end/run-single-test
160+
with:
161+
test_path: ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev
162+
file_path: 5-stream-mode.js
163+
subdomain: ${{ matrix.subdomain }}
164+
165+
- name: Run Redis tests
166+
uses: ./wp-content/plugins/crowdsec/.github/workflows/end-to-end/run-single-test
167+
with:
168+
test_path: ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev
169+
file_path: 6-redis.js
170+
subdomain: ${{ matrix.subdomain }}
171+
172+
- name: Run Memcached tests
173+
uses: ./wp-content/plugins/crowdsec/.github/workflows/end-to-end/run-single-test
174+
with:
175+
test_path: ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev
176+
file_path: 7-memcached.js
177+
subdomain: ${{ matrix.subdomain }}
178+
179+
- name: Run Geolocation tests
180+
uses: ./wp-content/plugins/crowdsec/.github/workflows/end-to-end/run-single-test
181+
with:
182+
test_path: ${{ github.workspace }}/${{ env.EXTENSION_PATH }}/tests/e2e-ddev
183+
file_path: 8-geolocation.js
184+
subdomain: ${{ matrix.subdomain }}
185+
186+
187+
- name: tmate debugging session
188+
uses: mxschmitt/action-tmate@v3
189+
with:
190+
limit-access-to-actor: true
191+
github-token: ${{ secrets.GITHUB_TOKEN }}
192+
timeout-minutes: 15
193+
if: failure()

.github/workflows/end-to-end/run-single-test/action.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@ inputs:
1010
required: true
1111
description: "Path to the js test file"
1212

13+
subdomain:
14+
required: false
15+
description: "Subdomain for Multisite frontend test"
16+
1317
runs:
1418
using: "composite"
1519
steps:
1620
- name: Run test
1721
shell: bash
1822
run: |
1923
cd ${{ inputs.test_path }}/__scripts__
20-
./run-tests.sh ci "./__tests__/${{ inputs.file_path }}"
24+
./run-tests.sh ci "./__tests__/${{ inputs.file_path }}" "${{ inputs.subdomain }}"
2125
cd ${{ inputs.test_path }}
2226
PENDING_TESTS=$(grep -oP '"numPendingTests":\K(.*),"numRuntimeErrorTestSuites"' .test-results.json | sed 's/,"numRuntimeErrorTestSuites"//g')
2327
if [[ $PENDING_TESTS == "0" ]]

0 commit comments

Comments
 (0)