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