Skip to content

Commit 38708a1

Browse files
pushing correct file
1 parent 4055af9 commit 38708a1

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Scan Branch Regression Errors
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
branch:
7+
description: 'Branch to scan (e.g., feature.ie-branch)'
8+
required: true
9+
type: string
10+
since:
11+
description: 'Start date for scan window (YYYY-MM-DD, leave empty for last 30 days)'
12+
required: false
13+
type: string
14+
until:
15+
description: 'End date for scan window (YYYY-MM-DD, leave empty for today)'
16+
required: false
17+
type: string
18+
19+
jobs:
20+
scan-failures:
21+
runs-on: ubuntu-latest
22+
env:
23+
TARGET_REPO: "ibexa/commerce"
24+
steps:
25+
- name: Checkout self
26+
uses: actions/checkout@v4
27+
28+
- name: Set date range for the last 30 days if not specified
29+
id: daterange
30+
run: |
31+
# If since/until not set, use last 30 days -> today
32+
if [ -z "${{ github.event.inputs.since }}" ]; then
33+
SINCE=$(date -u -d '30 days ago' +%Y-%m-%d)
34+
else
35+
SINCE="${{ github.event.inputs.since }}"
36+
fi
37+
if [ -z "${{ github.event.inputs.until }}" ]; then
38+
UNTIL=$(date -u +%Y-%m-%d)
39+
else
40+
UNTIL="${{ github.event.inputs.until }}"
41+
fi
42+
echo "since=$SINCE" >> $GITHUB_OUTPUT
43+
echo "until=$UNTIL" >> $GITHUB_OUTPUT
44+
45+
- name: Scan failed workflow runs in period for chosen branch
46+
shell: bash
47+
env:
48+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49+
run: |
50+
BRANCH="${{ github.event.inputs.branch }}"
51+
SINCE="${{ steps.daterange.outputs.since }}"
52+
UNTIL="${{ steps.daterange.outputs.until }}"
53+
echo "| Branch | Job Name | Failure Time | Error Description |" > results.md
54+
echo "|--------|----------|--------------|-------------------|" >> results.md
55+
56+
echo "Scanning branch $BRANCH from $SINCE to $UNTIL" >&2
57+
58+
# Get runs (paginated, only up to 100 runs per API call, modify as needed for deeper history)
59+
RUNS=$(gh api "/repos/${TARGET_REPO}/actions/runs?branch=${BRANCH}&status=failure&per_page=100" | jq -c '.workflow_runs[] | select(.created_at >= "'${SINCE}'T00:00:00Z" and .created_at <= "'${UNTIL}'T23:59:59Z")')
60+
if [ -z "$RUNS" ]; then
61+
echo "No failed runs found in this window" >&2
62+
else
63+
echo "$RUNS" | while read RUN; do
64+
RUN_ID=$(echo "$RUN" | jq -r '.id')
65+
JOBS=$(gh api "/repos/${TARGET_REPO}/actions/runs/${RUN_ID}/jobs?per_page=100" | jq -c '.jobs[] | select(.conclusion=="failure")')
66+
for JOB in $JOBS; do
67+
JOB_NAME=$(echo "$JOB" | jq -r '.name')
68+
FAILURE_TIME=$(echo "$JOB" | jq -r '.completed_at')
69+
LOG_URL=$(echo "$JOB" | jq -r '.logs_url')
70+
# Download logs and extract error description (first 'error', fallback last 10 lines)
71+
gh api "$LOG_URL" > job_log.txt
72+
ERROR_DESC=$(grep -i 'error' job_log.txt | head -n 1)
73+
if [[ -z "$ERROR_DESC" ]]; then
74+
ERROR_DESC=$(tail -n 10 job_log.txt | tr '\n' ' ')
75+
fi
76+
# Escape pipes just in case
77+
ERROR_DESC=$(echo "$ERROR_DESC" | sed 's/|/\\|/g')
78+
echo "| $BRANCH | $JOB_NAME | $FAILURE_TIME | $ERROR_DESC |" >> results.md
79+
done
80+
done
81+
fi
82+
83+
- name: Output table to summary
84+
shell: bash
85+
run: |
86+
cat results.md >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)