-
Notifications
You must be signed in to change notification settings - Fork 1
40 lines (34 loc) · 1.47 KB
/
notify_failure.yml
File metadata and controls
40 lines (34 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
name: Notify Failure
on:
workflow_call:
secrets:
GITHUB_TOKEN:
required: true
jobs:
notify_failure:
runs-on: ubuntu-latest
permissions:
issues: write
contents: read
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Manage issue
id: manage_issue
run: |
ISSUE_TITLE="[Workflow Log] Central error logging"
ISSUE_DATA=$(gh issue list -R "$GITHUB_REPOSITORY" --search "is:open in:title \"${ISSUE_TITLE}\"" --json number --limit 1)
ISSUE_NUMBER=$(echo "$ISSUE_DATA" | jq -r '.[0].number')
if [ -z "$ISSUE_NUMBER" ] || [ "$ISSUE_NUMBER" = "null" ]; then
NEW_ISSUE_NUMBER=$(gh issue create -R "$GITHUB_REPOSITORY" --title "$ISSUE_TITLE" \
--body "This issue serves as a central log for all workflow errors." \
| sed -n 's/.*#\([0-9]\+\).*/\1/p')
echo "issue_number=$NEW_ISSUE_NUMBER" >> "$GITHUB_OUTPUT"
else
echo "issue_number=$ISSUE_NUMBER" >> "$GITHUB_OUTPUT"
fi
- name: Create comment
run: |
gh issue comment ${{ steps.manage_issue.outputs.issue_number }} \
-R "$GITHUB_REPOSITORY" \
--body "***Workflow failure*** ([View workflow run for details](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}))"