Skip to content

Commit 32ccf9d

Browse files
committed
Merge branch 'main' into add-end-to-end-tests
2 parents 34f9671 + 8d4a752 commit 32ccf9d

File tree

71 files changed

+12964
-2745
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+12964
-2745
lines changed

.github/actions/code-quality/action.yml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,24 @@ inputs:
44
working-directory:
55
description: 'Directory to run composer and quality tools in'
66
required: true
7+
php-version:
8+
description: 'PHP version to use'
9+
required: false
10+
default: '7.4'
11+
composer-options:
12+
description: 'Additional composer options'
13+
required: false
14+
default: '--no-progress'
15+
716
runs:
817
using: "composite"
918
steps:
10-
- name: Setup PHP
11-
uses: shivammathur/setup-php@v2
12-
with:
13-
php-version: '7.4'
14-
tools: composer:v2
15-
coverage: none
16-
17-
- name: Install dependencies
18-
uses: ramsey/composer-install@v2
19+
- name: Setup PHP with Cached Composer
20+
uses: ./.github/actions/setup-php-composer
1921
with:
22+
php-version: ${{ inputs.php-version }}
2023
working-directory: ${{ inputs.working-directory }}
21-
composer-options: "--no-progress"
24+
composer-options: ${{ inputs.composer-options }}
2225

2326
- name: Run PHPStan
2427
working-directory: ${{ inputs.working-directory }}
@@ -33,4 +36,4 @@ runs:
3336
- name: Run PHP CodeSniffer
3437
working-directory: ${{ inputs.working-directory }}
3538
run: composer run-script check-cs
36-
shell: bash
39+
shell: bash
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: "Run Codeception Tests"
2+
description: "Sets up environment and runs Codeception test suites"
3+
inputs:
4+
working-directory:
5+
description: "Plugin directory to run tests in"
6+
required: true
7+
php:
8+
description: "PHP version"
9+
required: true
10+
extensions:
11+
description: "PHP extensions"
12+
required: true
13+
wordpress:
14+
description: "WordPress version"
15+
required: true
16+
composer-options:
17+
description: "Additional composer options"
18+
required: false
19+
default: "--no-progress"
20+
runs:
21+
using: "composite"
22+
steps:
23+
- name: Setup PHP with Cached Composer
24+
uses: ./.github/actions/setup-php-composer
25+
with:
26+
php-version: ${{ inputs.php }}
27+
working-directory: ${{ inputs.working-directory }}
28+
composer-options: ${{ inputs.composer-options }}
29+
30+
- name: Setup environment
31+
run: |
32+
cp ${{ inputs.working-directory }}/.docker/.env.ci ${{ inputs.working-directory }}/.env
33+
cd ${{ inputs.working-directory }}
34+
echo "INCLUDE_EXTENSIONS=${{ inputs.extensions }}" >> .env
35+
echo "WP_VERSION=${{ inputs.wordpress }}" >> .env
36+
echo "PHP_VERSION=${{ inputs.php }}" >> .env
37+
shell: bash
38+
39+
- name: Build test environment
40+
uses: nick-invision/retry@v2
41+
with:
42+
timeout_minutes: 10
43+
max_attempts: 3
44+
retry_on: error
45+
shell: bash
46+
command: |
47+
cd ${{ inputs.working-directory }}
48+
composer run docker:build
49+
env:
50+
WP_VERSION: ${{ inputs.wordpress }}
51+
PHP_VERSION: ${{ inputs.php }}
52+
53+
- name: Start test environment
54+
working-directory: ${{ inputs.working-directory }}
55+
shell: bash
56+
run: |
57+
docker compose --env-file .env up --detach
58+
59+
CONTAINER_ID=$(docker compose ps -q wordpress)
60+
if [ -n "$CONTAINER_ID" ]; then
61+
docker exec $CONTAINER_ID init-docker.sh
62+
else
63+
echo "Error: WordPress container not found."
64+
exit 1
65+
fi
66+
env:
67+
WP_VERSION: ${{ inputs.wordpress }}
68+
PHP_VERSION: ${{ inputs.php }}
69+
70+
- name: Run Acceptance Tests w/ Docker
71+
working-directory: ${{ inputs.working-directory }}
72+
shell: bash
73+
run: |
74+
docker exec \
75+
--env DEBUG=${{ env.DEBUG }} \
76+
--env SKIP_TESTS_CLEANUP=${{ env.SKIP_TESTS_CLEANUP }} \
77+
--env SUITES=acceptance \
78+
$(docker compose ps -q wordpress) \
79+
bash -c "cd wp-content/plugins/$(basename $(echo ${{ inputs.working-directory }} | sed 's:/*$::')) && bin/run-codeception.sh"
80+
env:
81+
DEBUG: ${{ env.ACTIONS_STEP_DEBUG }}
82+
SKIP_TESTS_CLEANUP: "true"
83+
continue-on-error: true
84+
85+
- name: Run Functional Tests w/ Docker
86+
working-directory: ${{ inputs.working-directory }}
87+
shell: bash
88+
run: |
89+
docker exec \
90+
--env DEBUG=${{ env.DEBUG }} \
91+
--env SKIP_TESTS_CLEANUP=${{ env.SKIP_TESTS_CLEANUP }} \
92+
--env SUITES=functional \
93+
$(docker compose ps -q wordpress) \
94+
bash -c "cd wp-content/plugins/$(basename ${{ inputs.working-directory }}) && bin/run-codeception.sh"
95+
env:
96+
DEBUG: ${{ env.ACTIONS_STEP_DEBUG }}
97+
SKIP_TESTS_CLEANUP: "true"
98+
continue-on-error: true
99+
100+
- name: Run WPUnit Tests w/ Docker
101+
working-directory: ${{ inputs.working-directory }}
102+
shell: bash
103+
run: |
104+
docker exec \
105+
--env COVERAGE=${{ inputs.coverage }} \
106+
--env USING_XDEBUG=${{ inputs.coverage }} \
107+
--env DEBUG=${{ env.DEBUG }} \
108+
--env SUITES=wpunit \
109+
$(docker compose ps -q wordpress) \
110+
bash -c "cd wp-content/plugins/$(basename ${{ inputs.working-directory }}) && bin/run-codeception.sh"
111+
env:
112+
DEBUG: ${{ env.ACTIONS_STEP_DEBUG }}

