Skip to content

Commit 7b35d65

Browse files
committed
Internal: add CI
1 parent 62ba4d2 commit 7b35d65

File tree

4 files changed

+266
-21
lines changed

4 files changed

+266
-21
lines changed

.github/workflows/phpunit.yml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: PHPUnit
2+
permissions:
3+
contents: read
4+
5+
on:
6+
push:
7+
paths-ignore:
8+
- '**.md'
9+
- '**.txt'
10+
- '.github/config.json'
11+
- 'bin/**'
12+
- '.gitignore'
13+
- 'docs/**'
14+
branches:
15+
- 'main'
16+
- '3.*'
17+
pull_request:
18+
paths-ignore:
19+
- '**.md'
20+
- '**.txt'
21+
- '.github/config.json'
22+
- 'bin/**'
23+
- '.gitignore'
24+
- 'docs/**'
25+
merge_group:
26+
27+
# This allows a subsequently queued workflow run to interrupt previous runs
28+
concurrency:
29+
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
30+
cancel-in-progress: true
31+
32+
jobs:
33+
file-diff:
34+
runs-on: ubuntu-latest
35+
name: File Diff
36+
if: startsWith( github.repository, 'elementor/' )
37+
outputs:
38+
php_diff: ${{ steps.php_diff_files.outputs.diff }}
39+
steps:
40+
- name: Checkout source code
41+
uses: actions/checkout@v4
42+
- name: Check PHP files diff
43+
id: php_diff_files
44+
uses: technote-space/get-diff-action@v6
45+
with:
46+
PATTERNS: |
47+
**/*.php
48+
**/*.twig
49+
composer.+(json|lock)
50+
.github/**/*.yml
51+
install-wp-tests.sh
52+
test:
53+
runs-on: ubuntu-22.04
54+
needs: [ 'file-diff' ]
55+
if: ${{ github.event.pull_request.title == null || needs.file-diff.outputs.php_diff }}
56+
strategy:
57+
fail-fast: false
58+
matrix:
59+
wordpress_versions: ['nightly', 'latest', '6.6', '6.5']
60+
php_versions: ['7.4', '8.0', '8.1', '8.2', '8.3']
61+
name: PHPUnit - WordPress ${{ matrix.wordpress_versions }} - PHP version ${{ matrix.php_versions }}
62+
env:
63+
WP_TESTS_DIR: /tmp/wordpress-tests-lib
64+
WP_TESTS_ELEMENTOR_DIR: /tmp/elementor/elementor.php
65+
WP_TESTS_HELLOPLUS_DIR: /tmp/hello-plus/hello-plus.php
66+
THEME_FILE: functions.php
67+
COVERAGE: ${{ matrix.php_versions >= 8.3 && matrix.wordpress_versions == 'latest' && github.event_name == 'push' }}
68+
services:
69+
mysql:
70+
image: mysql:5.7
71+
env:
72+
MYSQL_ROOT_PASSWORD: root
73+
ports:
74+
- 3306
75+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
76+
77+
steps:
78+
- name: Checkout source code
79+
uses: actions/checkout@v4
80+
with:
81+
fetch-depth: 0
82+
- name: Setup PHP
83+
uses: shivammathur/setup-php@v2
84+
with:
85+
php-version: ${{ matrix.php_versions }}
86+
coverage: none
87+
- name: Install Dependencies
88+
run: |
89+
bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1:${{ job.services.mysql.ports['3306'] }} ${{ matrix.wordpress_versions }} true
90+
composer update --no-interaction
91+
- name: Copy theme folder to /tmp/wordpress/wp-content/themes/
92+
run: |
93+
cp -a $GITHUB_WORKSPACE /tmp/wordpress/wp-content/themes/
94+
echo "Copied theme folder to /tmp/wordpress/wp-content/themes/$(basename $GITHUB_WORKSPACE)"
95+
- name: Run Tests with Coverage (latest PHP & WP)
96+
if: ${{ env.COVERAGE != 'false' }}
97+
run: |
98+
composer run coverage
99+
- name: Run Tests without Coverage
100+
if: ${{ env.COVERAGE == 'false' }}
101+
run: |
102+
composer run test
103+
104+
test-result:
105+
needs: test
106+
if: ${{ always() }} # Will be run even if 'test' matrix will be skipped
107+
runs-on: ubuntu-22.04
108+
name: PHPUnit - Test Results
109+
steps:
110+
- name: Test status
111+
run: echo "Test status is - ${{ needs.test.result }}"
112+
- name: Check test matrix status
113+
if: ${{ needs.test.result != 'success' && needs.test.result != 'skipped' }}
114+
run: exit 1

