Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

NUTCH-3085 Augment CI by adding code coverage and code quality reporting (#902)

Lewis John McGibbneyeed344510463
diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml
index 33af1af2e..92c609483 100644
--- a/.github/workflows/sonarcloud.yml
+++ b/.github/workflows/sonarcloud.yml
@@ -28,6 +28,11 @@ jobs:
repository: ${{ github.event.workflow_run.head_repository.full_name }}
ref: ${{ github.event.workflow_run.head_sha }}
fetch-depth: 0
+ - name: Fetch target branch for PR analysis
+ if: github.event.workflow_run.event == 'pull_request'
+ run: |
+ git remote add upstream https://github.com/${{ github.repository }}.git || true
+ git fetch upstream master:refs/remotes/upstream/master
- name: Set up JDK 17
uses: actions/setup-java@v5
with:
@@ -73,14 +78,28 @@ jobs:
echo "is_pr=false" >> "$GITHUB_OUTPUT"
exit 0
fi
- PR_NUMBER=$(gh api \
- "repos/${{ github.repository }}/commits/${{ github.event.workflow_run.head_sha }}/pulls" \
- --jq '.[0].number // empty')
- echo "number=${PR_NUMBER:-}" >> "$GITHUB_OUTPUT"
+
+ PR_NUMBER="${{ github.event.workflow_run.pull_requests[0].number }}"
+
+ if [ -z "$PR_NUMBER" ]; then
+ PR_NUMBER=$(gh api \
+ "repos/${{ github.repository }}/commits/${{ github.event.workflow_run.head_sha }}/pulls" \
+ --jq '.[0].number // empty')
+ fi
+
+ if [ -z "$PR_NUMBER" ]; then
+ PR_NUMBER=$(gh pr list --repo "${{ github.repository }}" --state open \
+ --json number,headRefOid \
+ --jq ".[] | select(.headRefOid == \"${{ github.event.workflow_run.head_sha }}\") | .number")
+ fi
+
if [ -n "$PR_NUMBER" ]; then
+ echo "number=${PR_NUMBER}" >> "$GITHUB_OUTPUT"
echo "is_pr=true" >> "$GITHUB_OUTPUT"
else
echo "is_pr=false" >> "$GITHUB_OUTPUT"
+ echo "skip=true" >> "$GITHUB_OUTPUT"
+ echo "⚠️ Could not resolve PR number for pull_request event. Skipping SonarCloud analysis."
fi
env:
GH_TOKEN: ${{ github.token }}
@@ -96,7 +115,7 @@ jobs:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: https://sonarcloud.io
- name: SonarCloud Scan (branch)
- if: steps.pr.outputs.is_pr == 'false'
+ if: steps.pr.outputs.is_pr == 'false' && steps.pr.outputs.skip != 'true'
uses: SonarSource/sonarqube-scan-action@v6
with:
args: >
diff --git a/README.md b/README.md
index 30fdc1d5a..fa6881604 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@ Apache Nutch README
===================
[![master pull request ci](https://github.com/apache/nutch/actions/workflows/master-build.yml/badge.svg)](https://github.com/apache/nutch/actions/workflows/master-build.yml)
-[![Quality gate](https://sonarcloud.io/api/project_badges/quality_gate?project=apache_nutch)](https://sonarcloud.io/summary/new_code?id=apache_nutch)
+[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=apache_nutch&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=apache_nutch)
<img src="https://nutch.apache.org/assets/img/nutch_logo_tm.png" align="right" width="300" />