.github/actions/create-plugin-artifact/action.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,23 @@ inputs:
44
slug:
55
description: 'Plugin slug (directory name under plugins/)'
66
required: true
7+
composer-options:
8+
description: 'Additional composer options'
9+
required: false
10+
default: '--no-progress'
711
runs:
812
using: "composite"
913
steps:
10-
- name: Set up PHP
11-
uses: shivammathur/setup-php@v2
14+
- name: Setup PHP with Cached Composer
15+
uses: ./.github/actions/setup-php-composer
1216
with:
13-
php-version: '7.4'
17+
php-version: ${{ inputs.php }}
18+
working-directory: plugins/${{ inputs.slug }}
19+
composer-options: ${{ inputs.composer-options }}
1420

15-
- name: Install dependencies and build
21+
- name: Create plugin artifact
1622
working-directory: plugins/${{ inputs.slug }}
1723
run: |
18-
composer install --no-dev --optimize-autoloader
1924
echo "${GITHUB_SHA}" > build-sha.txt
2025
rm -f plugin-build/${{ inputs.slug }}-*.zip
2126
composer archive -vvv --format=zip --file="plugin-build/${{ inputs.slug }}" --dir="."
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: "Setup PHP with Cached Composer"
2+
description: "Setup PHP and install Composer dependencies with caching"
3+
inputs:
4+
php-version:
5+
description: "PHP version to setup"
6+
required: false
7+
default: "7.4"
8+
working-directory:
9+
description: "Working directory for composer install"
10+
required: true
11+
composer-options:
12+
description: "Additional composer options"
13+
required: false
14+
default: "--no-progress --optimize-autoloader"
15+
tools:
16+
description: "Tools to install with PHP"
17+
required: false
18+
default: "composer:v2"
19+
20+
runs:
21+
using: "composite"
22+
steps:
23+
- name: Setup PHP
24+
uses: shivammathur/setup-php@v2
25+
with:
26+
php-version: ${{ inputs.php-version }}
27+
tools: ${{ inputs.tools }}
28+
coverage: none
29+
30+
- name: Validate Composer File
31+
shell: bash
32+
working-directory: ${{ inputs.working-directory }}
33+
run: |
34+
if [ ! -f "composer.json" ]; then
35+
echo "Error: composer.json missing in ${{ inputs.working-directory }}"
36+
exit 1
37+
fi
38+
39+
- name: Get Composer cache directory
40+
id: composer-cache
41+
shell: bash
42+
working-directory: ${{ inputs.working-directory }}
43+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
44+
45+
- name: Cache Composer dependencies
46+
uses: actions/cache@v4
47+
with:
48+
path: |
49+
${{ steps.composer-cache.outputs.dir }}
50+
${{ inputs.working-directory }}/vendor
51+
key: composer-${{ runner.os }}-php${{ inputs.php-version }}-${{ hashFiles(format('{0}/composer.lock', inputs.working-directory)) }}
52+
restore-keys: |
53+
composer-${{ runner.os }}-php${{ inputs.php-version }}-
54+
composer-${{ runner.os }}-
55+
56+
- name: Install Composer dependencies
57+
uses: ramsey/composer-install@v2
58+
with:
59+
working-directory: ${{ inputs.working-directory }}
60+
composer-options: ${{ inputs.composer-options }}

