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

lewismc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nutch.git


The following commit(s) were added to refs/heads/master by this push:
     new a25edb066 NUTCH-3219 GitHub Actions JUnit workflow does not comment on 
pull requests from forks (#977)
a25edb066 is described below

commit a25edb066de95a7f5cc990e2cd5b68a35ce5d521
Author: Lewis John McGibbney <[email protected]>
AuthorDate: Tue Oct 13 17:35:05 2026 -0700

    NUTCH-3219 GitHub Actions JUnit workflow does not comment on pull requests 
from forks (#977)
---
 .github/workflows/junit-report.yml | 43 ++++++++++++++++++++++++++++++++------
 .github/workflows/master-build.yml | 15 +++++++++++++
 2 files changed, 52 insertions(+), 6 deletions(-)

diff --git a/.github/workflows/junit-report.yml 
b/.github/workflows/junit-report.yml
index bd3da3be6..316f58d1d 100644
--- a/.github/workflows/junit-report.yml
+++ b/.github/workflows/junit-report.yml
@@ -82,24 +82,55 @@ jobs:
           EVENT_PR="${{ github.event.workflow_run.pull_requests[0].number }}"
           EVENT_PR_URL="${{ github.event.workflow_run.pull_requests[0].url }}"
           PR_NUMBER=""
+          PR_SOURCE=""
 
-          if [ -n "$EVENT_PR" ] && [ -n "$EVENT_PR_URL" ] && [[ 
"$EVENT_PR_URL" == *"/repos/${REPO}/pulls/"* ]]; then
+          # The producer records this during pull_request. It is required for
+          # fork PRs, where the workflow_run event and base-repo commit lookup
+          # do not contain the PR number.
+          if [ -f ./junit-ubuntu-jdk17/junit-pr-number ]; then
+            CANDIDATE=$(tr -d '[:space:]' < 
./junit-ubuntu-jdk17/junit-pr-number)
+            if [[ "$CANDIDATE" =~ ^[0-9]+$ ]]; then
+              PR_NUMBER="$CANDIDATE"
+              PR_SOURCE="artifact"
+            else
+              echo "::notice::Ignoring non-numeric PR metadata from artifact: 
${CANDIDATE}"
+            fi
+          fi
+
+          if [ -z "$PR_NUMBER" ] && [ -n "$EVENT_PR" ] && [ -n "$EVENT_PR_URL" 
] && [[ "$EVENT_PR_URL" == *"/repos/${REPO}/pulls/"* ]]; then
             PR_NUMBER="$EVENT_PR"
+            PR_SOURCE="workflow_run"
           fi
 
           if [ -z "$PR_NUMBER" ]; then
             PR_NUMBER=$(gh api \
               "repos/${REPO}/commits/${HEAD_SHA}/pulls" \
               --jq "[.[] | select(.base.repo.full_name == \"${REPO}\")] | 
first | .number // empty")
+            if [ -n "$PR_NUMBER" ]; then
+              PR_SOURCE="commit"
+            fi
           fi
 
-          echo "number=${PR_NUMBER:-}" >> "$GITHUB_OUTPUT"
-          if [ -n "${PR_NUMBER:-}" ]; then
-            echo "has_pr=true" >> "$GITHUB_OUTPUT"
-          else
+          if [ -z "$PR_NUMBER" ]; then
+            echo "::notice::No PR number found in artifact, workflow_run 
payload, or commit association. Publishing the check without a PR comment."
+            echo "number=" >> "$GITHUB_OUTPUT"
             echo "has_pr=false" >> "$GITHUB_OUTPUT"
+            exit 0
           fi
-          echo "Resolved PR number='${PR_NUMBER:-}' 
has_pr='${PR_NUMBER:+true}' repo='${REPO}' sha='${HEAD_SHA}'"
+
+          PR_JSON=$(gh api "repos/${REPO}/pulls/${PR_NUMBER}")
+          PR_BASE=$(jq -r '.base.repo.full_name // empty' <<< "$PR_JSON")
+          PR_HEAD=$(jq -r '.head.sha // empty' <<< "$PR_JSON")
+          if [ "$PR_BASE" != "$REPO" ] || [ "$PR_HEAD" != "$HEAD_SHA" ]; then
+            echo "::notice::PR ${PR_NUMBER} from ${PR_SOURCE} failed 
validation (base='${PR_BASE}' head='${PR_HEAD}'). Publishing the check without 
a PR comment."
+            echo "number=" >> "$GITHUB_OUTPUT"
+            echo "has_pr=false" >> "$GITHUB_OUTPUT"
+            exit 0
+          fi
+
+          echo "number=${PR_NUMBER}" >> "$GITHUB_OUTPUT"
+          echo "has_pr=true" >> "$GITHUB_OUTPUT"
+          echo "Resolved PR number='${PR_NUMBER}' source='${PR_SOURCE}' 
has_pr='true' repo='${REPO}' sha='${HEAD_SHA}'"
         env:
           GH_TOKEN: ${{ github.token }}
       - name: Publish Test Report
diff --git a/.github/workflows/master-build.yml 
b/.github/workflows/master-build.yml
index 8d1df20c8..c4e53ffce 100644
--- a/.github/workflows/master-build.yml
+++ b/.github/workflows/master-build.yml
@@ -322,6 +322,18 @@ jobs:
           else
             echo "has_results=false" >> $GITHUB_OUTPUT
           fi
+      # workflow_run.pull_requests is empty for fork PRs, and the base-repo
+      # commit lookup cannot see a fork commit. Record the trusted pull_request
+      # number so junit-report.yml can validate and post the sticky comment.
+      - name: Record PR number for JUnit comment
+        if: >-
+          always() && github.event_name == 'pull_request'
+          && matrix.os == 'ubuntu-24.04' && matrix.java == '17'
+          && steps.ran.outputs.value == 'true'
+          && steps.check_tests.outputs.has_results == 'true'
+        run: |
+          mkdir -p build
+          printf '%s\n' "${{ github.event.pull_request.number }}" > 
build/junit-pr-number
       # Scenario 1: Approved deprecations are allowlisted and do not fail the 
build.
       # Scenario 2: Any other deprecation in the Nutch codebase fails the 
build.
       - name: Check for deprecation warnings
@@ -381,6 +393,9 @@ jobs:
           path: |
             ./build/test/TEST-*.xml
             ./build/**/test/TEST-*.xml
+            # Optional: present only for pull_request runs. A wildcard keeps
+            # push uploads working when the file was not recorded.
+            ./build/junit-pr-number*
           retention-days: 1
       - name: Upload Coverage Data
         uses: actions/upload-artifact@v7

Reply via email to