-
Notifications
You must be signed in to change notification settings - Fork 144
Run unit tests only for plugins with changes #1838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from all commits
1e0b484
d5e614d
0bc67df
cbce9b4
76a48cf
d098b38
020cce3
eb4dad0
bea1bc0
3c66be3
fd07a0c
fa1a433
11949ac
1033ad7
af6f8ff
90a5ab7
5323c60
8917216
8713f45
f89cf3e
7aff9b2
27cd4d0
0be7a66
6b34020
e21ec9e
db41189
9c8c17e
93dbf21
c1c5b11
12210f8
bc5cfe9
264add9
7066ece
3a30efb
e9596f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,6 +13,7 @@ on: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - '**/package.json' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - 'package-lock.json' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - 'phpunit.xml.dist' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - 'tools/phpunit/bootstrap.php' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - 'composer.json' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - 'composer.lock' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pull_request: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -24,6 +25,7 @@ on: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - '**/package.json' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - 'package-lock.json' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - 'phpunit.xml.dist' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - 'tools/phpunit/bootstrap.php' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - 'composer.json' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - 'composer.lock' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| types: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -61,6 +63,55 @@ jobs: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| steps: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # 0.12.1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Get changed files | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id: changed-files | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uses: tj-actions/changed-files@e0021407031f5be11a464abee9a0776171c79891 # v47.0.1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dir_names: true # Output unique changed directories. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dir_names_max_depth: 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| files_yaml: | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| plugins: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - 'plugins/**' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| config: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - '.github/workflows/php-test-plugins.yml' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - '.wp-env.json' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - '**/package.json' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - 'package-lock.json' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - 'phpunit.xml.dist' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - 'tools/phpunit/bootstrap.php' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - 'composer.json' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - 'composer.lock' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Get changed plugins | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id: changed-plugins | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [[ "${{ github.event_name }}" == "push" || "${{ steps.changed-files.outputs.config_any_changed }}" == "true" ]]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ALL_CHANGED_PLUGINS=($(ls plugins)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "all_changed_plugins=${ALL_CHANGED_PLUGINS[*]}" >> $GITHUB_OUTPUT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exit 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+87
to
+91
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| declare -a ALL_CHANGED_PLUGINS=() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for DIR in ${{ steps.changed-files.outputs.plugins_all_changed_files }}; do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PLUGIN_NAME=$(basename "$DIR") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ALL_CHANGED_PLUGINS+=("$PLUGIN_NAME") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Define and add plugin dependents (e.g., changes to Optimization Detective should trigger its dependents). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| declare -A PLUGIN_DEPENDENTS=( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ["optimization-detective"]="embed-optimizer image-prioritizer" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for PLUGIN in "${ALL_CHANGED_PLUGINS[@]}"; do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [[ -n "${PLUGIN_DEPENDENTS[$PLUGIN]}" ]]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for DEP in ${PLUGIN_DEPENDENTS[$PLUGIN]}; do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [[ ! " ${ALL_CHANGED_PLUGINS[*]} " =~ " ${DEP} " ]]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ALL_CHANGED_PLUGINS+=("$DEP") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [[ ${#ALL_CHANGED_PLUGINS[@]} -eq 0 ]]; then | |
| echo "No changed plugins detected; skipping plugin tests." | |
| echo "all_changed_plugins=" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi |
Copilot
AI
Jan 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The script uses unquoted variable expansion in the for loops (${{ steps.changed-plugins.outputs.all_changed_plugins }}), which could cause issues if plugin names contain spaces or special characters. While plugin names in this repository don't have spaces, it's a best practice to quote these expansions for robustness.
ShyamGadde marked this conversation as resolved.
Show resolved
Hide resolved
Copilot
AI
Jan 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The codecov CLI verification steps create a .gpg directory but don't clean it up afterward. This could leave sensitive keyring files on the runner. Add a cleanup step or use the system's default GPG directory instead.
Copilot
AI
Jan 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The codecov upload command assumes that coverage files exist for all changed plugins, but if a test execution fails for any plugin, the corresponding coverage file won't be generated. This will cause the upload to fail with --fail-on-error. Consider checking if files exist before attempting to upload them, or handle missing files gracefully.
| ./codecov upload-coverage "${cc_args[@]}" \ | |
| --file ./single-site-reports/coverage-$PLUGIN.xml \ | |
| --file ./multisite-reports/coverage-multisite-$PLUGIN.xml \ | |
| --flag $PLUGIN \ | |
| --name $PLUGIN-coverage | |
| single_site_report="./single-site-reports/coverage-$PLUGIN.xml" | |
| multisite_report="./multisite-reports/coverage-multisite-$PLUGIN.xml" | |
| files=() | |
| if [ -f "$single_site_report" ]; then | |
| files+=(--file "$single_site_report") | |
| else | |
| echo "::warning::Single-site coverage report not found for plugin '$PLUGIN' at '$single_site_report'." | |
| fi | |
| if [ -f "$multisite_report" ]; then | |
| files+=(--file "$multisite_report") | |
| else | |
| echo "::warning::Multisite coverage report not found for plugin '$PLUGIN' at '$multisite_report'." | |
| fi | |
| if [ ${#files[@]} -eq 0 ]; then | |
| echo "::warning::No coverage reports found for plugin '$PLUGIN'. Skipping Codecov upload for this plugin." | |
| echo "::endgroup::" | |
| continue | |
| fi | |
| ./codecov upload-coverage "${cc_args[@]}" "${files[@]}" \ | |
| --flag "$PLUGIN" \ | |
| --name "$PLUGIN-coverage" |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -8,8 +8,48 @@ coverage: | |||||
| target: auto | ||||||
| threshold: 80% | ||||||
| base: auto | ||||||
| branches: | ||||||
| - trunk | ||||||
| informational: true | ||||||
| patch: | ||||||
| default: | ||||||
| threshold: 80% | ||||||
| threshold: 20% | ||||||
|
||||||
| threshold: 20% | |
| threshold: 80% |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@westonruter Would you prefer that we display the carried forward flags in the PR comment, as shown below, or would you rather exclude them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose it doesn't hurt to include?

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This limits the directory output to a maximum depth of 2. For example,
plugins/<plugin-name>/testswill be returned asplugins/<plugin-name>.Since
dir_names: trueensures only unique directories are listed, combining it withdir_names_max_depth: 2allows us to extract a clean list of changed plugin names. This avoids additional logic in the next step for determining modified plugins.