.github/workflows/code-quality.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
name: Code Quality
22

33
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'plugins/**.php'
49
pull_request:
510
paths:
6-
- 'plugins/**'
11+
- 'plugins/**.php'
712

813
jobs:
914
run:

.github/workflows/codeception.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Codeception
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'plugins/**.php'
9+
pull_request:
10+
paths:
11+
- 'plugins/**.php'
12+
13+
# Cancel previous workflow run groups that have not completed.
14+
concurrency:
15+
# Group workflow runs by workflow name, along with the head branch ref of the pull request
16+
# or otherwise the branch or tag ref.
17+
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.ref }}
18+
cancel-in-progress: true
19+
20+
jobs:
21+
continuous_integration:
22+
runs-on: ubuntu-latest
23+
name: WordPress ${{ matrix.wordpress }} on PHP ${{ matrix.php }}
24+
25+
strategy:
26+
matrix:
27+
php: ["8.3","8.2","8.1"]
28+
wordpress: ["6.8","6.7","6.6","6.5"]
29+
include:
30+
- php: "8.2"
31+
wordpress: "6.8"
32+
coverage: 1
33+
fail-fast: false
34+
35+
steps:
36+
- name: Checkout
37+
uses: actions/checkout@v4
38+
39+
- name: Get changed plugin directory
40+
id: plugin
41+
run: |
42+
git fetch --prune --unshallow
43+
plugin=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '^plugins/' | head -1 | cut -d/ -f2)
44+
echo "slug=$plugin" >> $GITHUB_OUTPUT
45+
46+
- name: Validate composer.json
47+
run: |
48+
if [ ! -f "plugins/${{ steps.plugin.outputs.slug }}/composer.json" ]; then
49+
echo "Warning: composer.json missing in plugins/${{ steps.plugin.outputs.slug }}"
50+
fi
51+
52+
- name: Run Codeception Tests
53+
uses: ./.github/actions/codeception
54+
with:
55+
working-directory: plugins/${{ steps.plugin.outputs.slug }}
56+
php: ${{ matrix.php }}
57+
wordpress: ${{ matrix.wordpress }}
58+
extensions: json,mbstring

.github/workflows/plugin-artifact-for-pr.yml

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ name: Plugin Artifact for PR
33
on:
44
pull_request:
55
paths:
6-
- 'plugins/**'
6+
- 'plugins/**.php'
7+
- 'plugins/**.js'
8+
- 'plugins/**.css'
9+
- 'plugins/**.json'
710

811
jobs:
912
create-plugin-artifact:
@@ -39,10 +42,36 @@ jobs:
3942
const runId = context.runId;
4043
const artifactUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`;
4144
const slug = process.env.PLUGIN_SLUG;
42-
const body = `ℹ️ [Download the ${slug} plugin artifact from this workflow run](${artifactUrl}) (see the 'Artifacts' section at the bottom).`;
43-
await github.rest.issues.createComment({
45+
const body = `ℹ️ [Download the latest ${slug} plugin zip from this PR](${artifactUrl})\n<em>(See the 'Artifacts' section at the bottom)</em>`;
46+
47+
// Find existing comment from this bot
48+
const comments = await github.rest.issues.listComments({
4449
issue_number: pr.number,
4550
owner: context.repo.owner,
46-
repo: context.repo.repo,
47-
body
51+
repo: context.repo.repo
4852
});
53+
54+
const botComment = comments.data.find(comment =>
55+
comment.user.type === 'Bot' &&
56+
comment.user.login === 'github-actions[bot]' &&
57+
comment.body.includes(`ℹ️ [Download the latest ${slug} plugin zip from this PR]`)
58+
);
59+
60+
if (botComment) {
61+
// Update existing comment
62+
core.info(`Updating existing comment with ID: ${botComment.id}`);
63+
await github.rest.issues.updateComment({
64+
comment_id: botComment.id,
65+
owner: context.repo.owner,
66+
repo: context.repo.repo,
67+
body
68+
});
69+
} else {
70+
// Create new comment
71+
await github.rest.issues.createComment({
72+
issue_number: pr.number,
73+
owner: context.repo.owner,
74+
repo: context.repo.repo,
75+
body
76+
});
77+
}

0 commit comments

Comments
 (0)