-
Notifications
You must be signed in to change notification settings - Fork 109
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
base: trunk
Are you sure you want to change the base?
Changes from 12 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
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 |
---|---|---|
|
@@ -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 | ||
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=( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe call this There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PhpStorm (via Shellcheck) is flagging this line:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed it in 11949ac. |
||
ALL_CHANGED_PLUGINS+=("$DEP") | ||
fi | ||
done | ||
fi | ||
done | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently, |
||
|
||
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: | ||
|
@@ -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 }} | ||
|
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>/tests
will be returned asplugins/<plugin-name>
.Since
dir_names: true
ensures only unique directories are listed, combining it withdir_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.