Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
af447eb
fix: improve snippet filtering for multisite support
imantsk Dec 15, 2025
750af73
fix: enhance multisite snippet handling by ensuring local snippets us…
imantsk Dec 15, 2025
2966921
fix: refactor snippet execution logic for multisite support by centra…
imantsk Dec 15, 2025
0ce8c45
phpcs: enhance documentation for Snippet_Files class with detailed PH…
imantsk Dec 15, 2025
5c5c035
fix: reorganize class and move private method to the bottom
imantsk Dec 15, 2025
4223530
fix: multisite capability check in Plugin class
imantsk Dec 15, 2025
49f9e95
fix: add screenshot assertions maxDiffPixelRatio
imantsk Dec 18, 2025
2fb1b60
fix: enhance Playwright test workflow with multisite support and impr…
imantsk Dec 18, 2025
47a20a4
fix: clarify documentation is_network_snippet_enabled
imantsk Dec 18, 2025
d840f7d
fix: update create_all_flat_files method to remove unused parameter a…
imantsk Dec 18, 2025
6e1b965
Merge branch 'core/core' into fix/multisite-issues
imantsk Dec 18, 2025
c49e829
fix: enhance Playwright test workflow and add wpCli helper for WP-CLI…
imantsk Dec 18, 2025
faf2978
fix: update Playwright workflow to support `multisite` configuration …
imantsk Dec 18, 2025
81579b5
fix: remove unnecessary WordPress mode echo statement from Playwright…
imantsk Dec 18, 2025
cc2ec6b
fix: update Playwright workflow conditions to support multisite execu…
imantsk Dec 18, 2025
7ceb12a
fix: enhance pull request workflow to handle labeled and unlabeled ev…
imantsk Dec 18, 2025
ad354e0
fix: correct artifact name output in build workflow and update zip fi…
imantsk Dec 18, 2025
64c39f9
fix: concurrency conditions in Playwright workflow
imantsk Dec 18, 2025
bac0f66
fix: standardize GH_TOKEN usage in pull request workflow
imantsk Dec 18, 2025
c2a10bb
fix: update GH_TOKEN usage to use secrets in pull request workflow
imantsk Dec 18, 2025
d9e36f7
fix: concurrency settings in Playwright workflow
imantsk Dec 18, 2025
8145e5d
fix: add concurrency settings for pull request builds
imantsk Dec 18, 2025
9cb25e7
fix: concurrency settings in Playwright workflow
imantsk Dec 18, 2025
7aad242
fix: add emoji to build started message in pull request workflow
imantsk Dec 18, 2025
a4d74ab
fix: update flat files setup to support multisite mode
imantsk Dec 19, 2025
da2faf9
fix: add multisite mode support to Playwright test environment
imantsk Dec 19, 2025
e4af12e
fix: correct wpAdminbase path for multisite mode in flat files setup
imantsk Dec 19, 2025
da84739
fix: improve caching strategy for Playwright tests to avoid collision…
imantsk Dec 19, 2025
919ca63
chore: test workflow setup cache
imantsk Dec 19, 2025
b8e2474
chore(ci): make cache keys deterministic and add cache debug logging
imantsk Dec 19, 2025
2c598ed
Revert "chore(ci): make cache keys deterministic and add cache debug …
imantsk Dec 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.build.outputs.version }}
artifact_name: ${{ steps.build.outputs.name }}
artifact_name: ${{ steps.build.outputs.artifact_name }}
artifact_url: ${{ steps.artifacts.outputs.artifact-url }}
artifact_id: ${{ steps.artifacts.outputs.artifact-id }}
steps:
Expand All @@ -51,8 +51,12 @@ jobs:
npm install && npm run bundle

name=$(jq -r .name package.json)
version=$(jq -r .version package.json)
artifact_name="${name}.${version}"

echo "name=$name" >> $GITHUB_OUTPUT
echo "version=$(jq -r .version package.json)" >> $GITHUB_OUTPUT
echo "version=$version" >> $GITHUB_OUTPUT
echo "artifact_name=$artifact_name" >> $GITHUB_OUTPUT

