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

pcongiusti 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 61a76e318e98 feat(ci): add a parent pom properties detector
61a76e318e98 is described below

commit 61a76e318e986a4073ec0b0eda2866ad90e4cf04
Author: Pasquale Congiusti <[email protected]>
AuthorDate: Fri Oct 31 11:58:13 2025 +0100

    feat(ci): add a parent pom properties detector
    
    The new script triggers a test for those modules using the dependency 
changed in the parent pom.
    This is very useful to enable automatically tests for dependabot upgrades.
    
    Closes CAMEL-20875
---
 .github/actions/detect-dependencies/action.yaml    | 35 ++++++++++
 .github/actions/detect-dependencies/detect-test.sh | 76 ++++++++++++++++++++++
 .github/workflows/pr-build-main.yml                |  8 ++-
 3 files changed, 117 insertions(+), 2 deletions(-)

diff --git a/.github/actions/detect-dependencies/action.yaml 
b/.github/actions/detect-dependencies/action.yaml
new file mode 100644
index 000000000000..52a142f8075a
--- /dev/null
+++ b/.github/actions/detect-dependencies/action.yaml
@@ -0,0 +1,35 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+name: "Parent pom dependencies detector"
+description: "Test only projects which have a dependency changed in the parent 
pom (typically dependabot)"
+inputs:
+  github-token:
+    description: 'The github token to access to the API'
+    required: false
+runs:
+  using: "composite"
+  steps:
+    - id: install-mvnd
+      uses: apache/camel/.github/actions/install-mvnd@main
+      with:
+        dry-run: ${{ inputs.skip-mvnd-install }}
+    - name: maven test
+      env:
+        GITHUB_TOKEN: ${{ inputs.github-token }}
+      shell: bash
+      run: ${{ github.action_path }}/detect-test.sh ${{ github.base_ref }} ${{ 
steps.install-mvnd.outputs.mvnd-dir }}/mvnd
diff --git a/.github/actions/detect-dependencies/detect-test.sh 
b/.github/actions/detect-dependencies/detect-test.sh
new file mode 100755
index 000000000000..46571037ac1c
--- /dev/null
+++ b/.github/actions/detect-dependencies/detect-test.sh
@@ -0,0 +1,76 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+set -euo pipefail
+
+detect_changed_properties() {
+  local base_branch="$1"
+
+  git diff "${base_branch}" -- parent/pom.xml | \
+    grep -E '^[+-]\s*<[^>]+>[^<]*</[^>]+>' | \
+    grep -vE '^\+\+\+|---' | \
+    grep -E 'version|dependency|artifact' | \
+    sed -E 's/^[+-]\s*<([^>]+)>.*/\1/' | \
+    sort -u
+}
+
+find_affected_modules() {
+  local property_name="$1"
+
+  local affected=()
+  while IFS= read -r pom; do
+    if grep -q "\${${property_name}}" "$pom"; then
+      affected+=("$(dirname "$pom")")
+    fi
+  done < <(find . -name "pom.xml")
+
+  affected_transformed=""
+
+  for dir in "${affected[@]}"; do
+      base=$(basename "$dir")
+      affected_transformed+=":$base,"
+  done
+
+  echo "$affected_transformed"
+}
+
+main() {
+  echo "Using MVND_OPTS=$MVND_OPTS"
+  local base_branch=${1}
+  local mavenBinary=${2}
+
+  git fetch origin $base_branch:$base_branch
+
+  changed_props=$(detect_changed_properties "$base_branch")
+
+  if [ -z "$changed_props" ]; then
+    echo "✅ No property changes detected."
+    exit 0
+  fi
+
+  modules_affected=""
+
+  while read -r prop; do
+    modules=$(find_affected_modules "$prop")
+    modules_affected+="$modules"
+  done <<< "$changed_props"
+
+  echo "🧪 Testing the following modules $modules_affected"
+  $mavenBinary $MVND_OPTS clean test -pl "$modules_affected" -amd
+}
+
+main "$@"
diff --git a/.github/workflows/pr-build-main.yml 
b/.github/workflows/pr-build-main.yml
index c0effe5c00f7..f4dc1b7c14cf 100644
--- a/.github/workflows/pr-build-main.yml
+++ b/.github/workflows/pr-build-main.yml
@@ -15,7 +15,7 @@
 # limitations under the License.
 #
 
-name: PR Build (Camel 4)
+name: Build and test
 
 on:
   pull_request:
@@ -29,7 +29,7 @@ on:
       - Jenkinsfile.*
       - NOTICE.txt
 
-permissions: 
+permissions:
   contents: read
 
 jobs:
@@ -81,3 +81,7 @@ jobs:
           github-token: ${{ secrets.GITHUB_TOKEN }}
           skip-mvnd-install: 'true'
           artifact-upload-suffix: java-${{ matrix.java }}
+      - name: mvn test parent pom dependencies changed
+        uses: ./.github/actions/detect-dependencies
+        with:
+          github-token: ${{ secrets.GITHUB_TOKEN }}

Reply via email to