.github/workflows/playwright.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Playwright Tests
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
permissions:
8+
contents: read
9+
actions: write
10+
11+
jobs:
12+
playwright-tests:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: '20'
23+
cache: 'npm'
24+
registry-url: 'https://npm.pkg.github.com'
25+
scope: '@elementor'
26+
27+
- name: Setup PHP
28+
uses: shivammathur/setup-php@v2
29+
with:
30+
php-version: '8.1'
31+
tools: composer
32+
coverage: none
33+
34+
- name: Install Composer dependencies
35+
run: composer install --no-dev --optimize-autoloader
36+
37+
- name: Install npm dependencies
38+
run: npm ci
39+
env:
40+
NODE_AUTH_TOKEN: ${{ secrets.CLOUD_DEVOPS_TOKEN }}
41+
42+
- name: Start wp-env
43+
run: npm run wp-env:start
44+
45+
- name: Setup Playwright
46+
run: npm run test:setup:playwright
47+
48+
- name: Setup Chromium
49+
run: npm run test:setup:chromium
50+
51+
- name: Run Playwright tests
52+
id: playwright-tests
53+
run: |
54+
npm run test:playwright
55+
echo "exit_code=$?" >> $GITHUB_OUTPUT
56+
continue-on-error: false
57+
58+
- name: Check test results
59+
if: steps.playwright-tests.outcome == 'failure'
60+
run: |
61+
echo "❌ Playwright tests failed!"
62+
exit 1
63+
64+
- name: Stop wp-env
65+
if: always()
66+
run: npm run wp-env:stop

.wp-env.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"core": null,
33
"phpVersion": "8.0",
44
"plugins": [
5-
"../../plugins/elementor/"
5+
"https://downloads.wordpress.org/plugin/elementor.latest-stable.zip"
66
],
77
"themes": [
88
"./"

bin/install-wp-tests.sh

Lines changed: 85 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
if [ $# -lt 3 ]; then
4-
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version] [skip-database-creation]"
4+
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version]"
55
exit 1
66
fi
77

@@ -10,25 +10,36 @@ DB_USER=$2
1010
DB_PASS=$3
1111
DB_HOST=${4-localhost}
1212
WP_VERSION=${5-latest}
13-
SKIP_DB_CREATE=${6-false}
1413

1514
WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib}
1615
WP_CORE_DIR=${WP_CORE_DIR-/tmp/wordpress/}
17-
18-
ELEMENTOR_PLUGIN_DIR=${ELEMENTOR_PLUGIN_DIR-/tmp/wordpress/wp-content/plugins}
16+
ELEMENTOR_PLUGIN_DIR=${ELEMENTOR_PLUGIN_DIR-/tmp}
17+
HELLO_PLUS_PLUGIN_DIR=${HELLO_PLUS_PLUGIN_DIR-/tmp}
1918

2019
download() {
20+
local url="$1"
21+
local output="$2"
22+
2123
if [ `which curl` ]; then
22-
curl --location -s "$1" > "$2";
24+
curl --location --fail --show-error --silent --output "$output" "$url"
25+
local exit_code=$?
2326
elif [ `which wget` ]; then
24-
wget -nv -O "$2" "$1"
27+
wget -nv -O "$output" "$url"
28+
local exit_code=$?
29+
else
30+
echo "Error: Neither curl nor wget found. Please install one of them."
31+
exit 1
32+
fi
33+
34+
if [ $exit_code -ne 0 ]; then
35+
echo "Error: Failed to download $url"
36+
rm -f "$output"
37+
exit 1
2538
fi
2639
}
2740

