Skip to content
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

Run unit tests only for plugins with changes #1838

Open
wants to merge 26 commits into
base: trunk
Choose a base branch
from
Open
Changes from 12 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1e0b484
Run unit tests only for plugins with changes
ShyamGadde Jan 23, 2025
d5e614d
Add spaces to avoid problems with partial matches
ShyamGadde Jan 23, 2025
0bc67df
Test all plugins when commits added to trunk
ShyamGadde Jan 23, 2025
cbce9b4
Test all plugins when non-plugin files are changed
ShyamGadde Jan 23, 2025
76a48cf
Trigger tests for dependent plugins on changes to OD
ShyamGadde Jan 23, 2025
d098b38
Check for duplicates in the plugins array for good measure
ShyamGadde Jan 23, 2025
020cce3
Fix Git diff listing files not changed by PR
ShyamGadde Jan 23, 2025
eb4dad0
Fix error with merge base resolution
ShyamGadde Jan 23, 2025
bea1bc0
Use tj-actions/changed-files for determining changed files
ShyamGadde Jan 30, 2025
3c66be3
Refactor logic to determine changes to config files
ShyamGadde Jan 30, 2025
fd07a0c
Simplify changed plugins detection
ShyamGadde Jan 30, 2025
fa1a433
Remove debug print statement
ShyamGadde Jan 30, 2025
11949ac
Fix array expansion to avoid SC2199 warning
ShyamGadde Feb 3, 2025
1033ad7
Test all plugins on changes to PHPUnit bootstrap file
ShyamGadde Feb 3, 2025
af6f8ff
Add PHPUnit bootstrap file to list of paths to trigger this workflow
ShyamGadde Feb 3, 2025
90a5ab7
Rename PLUGIN_DEPENDENCIES to PLUGIN_DEPENDENTS for clarity
ShyamGadde Feb 4, 2025
5323c60
Merge branch 'trunk' into update/skip-unnecessary-plugin-tests
ShyamGadde Feb 4, 2025
8917216
Restore EOF EOL
ShyamGadde Feb 4, 2025
8713f45
Remove deprecated Codecov configuration
ShyamGadde Feb 5, 2025
f89cf3e
Merge branch 'trunk' into update/skip-unnecessary-plugin-tests
ShyamGadde Feb 6, 2025
7aff9b2
Revert "Remove deprecated Codecov configuration"
ShyamGadde Feb 6, 2025
27cd4d0
Merge branch 'trunk' into update/skip-unnecessary-plugin-tests
ShyamGadde Feb 10, 2025
0be7a66
Show only patch coverage in PR comment
ShyamGadde Feb 10, 2025
6b34020
Limit Project coverage status checks to only the trunk
ShyamGadde Feb 10, 2025
e21ec9e
Use condensed variants of header, files and footer in the PR comment
ShyamGadde Feb 10, 2025
db41189
Reduce patch coverage threshold to 20 percent
ShyamGadde Feb 10, 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
80 changes: 60 additions & 20 deletions .github/workflows/php-test-plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,54 @@ jobs:
steps:
- uses: styfle/[email protected]
- uses: actions/checkout@v4
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v45
with:
dir_names: true # Output unique changed directories.
dir_names_max_depth: 2
Copy link
Contributor Author

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>/tests will be returned as plugins/<plugin-name>.
Since dir_names: true ensures only unique directories are listed, combining it with dir_names_max_depth: 2 allows us to extract a clean list of changed plugin names. This avoids additional logic in the next step for determining modified plugins.

files_yaml: |
plugins:
- 'plugins/**'
config:
- '.github/workflows/php-test-plugins.yml'
- '.wp-env.json'
- '**/package.json'
- 'package-lock.json'
- 'phpunit.xml.dist'
- 'composer.json'
- 'composer.lock'
ShyamGadde marked this conversation as resolved.
Show resolved Hide resolved
- 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

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 dependencies (e.g., optimization-detective triggers others).
declare -A PLUGIN_DEPENDENCIES=(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe call this PLUGIN_DEPENDENTS to clarify? In this case, Optimization Detective is a dependency of the other two, but the other two are dependents of Optimization Detective.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. Updated it in 90a5ab7.

["optimization-detective"]="embed-optimizer image-prioritizer"
)
for PLUGIN in "${ALL_CHANGED_PLUGINS[@]}"; do
if [[ -n "${PLUGIN_DEPENDENCIES[$PLUGIN]}" ]]; then
for DEP in ${PLUGIN_DEPENDENCIES[$PLUGIN]}; do
if [[ ! " ${ALL_CHANGED_PLUGINS[@]} " =~ " ${DEP} " ]]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PhpStorm (via Shellcheck) is flagging this line:

