Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion .distignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ vendor
.gitignore
.phpcs.xml.dist
.prettierrc.js
eslint.config.mjs
.wp-env.json
.wp-env.override.json
composer.json
composer.lock
eslint.config.mjs
package-lock.json
package.json
phpstan.neon.dist
README.md
webpack.config.js
177 changes: 177 additions & 0 deletions .github/workflows/plugin-check-playground.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
# Run WP.org's Plugin Check against the built, distributable plugin using
# WordPress Playground — mirroring the command we run locally.
name: Plugin Check (Playground)

on:
pull_request:
branches:
- trunk

# Allow the workflow to leave/update a comment on the pull request.
permissions:
contents: read
pull-requests: write

jobs:
plugin-check:
runs-on: ubuntu-latest
steps:
- name: Check out the latest code
uses: actions/checkout@v6

- name: Set up Node
uses: actions/setup-node@v6
with:
node-version: 24
cache: npm

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
coverage: none
tools: wp-cli

- name: Install dependencies
run: npm ci

- name: Build the project
run: npm run build

- name: Install dist-archive-command
env:
GITHUB_TOKEN: ''
COMPOSER_AUTH: ''
run: |
# setup-php writes the runner token into Composer's global auth.json,
# and wp-cli's older bundled Composer rejects its format ("invalid
# characters"). dist-archive-command is public, so remove the stored
# token before installing.
composer config --global --unset --auth github-oauth.github.com 2>/dev/null || true
rm -f "$(composer -n config --global home 2>/dev/null)/auth.json" || true
rm -f "$HOME/.composer/auth.json" "$HOME/.config/composer/auth.json" || true
wp package install wp-cli/dist-archive-command:3.1.0

- name: Extract the zip to a fresh directory
run: |
wp dist-archive ./ /tmp/toggle-block.zip
rm -rf /tmp/toggle-block
mkdir -p /tmp/toggle-block
unzip -q /tmp/toggle-block.zip -d /tmp/toggle-block

- name: Add the Playground blueprint to the extracted plugin
run: |
plugin_dir="$(find /tmp/toggle-block -mindepth 1 -maxdepth 1 -type d | head -n1)"
echo "PLUGIN_DIR=${plugin_dir}" >> "$GITHUB_ENV"
cat > "${plugin_dir}/blueprint.json" <<'JSON'
{
"steps": [
{"step": "installPlugin", "pluginData": {"resource": "wordpress.org/plugins", "slug": "plugin-check"}},
{"step": "wp-cli", "command": "wp plugin activate plugin-check toggle-block"},
{"step": "cp",
"fromPath": "/wordpress/wp-content/plugins/plugin-check/drop-ins/object-cache.copy.php",
"toPath": "/wordpress/wp-content/object-cache.php"}
]
}
JSON

- name: Run Plugin Check via WordPress Playground
run: |
cd "$PLUGIN_DIR"
npx --yes @wp-playground/cli php \
--blueprint=blueprint.json \
--mount=./:/wordpress/wp-content/plugins/toggle-block \
--quiet \
-- /tmp/wp-cli.phar plugin check toggle-block \
--categories=plugin_repo \
--format=json \
--error-severity=7 \
--warning-severity=6 \
--include-low-severity-errors \
> /tmp/plugin-check-result.json || true
echo "Plugin Check raw output:"
cat /tmp/plugin-check-result.json

- name: Report results on the pull request
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const marker = '<!-- plugin-check-playground -->';

let raw = '';
try {
raw = fs.readFileSync('/tmp/plugin-check-result.json', 'utf8').trim();
} catch (e) {}

// The Playground/WP-CLI output should be a JSON array; slice from
// the first '[' to the last ']' in case of stray leading output.
let issues = [];
const start = raw.indexOf('[');
const end = raw.lastIndexOf(']');
if (start !== -1 && end !== -1) {
try {
issues = JSON.parse(raw.slice(start, end + 1));
} catch (e) {
core.warning(`Could not parse Plugin Check output: ${e.message}`);
}
}

const errors = issues.filter(
(i) => String(i.type).toUpperCase() === 'ERROR'
);
const warnings = issues.filter(
(i) => String(i.type).toUpperCase() === 'WARNING'
);

let body;
if (issues.length === 0) {
body =
`${marker}\n### ✅ Plugin Check passed\n\n` +
'No errors or warnings from `plugin check --categories=plugin_repo`.';
} else {
const esc = (s) => String(s ?? '').replace(/\|/g, '\\|');
const rows = issues
.map(
(i) =>
`| ${esc(i.file)} | ${esc(i.line)}:${esc(i.column)} | ${esc(i.type)} | \`${esc(i.code)}\` | ${esc(i.message)} |`
)
.join('\n');
body =
`${marker}\n### Plugin Check: ${errors.length} error(s), ${warnings.length} warning(s)\n\n` +
'| File | Line:Col | Type | Code | Message |\n' +
'| --- | --- | --- | --- | --- |\n' +
rows;
}

const { owner, repo } = context.repo;
const issue_number = context.issue.number;

if (issue_number) {
const comments = await github.paginate(
github.rest.issues.listComments,
{ owner, repo, issue_number }
);
const existing = comments.find(
(c) => c.body && c.body.includes(marker)
);
if (existing) {
await github.rest.issues.updateComment({
owner,
repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body,
});
}
}

if (errors.length > 0) {
core.setFailed(`Plugin Check reported ${errors.length} error(s).`);
}
18 changes: 0 additions & 18 deletions .github/workflows/plugin-check.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .wp-env.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"core": "WordPress/WordPress#6.9",
"core": "WordPress/WordPress#7.0",
"phpVersion": "8.2",
"plugins": [
"."
Expand Down
Loading
Loading