This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 2f4e7f4d8827 Fix detect-dependencies CI action for parent/pom.xml 
changes
2f4e7f4d8827 is described below

commit 2f4e7f4d8827e5476371fe11be82211afd746193
Author: Guillaume Nodet <[email protected]>
AuthorDate: Tue Mar 24 13:12:52 2026 +0100

    Fix detect-dependencies CI action for parent/pom.xml changes
    
    - Replace git diff with GitHub API diff endpoint to work with shallow clones
      (fetch-depth=1). The three-dot git diff requires a merge base which is
      unavailable in shallow clones, causing the script to silently skip 
detection.
    - Replace base-ref input with pr-id and github-repo inputs, consistent with
      incremental-build action.
    - Use pr-id input instead of context.issue.number for comment posting, 
fixing
      workflow_dispatch triggers where context.issue.number is undefined.
    - Use install instead of test as the Maven goal, consistent with
      incremental-build.sh, to avoid jandex plugin failures in test-infra 
modules.
---
 .github/actions/detect-dependencies/action.yaml    | 13 +++--
 .github/actions/detect-dependencies/detect-test.sh | 65 +++++++++++++++++-----
 .github/workflows/pr-build-main.yml                |  3 +-
 3 files changed, 61 insertions(+), 20 deletions(-)

diff --git a/.github/actions/detect-dependencies/action.yaml 
b/.github/actions/detect-dependencies/action.yaml
index 92745a7c3514..285f90c8e6d7 100644
--- a/.github/actions/detect-dependencies/action.yaml
+++ b/.github/actions/detect-dependencies/action.yaml
@@ -21,10 +21,13 @@ inputs:
   github-token:
     description: 'The github token to access to the API'
     required: false
-  base-ref:
-    description: 'The base branch to compare against (defaults to 
github.base_ref)'
+  pr-id:
+    description: 'Id of the pull request'
+    required: true
+  github-repo:
+    description: 'The GitHub repository name (example, apache/camel)'
     required: false
-    default: ''
+    default: 'apache/camel'
   skip-mvnd-install:
     description: 'Skip mvnd installation (use if already installed)'
     required: false
@@ -40,7 +43,7 @@ runs:
       env:
         GITHUB_TOKEN: ${{ inputs.github-token }}
       shell: bash
-      run: ${{ github.action_path }}/detect-test.sh ${{ inputs.base-ref || 
github.base_ref }} ${{ steps.install-mvnd.outputs.mvnd-dir }}/mvnd
+      run: ${{ github.action_path }}/detect-test.sh ${{ 
steps.install-mvnd.outputs.mvnd-dir }}/mvnd ${{ inputs.pr-id }} ${{ 
inputs.github-repo }}
     - name: Post dependency change comment
       if: always()
       uses: actions/github-script@v8
@@ -53,7 +56,7 @@ runs:
           const body = fs.readFileSync(commentFile, 'utf8').trim();
           if (!body) return;
 