Arrays implicitly concatenate in [[ ]]. Use a loop (or explicit * instead of @).
See SC2199.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it in 11949ac.

ALL_CHANGED_PLUGINS+=("$DEP")
fi
done
fi
done
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, optimization-detective is the only plugin with dependencies, so we could simplify this by checking for it explicitly instead of maintaining a general dependency structure. However, I think this approach keeps things flexible if more dependencies are introduced in the future.


ALL_CHANGED_PLUGINS=($(echo "${ALL_CHANGED_PLUGINS[@]}" | tr ' ' '\n' | sort | tr '\n' ' '))
echo "all_changed_plugins=${ALL_CHANGED_PLUGINS[*]}" >> $GITHUB_OUTPUT
- name: Setup Node.js (.nvmrc)
uses: actions/setup-node@v4
with:
Expand Down Expand Up @@ -88,32 +136,24 @@ jobs:
- name: Running single site unit tests
run: |
if [ "${{ matrix.coverage }}" == "true" ]; then
npm run test-php:performance-lab -- -- -- --coverage-clover=./single-site-reports/coverage-performance-lab.xml
npm run test-php:auto-sizes -- -- -- --coverage-clover=./single-site-reports/coverage-auto-sizes.xml
npm run test-php:dominant-color-images -- -- -- --coverage-clover=./single-site-reports/coverage-dominant-color-images.xml
npm run test-php:embed-optimizer -- -- -- --coverage-clover=./single-site-reports/coverage-embed-optimizer.xml
npm run test-php:image-prioritizer -- -- -- --coverage-clover=./single-site-reports/coverage-image-prioritizer.xml
npm run test-php:optimization-detective -- -- -- --coverage-clover=./single-site-reports/coverage-optimization-detective.xml
npm run test-php:speculation-rules -- -- -- --coverage-clover=./single-site-reports/coverage-speculation-rules.xml
npm run test-php:web-worker-offloading -- -- -- --coverage-clover=./single-site-reports/coverage-web-worker-offloading.xml
npm run test-php:webp-uploads -- -- -- --coverage-clover=./single-site-reports/coverage-webp-uploads.xml
for PLUGIN in ${{ steps.changed-plugins.outputs.all_changed_plugins }}; do
npm run test-php:$PLUGIN -- -- -- --coverage-clover=./single-site-reports/coverage-$PLUGIN.xml
done
else
npm run test-php
for PLUGIN in ${{ steps.changed-plugins.outputs.all_changed_plugins }}; do
npm run test-php:$PLUGIN
done
fi
- name: Running multisite unit tests
run: |
if [ "${{ matrix.coverage }}" == "true" ]; then
npm run test-php-multisite:performance-lab -- -- -- --coverage-clover=./multisite-reports/coverage-multisite-performance-lab.xml
npm run test-php-multisite:auto-sizes -- -- -- --coverage-clover=./multisite-reports/coverage-multisite-auto-sizes.xml
npm run test-php-multisite:dominant-color-images -- -- -- --coverage-clover=./multisite-reports/coverage-multisite-dominant-color-images.xml
npm run test-php-multisite:embed-optimizer -- -- -- --coverage-clover=./multisite-reports/coverage-multisite-embed-optimizer.xml
npm run test-php-multisite:image-prioritizer -- -- -- --coverage-clover=./multisite-reports/coverage-multisite-image-prioritizer.xml
npm run test-php-multisite:optimization-detective -- -- -- --coverage-clover=./multisite-reports/coverage-multisite-optimization-detective.xml
npm run test-php-multisite:speculation-rules -- -- -- --coverage-clover=./multisite-reports/coverage-multisite-speculation-rules.xml
npm run test-php-multisite:web-worker-offloading -- -- -- --coverage-clover=./multisite-reports/coverage-multisite-web-worker-offloading.xml
npm run test-php-multisite:webp-uploads -- -- -- --coverage-clover=./multisite-reports/coverage-multisite-webp-uploads.xml
for PLUGIN in ${{ steps.changed-plugins.outputs.all_changed_plugins }}; do
npm run test-php-multisite:$PLUGIN -- -- -- --coverage-clover=./multisite-reports/coverage-multisite-$PLUGIN.xml
done
else
npm run test-php-multisite
for PLUGIN in ${{ steps.changed-plugins.outputs.all_changed_plugins }}; do
npm run test-php-multisite:$PLUGIN
done
fi
- name: Upload single site coverage reports to Codecov
if: ${{ matrix.coverage == true }}
Expand Down
Loading