Skip to content

Commit 5fb51ef

Browse files
committed
Fix extraction of PR number
Now the PR number is written by `quality-monitor-build.yml` and attached as an artifact. This artifact is then read by `quality-monitor-comment-pr.yml`. So the PR number is always available and the delta computation works.
1 parent 5120568 commit 5fb51ef

3 files changed

Lines changed: 28 additions & 23 deletions

File tree

.github/scripts/fetch-artifacts.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ set -euo pipefail
99
# ARTIFACT_NAMES: comma-separated list of artifact names (in the same order as WORKFLOWS)
1010
# Optional:
1111
# RETRIES: number of polling attempts per workflow (default: 30)
12-
# SLEEP_SEC: seconds to wait between attempts (default: 10)
12+
# SLEEP_SEC: seconds to wait between attempts (default: 30)
1313
# ALLOWED_EVENTS: comma-separated list of workflow run events to consider (default: pull_request,pull_request_target)
1414

1515
IFS=',' read -r -a WORKFLOWS_ARR <<< "${OTHER_WORKFLOWS}"
@@ -19,7 +19,7 @@ SHA="${HEAD_SHA}"
1919
TOKEN="${TOKEN}"
2020
API_BASE="https://api.github.com/repos/${REPO}"
2121
RETRIES=${RETRIES:-30}
22-
SLEEP_SEC=${SLEEP_SEC:-10}
22+
SLEEP_SEC=${SLEEP_SEC:-30}
2323
ALLOWED_EVENTS=${ALLOWED_EVENTS:-pull_request,pull_request_target}
2424

2525
mkdir -p artifacts

.github/workflows/quality-monitor-build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,14 @@ jobs:
4444
exit 1;
4545
fi
4646
mv -fv maven.log target/maven.log
47+
- name: Write PR number
48+
run: echo '${{ github.event.pull_request.number }}' > pr-number.txt
4749
- name: Upload Quality Reports
4850
uses: actions/upload-artifact@v7
4951
with:
5052
name: quality-reports
5153
path: |
54+
pr-number.txt
5255
**/target/**/*.json
5356
**/target/**/*.xml
5457
**/target/**/*.log

.github/workflows/quality-monitor-comment-pr.yml

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,13 @@ permissions:
1313

1414
jobs:
1515
comment:
16-
if: ${{ github.event.workflow_run.event == 'pull_request' }}
16+
if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }}
1717
runs-on: ubuntu-latest
1818
name: Comment on PR
1919

2020
steps:
21-
- name: Extract PR number and SHA
22-
id: pr
23-
run: |
24-
pr_number='${{ github.event.workflow_run.pull_requests[0].number }}'
25-
echo "number=$pr_number" >> "$GITHUB_OUTPUT"
26-
sha='${{ github.event.workflow_run.head_sha }}'
27-
echo "sha=$sha" >> "$GITHUB_OUTPUT"
2821
- name: Checkout PR
2922
uses: actions/checkout@v6
30-
with:
31-
ref: ${{ steps.pr.outputs.sha }}
32-
- name: Install jq and unzip
33-
run: sudo apt-get update && sudo apt-get install -y jq unzip
34-
- name: Prepare environment
35-
env:
36-
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
37-
REPO: ${{ github.repository }}
38-
TOKEN: ${{ secrets.GITHUB_TOKEN }}
39-
run: |
40-
echo "HEAD_SHA=$HEAD_SHA"
41-
echo "REPO=$REPO"
4223
- name: Fetch reports from dependency check and quality monitor workflows
4324
env:
4425
REPO: ${{ github.repository }}
@@ -56,6 +37,27 @@ jobs:
5637
mkdir -p reports/target
5738
mv artifacts/*/target/* reports/target
5839
ls -la reports/target/* || true
40+
mv artifacts/*/pr-number.txt reports/
41+
- name: Extract PR number and SHA
42+
id: pr
43+
run: |
44+
pr_number="$(cat reports/pr-number.txt | tr -d '\r\n' | xargs)"
45+
if [ -z "$pr_number" ] || [ "$pr_number" = "null" ]; then
46+
echo "No PR associated with this workflow run" >&2
47+
exit 1
48+
fi
49+
echo "PR number from reports/pr-number.txt: $pr_number"
50+
echo "number=$pr_number" >> "$GITHUB_OUTPUT"
51+
- name: Install jq and unzip
52+
run: sudo apt-get update && sudo apt-get install -y jq unzip
53+
- name: Prepare environment
54+
env:
55+
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
56+
REPO: ${{ github.repository }}
57+
TOKEN: ${{ secrets.GITHUB_TOKEN }}
58+
run: |
59+
echo "HEAD_SHA=$HEAD_SHA"
60+
echo "REPO=$REPO"
5961
- name: Read Quality Monitor Configuration
6062
id: quality-monitor
6163
run: echo "json=$(jq -c . .github/quality-monitor-pr.json)" >> "$GITHUB_OUTPUT"
@@ -65,7 +67,7 @@ jobs:
6567
- name: Run Quality Monitor and Comment on PR
6668
uses: uhafner/quality-monitor@v4
6769
with:
68-
sha: ${{ steps.pr.outputs.sha }}
70+
sha: ${{ github.event.workflow_run.head_sha }}
6971
config: ${{ steps.quality-monitor.outputs.json }}
7072
quality-gates: ${{ steps.quality-gates.outputs.json }}
7173
pr-number: ${{ steps.pr.outputs.number }}

0 commit comments

Comments
 (0)