From 1e0b4841f83b13751df7eb8f7c91e4233c3af804 Mon Sep 17 00:00:00 2001 From: Shyamsundar Gadde Date: Thu, 23 Jan 2025 16:19:05 +0530 Subject: [PATCH 01/23] Run unit tests only for plugins with changes Signed-off-by: Shyamsundar Gadde --- .github/workflows/php-test-plugins.yml | 56 +++++++++++++++++--------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/.github/workflows/php-test-plugins.yml b/.github/workflows/php-test-plugins.yml index ec1aebda1b..873eaa044a 100644 --- a/.github/workflows/php-test-plugins.yml +++ b/.github/workflows/php-test-plugins.yml @@ -57,6 +57,30 @@ jobs: steps: - uses: styfle/cancel-workflow-action@0.12.1 - uses: actions/checkout@v4 + - name: Determine affected plugins + id: affected-plugins + run: | + BASE_SHA=${{ github.event.pull_request.base.sha }} + HEAD_SHA=${{ github.sha }} + + CHANGED_FILES=$(git diff --name-only $BASE_SHA $HEAD_SHA) + echo "Changed files:" + echo "$CHANGED_FILES" + + declare -a AFFECTED_PLUGINS=() + for FILE in $CHANGED_FILES; do + if [[ "$FILE" == plugins/* ]]; then + PLUGIN_NAME=$(echo "$FILE" | cut -d'/' -f2) + if [[ ! "${AFFECTED_PLUGINS[@]}" =~ "${PLUGIN_NAME}" ]]; then + AFFECTED_PLUGINS+=("$PLUGIN_NAME") + fi + fi + done + + echo "Plugins with changes: ${AFFECTED_PLUGINS[*]}" + + # Output the list of plugins to test. + echo "plugins=${AFFECTED_PLUGINS[*]}" >> $GITHUB_OUTPUT - name: Setup Node.js (.nvmrc) uses: actions/setup-node@v4 with: @@ -88,32 +112,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.affected-plugins.outputs.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.affected-plugins.outputs.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.affected-plugins.outputs.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.affected-plugins.outputs.plugins }}; do + npm run test-php-multisite:$PLUGIN + done fi - name: Upload single site coverage reports to Codecov if: ${{ matrix.coverage == true }} From d5e614da4d0843a3fc7da4e49030eabda1818b76 Mon Sep 17 00:00:00 2001 From: Shyamsundar Gadde Date: Thu, 23 Jan 2025 16:21:16 +0530 Subject: [PATCH 02/23] Add spaces to avoid problems with partial matches Signed-off-by: Shyamsundar Gadde --- .github/workflows/php-test-plugins.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/php-test-plugins.yml b/.github/workflows/php-test-plugins.yml index 873eaa044a..d8f31fb6a8 100644 --- a/.github/workflows/php-test-plugins.yml +++ b/.github/workflows/php-test-plugins.yml @@ -71,7 +71,7 @@ jobs: for FILE in $CHANGED_FILES; do if [[ "$FILE" == plugins/* ]]; then PLUGIN_NAME=$(echo "$FILE" | cut -d'/' -f2) - if [[ ! "${AFFECTED_PLUGINS[@]}" =~ "${PLUGIN_NAME}" ]]; then + if [[ ! " ${AFFECTED_PLUGINS[@]} " =~ " ${PLUGIN_NAME} " ]]; then AFFECTED_PLUGINS+=("$PLUGIN_NAME") fi fi From 0bc67df0a96025dc8dc7a8e23f61bf22bb95a684 Mon Sep 17 00:00:00 2001 From: Shyamsundar Gadde Date: Thu, 23 Jan 2025 16:29:45 +0530 Subject: [PATCH 03/23] Test all plugins when commits added to trunk Signed-off-by: Shyamsundar Gadde --- .github/workflows/php-test-plugins.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/php-test-plugins.yml b/.github/workflows/php-test-plugins.yml index d8f31fb6a8..9f707ec01f 100644 --- a/.github/workflows/php-test-plugins.yml +++ b/.github/workflows/php-test-plugins.yml @@ -59,7 +59,18 @@ jobs: - uses: actions/checkout@v4 - name: Determine affected plugins id: affected-plugins + env: + GITHUB_EVENT_NAME: ${{ github.event_name }} run: | + # For push to 'trunk' or 'release/**' events, test all plugins regardless of changes. + if [ "$GITHUB_EVENT_NAME" = "push" ]; then + AFFECTED_PLUGINS=($(ls plugins)) + echo "Event: $GITHUB_EVENT_NAME - Running tests for all plugins. Affected plugins: ${AFFECTED_PLUGINS[*]}" + echo "plugins=${AFFECTED_PLUGINS[*]}" >> $GITHUB_OUTPUT + exit 0 + fi + + # For pull_request events, determine changes. BASE_SHA=${{ github.event.pull_request.base.sha }} HEAD_SHA=${{ github.sha }} From cbce9b444ae71060484874bc8d8bb684fba5acbd Mon Sep 17 00:00:00 2001 From: Shyamsundar Gadde Date: Thu, 23 Jan 2025 16:33:04 +0530 Subject: [PATCH 04/23] Test all plugins when non-plugin files are changed Signed-off-by: Shyamsundar Gadde --- .github/workflows/php-test-plugins.yml | 30 ++++++++++++++++++++------ 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/.github/workflows/php-test-plugins.yml b/.github/workflows/php-test-plugins.yml index 9f707ec01f..4ce5a27c13 100644 --- a/.github/workflows/php-test-plugins.yml +++ b/.github/workflows/php-test-plugins.yml @@ -78,17 +78,33 @@ jobs: echo "Changed files:" echo "$CHANGED_FILES" - declare -a AFFECTED_PLUGINS=() + # Check for global changes (any file outside plugins/). + GLOBAL_CHANGES=false for FILE in $CHANGED_FILES; do - if [[ "$FILE" == plugins/* ]]; then - PLUGIN_NAME=$(echo "$FILE" | cut -d'/' -f2) - if [[ ! " ${AFFECTED_PLUGINS[@]} " =~ " ${PLUGIN_NAME} " ]]; then - AFFECTED_PLUGINS+=("$PLUGIN_NAME") - fi + if [[ "$FILE" != plugins/* ]]; then + GLOBAL_CHANGES=true + break fi done - echo "Plugins with changes: ${AFFECTED_PLUGINS[*]}" + if [ "$GLOBAL_CHANGES" = true ]; then + # Test all plugins if global changes detected. + AFFECTED_PLUGINS=($(ls plugins)) + echo "Global changes detected; testing all plugins: ${AFFECTED_PLUGINS[*]}" + else + # Extract affected plugins. + declare -a AFFECTED_PLUGINS=() + for FILE in $CHANGED_FILES; do + if [[ "$FILE" == plugins/* ]]; then + PLUGIN_NAME=$(echo "$FILE" | cut -d'/' -f2) + if [[ ! " ${AFFECTED_PLUGINS[@]} " =~ " ${PLUGIN_NAME} " ]]; then + AFFECTED_PLUGINS+=("$PLUGIN_NAME") + fi + fi + done + + + fi # Output the list of plugins to test. echo "plugins=${AFFECTED_PLUGINS[*]}" >> $GITHUB_OUTPUT From 76a48cfa4be9411c64171a42aa319dcadebfd7c6 Mon Sep 17 00:00:00 2001 From: Shyamsundar Gadde Date: Thu, 23 Jan 2025 16:35:58 +0530 Subject: [PATCH 05/23] Trigger tests for dependent plugins on changes to OD Signed-off-by: Shyamsundar Gadde --- .github/workflows/php-test-plugins.yml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/.github/workflows/php-test-plugins.yml b/.github/workflows/php-test-plugins.yml index 4ce5a27c13..50e22aa0af 100644 --- a/.github/workflows/php-test-plugins.yml +++ b/.github/workflows/php-test-plugins.yml @@ -92,7 +92,7 @@ jobs: AFFECTED_PLUGINS=($(ls plugins)) echo "Global changes detected; testing all plugins: ${AFFECTED_PLUGINS[*]}" else - # Extract affected plugins. + # Extract affected plugins and their dependencies. declare -a AFFECTED_PLUGINS=() for FILE in $CHANGED_FILES; do if [[ "$FILE" == plugins/* ]]; then @@ -103,7 +103,22 @@ jobs: fi done + # Define plugin dependencies (e.g., optimization-detective triggers others). + declare -A PLUGIN_DEPENDENCIES=( + ["optimization-detective"]="embed-optimizer image-prioritizer" + ) + # Add dependent plugins to the list. + for PLUGIN in "${AFFECTED_PLUGINS[@]}"; do + if [[ -n "${PLUGIN_DEPENDENCIES[$PLUGIN]}" ]]; then + DEPENDENCIES=(${PLUGIN_DEPENDENCIES[$PLUGIN]}) + for DEP in "${DEPENDENCIES[@]}"; do + if [[ ! " ${AFFECTED_PLUGINS[@]} " =~ " ${DEP} " ]]; then + AFFECTED_PLUGINS+=("$DEP") + fi + done + fi + done fi # Output the list of plugins to test. From d098b384fe1e56756dac6bd82c1f020302e479d7 Mon Sep 17 00:00:00 2001 From: Shyamsundar Gadde Date: Thu, 23 Jan 2025 16:53:47 +0530 Subject: [PATCH 06/23] Check for duplicates in the plugins array for good measure Signed-off-by: Shyamsundar Gadde --- .github/workflows/php-test-plugins.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/php-test-plugins.yml b/.github/workflows/php-test-plugins.yml index 50e22aa0af..5ea6a546c7 100644 --- a/.github/workflows/php-test-plugins.yml +++ b/.github/workflows/php-test-plugins.yml @@ -119,6 +119,10 @@ jobs: done fi done + + # Remove duplicate entries. + AFFECTED_PLUGINS=($(echo "${AFFECTED_PLUGINS[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ')) + echo "Plugins with changes: ${AFFECTED_PLUGINS[*]}" fi # Output the list of plugins to test. From 020cce311fbd33858e95ee13317bd6baaa6e6074 Mon Sep 17 00:00:00 2001 From: Shyamsundar Gadde Date: Thu, 23 Jan 2025 17:07:33 +0530 Subject: [PATCH 07/23] Fix Git diff listing files not changed by PR Signed-off-by: Shyamsundar Gadde --- .github/workflows/php-test-plugins.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/php-test-plugins.yml b/.github/workflows/php-test-plugins.yml index 5ea6a546c7..3ece762f84 100644 --- a/.github/workflows/php-test-plugins.yml +++ b/.github/workflows/php-test-plugins.yml @@ -70,11 +70,8 @@ jobs: exit 0 fi - # For pull_request events, determine changes. - BASE_SHA=${{ github.event.pull_request.base.sha }} - HEAD_SHA=${{ github.sha }} - - CHANGED_FILES=$(git diff --name-only $BASE_SHA $HEAD_SHA) + # Get PR-specific changes using merge-base diff. + CHANGED_FILES=$(git diff --name-only HEAD^1...HEAD^2) # In this context, `HEAD^1` is the base branch and `HEAD^2` is the PR branch. echo "Changed files:" echo "$CHANGED_FILES" From eb4dad06c904e89e8152b81f6aa4740fa1be5af5 Mon Sep 17 00:00:00 2001 From: Shyamsundar Gadde Date: Thu, 23 Jan 2025 17:08:23 +0530 Subject: [PATCH 08/23] Fix error with merge base resolution Signed-off-by: Shyamsundar Gadde --- .github/workflows/php-test-plugins.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/php-test-plugins.yml b/.github/workflows/php-test-plugins.yml index 3ece762f84..e719c037c7 100644 --- a/.github/workflows/php-test-plugins.yml +++ b/.github/workflows/php-test-plugins.yml @@ -57,6 +57,8 @@ jobs: steps: - uses: styfle/cancel-workflow-action@0.12.1 - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Required for accurate merge-base resolution. - name: Determine affected plugins id: affected-plugins env: From bea1bc090b332dace4dd52bd5c0ea91f62e7c55a Mon Sep 17 00:00:00 2001 From: Shyamsundar Gadde Date: Thu, 30 Jan 2025 22:55:46 +0530 Subject: [PATCH 09/23] Use tj-actions/changed-files for determining changed files Signed-off-by: Shyamsundar Gadde --- .github/workflows/php-test-plugins.yml | 56 +++++++++++++------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/.github/workflows/php-test-plugins.yml b/.github/workflows/php-test-plugins.yml index e719c037c7..31bdfe0550 100644 --- a/.github/workflows/php-test-plugins.yml +++ b/.github/workflows/php-test-plugins.yml @@ -57,29 +57,29 @@ jobs: steps: - uses: styfle/cancel-workflow-action@0.12.1 - uses: actions/checkout@v4 - with: - fetch-depth: 0 # Required for accurate merge-base resolution. - - name: Determine affected plugins - id: affected-plugins + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v45 + - name: Get changed plugins + id: changed-plugins env: GITHUB_EVENT_NAME: ${{ github.event_name }} run: | # For push to 'trunk' or 'release/**' events, test all plugins regardless of changes. if [ "$GITHUB_EVENT_NAME" = "push" ]; then - AFFECTED_PLUGINS=($(ls plugins)) - echo "Event: $GITHUB_EVENT_NAME - Running tests for all plugins. Affected plugins: ${AFFECTED_PLUGINS[*]}" - echo "plugins=${AFFECTED_PLUGINS[*]}" >> $GITHUB_OUTPUT + ALL_CHANGED_PLUGINS=($(ls plugins)) + echo "Event: $GITHUB_EVENT_NAME - Running tests for all plugins. Affected plugins: ${ALL_CHANGED_PLUGINS[*]}" + echo "all_changed_plugins=${ALL_CHANGED_PLUGINS[*]}" >> $GITHUB_OUTPUT exit 0 fi - # Get PR-specific changes using merge-base diff. - CHANGED_FILES=$(git diff --name-only HEAD^1...HEAD^2) # In this context, `HEAD^1` is the base branch and `HEAD^2` is the PR branch. - echo "Changed files:" - echo "$CHANGED_FILES" + ALL_CHANGED_FILES=${{ steps.changed-files.outputs.all_changed_files }} + echo "All Changed files:" + echo "$ALL_CHANGED_FILES" # Check for global changes (any file outside plugins/). GLOBAL_CHANGES=false - for FILE in $CHANGED_FILES; do + for FILE in $ALL_CHANGED_FILES; do if [[ "$FILE" != plugins/* ]]; then GLOBAL_CHANGES=true break @@ -88,16 +88,16 @@ jobs: if [ "$GLOBAL_CHANGES" = true ]; then # Test all plugins if global changes detected. - AFFECTED_PLUGINS=($(ls plugins)) - echo "Global changes detected; testing all plugins: ${AFFECTED_PLUGINS[*]}" + ALL_CHANGED_PLUGINS=($(ls plugins)) + echo "Global changes detected; testing all plugins: ${ALL_CHANGED_PLUGINS[*]}" else # Extract affected plugins and their dependencies. - declare -a AFFECTED_PLUGINS=() - for FILE in $CHANGED_FILES; do + declare -a ALL_CHANGED_PLUGINS=() + for FILE in $ALL_CHANGED_FILES; do if [[ "$FILE" == plugins/* ]]; then PLUGIN_NAME=$(echo "$FILE" | cut -d'/' -f2) - if [[ ! " ${AFFECTED_PLUGINS[@]} " =~ " ${PLUGIN_NAME} " ]]; then - AFFECTED_PLUGINS+=("$PLUGIN_NAME") + if [[ ! " ${ALL_CHANGED_PLUGINS[@]} " =~ " ${PLUGIN_NAME} " ]]; then + ALL_CHANGED_PLUGINS+=("$PLUGIN_NAME") fi fi done @@ -108,24 +108,24 @@ jobs: ) # Add dependent plugins to the list. - for PLUGIN in "${AFFECTED_PLUGINS[@]}"; do + for PLUGIN in "${ALL_CHANGED_PLUGINS[@]}"; do if [[ -n "${PLUGIN_DEPENDENCIES[$PLUGIN]}" ]]; then DEPENDENCIES=(${PLUGIN_DEPENDENCIES[$PLUGIN]}) for DEP in "${DEPENDENCIES[@]}"; do - if [[ ! " ${AFFECTED_PLUGINS[@]} " =~ " ${DEP} " ]]; then - AFFECTED_PLUGINS+=("$DEP") + if [[ ! " ${ALL_CHANGED_PLUGINS[@]} " =~ " ${DEP} " ]]; then + ALL_CHANGED_PLUGINS+=("$DEP") fi done fi done # Remove duplicate entries. - AFFECTED_PLUGINS=($(echo "${AFFECTED_PLUGINS[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ')) - echo "Plugins with changes: ${AFFECTED_PLUGINS[*]}" + ALL_CHANGED_PLUGINS=($(echo "${ALL_CHANGED_PLUGINS[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ')) + echo "Plugins with changes: ${ALL_CHANGED_PLUGINS[*]}" fi # Output the list of plugins to test. - echo "plugins=${AFFECTED_PLUGINS[*]}" >> $GITHUB_OUTPUT + echo "all_changed_plugins=${ALL_CHANGED_PLUGINS[*]}" >> $GITHUB_OUTPUT - name: Setup Node.js (.nvmrc) uses: actions/setup-node@v4 with: @@ -157,22 +157,22 @@ jobs: - name: Running single site unit tests run: | if [ "${{ matrix.coverage }}" == "true" ]; then - for PLUGIN in ${{ steps.affected-plugins.outputs.plugins }}; do + 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 - for PLUGIN in ${{ steps.affected-plugins.outputs.plugins }}; do + 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 - for PLUGIN in ${{ steps.affected-plugins.outputs.plugins }}; do + 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 - for PLUGIN in ${{ steps.affected-plugins.outputs.plugins }}; do + for PLUGIN in ${{ steps.changed-plugins.outputs.all_changed_plugins }}; do npm run test-php-multisite:$PLUGIN done fi From 3c66be3b216b449f04cbadc102f9f8d2346f8dbc Mon Sep 17 00:00:00 2001 From: Shyamsundar Gadde Date: Fri, 31 Jan 2025 01:18:50 +0530 Subject: [PATCH 10/23] Refactor logic to determine changes to config files Signed-off-by: Shyamsundar Gadde --- .github/workflows/php-test-plugins.yml | 86 ++++++++++++-------------- 1 file changed, 39 insertions(+), 47 deletions(-) diff --git a/.github/workflows/php-test-plugins.yml b/.github/workflows/php-test-plugins.yml index 31bdfe0550..a3ea99ccfa 100644 --- a/.github/workflows/php-test-plugins.yml +++ b/.github/workflows/php-test-plugins.yml @@ -60,71 +60,63 @@ jobs: - name: Get changed files id: changed-files uses: tj-actions/changed-files@v45 + with: + 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' - name: Get changed plugins id: changed-plugins - env: - GITHUB_EVENT_NAME: ${{ github.event_name }} run: | - # For push to 'trunk' or 'release/**' events, test all plugins regardless of changes. - if [ "$GITHUB_EVENT_NAME" = "push" ]; then + if [[ "${{ github.event_name }}" == "push" || "${{ steps.changed-files.outputs.config_any_changed }}" == "true" ]]; then ALL_CHANGED_PLUGINS=($(ls plugins)) - echo "Event: $GITHUB_EVENT_NAME - Running tests for all plugins. Affected plugins: ${ALL_CHANGED_PLUGINS[*]}" echo "all_changed_plugins=${ALL_CHANGED_PLUGINS[*]}" >> $GITHUB_OUTPUT exit 0 fi - ALL_CHANGED_FILES=${{ steps.changed-files.outputs.all_changed_files }} + ALL_CHANGED_FILES="${{ steps.changed-files.outputs.plugins_all_changed_files }}" echo "All Changed files:" echo "$ALL_CHANGED_FILES" - # Check for global changes (any file outside plugins/). - GLOBAL_CHANGES=false + # Extract affected plugins. + declare -a ALL_CHANGED_PLUGINS=() for FILE in $ALL_CHANGED_FILES; do - if [[ "$FILE" != plugins/* ]]; then - GLOBAL_CHANGES=true - break + if [[ "$FILE" == plugins/* ]]; then + PLUGIN_NAME=$(echo "$FILE" | cut -d'/' -f2) + if [[ ! " ${ALL_CHANGED_PLUGINS[@]} " =~ " ${PLUGIN_NAME} " ]]; then + ALL_CHANGED_PLUGINS+=("$PLUGIN_NAME") + fi fi done - if [ "$GLOBAL_CHANGES" = true ]; then - # Test all plugins if global changes detected. - ALL_CHANGED_PLUGINS=($(ls plugins)) - echo "Global changes detected; testing all plugins: ${ALL_CHANGED_PLUGINS[*]}" - else - # Extract affected plugins and their dependencies. - declare -a ALL_CHANGED_PLUGINS=() - for FILE in $ALL_CHANGED_FILES; do - if [[ "$FILE" == plugins/* ]]; then - PLUGIN_NAME=$(echo "$FILE" | cut -d'/' -f2) - if [[ ! " ${ALL_CHANGED_PLUGINS[@]} " =~ " ${PLUGIN_NAME} " ]]; then - ALL_CHANGED_PLUGINS+=("$PLUGIN_NAME") - fi - fi - done - - # Define plugin dependencies (e.g., optimization-detective triggers others). - declare -A PLUGIN_DEPENDENCIES=( - ["optimization-detective"]="embed-optimizer image-prioritizer" - ) + # Define plugin dependencies (e.g., optimization-detective triggers others). + declare -A PLUGIN_DEPENDENCIES=( + ["optimization-detective"]="embed-optimizer image-prioritizer" + ) - # Add dependent plugins to the list. - for PLUGIN in "${ALL_CHANGED_PLUGINS[@]}"; do - if [[ -n "${PLUGIN_DEPENDENCIES[$PLUGIN]}" ]]; then - DEPENDENCIES=(${PLUGIN_DEPENDENCIES[$PLUGIN]}) - for DEP in "${DEPENDENCIES[@]}"; do - if [[ ! " ${ALL_CHANGED_PLUGINS[@]} " =~ " ${DEP} " ]]; then - ALL_CHANGED_PLUGINS+=("$DEP") - fi - done - fi - done + # Add dependent plugins to the list. + for PLUGIN in "${ALL_CHANGED_PLUGINS[@]}"; do + if [[ -n "${PLUGIN_DEPENDENCIES[$PLUGIN]}" ]]; then + DEPENDENCIES=(${PLUGIN_DEPENDENCIES[$PLUGIN]}) + for DEP in "${DEPENDENCIES[@]}"; do + if [[ ! " ${ALL_CHANGED_PLUGINS[@]} " =~ " ${DEP} " ]]; then + ALL_CHANGED_PLUGINS+=("$DEP") + fi + done + fi + done - # Remove duplicate entries. - ALL_CHANGED_PLUGINS=($(echo "${ALL_CHANGED_PLUGINS[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ')) - echo "Plugins with changes: ${ALL_CHANGED_PLUGINS[*]}" - fi + # Sort entries. + ALL_CHANGED_PLUGINS=($(echo "${ALL_CHANGED_PLUGINS[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ')) + echo "Plugins with changes: ${ALL_CHANGED_PLUGINS[*]}" - # Output the list of plugins to test. echo "all_changed_plugins=${ALL_CHANGED_PLUGINS[*]}" >> $GITHUB_OUTPUT - name: Setup Node.js (.nvmrc) uses: actions/setup-node@v4 From fd07a0c1f6e8a835c585fc0dd28b7f950ce2a31d Mon Sep 17 00:00:00 2001 From: Shyamsundar Gadde Date: Fri, 31 Jan 2025 02:43:33 +0530 Subject: [PATCH 11/23] Simplify changed plugins detection Signed-off-by: Shyamsundar Gadde --- .github/workflows/php-test-plugins.yml | 29 ++++++++++---------------- 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/.github/workflows/php-test-plugins.yml b/.github/workflows/php-test-plugins.yml index a3ea99ccfa..eda8d90914 100644 --- a/.github/workflows/php-test-plugins.yml +++ b/.github/workflows/php-test-plugins.yml @@ -61,6 +61,8 @@ jobs: 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/**' @@ -81,31 +83,22 @@ jobs: exit 0 fi - ALL_CHANGED_FILES="${{ steps.changed-files.outputs.plugins_all_changed_files }}" - echo "All Changed files:" - echo "$ALL_CHANGED_FILES" - - # Extract affected plugins. declare -a ALL_CHANGED_PLUGINS=() - for FILE in $ALL_CHANGED_FILES; do - if [[ "$FILE" == plugins/* ]]; then - PLUGIN_NAME=$(echo "$FILE" | cut -d'/' -f2) - if [[ ! " ${ALL_CHANGED_PLUGINS[@]} " =~ " ${PLUGIN_NAME} " ]]; then - ALL_CHANGED_PLUGINS+=("$PLUGIN_NAME") - fi - fi + for DIR in ${{ steps.changed-files.outputs.plugins_all_changed_files }}; do + PLUGIN_NAME=$(basename "$DIR") + ALL_CHANGED_PLUGINS+=("$PLUGIN_NAME") done - # Define plugin dependencies (e.g., optimization-detective triggers others). + # Print the list of changed plugins. + echo "Plugins with changes: ${ALL_CHANGED_PLUGINS[*]}" + + # Define and add plugin dependencies (e.g., optimization-detective triggers others). declare -A PLUGIN_DEPENDENCIES=( ["optimization-detective"]="embed-optimizer image-prioritizer" ) - - # Add dependent plugins to the list. for PLUGIN in "${ALL_CHANGED_PLUGINS[@]}"; do if [[ -n "${PLUGIN_DEPENDENCIES[$PLUGIN]}" ]]; then - DEPENDENCIES=(${PLUGIN_DEPENDENCIES[$PLUGIN]}) - for DEP in "${DEPENDENCIES[@]}"; do + for DEP in ${PLUGIN_DEPENDENCIES[$PLUGIN]}; do if [[ ! " ${ALL_CHANGED_PLUGINS[@]} " =~ " ${DEP} " ]]; then ALL_CHANGED_PLUGINS+=("$DEP") fi @@ -114,7 +107,7 @@ jobs: done # Sort entries. - ALL_CHANGED_PLUGINS=($(echo "${ALL_CHANGED_PLUGINS[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ')) + ALL_CHANGED_PLUGINS=($(echo "${ALL_CHANGED_PLUGINS[@]}" | tr ' ' '\n' | sort | tr '\n' ' ')) echo "Plugins with changes: ${ALL_CHANGED_PLUGINS[*]}" echo "all_changed_plugins=${ALL_CHANGED_PLUGINS[*]}" >> $GITHUB_OUTPUT From fa1a43304c968d8e41c463c915f14a71f8854bf4 Mon Sep 17 00:00:00 2001 From: Shyamsundar Gadde Date: Fri, 31 Jan 2025 02:52:56 +0530 Subject: [PATCH 12/23] Remove debug print statement Signed-off-by: Shyamsundar Gadde --- .github/workflows/php-test-plugins.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/php-test-plugins.yml b/.github/workflows/php-test-plugins.yml index eda8d90914..1996f37afd 100644 --- a/.github/workflows/php-test-plugins.yml +++ b/.github/workflows/php-test-plugins.yml @@ -89,9 +89,6 @@ jobs: ALL_CHANGED_PLUGINS+=("$PLUGIN_NAME") done - # Print the list of changed plugins. - echo "Plugins with changes: ${ALL_CHANGED_PLUGINS[*]}" - # Define and add plugin dependencies (e.g., optimization-detective triggers others). declare -A PLUGIN_DEPENDENCIES=( ["optimization-detective"]="embed-optimizer image-prioritizer" @@ -106,10 +103,7 @@ jobs: fi done - # Sort entries. ALL_CHANGED_PLUGINS=($(echo "${ALL_CHANGED_PLUGINS[@]}" | tr ' ' '\n' | sort | tr '\n' ' ')) - echo "Plugins with changes: ${ALL_CHANGED_PLUGINS[*]}" - echo "all_changed_plugins=${ALL_CHANGED_PLUGINS[*]}" >> $GITHUB_OUTPUT - name: Setup Node.js (.nvmrc) uses: actions/setup-node@v4 From 11949acd5566d33b9517cb192b54747fb3280e0b Mon Sep 17 00:00:00 2001 From: Shyamsundar Gadde Date: Mon, 3 Feb 2025 15:22:04 +0530 Subject: [PATCH 13/23] Fix array expansion to avoid SC2199 warning Signed-off-by: Shyamsundar Gadde --- .github/workflows/php-test-plugins.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/php-test-plugins.yml b/.github/workflows/php-test-plugins.yml index 1996f37afd..e08d342288 100644 --- a/.github/workflows/php-test-plugins.yml +++ b/.github/workflows/php-test-plugins.yml @@ -96,7 +96,7 @@ jobs: 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 + if [[ ! " ${ALL_CHANGED_PLUGINS[*]} " =~ " ${DEP} " ]]; then ALL_CHANGED_PLUGINS+=("$DEP") fi done From 1033ad78347d6cd4ca8e93d93fd8f775d7c72f86 Mon Sep 17 00:00:00 2001 From: Shyamsundar Gadde Date: Mon, 3 Feb 2025 15:26:24 +0530 Subject: [PATCH 14/23] Test all plugins on changes to PHPUnit bootstrap file Signed-off-by: Shyamsundar Gadde --- .github/workflows/php-test-plugins.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/php-test-plugins.yml b/.github/workflows/php-test-plugins.yml index e08d342288..5a0356958c 100644 --- a/.github/workflows/php-test-plugins.yml +++ b/.github/workflows/php-test-plugins.yml @@ -72,6 +72,7 @@ jobs: - '**/package.json' - 'package-lock.json' - 'phpunit.xml.dist' + - 'tools/phpunit/bootstrap.php' - 'composer.json' - 'composer.lock' - name: Get changed plugins From af6f8ff933a733bf9764514007a72356b3d5bb79 Mon Sep 17 00:00:00 2001 From: Shyamsundar Gadde Date: Mon, 3 Feb 2025 15:28:07 +0530 Subject: [PATCH 15/23] Add PHPUnit bootstrap file to list of paths to trigger this workflow Signed-off-by: Shyamsundar Gadde --- .github/workflows/php-test-plugins.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/php-test-plugins.yml b/.github/workflows/php-test-plugins.yml index 5a0356958c..d63ea7a6c8 100644 --- a/.github/workflows/php-test-plugins.yml +++ b/.github/workflows/php-test-plugins.yml @@ -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: From 90a5ab7cbe02620542714463561dc8781badc39b Mon Sep 17 00:00:00 2001 From: Shyamsundar Gadde Date: Tue, 4 Feb 2025 21:55:34 +0530 Subject: [PATCH 16/23] Rename PLUGIN_DEPENDENCIES to PLUGIN_DEPENDENTS for clarity Signed-off-by: Shyamsundar Gadde --- .github/workflows/php-test-plugins.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/php-test-plugins.yml b/.github/workflows/php-test-plugins.yml index d63ea7a6c8..5cdaba334f 100644 --- a/.github/workflows/php-test-plugins.yml +++ b/.github/workflows/php-test-plugins.yml @@ -92,13 +92,13 @@ jobs: ALL_CHANGED_PLUGINS+=("$PLUGIN_NAME") done - # Define and add plugin dependencies (e.g., optimization-detective triggers others). - declare -A PLUGIN_DEPENDENCIES=( + # 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_DEPENDENCIES[$PLUGIN]}" ]]; then - for DEP in ${PLUGIN_DEPENDENCIES[$PLUGIN]}; 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 @@ -175,4 +175,4 @@ jobs: directory: ./multisite-reports flags: multisite name: ${{ matrix.php }}-multisite-coverage - fail_ci_if_error: true + fail_ci_if_error: true \ No newline at end of file From 89172169fe60cd26fedd81f286bf1695e6b71568 Mon Sep 17 00:00:00 2001 From: Shyamsundar Gadde Date: Tue, 4 Feb 2025 22:01:13 +0530 Subject: [PATCH 17/23] Restore EOF EOL Signed-off-by: Shyamsundar Gadde --- .github/workflows/php-test-plugins.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/php-test-plugins.yml b/.github/workflows/php-test-plugins.yml index 5cdaba334f..15e2101dd9 100644 --- a/.github/workflows/php-test-plugins.yml +++ b/.github/workflows/php-test-plugins.yml @@ -175,4 +175,4 @@ jobs: directory: ./multisite-reports flags: multisite name: ${{ matrix.php }}-multisite-coverage - fail_ci_if_error: true \ No newline at end of file + fail_ci_if_error: true From 8713f45930ef563be482cfe5c26b3bd84869e32f Mon Sep 17 00:00:00 2001 From: Shyamsundar Gadde Date: Wed, 5 Feb 2025 20:47:46 +0530 Subject: [PATCH 18/23] Remove deprecated Codecov configuration Ref: https://docs.codecov.com/docs/commit-status#base Signed-off-by: Shyamsundar Gadde --- codecov.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/codecov.yml b/codecov.yml index 94ce322661..f91d56544a 100644 --- a/codecov.yml +++ b/codecov.yml @@ -7,7 +7,6 @@ coverage: default: target: auto threshold: 80% - base: auto informational: true patch: default: From 7aff9b20bb068339ec762e7027c78a050488f4bb Mon Sep 17 00:00:00 2001 From: Shyamsundar Gadde Date: Thu, 6 Feb 2025 19:12:00 +0530 Subject: [PATCH 19/23] Revert "Remove deprecated Codecov configuration" This reverts commit 8713f45930ef563be482cfe5c26b3bd84869e32f. --- codecov.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/codecov.yml b/codecov.yml index f91d56544a..94ce322661 100644 --- a/codecov.yml +++ b/codecov.yml @@ -7,6 +7,7 @@ coverage: default: target: auto threshold: 80% + base: auto informational: true patch: default: From 0be7a66d9d0925b11ae103fa3bfd2e4326a501c5 Mon Sep 17 00:00:00 2001 From: Shyamsundar Gadde Date: Mon, 10 Feb 2025 14:52:04 +0530 Subject: [PATCH 20/23] Show only patch coverage in PR comment Signed-off-by: Shyamsundar Gadde --- codecov.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/codecov.yml b/codecov.yml index 94ce322661..2c6366b3e5 100644 --- a/codecov.yml +++ b/codecov.yml @@ -13,3 +13,5 @@ coverage: default: threshold: 80% informational: true +comment: + hide_project_coverage: TRUE From 6b340200605062093680681339d10c3a777e2693 Mon Sep 17 00:00:00 2001 From: Shyamsundar Gadde Date: Mon, 10 Feb 2025 14:55:24 +0530 Subject: [PATCH 21/23] Limit Project coverage status checks to only the trunk Signed-off-by: Shyamsundar Gadde --- codecov.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/codecov.yml b/codecov.yml index 2c6366b3e5..9a29883ba6 100644 --- a/codecov.yml +++ b/codecov.yml @@ -8,6 +8,8 @@ coverage: target: auto threshold: 80% base: auto + branches: + - trunk informational: true patch: default: From e21ec9e7ab57adc3ef53d630f25b6ea84f011164 Mon Sep 17 00:00:00 2001 From: Shyamsundar Gadde Date: Mon, 10 Feb 2025 15:34:41 +0530 Subject: [PATCH 22/23] Use condensed variants of header, files and footer in the PR comment Signed-off-by: Shyamsundar Gadde --- codecov.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/codecov.yml b/codecov.yml index 9a29883ba6..052b2d6dda 100644 --- a/codecov.yml +++ b/codecov.yml @@ -17,3 +17,4 @@ coverage: informational: true comment: hide_project_coverage: TRUE + layout: "condensed_header, condensed_files, condensed_footer" From db41189e0ff19510206dcb3fecf7668fe689be41 Mon Sep 17 00:00:00 2001 From: Shyamsundar Gadde Date: Tue, 11 Feb 2025 05:26:20 +0530 Subject: [PATCH 23/23] Reduce patch coverage threshold to 20 percent Signed-off-by: Shyamsundar Gadde --- codecov.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codecov.yml b/codecov.yml index 052b2d6dda..0d658eba36 100644 --- a/codecov.yml +++ b/codecov.yml @@ -13,7 +13,7 @@ coverage: informational: true patch: default: - threshold: 80% + threshold: 20% informational: true comment: hide_project_coverage: TRUE