⚠️ Report Workflow Failures #34180
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: ⚠️ Report Workflow Failures | |
on: | |
workflow_run: | |
workflows: | |
- '**' | |
types: [completed] | |
workflow_dispatch: | |
jobs: | |
monitor-workflows: | |
name: Monitor Workflows | |
runs-on: ubuntu-latest | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
github-token: ${{ github.token }} | |
steps: | |
- name: Check if actor is the repository owner | |
if: ${{ github.actor != github.repository_owner }} | |
run: echo "Actor is not the repository owner, proceeding with the workflow." | |
- name: Get Failed Jobs | |
id: get-failed-jobs | |
if: ${{ github.actor != github.repository_owner }} | |
run: | | |
run_id=${{ github.event.workflow_run.id }} | |
response=$(gh api repos/${{ github.repository }}/actions/runs/$run_id/jobs --jq '.jobs') | |
if [ -z "$response" ]; then | |
echo "Failed to fetch jobs data. Please verify the token or permissions." >&2 | |
exit 1 | |
fi | |
failed_jobs=$(echo "$response" | jq -r '[.[] | select(.conclusion == "failure") | .name] | join(", ")') | |
echo "failed_jobs=$failed_jobs" >> $GITHUB_ENV | |
- name: Create Issue for Failed Jobs | |
if: env.failed_jobs != '' && github.actor != github.repository_owner | |
uses: offensive-vk/auto-issue@v7 | |
with: | |
github-token: ${{ secrets.BOT_TOKEN }} | |
title: | | |
🚨 Workflow Failure: ${{ github.event.workflow.name }} | |
assignees: TheHamsterBot | |
labels: hamster,reporter | |
body: | | |
> [!CAUTION] | |
> The workflow **${{ github.event.workflow_run.name }}** (ID: ${{ github.event.workflow_run.id }}) encountered failed jobs. | |
## **Failed Jobs:** | |
- ${{ env.failed_jobs }} | |
## **Failure Details:** | |
- **Workflow Path**: ${{ github.workflow_ref }} | |
- **Conclusion**: `${{ github.event.workflow_run.conclusion }}` | |
- **Status Message**: `${{ github.event.workflow_run.status|| 'N/A' }}` | |
Thanks. | |
**Your Hamster** 🐹 | |
<code>PF78VAPPKLZ2</code> |