reusable-workflow-notification.yml 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # this is useful because notifications for scheduled workflows are only sent to the user who
  2. # initially created the given workflow
  3. name: Reusable - Workflow notification
  4. on:
  5. workflow_call:
  6. inputs:
  7. success:
  8. type: boolean
  9. required: true
  10. jobs:
  11. workflow-notification:
  12. runs-on: ubuntu-latest
  13. steps:
  14. - uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
  15. - name: Open issue or add comment if issue already open
  16. env:
  17. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  18. run: |
  19. # TODO (trask) search doesn't support exact phrases, so it's possible that this could grab the wrong issue
  20. number=$(gh issue list --search "in:title Workflow failed: $GITHUB_WORKFLOW" --limit 1 --json number -q .[].number)
  21. echo $number
  22. echo ${{ inputs.success }}
  23. if [[ $number ]]; then
  24. if [[ "${{ inputs.success }}" == "true" ]]; then
  25. gh issue close $number
  26. else
  27. gh issue comment $number \
  28. --body "See [$GITHUB_WORKFLOW #$GITHUB_RUN_NUMBER](https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID)."
  29. fi
  30. elif [[ "${{ inputs.success }}" == "false" ]]; then
  31. gh issue create --title "Workflow failed: $GITHUB_WORKFLOW (#$GITHUB_RUN_NUMBER)" \
  32. --body "See [$GITHUB_WORKFLOW #$GITHUB_RUN_NUMBER](https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID)."
  33. fi