Skip to content

Commit 9afe8f7

Browse files
authored
[ci] Enabled CI failure bot
1 parent 55df52f commit 9afe8f7

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: CI Failure Bot
2+
3+
on:
4+
workflow_run:
5+
workflows: ["OpenWISP Controller CI Build"]
6+
types:
7+
- completed
8+
9+
permissions:
10+
pull-requests: write
11+
actions: read
12+
contents: read
13+
14+
concurrency:
15+
group: ci-failure-${{ github.repository }}-${{ github.event.workflow_run.pull_requests[0].number || github.event.workflow_run.head_branch }}
16+
cancel-in-progress: true
17+
18+
jobs:
19+
find-pr:
20+
runs-on: ubuntu-latest
21+
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
22+
outputs:
23+
pr_number: ${{ steps.pr.outputs.number }}
24+
steps:
25+
- name: Find PR Number
26+
id: pr
27+
env:
28+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
REPO: ${{ github.repository }}
30+
PR_NUMBER_PAYLOAD: ${{ github.event.workflow_run.pull_requests[0].number }}
31+
EVENT_HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
32+
run: |
33+
PR_NUMBER="$PR_NUMBER_PAYLOAD"
34+
if [ -n "$PR_NUMBER" ]; then
35+
echo "Found PR #$PR_NUMBER from workflow payload."
36+
echo "number=$PR_NUMBER" >> $GITHUB_OUTPUT
37+
exit 0
38+
fi
39+
HEAD_SHA="$EVENT_HEAD_SHA"
40+
echo "Payload empty. Searching for PR via Commits API..."
41+
PR_NUMBER=$(gh api repos/$REPO/commits/$HEAD_SHA/pulls -q '.[0].number' 2>/dev/null || true)
42+
if [ -n "$PR_NUMBER" ] && [ "$PR_NUMBER" != "null" ]; then
43+
echo "Found PR #$PR_NUMBER using Commits API."
44+
echo "number=$PR_NUMBER" >> $GITHUB_OUTPUT
45+
exit 0
46+
fi
47+
echo "API lookup failed/empty. Scanning open PRs for matching head SHA..."
48+
PR_NUMBER=$(gh pr list --repo "$REPO" --state open --limit 100 --json number,headRefOid --jq ".[] | select(.headRefOid == \"$HEAD_SHA\") | .number" | head -n 1)
49+
if [ -n "$PR_NUMBER" ]; then
50+
echo "Found PR #$PR_NUMBER by scanning open PRs."
51+
echo "number=$PR_NUMBER" >> $GITHUB_OUTPUT
52+
exit 0
53+
fi
54+
echo "::warning::No open PR found. This workflow run might not be attached to an open PR."
55+
exit 0
56+
57+
call-ci-failure-bot:
58+
needs: find-pr
59+
if: ${{ needs.find-pr.outputs.pr_number != '' }}
60+
uses: openwisp/openwisp-utils/.github/workflows/reusable-bot-ci-failure.yml@master
61+
with:
62+
pr_number: ${{ needs.find-pr.outputs.pr_number }}
63+
head_sha: ${{ github.event.workflow_run.head_sha }}
64+
head_repo: ${{ github.event.workflow_run.head_repository.full_name }}
65+
base_repo: ${{ github.repository }}
66+
run_id: ${{ github.event.workflow_run.id }}
67+
pr_author: ${{ github.event.workflow_run.actor.login }}
68+
actor: ${{ github.actor }}
69+
secrets:
70+
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
71+
APP_ID: ${{ secrets.OPENWISP_BOT_APP_ID }}
72+
PRIVATE_KEY: ${{ secrets.OPENWISP_BOT_PRIVATE_KEY }}

0 commit comments

Comments
 (0)