Добавлены уведомления о релизной сборке в Telegram
This commit is contained in:
38
.github/workflows/build.yml
vendored
38
.github/workflows/build.yml
vendored
@@ -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 = "⏳ <b>Старт сборки релиза</b>`n<b>Репозиторий:</b> <code>${{ github.repository }}</code>`n<b>Тег:</b> <code>$target</code>`n<a href=`"$runUrl`">Открыть лог сборки</a>"
|
||||
.\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 = "🏁 <b>Релиз собран успешно</b>`n<b>Тег:</b> <code>${{ github.ref_name }}</code>`n<a href=`"$releaseUrl`">Открыть готовый релиз</a>"
|
||||
.\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 = "❌ <b>Сборка релиза завершилась ошибкой</b>`n<b>Тег:</b> <code>${{ github.ref_name }}</code>`n<a href=`"$runUrl`">Открыть лог сборки</a>"
|
||||
.\scripts\send-telegram-notification.ps1 -BotToken $env:BOT_TOKEN -ChatId $env:TG_CHAT_ID -ThreadId $env:TG_THREAD_ID -Text $text
|
||||
|
||||
39
scripts/send-telegram-notification.ps1
Normal file
39
scripts/send-telegram-notification.ps1
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user