From d17bd723e31af48c571e6fbca93e93dfb06d4d15 Mon Sep 17 00:00:00 2001 From: XapcT Date: Sat, 11 Apr 2026 18:23:49 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D1=83=D0=B2=D0=B5=D0=B4=D0=BE=D0=BC=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=BE=20=D1=80=D0=B5=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=BD=D0=BE=D0=B9=20=D1=81=D0=B1=D0=BE=D1=80=D0=BA=D0=B5=20?= =?UTF-8?q?=D0=B2=20Telegram?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 38 +++++++++++++++++++++++++ scripts/send-telegram-notification.ps1 | 39 ++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 scripts/send-telegram-notification.ps1 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 325ca2e..c5b0660 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,6 +12,10 @@ permissions: jobs: build: runs-on: windows-latest + environment: TgBot + env: + TG_CHAT_ID: -1003975565934 + TG_THREAD_ID: 2 defaults: run: @@ -44,6 +48,18 @@ jobs: } "version_tag=$versionTag" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8 + - name: Notify Telegram about build start + if: startsWith(github.ref, 'refs/tags/v') + continue-on-error: true + env: + BOT_TOKEN: ${{ secrets.BOT_TOKEN }} + run: | + $ErrorActionPreference = "Stop" + $target = if ("${{ steps.vars.outputs.version_tag }}") { "${{ steps.vars.outputs.version_tag }}" } else { "${{ github.ref_name }}" } + $runUrl = "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" + $text = "⏳ Старт сборки релиза`nРепозиторий: ${{ github.repository }}`nТег: $target`nОткрыть лог сборки" + .\scripts\send-telegram-notification.ps1 -BotToken $env:BOT_TOKEN -ChatId $env:TG_CHAT_ID -ThreadId $env:TG_THREAD_ID -Text $text -DisableNotification + - name: Download latest LSLib release run: | $ErrorActionPreference = "Stop" @@ -115,3 +131,25 @@ jobs: --repo "${{ github.repository }}" ` --clobber } + + - name: Notify Telegram about build success + if: success() && startsWith(github.ref, 'refs/tags/v') + continue-on-error: true + env: + BOT_TOKEN: ${{ secrets.BOT_TOKEN }} + run: | + $ErrorActionPreference = "Stop" + $releaseUrl = "${{ github.server_url }}/${{ github.repository }}/releases/tag/${{ github.ref_name }}" + $text = "🏁 Релиз собран успешно`nТег: ${{ github.ref_name }}`nОткрыть готовый релиз" + .\scripts\send-telegram-notification.ps1 -BotToken $env:BOT_TOKEN -ChatId $env:TG_CHAT_ID -ThreadId $env:TG_THREAD_ID -Text $text -DisableNotification + + - name: Notify Telegram about build failure + if: failure() && startsWith(github.ref, 'refs/tags/v') + continue-on-error: true + env: + BOT_TOKEN: ${{ secrets.BOT_TOKEN }} + run: | + $ErrorActionPreference = "Stop" + $runUrl = "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" + $text = "❌ Сборка релиза завершилась ошибкой`nТег: ${{ github.ref_name }}`nОткрыть лог сборки" + .\scripts\send-telegram-notification.ps1 -BotToken $env:BOT_TOKEN -ChatId $env:TG_CHAT_ID -ThreadId $env:TG_THREAD_ID -Text $text diff --git a/scripts/send-telegram-notification.ps1 b/scripts/send-telegram-notification.ps1 new file mode 100644 index 0000000..f4203cc --- /dev/null +++ b/scripts/send-telegram-notification.ps1 @@ -0,0 +1,39 @@ +[CmdletBinding()] +param( + [Parameter(Mandatory = $true)] + [string]$BotToken, + + [Parameter(Mandatory = $true)] + [string]$ChatId, + + [Parameter(Mandatory = $true)] + [string]$ThreadId, + + [Parameter(Mandatory = $true)] + [string]$Text, + + [switch]$DisableNotification +) + +$ErrorActionPreference = "Stop" + +$normalizedText = $Text. + Replace("``r``n", "`r`n"). + Replace("``n", "`n"). + Replace("%0A", "`n") + +$body = @{ + chat_id = $ChatId + message_thread_id = $ThreadId + parse_mode = "HTML" + text = $normalizedText +} + +if ($DisableNotification) { + $body.disable_notification = "true" +} + +Invoke-RestMethod ` + -Method Post ` + -Uri ("https://api.telegram.org/bot{0}/sendMessage" -f $BotToken) ` + -Body $body | Out-Null