Apache Nutch is an extensible and scalable web crawler
NUTCH-3219 GitHub Actions JUnit workflow does not comment on pull requests from forks (#977)
Lewis John McGibbneya25edb066de9
diff --git a/.github/workflows/junit-report.yml b/.github/workflows/junit-report.ymlindex 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/"* ]]; thenPR_NUMBER="$EVENT_PR"+ PR_SOURCE="workflow_run"fiif [ -z "$PR_NUMBER" ]; thenPR_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"+ fifi- 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 0fi- 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 Reportdiff --git a/.github/workflows/master-build.yml b/.github/workflows/master-build.ymlindex 8d1df20c8..c4e53ffce 100644--- a/.github/workflows/master-build.yml+++ b/.github/workflows/master-build.yml@@ -322,6 +322,18 @@ jobs:elseecho "has_results=false" >> $GITHUB_OUTPUTfi+ # 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 Datauses: actions/upload-artifact@v7