diff --git a/.github/actions/plugin-check-report/README.md b/.github/actions/plugin-check-report/README.md index d9ca456e..67c03d10 100644 --- a/.github/actions/plugin-check-report/README.md +++ b/.github/actions/plugin-check-report/README.md @@ -246,6 +246,7 @@ the check to require in branch protection is `plugin-check / Plugin Check`. | `php-version` | `7.4` | PHP that builds `vendor/`. Use the oldest the plugin supports | | `exclude-checks` | empty | Checks to skip, one per line. Replaces `.plugin-check.json` when it names any. See [Excluding checks](#excluding-checks) | | `cache-paths` | empty | Build caches kept between runs, one path per line, relative to the repository | +| `memory-limit` | empty | WordPress memory limit for the check, e.g. `512M` or `1G`. Empty keeps the WordPress default (256M with WP-CLI 3). A large plugin needs more, or Plugin Check stops with "Allowed memory size exhausted" and an empty results file | | `mode` | `baseline` | `baseline` or `strict`. See [Modes](#modes) | | `submodules` | `false` | Passed to `actions/checkout` | | `head-ref` | empty | Manual runs only: the branch, tag or commit to check. Empty checks the ref the run started on. See [Manual runs](#manual-runs) | diff --git a/.github/workflows/plugin-check.yml b/.github/workflows/plugin-check.yml index 1e83440c..3a56de47 100644 --- a/.github/workflows/plugin-check.yml +++ b/.github/workflows/plugin-check.yml @@ -104,6 +104,14 @@ on: required: false type: string default: '' + memory-limit: + description: >- + WordPress memory limit for the check, e.g. `512M` or `1G`, or `-1` for none. Empty keeps the + WordPress default (256M with WP-CLI 3). A large plugin needs more: Plugin Check stops with + "Allowed memory size exhausted" and the results file is empty. + required: false + type: string + default: '' mode: description: >- `baseline`: fail only when a rule has more errors than the baseline. `strict`: fail on any @@ -529,6 +537,26 @@ jobs: done cat "$RUNNER_TEMP/docker-pull.log" 2>/dev/null || true + # The action writes its own .wp-env.json in the workspace root, so a repository cannot add a + # setting to it. wp-env merges .wp-env.override.json from the same folder over that file, and + # the action does not touch it. WP_MAX_MEMORY_LIMIT is the limit WordPress applies to WP-CLI + # commands that load the admin side, which WP-CLI 3 does. The value is checked first, so only a + # size reaches the JSON. The step always runs: with no input it removes the file, so a runner + # that keeps its workspace between runs does not carry an earlier run's limit over. + - name: Set the memory limit + env: + MEMORY_LIMIT: ${{ inputs.memory-limit }} + run: | + if [ -z "$MEMORY_LIMIT" ]; then + rm -f .wp-env.override.json + exit 0 + fi + if ! [[ "$MEMORY_LIMIT" =~ ^(-1|[0-9]+[KMG])$ ]]; then + echo "::error title=Plugin Check::memory-limit must be a size such as 512M or 1G, or -1: $MEMORY_LIMIT" + exit 1 + fi + echo "{\"config\": {\"WP_MAX_MEMORY_LIMIT\": \"$MEMORY_LIMIT\"}}" > .wp-env.override.json + # Fails on any error, which is expected while a plugin still has known problems: the report # job decides pass or fail from the counts. The action writes its results to # $RUNNER_TEMP/plugin-check-results.txt and uploads them as the plugin-check-results