Skip to content

Commit c84c723

Browse files
committed
Fix trigger of quality monitor
1 parent 7418bb7 commit c84c723

File tree

2 files changed

+22
-30
lines changed

2 files changed

+22
-30
lines changed

.github/scripts/fetch-artifacts.sh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ set -euo pipefail
1010
# Optional:
1111
# RETRIES: number of polling attempts per workflow (default: 30)
1212
# SLEEP_SEC: seconds to wait between attempts (default: 10)
13+
# ALLOWED_EVENTS: comma-separated list of workflow run events to consider (default: pull_request,pull_request_target)
1314

1415
IFS=',' read -r -a WORKFLOWS_ARR <<< "${OTHER_WORKFLOWS}"
1516
IFS=',' read -r -a ARTIFACTS_ARR <<< "${ARTIFACT_NAMES}"
@@ -19,6 +20,7 @@ TOKEN="${TOKEN}"
1920
API_BASE="https://api.github.com/repos/${REPO}"
2021
RETRIES=${RETRIES:-30}
2122
SLEEP_SEC=${SLEEP_SEC:-10}
23+
ALLOWED_EVENTS=${ALLOWED_EVENTS:-pull_request,pull_request_target}
2224

2325
mkdir -p artifacts
2426

@@ -40,13 +42,14 @@ for idx in "${!WORKFLOWS_ARR[@]}"; do
4042
attempt=$((attempt+1))
4143
echo " attempt $attempt/$RETRIES"
4244

43-
# 1) Liste Runs für das Workflow (workflow id/name/file)
45+
# 1) List workflow runs (workflow id/name/file)
4446
resp=$(curl -s -H "Authorization: Bearer ${TOKEN}" "${API_BASE}/actions/workflows/${wf}/runs?per_page=50")
4547

46-
# 2) Finde Run mit matching head_sha
47-
run_id=$(echo "$resp" | jq -r --arg SHA "$SHA" '.workflow_runs[] | select(.head_sha==$SHA) | .id' | head -n1 || true)
48-
run_status=$(echo "$resp" | jq -r --arg SHA "$SHA" '.workflow_runs[] | select(.head_sha==$SHA) | .status' | head -n1 || true)
49-
run_conclusion=$(echo "$resp" | jq -r --arg SHA "$SHA" '.workflow_runs[] | select(.head_sha==$SHA) | .conclusion' | head -n1 || true)
48+
# 2) Find run with matching head_sha (and allowed event types)
49+
regex_events=$(echo "$ALLOWED_EVENTS" | tr ',' '|' | tr -d '[:space:]')
50+
run_id=$(echo "$resp" | jq -r --arg SHA "$SHA" --arg RE "$regex_events" '.workflow_runs[] | select(.head_sha==$SHA and (.event|test($RE))) | .id' | head -n1 || true)
51+
run_status=$(echo "$resp" | jq -r --arg SHA "$SHA" --arg RE "$regex_events" '.workflow_runs[] | select(.head_sha==$SHA and (.event|test($RE))) | .status' | head -n1 || true)
52+
run_conclusion=$(echo "$resp" | jq -r --arg SHA "$SHA" --arg RE "$regex_events" '.workflow_runs[] | select(.head_sha==$SHA and (.event|test($RE))) | .conclusion' | head -n1 || true)
5053

5154
if [ -n "${run_id}" ] && [ "${run_id}" != "null" ]; then
5255
echo " Found run ${run_id} status=${run_status} conclusion=${run_conclusion}"
Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,63 @@
11
name: 'Quality Monitor Comment PR'
22

33
on:
4-
workflow_run:
5-
workflows: ['Quality Monitor', 'Dependency Check']
6-
types: [completed]
4+
pull_request:
75

86
permissions:
9-
actions: read
107
contents: read
8+
actions: read
119
pull-requests: write
1210
checks: write
1311

1412
jobs:
1513
comment:
16-
if: ${{ github.event.workflow_run.event == 'pull_request' }}
1714
runs-on: ubuntu-latest
1815
name: Comment on PR
1916

2017
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"
2818
- name: Checkout PR
2919
uses: actions/checkout@v6
3020
with:
31-
ref: ${{ steps.pr.outputs.sha }}
21+
ref: ${{ github.event.pull_request.head.sha }}
22+
3223
- name: Install jq and unzip
3324
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"
25+
4226
- name: Fetch reports from dependency check and quality monitor workflows
4327
env:
4428
REPO: ${{ github.repository }}
45-
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
29+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
4630
TOKEN: ${{ secrets.GITHUB_TOKEN }}
4731
OTHER_WORKFLOWS: "quality-monitor-build.yml,dependency-check.yml"
4832
ARTIFACT_NAMES: "quality-reports,dependency-report"
49-
RETRIES: 30
33+
ALLOWED_EVENTS: "pull_request,pull_request_target"
34+
RETRIES: 60
5035
SLEEP_SEC: 10
5136
run: |
5237
chmod +x ./.github/scripts/fetch-artifacts.sh
5338
./.github/scripts/fetch-artifacts.sh
39+
5440
- name: List downloaded reports
5541
run: |
5642
mkdir -p reports/target
5743
mv artifacts/*/target/* reports/target
5844
ls -la reports/target/* || true
45+
5946
- name: Read Quality Monitor Configuration
6047
id: quality-monitor
6148
run: echo "json=$(jq -c . .github/quality-monitor-pr.json)" >> "$GITHUB_OUTPUT"
49+
6250
- name: Read Quality Gates Configuration
6351
id: quality-gates
6452
run: echo "json=$(jq -c . .github/quality-gates-pr.json)" >> "$GITHUB_OUTPUT"
53+
6554
- name: Run Quality Monitor and Comment on PR
6655
uses: uhafner/quality-monitor@v4
6756
with:
68-
sha: ${{ steps.pr.outputs.sha }}
57+
sha: ${{ github.event.pull_request.head.sha }}
6958
config: ${{ steps.quality-monitor.outputs.json }}
7059
quality-gates: ${{ steps.quality-gates.outputs.json }}
71-
pr-number: ${{ steps.pr.outputs.number }}
60+
pr-number: ${{ github.event.pull_request.number }}
7261
comments-strategy: REMOVE
7362
show-headers: true
7463
title-metric: none

0 commit comments

Comments
 (0)