From ca2f59dd8220566f745e5a2d1cb3d6af886e92cd Mon Sep 17 00:00:00 2001 From: p0n1 Date: Thu, 26 Sep 2024 10:35:06 +0800 Subject: [PATCH] ci: better notification --- .github/workflows/notify.yml | 178 ++++++++++++++++++----------------- 1 file changed, 90 insertions(+), 88 deletions(-) diff --git a/.github/workflows/notify.yml b/.github/workflows/notify.yml index 165ac96..9d2fe7f 100644 --- a/.github/workflows/notify.yml +++ b/.github/workflows/notify.yml @@ -1,100 +1,102 @@ -name: Telegram Notifications +name: Telegram Notification on: push: branches: [ main ] pull_request: - types: [ opened, closed, reopened ] + types: [opened, closed, reopened] issues: - types: [ opened, closed, reopened ] + types: [opened, closed, reopened] release: - types: [ published ] + types: [published] jobs: notify: + name: Notify Telegram runs-on: ubuntu-latest steps: - - name: Send Telegram Message on Push - if: github.event_name == 'push' - uses: appleboy/telegram-action@master - with: - to: ${{ secrets.TELEGRAM_TO }} - token: ${{ secrets.TELEGRAM_TOKEN }} - format: html - message: | - New push to ${{ github.repository }} - - Branch: ${{ github.ref_name }} - Committer: ${{ github.event.pusher.name }} - Commit message: ${{ github.event.head_commit.message }} - - Changes: - • Added: ${{ github.event.head_commit.added.length }} file(s) - • Modified: ${{ github.event.head_commit.modified.length }} file(s) - • Removed: ${{ github.event.head_commit.removed.length }} file(s) - - View commit details - - - name: Send Telegram Message on Pull Request - if: github.event_name == 'pull_request' - uses: appleboy/telegram-action@master - with: - to: ${{ secrets.TELEGRAM_TO }} - token: ${{ secrets.TELEGRAM_TOKEN }} - format: html - message: | - Pull Request ${{ github.event.action }} - - Title: ${{ github.event.pull_request.title }} - PR #${{ github.event.pull_request.number }} - - Author: ${{ github.event.pull_request.user.login }} - Base branch: ${{ github.event.pull_request.base.ref }} - Head branch: ${{ github.event.pull_request.head.ref }} - - Status: ${{ github.event.pull_request.state }} - ${{ github.event.pull_request.additions }} addition(s), ${{ github.event.pull_request.deletions }} deletion(s) - - ${{ github.event.pull_request.body }} - - View Pull Request - - - name: Send Telegram Message on Issue - if: github.event_name == 'issues' - uses: appleboy/telegram-action@master - with: - to: ${{ secrets.TELEGRAM_TO }} - token: ${{ secrets.TELEGRAM_TOKEN }} - format: html - message: | - Issue ${{ github.event.action }} - - Title: ${{ github.event.issue.title }} - Issue #${{ github.event.issue.number }} - - Author: ${{ github.event.issue.user.login }} - Labels: ${{ join(github.event.issue.labels.*.name, ', ') }} - - ${{ github.event.issue.body }} - - View Issue - - - name: Send Telegram Message on Release - if: github.event_name == 'release' - uses: appleboy/telegram-action@master - with: - to: ${{ secrets.TELEGRAM_TO }} - token: ${{ secrets.TELEGRAM_TOKEN }} - format: html - message: | - New Release Published - - Version: ${{ github.event.release.tag_name }} - Name: ${{ github.event.release.name }} - - Author: ${{ github.event.release.author.login }} - Created at: ${{ github.event.release.created_at }} - - ${{ github.event.release.body }} - - View Release \ No newline at end of file + - name: Send Telegram Message on Push + if: github.event_name == 'push' + uses: appleboy/telegram-action@master + with: + to: ${{ secrets.TELEGRAM_TO }} + token: ${{ secrets.TELEGRAM_TOKEN }} + format: markdown + message: | + *New Push to ${{ github.repository }}* + + *Branch:* `${{ github.ref_name }}` + *Pusher:* ${{ github.actor }} + + *Commit Message:* + ``` + ${{ github.event.head_commit.message }} + ``` + + [View Commit](https://github.com/${{ github.repository }}/commit/${{github.sha}}) + + - name: Send Telegram Message on Pull Request + if: github.event_name == 'pull_request' + uses: appleboy/telegram-action@master + with: + to: ${{ secrets.TELEGRAM_TO }} + token: ${{ secrets.TELEGRAM_TOKEN }} + format: markdown + message: | + *Pull Request ${{ github.event.action }} in ${{ github.repository }}* + + *Title:* ${{ github.event.pull_request.title }} + *PR #:* ${{ github.event.pull_request.number }} + *State:* ${{ github.event.pull_request.state }} + *Author:* ${{ github.event.pull_request.user.login }} + + [View PR](${{ github.event.pull_request.html_url }}) + + - name: Send Telegram Message on Issue + if: github.event_name == 'issues' + uses: appleboy/telegram-action@master + with: + to: ${{ secrets.TELEGRAM_TO }} + token: ${{ secrets.TELEGRAM_TOKEN }} + format: markdown + message: | + *Issue ${{ github.event.action }} in ${{ github.repository }}* + + *Title:* ${{ github.event.issue.title }} + *Issue #:* ${{ github.event.issue.number }} + *State:* ${{ github.event.issue.state }} + *Author:* ${{ github.event.issue.user.login }} + + [View Issue](${{ github.event.issue.html_url }}) + + - name: Send Telegram Message on Release + if: github.event_name == 'release' + uses: appleboy/telegram-action@master + with: + to: ${{ secrets.TELEGRAM_TO }} + token: ${{ secrets.TELEGRAM_TOKEN }} + format: markdown + message: | + *New Release Published in ${{ github.repository }}* + + *Tag:* ${{ github.event.release.tag_name }} + *Name:* ${{ github.event.release.name }} + *Author:* ${{ github.event.release.author.login }} + + *Description:* + ``` + ${{ github.event.release.body }} + ``` + + [View Release](${{ github.event.release.html_url }}) + + - name: Send Telegram Message on Failure + if: failure() + uses: appleboy/telegram-action@master + with: + to: ${{ secrets.TELEGRAM_TO }} + token: ${{ secrets.TELEGRAM_TOKEN }} + message: | + ❌ Workflow failed in ${{ github.repository }} + Event: ${{ github.event_name }} + See details: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} \ No newline at end of file