-          const prNumber = context.issue.number;
+          const prNumber = ${{ inputs.pr-id || 0 }};
           if (!prNumber) {
             core.warning('Could not determine PR number, skipping dependency 
comment');
             return;
diff --git a/.github/actions/detect-dependencies/detect-test.sh 
b/.github/actions/detect-dependencies/detect-test.sh
index 2e86c7b4cbba..2f55e1c2f918 100755
--- a/.github/actions/detect-dependencies/detect-test.sh
+++ b/.github/actions/detect-dependencies/detect-test.sh
@@ -20,25 +20,58 @@
 # find which modules depend on those artifacts (including transitive
 # dependencies) and runs their tests.
 #
+# Uses the GitHub API to fetch the PR diff (works with shallow clones).
+#
 # Approach:
-#   1. Diff parent/pom.xml to find changed property names
-#   2. Parse parent/pom.xml to map property -> groupId:artifactId
+#   1. Fetch PR diff via GitHub API, extract parent/pom.xml changes
+#   2. Find changed property names from the diff
+#   3. Parse parent/pom.xml to map property -> groupId:artifactId
 #      (detecting BOM imports vs regular dependencies)
-#   3. Use toolbox:tree-find to find all modules depending on those
+#   4. Use toolbox:tree-find to find all modules depending on those
 #      artifacts (direct + transitive)
-#   4. Run tests for affected modules
+#   5. Run tests for affected modules
 
 set -euo pipefail
 
 MAX_MODULES=50
 TOOLBOX_PLUGIN="eu.maveniverse.maven.plugins:toolbox"
 
-# Detect which properties changed in parent/pom.xml compared to the base 
branch.
+# Fetch the PR diff from the GitHub API and extract only the parent/pom.xml
+# portion. Returns the unified diff for parent/pom.xml, or empty if not 
changed.
+fetch_parent_pom_diff() {
+  local pr_id="$1"
+  local repository="$2"
+
+  local diff_output
+  diff_output=$(curl -s -w "\n%{http_code}" \
+    -H "Authorization: Bearer ${GITHUB_TOKEN}" \
+    -H "Accept: application/vnd.github.v3.diff" \
+    "https://api.github.com/repos/${repository}/pulls/${pr_id}";)
+
+  local http_code
+  http_code=$(echo "$diff_output" | tail -n 1)
+  local diff_body
+  diff_body=$(echo "$diff_output" | sed '$d')
+
+  if [[ "$http_code" -lt 200 || "$http_code" -ge 300 || -z "$diff_body" ]]; 
then
+    echo "WARNING: Failed to fetch PR diff (HTTP $http_code)" >&2
+    return
+  fi
+
+  # Extract only the parent/pom.xml diff section
+  echo "$diff_body" | awk '
+    /^diff --git/ && found { exit }
+    /^diff --git a\/parent\/pom.xml/ { found=1 }
+    found { print }
+  '
+}
+
+# Detect which properties changed in the parent/pom.xml diff.
 # Returns one property name per line.
 detect_changed_properties() {
-  local base_branch="$1"
+  local diff_content="$1"
 
-  git diff "${base_branch}"...HEAD -- parent/pom.xml | \
+  echo "$diff_content" | \
     grep -E '^[+-][[:space:]]*<[^>]+>[^<]*</[^>]+>' | \
     grep -vE '^\+\+\+|^---' | \
     sed -E 's/^[+-][[:space:]]*<([^>]+)>.*/\1/' | \
@@ -116,21 +149,24 @@ find_modules_with_toolbox() {
 
 main() {
   echo "Using MVND_OPTS=$MVND_OPTS"
-  local base_branch=${1}
-  local mavenBinary=${2}
+  local mavenBinary=${1}
+  local prId=${2}
+  local repository=${3}
   local log="detect-dependencies.log"
   local 
exclusionList="!:camel-allcomponents,!:dummy-component,!:camel-catalog,!:camel-catalog-console,!:camel-catalog-lucene,!:camel-catalog-maven,!:camel-catalog-suggest,!:camel-route-parser,!:camel-csimple-maven-plugin,!:camel-report-maven-plugin,!:camel-endpointdsl,!:camel-componentdsl,!:camel-endpointdsl-support,!:camel-yaml-dsl,!:camel-kamelet-main,!:camel-yaml-dsl-deserializers,!:camel-yaml-dsl-maven-plugin,!:camel-jbang-core,!:camel-jbang-main,!:camel-jbang-plugin-generate,!:came
 [...]
 
-  git fetch origin "$base_branch":"$base_branch" 2>/dev/null || true
+  # Fetch diff via GitHub API (works with shallow clones)
+  echo "Fetching PR #${prId} diff from GitHub API..."
+  local parent_diff
+  parent_diff=$(fetch_parent_pom_diff "$prId" "$repository")
 
-  # Check if parent/pom.xml was actually changed
-  if ! git diff --name-only "${base_branch}"...HEAD -- parent/pom.xml | grep 
-q .; then
+  if [ -z "$parent_diff" ]; then
     echo "parent/pom.xml not changed, nothing to do"
     exit 0
   fi
 
   local changed_props
-  changed_props=$(detect_changed_properties "$base_branch")
+  changed_props=$(detect_changed_properties "$parent_diff")
 
   if [ -z "$changed_props" ]; then
     echo "No property changes detected in parent/pom.xml"
@@ -292,7 +328,8 @@ main() {
   fi
 
   echo "Running targeted tests for affected modules..."
-  $mavenBinary -l $log $MVND_OPTS test -pl "${filtered_ids},${exclusionList}" 
-amd
+  # Use install instead of test, otherwise test-infra modules fail due to 
jandex maven plugin
+  $mavenBinary -l $log $MVND_OPTS install -pl 
"${filtered_ids},${exclusionList}" -amd
   local ret=$?
 
   if [ ${ret} -eq 0 ]; then
diff --git a/.github/workflows/pr-build-main.yml 
b/.github/workflows/pr-build-main.yml
index b66a526ebba4..fe32bbacbf7a 100644
--- a/.github/workflows/pr-build-main.yml
+++ b/.github/workflows/pr-build-main.yml
@@ -147,5 +147,6 @@ jobs:
         uses: ./.github/actions/detect-dependencies
         with:
           github-token: ${{ secrets.GITHUB_TOKEN }}
-          base-ref: ${{ github.base_ref || 'main' }}
+          pr-id: ${{ github.event.number || inputs.pr_number }}
+          github-repo: ${{ github.repository }}
           skip-mvnd-install: 'true'

Reply via email to