3131 scan-failures :
3232 runs-on : ubuntu-latest
3333 env :
34- TARGET_REPO : " ibexa/headless"
34+ TARGET_REPO : " ibexa/commerce"
35+ WORKFLOW_NAME : " Browser Tests"
3536 steps :
3637 - name : Checkout self
3738 uses : actions/checkout@v4
@@ -53,29 +54,42 @@ jobs:
5354 echo "since=$SINCE" >> $GITHUB_OUTPUT
5455 echo "until=$UNTIL" >> $GITHUB_OUTPUT
5556
56- - name : Scan failed workflow runs in period for chosen branch
57+ - name : Find workflow ID by name
58+ id : workflow_id
59+ env :
60+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
61+ run : |
62+ WORKFLOW_ID=$(gh api "/repos/${TARGET_REPO}/actions/workflows" | jq '.workflows[] | select(.name == "${WORKFLOW_NAME}") | .id')
63+ if [ -z "$WORKFLOW_ID" ]; then
64+ echo "Could not find workflow with name: ${WORKFLOW_NAME}" >&2
65+ exit 1
66+ fi
67+ echo "id=$WORKFLOW_ID" >> $GITHUB_OUTPUT
68+
69+ - name : Scan failed runs for Browser Tests in period for chosen branch
5770 shell : bash
5871 env :
5972 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
6073 run : |
6174 BRANCH="${{ github.event.inputs.branch }}"
6275 SINCE="${{ steps.daterange.outputs.since }}"
6376 UNTIL="${{ steps.daterange.outputs.until }}"
77+ WORKFLOW_ID="${{ steps.workflow_id.outputs.id }}"
6478 echo "| Branch | Job Name | Failure Time | Error Description |" > results.md
6579 echo "|--------|----------|--------------|-------------------|" >> results.md
6680
67- echo "Scanning branch $BRANCH from $SINCE to $UNTIL" >&2
68-
81+ echo "Scanning failures for workflow: Browser Tests on branch $BRANCH from $SINCE to $UNTIL" >&2
6982
70- RAW_RUNS=$(gh api "/repos/${TARGET_REPO}/actions/runs?branch=${BRANCH}&status=failure&per_page=100")
71- if [ -z "$RAW_RUNS" ]; then
72- echo "No API response or empty response for workflow runs." >&2
73- else
74- RUNS=$(echo "$RAW_RUNS" | jq -c '.workflow_runs[] | select(.created_at >= "'${SINCE}'T00:00:00Z" and .created_at <= "'${UNTIL}'T23:59:59Z")')
83+ RAW_RUNS=$(gh api "/repos/${TARGET_REPO}/actions/workflows/${WORKFLOW_ID}/runs?branch=${BRANCH}&status=failure&per_page=100")
84+ if ! echo "$RAW_RUNS" | jq empty 2>/dev/null; then
85+ echo "API response is not valid JSON: $RAW_RUNS" >&2
86+ exit 1
7587 fi
7688
89+ RUNS=$(echo "$RAW_RUNS" | jq -c '.workflow_runs[] | select(.created_at >= "'${SINCE}'T00:00:00Z" and .created_at <= "'${UNTIL}'T23:59:59Z")')
90+
7791 if [ -z "$RUNS" ]; then
78- echo "No failed runs found in this window" >&2
92+ echo "No failed runs found for workflow: Browser Tests on branch $BRANCH in this window" >&2
7993 else
8094 echo "$RUNS" | while read RUN; do
8195 RUN_ID=$(echo "$RUN" | jq -r '.id')
@@ -84,13 +98,11 @@ jobs:
8498 JOB_NAME=$(echo "$JOB" | jq -r '.name')
8599 FAILURE_TIME=$(echo "$JOB" | jq -r '.completed_at')
86100 LOG_URL=$(echo "$JOB" | jq -r '.logs_url')
87- # Download logs and extract error description (first 'error', fallback last 10 lines)
88101 gh api "$LOG_URL" > job_log.txt
89102 ERROR_DESC=$(grep -i 'error' job_log.txt | head -n 1)
90103 if [[ -z "$ERROR_DESC" ]]; then
91104 ERROR_DESC=$(tail -n 10 job_log.txt | tr '\n' ' ')
92105 fi
93- # Escape pipes just in case
94106 ERROR_DESC=$(echo "$ERROR_DESC" | sed 's/|/\\|/g')
95107 echo "| $BRANCH | $JOB_NAME | $FAILURE_TIME | $ERROR_DESC |" >> results.md
96108 done
0 commit comments