Skip to content

PythonBot - Workflow Failure Notifier #75

PythonBot - Workflow Failure Notifier

PythonBot - Workflow Failure Notifier #75

name: PythonBot - Workflow Failure Notifier
on:
workflow_dispatch:
workflow_run:
workflows:
- "Primary PR Check - Broken Markdown Links"
- "Primary PR Check - Code-coverage"
- "Primary PR Check - Test Files Naming"
- "Secondary PR Check - Examples"
- "Secondary PR Check - TCK Unit Test"
- "Secondary PR Check - Hiero Solo Integration & Unit Tests"
- "Secondary PR Check - Dependency Compatibility"
types:
- completed
permissions:
contents: read
pull-requests: write
concurrency:
group: "workflow-failure-${{ github.event.workflow_run.head_branch }}"
cancel-in-progress: true
jobs:
notify-pr:
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
runs-on: hl-sdk-py-lin-md
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
with:
egress-policy: audit
- name: Get associated PR number
id: get-pr
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Get branch from the workflow run
HEAD_BRANCH=$(gh run view ${{ github.event.workflow_run.id }} \
--repo ${{ github.repository }} \
--json headBranch --jq '.headBranch')
# Find the PR number for this branch (only open PRs)
PR_NUMBER=$(gh pr list --repo ${{ github.repository }} --state open --head "$HEAD_BRANCH" --json number --jq '.[0].number')
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
- name: Comment on PR
if: env.PR_NUMBER != ''
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
REPO="${{ github.repository }}"
COMMENT=$(cat <<EOF
<!-- workflow-failure-bot -->
Hi, this is WorkflowBot.
Your pull request cannot be merged as it is not passing all our workflow checks.
Please click on each check to review the logs and resolve issues so all checks pass.
To help you:
- [DCO signing guide](https://github.com/hiero-ledger/sdk-collaboration-hub/blob/main/guides/issue-progression/for-developers/signing.md)
- [Merge conflicts guide](https://github.com/hiero-ledger/sdk-collaboration-hub/blob/main/guides/issue-progression/for-developers/merge_conflicts.md)
- [Rebase guide](https://github.com/hiero-ledger/sdk-collaboration-hub/blob/main/guides/issue-progression/for-developers/rebasing.md)
- [Testing guide](https://github.com/hiero-ledger/hiero-sdk-python/blob/main/docs/sdk_developers/testing.md)
- [Discord](https://github.com/hiero-ledger/sdk-collaboration-hub/blob/main/guides/issue-progression/for-developers/discord.md)
- [Community Calls](https://zoom-lfx.platform.linuxfoundation.org/meetings/hiero?view=week)
Thank you for contributing!
From the Hiero Python SDK Team
EOF
)
EXISTING_COMMENT=$(gh pr view "$PR_NUMBER" --repo "$REPO" --comments \
--json comments --jq '.comments[] | select(.body | contains("<!-- workflow-failure-bot -->")) | .id')
if [ -z "$EXISTING_COMMENT" ]; then
gh pr comment "$PR_NUMBER" --repo "$REPO" --body "$COMMENT"
else
echo "Comment already exists, skipping."
fi