mkdir -p ./upload/$name
mv ./bundle/* ./upload/$name/ 2>/dev/null || true
Expand All @@ -61,5 +65,5 @@ jobs:
id: artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ steps.build.outputs.name }}
name: ${{ steps.build.outputs.artifact_name }}
path: ./upload
173 changes: 158 additions & 15 deletions .github/workflows/playwright-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,46 @@ on:
required: true
type: string
description: 'Playwright project name to run'
multisite:
required: false
type: boolean
default: false
description: 'If true, convert the site to multisite and create a subsite.'

jobs:
playwright-test:
name: Playwright tests (${{ inputs.test-mode == 'default' && 'Default Mode' || 'File-based Execution' }})
runs-on: ubuntu-22.04
services:
mysql:
image: mysql:8.0
env:
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
MYSQL_ROOT_PASSWORD: root
options: >-
--health-cmd="mysqladmin ping -h localhost -proot"
--health-interval=10s
--health-timeout=5s
--health-retries=10

wordpress:
image: wordpress:php8.1-apache
env:
WORDPRESS_DB_HOST: mysql:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
WORDPRESS_DEBUG: 1
WORDPRESS_CONFIG_EXTRA: |
define( 'FS_METHOD', 'direct' );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
define( 'SCRIPT_DEBUG', true );
define( 'WP_ENVIRONMENT_TYPE', 'local' );
ports:
- 8888:80
steps:
- name: Checkout source code
uses: actions/checkout@v4
Expand Down Expand Up @@ -55,45 +90,153 @@ jobs:
path: |
node_modules
src/vendor
key: ${{ runner.os }}-deps-${{ steps.deps-hash.outputs.deps_hash }}
key: ${{ runner.os }}-${{ inputs.test-mode }}-deps-${{ steps.deps-hash.outputs.deps_hash }}-${{ github.run_id }}-${{ github.job }}
restore-keys: |
${{ runner.os }}-deps-
${{ runner.os }}-${{ inputs.test-mode }}-deps-${{ steps.deps-hash.outputs.deps_hash }}-

- name: Install workflow dependencies (wp-env, playwright)
if: steps.deps-cache.outputs.cache-hit != 'true'
- name: Install workflow dependencies
if: steps.deps-cache.outputs.cache-matched-key == ''
run: npm run prepare-environment:ci && npm run bundle

- name: Save vendor and node_modules cache
if: steps.deps-cache.outputs.cache-hit != 'true'
if: steps.deps-cache.outputs.cache-matched-key == ''
uses: actions/cache/save@v4
with:
path: |
src/vendor
node_modules
key: ${{ runner.os }}-deps-${{ steps.deps-hash.outputs.deps_hash }}
key: ${{ steps.deps-cache.outputs.cache-primary-key }}

- name: Start WordPress environment
- name: Wait for WordPress to be reachable
run: |
for i in $(seq 1 60); do
if curl -fsS http://localhost:8888/wp-login.php >/dev/null; then
echo "WordPress is reachable."
exit 0
fi
echo "Waiting for WordPress... ($i/60)"
sleep 2
done

echo "WordPress did not start in time."
echo "::group::WordPress container logs"
docker logs "${{ job.services.wordpress.id }}" || true
echo "::endgroup::"
exit 1

- name: Download WP-CLI
run: |
curl -fsSL -o "${RUNNER_TEMP}/wp-cli.phar" https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

- name: "Install WordPress: ${{ inputs.multisite && 'Multisite' || 'Single Site' }}"
env:
WP_CONTAINER: ${{ job.services.wordpress.id }}
WP_URL: http://localhost:8888
WP_ADMIN_USER: admin
WP_ADMIN_PASSWORD: password
WP_ADMIN_EMAIL: admin@example.org
run: |
npx wp-env start
set -euo pipefail

docker cp "${RUNNER_TEMP}/wp-cli.phar" "$WP_CONTAINER:/tmp/wp-cli.phar"

# Install WordPress if it isn't already installed.
if ! docker exec -u root -w /var/www/html "$WP_CONTAINER" php /tmp/wp-cli.phar core is-installed --allow-root >/dev/null 2>&1; then
docker exec -u root -w /var/www/html "$WP_CONTAINER" php /tmp/wp-cli.phar core install \
--url="$WP_URL" \
--title="Test Blog" \
--admin_user="$WP_ADMIN_USER" \
--admin_password="$WP_ADMIN_PASSWORD" \
--admin_email="$WP_ADMIN_EMAIL" \
--skip-email \
--allow-root
fi

if [ "${{ inputs.multisite }}" = "true" ]; then
# Convert single site -> multisite (subdirectory). Subdomains don't work with localhost.
if ! docker exec -u root -w /var/www/html "$WP_CONTAINER" php /tmp/wp-cli.phar core is-installed --network --allow-root >/dev/null 2>&1; then
docker exec -u root -w /var/www/html "$WP_CONTAINER" php /tmp/wp-cli.phar core multisite-convert \
--title="Test Network" \
--base=/ \
--allow-root
fi

# Create a subsite for future multisite test coverage.
if ! docker exec -u root -w /var/www/html "$WP_CONTAINER" php /tmp/wp-cli.phar site list --field=path --allow-root | grep -qx "/subsite/"; then
docker exec -u root -w /var/www/html "$WP_CONTAINER" php /tmp/wp-cli.phar site create \
--slug=subsite \
--title="Subsite" \
--email="$WP_ADMIN_EMAIL" \
--allow-root
fi
fi

- name: Install plugin into WordPress container
env:
WP_CONTAINER: ${{ job.services.wordpress.id }}
run: |
set -euo pipefail

docker exec -u root -w /var/www/html "$WP_CONTAINER" rm -rf wp-content/plugins/code-snippets
docker cp src "$WP_CONTAINER:/var/www/html/wp-content/plugins/code-snippets"
docker exec -u root -w /var/www/html "$WP_CONTAINER" chown -R www-data:www-data wp-content/plugins/code-snippets

- name: Activate code-snippets plugin
run: npx wp-env run cli wp plugin activate code-snippets
env:
WP_CONTAINER: ${{ job.services.wordpress.id }}
run: |
set -euo pipefail
if [ "${{ inputs.multisite }}" = "true" ]; then
docker exec -u root -w /var/www/html "$WP_CONTAINER" php /tmp/wp-cli.phar plugin activate code-snippets --network --allow-root
else
docker exec -u root -w /var/www/html "$WP_CONTAINER" php /tmp/wp-cli.phar plugin activate code-snippets --allow-root
fi

- name: WordPress debug information
env:
WP_CONTAINER: ${{ job.services.wordpress.id }}
run: |
npx wp-env run cli wp core version
npx wp-env run cli wp --info
docker exec -u root -w /var/www/html "$WP_CONTAINER" php /tmp/wp-cli.phar core version --allow-root
docker exec -u root -w /var/www/html "$WP_CONTAINER" php /tmp/wp-cli.phar --allow-root --info

- name: Restore Playwright browsers cache
id: playwright-browsers-cache
uses: actions/cache/restore@v4
with:
path: |
~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-browsers-${{ hashFiles('package-lock.json') }}-${{ github.run_id }}-${{ github.job }}
restore-keys: |
${{ runner.os }}-playwright-browsers-${{ hashFiles('package-lock.json') }}-

- name: Install playwright/test
if: steps.playwright-browsers-cache.outputs.cache-matched-key == ''
run: |
npx playwright install chromium

- name: Save Playwright browsers cache
if: steps.playwright-browsers-cache.outputs.cache-matched-key == ''
uses: actions/cache/save@v4
with:
path: |
~/.cache/ms-playwright
key: ${{ steps.playwright-browsers-cache.outputs.cache-primary-key }}

- name: Run Playwright tests
env:
WP_E2E_WPCLI_MODE: gh-actions-ci
WP_E2E_WPCLI_PHAR: /tmp/wp-cli.phar
WP_E2E_WPCLI_URL: http://localhost:8888
WP_E2E_WP_CONTAINER: ${{ job.services.wordpress.id }}
WP_E2E_MULTISITE_MODE: ${{ inputs.multisite }}
run: npm run test:playwright -- --project=${{ inputs.project-name }}

- name: Stop WordPress environment
if: always()
run: npx wp-env stop

- name: Print WordPress logs on failure
if: failure()
run: |
echo "::group::WordPress container logs"
docker logs "${{ job.services.wordpress.id }}" || true
echo "::endgroup::"

- uses: actions/upload-artifact@v4
if: always()
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,25 @@ permissions:
actions: read

concurrency:
group: playwright-${{ github.event_name }}-${{ github.event_name == 'pull_request' && github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
group: playwright-${{ github.workflow }}-${{ github.event_name }}-${{ github.event_name == 'pull_request' && github.event.pull_request.number || github.ref }}-${{ (github.event_name != 'pull_request' || (contains(github.event.pull_request.labels.*.name, 'run-tests') && (github.event.action != 'labeled' || github.event.label.name == 'run-tests' || github.event.label.name == 'multisite'))) && 'tests' || github.run_id }}
cancel-in-progress: ${{ github.event_name != 'pull_request' || (contains(github.event.pull_request.labels.*.name, 'run-tests') && (github.event.action != 'labeled' || github.event.label.name == 'run-tests' || github.event.label.name == 'multisite')) }}

jobs:
playwright-default:
if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-tests')
if: github.event_name != 'pull_request' || (contains(github.event.pull_request.labels.*.name, 'run-tests') && (github.event.action != 'labeled' || github.event.label.name == 'run-tests' || github.event.label.name == 'multisite'))
uses: ./.github/workflows/playwright-test.yml
with:
test-mode: 'default'
project-name: 'chromium-db-snippets'
multisite: ${{ github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'run-tests') && contains(github.event.pull_request.labels.*.name, 'multisite') }}

playwright-file-based-execution:
if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-tests')
if: github.event_name != 'pull_request' || (contains(github.event.pull_request.labels.*.name, 'run-tests') && (github.event.action != 'labeled' || github.event.label.name == 'run-tests' || github.event.label.name == 'multisite'))
uses: ./.github/workflows/playwright-test.yml
with:
test-mode: 'file-based-execution'
project-name: 'chromium-file-based-snippets'
multisite: ${{ github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'run-tests') && contains(github.event.pull_request.labels.*.name, 'multisite') }}

test-result:
needs: [playwright-default, playwright-file-based-execution]
Expand Down
Loading