2841
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+(\.[0-9]+)? ]]; then
2942
WP_TESTS_TAG="tags/$WP_VERSION"
30-
elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
31-
WP_TESTS_TAG="trunk"
3243
else
3344
# http serves a single offer, whereas https serves multiple. we only want one
3445
download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json
@@ -49,7 +60,6 @@ install_wp() {
4960
fi
5061

5162
mkdir -p $WP_CORE_DIR
52-
5363
if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
5464
mkdir -p /tmp/wordpress-nightly
5565
download https://wordpress.org/nightly-builds/wordpress-latest.zip /tmp/wordpress-nightly/wordpress-nightly.zip
@@ -88,27 +98,21 @@ install_test_suite() {
8898
# set up testing suite
8999
mkdir -p $WP_TESTS_DIR
90100
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
91-
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data
92101
fi
93102

103+
cd $WP_TESTS_DIR
104+
94105
if [ ! -f wp-tests-config.php ]; then
95106
download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
96-
# remove all forward slashes in the end
97-
WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::")
98-
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php
107+
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR':" "$WP_TESTS_DIR"/wp-tests-config.php
99108
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
100109
sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
101110
sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
102111
sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php
103112
fi
104-
105113
}
106114

107115
install_db() {
108-
if [ ${SKIP_DB_CREATE} = "true" ]; then
109-
return 0
110-
fi
111-
112116
# parse DB_HOST for port or socket references
113117
local PARTS=(${DB_HOST//\:/ })
114118
local DB_HOSTNAME=${PARTS[0]};
@@ -130,12 +134,73 @@ install_db() {
130134
}
131135

132136
install_elementor_plugin() {
137+
echo "Installing Elementor plugin..."
133138
rm -rf ${ELEMENTOR_PLUGIN_DIR}/elementor
134-
download https://downloads.wordpress.org/plugin/elementor.latest-stable.zip /tmp/elementor.zip
135-
unzip -q /tmp/elementor.zip -d ${ELEMENTOR_PLUGIN_DIR}
139+
140+
# Download the plugin
141+
local zip_file="/tmp/elementor.zip"
142+
rm -f "$zip_file"
143+
144+
echo "Downloading Elementor from WordPress.org..."
145+
download https://downloads.wordpress.org/plugin/elementor.latest-stable.zip "$zip_file"
146+
147+
# Validate the downloaded file is a valid zip
148+
if ! unzip -t "$zip_file" >/dev/null 2>&1; then
149+
echo "Error: Downloaded file is not a valid zip archive"
150+
echo "File size: $(ls -lh "$zip_file" 2>/dev/null | awk '{print $5}' || echo 'File not found')"
151+
echo "File type: $(file "$zip_file" 2>/dev/null || echo 'Cannot determine file type')"
152+
rm -f "$zip_file"
153+
exit 1
154+
fi
155+
156+
# Extract the plugin
157+
echo "Extracting Elementor plugin..."
158+
if ! unzip -q "$zip_file" -d ${ELEMENTOR_PLUGIN_DIR}; then
159+
echo "Error: Failed to extract Elementor plugin"
160+
rm -f "$zip_file"
161+
exit 1
162+
fi
163+
164+
# Clean up
165+
rm -f "$zip_file"
166+
echo "Elementor plugin installed successfully"
167+
}
168+
169+
install_hello_plus_plugin() {
170+
echo "Installing Hello Plus plugin..."
171+
rm -rf ${HELLO_PLUS_PLUGIN_DIR}/hello-plus
172+
173+
# Download the plugin
174+
local zip_file="/tmp/hello-plus.zip"
175+
rm -f "$zip_file"
176+
177+
echo "Downloading Hello Plus from WordPress.org..."
178+
download https://downloads.wordpress.org/plugin/hello-plus.latest-stable.zip "$zip_file"
179+
180+
# Validate the downloaded file is a valid zip
181+
if ! unzip -t "$zip_file" >/dev/null 2>&1; then
182+
echo "Error: Downloaded file is not a valid zip archive"
183+
echo "File size: $(ls -lh "$zip_file" 2>/dev/null | awk '{print $5}' || echo 'File not found')"
184+
echo "File type: $(file "$zip_file" 2>/dev/null || echo 'Cannot determine file type')"
185+
rm -f "$zip_file"
186+
exit 1
187+
fi
188+
189+
# Extract the plugin
190+
echo "Extracting Hello Plus plugin..."
191+
if ! unzip -q "$zip_file" -d ${HELLO_PLUS_PLUGIN_DIR}; then
192+
echo "Error: Failed to extract Hello Plus plugin"
193+
rm -f "$zip_file"
194+
exit 1
195+
fi
196+
197+
# Clean up
198+
rm -f "$zip_file"
199+
echo "Hello Plus plugin installed successfully"
136200
}
137201

138202
install_wp
139203
install_test_suite
140204
install_db
141205
install_elementor_plugin
206+
install_hello_plus_plugin

0 commit comments

Comments
 (0)