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

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

commit 764112d92298a70dcb1c6ed9d9b8a034a4c66390
Author: Dimitris Soumis <[email protected]>
AuthorDate: Fri Oct 16 00:54:02 2026 +0300

    Add PR diff-coverage workflow (report-only)
---
 .github/scripts/select-tests.sh      | 56 ++++++++++++++++++++++++
 .github/scripts/select-tests.test.sh | 66 ++++++++++++++++++++++++++++
 .github/workflows/coverage.yml       | 85 ++++++++++++++++++++++++++++++++++++
 3 files changed, 207 insertions(+)

diff --git a/.github/scripts/select-tests.sh b/.github/scripts/select-tests.sh
new file mode 100755
index 0000000000..78691bd0a4
--- /dev/null
+++ b/.github/scripts/select-tests.sh
@@ -0,0 +1,56 @@
+#!/usr/bin/env bash
+
+# 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.
+
+# Reads changed file paths on stdin (one repo-relative path per line) and
+# prints a comma-separated Ant <fileset> includes value selecting the mirror
+# test package (test/<pkg>/Test*.java) of each changed java/ source file whose
+# mirror package exists and contains at least one Test*.java. Prints nothing
+# if none match.
+#
+# Usage: git diff --name-only --diff-filter=d <base>...HEAD | select-tests.sh
+set -euo pipefail
+
+repo_root="${SELECT_TESTS_ROOT:-$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && 
pwd)}"
+
+declare -A seen=()   # dedupe set, keyed by include pattern
+includes=()          # ordered list of include patterns to emit
+
+while IFS= read -r path; do
+  # Consider only source files under java/ ending in .java.
+  case "$path" in
+    java/*.java) ;;
+    *) continue ;;
+  esac
+
+  # Package dir: strip the leading java/ and the trailing /<Class>.java.
+  pkg="$(dirname "${path#java/}")"
+  [ "$pkg" = "." ] && continue
+
+  # Exact mirror package, non-recursive.
+  include="${pkg}/Test*.java"
+  [ -n "${seen[$include]:-}" ] && continue
+
+  # Only select it if the mirror package actually has a Test*.java.
+  if compgen -G "${repo_root}/test/${pkg}/Test*.java" > /dev/null; then
+    seen[$include]=1
+    includes+=("$include")
+  fi
+done
+
+if [ "${#includes[@]}" -gt 0 ]; then
+  printf '%s\n' "${includes[@]}" | sort | paste -sd, -
+fi
diff --git a/.github/scripts/select-tests.test.sh 
b/.github/scripts/select-tests.test.sh
new file mode 100644
index 0000000000..3dde33164c
--- /dev/null
+++ b/.github/scripts/select-tests.test.sh
@@ -0,0 +1,66 @@
+#!/usr/bin/env bash
+
+# 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
+
+script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+script="${script_dir}/select-tests.sh"
+
+fixture="$(mktemp -d)"
+trap 'rm -rf "$fixture"' EXIT
+
+mkdir -p "$fixture/test/org/apache/tomcat/util/http/parser"
+touch    "$fixture/test/org/apache/tomcat/util/http/parser/TestHttpParser.java"
+touch    "$fixture/test/org/apache/tomcat/util/http/parser/TestMediaType.java"
+
+run() { SELECT_TESTS_ROOT="$fixture" bash "$script"; }
+
+fail=0
+assert_eq() {
+  local desc="$1" expected="$2" actual="$3"
+  if [ "$expected" = "$actual" ]; then
+    echo "ok   - $desc"
+  else
+    echo "FAIL - $desc"; echo "       expected: [$expected]"; echo "       
actual:   [$actual]"; fail=1
+  fi
+}
+
+# 1. Source file with a mirror test package -> include for that package.
+out="$(printf '%s\n' 'java/org/apache/tomcat/util/http/parser/MediaType.java' 
| run)"
+assert_eq "maps source to mirror test package" \
+  "org/apache/tomcat/util/http/parser/Test*.java" "$out"
+
+# 2. Source file whose mirror package has no tests -> nothing.
+out="$(printf '%s\n' 'java/org/apache/catalina/Host.java' | run)"
+assert_eq "skips source with no mirror test package" "" "$out"
+
+# 3. Two source files in the same package -> deduped to one include.
+out="$(printf '%s\n' \
+  'java/org/apache/tomcat/util/http/parser/MediaType.java' \
+  'java/org/apache/tomcat/util/http/parser/HttpParser.java' | run)"
+assert_eq "dedupes same package" \
+  "org/apache/tomcat/util/http/parser/Test*.java" "$out"
+
+# 4. Non-source paths are ignored.
+out="$(printf '%s\n' 'build.xml' 'test/foo/TestBar.java' 'README.md' | run)"
+assert_eq "ignores non-java-source paths" "" "$out"
+
+# 5. Empty input -> empty output.
+out="$(printf '' | run)"
+assert_eq "empty input yields empty output" "" "$out"
+
+exit "$fail"
diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml
new file mode 100644
index 0000000000..be532fcf22
--- /dev/null
+++ b/.github/workflows/coverage.yml
@@ -0,0 +1,85 @@
+#    Licensed 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: Diff Coverage
+
+on:
+  pull_request:
+    branches:
+      - main
+
+permissions:
+  contents: read
+
+env:
+  LC_ALL: en_US.UTF-8
+
+jobs:
+  diff-coverage:
+    name: targeted tests
+    runs-on: ubuntu-latest
+    steps:
+      - name: Git Checkout
+        uses: actions/checkout@v7
+        with:
+          fetch-depth: 0
+
+      - name: Set up Java
+        uses: actions/setup-java@v6
+        with:
+          java-version: 21
+          distribution: zulu
+
+      - name: Set up Python
+        uses: actions/setup-python@v5
+        with:
+          python-version: '3.x'
+
+      - name: Install diff-cover
+        run: pip install diff-cover
+
+      - name: Determine base ref
+        id: base
+        run: echo "ref=origin/${{ github.event.pull_request.base.ref }}" >> 
"$GITHUB_OUTPUT"
+
+      - name: Select targeted tests
+        id: select
+        run: |
+          includes="$(git diff --name-only --diff-filter=d "${{ 
steps.base.outputs.ref }}"...HEAD \
+            | bash .github/scripts/select-tests.sh)"
+          echo "includes=$includes" >> "$GITHUB_OUTPUT"
+          if [ -z "$includes" ]; then
+            echo "No targeted tests for the changed files; skipping coverage." 
>> "$GITHUB_STEP_SUMMARY"
+          else
+            echo "Targeted tests: \`$includes\`" >> "$GITHUB_STEP_SUMMARY"
+          fi
+
+      - name: Run targeted tests with coverage
+        if: steps.select.outputs.includes != ''
+        run: |
+          ant -noinput deploy test-nio coverage-report \
+            -Dtest.coverage=true \
+            -Dtest.name="${{ steps.select.outputs.includes }}"
+        env:
+          ANT_OPTS: -Dtest.openssl.exists=false -Dtest.excludePerformance=true
+
+      - name: Report diff coverage
+        if: steps.select.outputs.includes != ''
+        run: |
+          diff-cover output/coverage/jacoco.xml \
+            --compare-branch "${{ steps.base.outputs.ref }}" \
+            --src-roots java \
+            --format markdown:diff-cover.md
+          {
+            echo '## Diff coverage (targeted tests)'
+            cat diff-cover.md
+          } >> "$GITHUB_STEP_SUMMARY"


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to