From 8f8233ab0bdb78e351b735b79d6b1fb6252a7bb8 Mon Sep 17 00:00:00 2001 From: Shahovalov MIkhail Date: Sat, 11 Apr 2026 20:03:24 +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=D0=BB=D0=BE=D0=BA=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B?= =?UTF-8?q?=D0=B9=20env=20=D0=B8=20Telegram-=D1=83=D0=B2=D0=B5=D0=B4=D0=BE?= =?UTF-8?q?=D0=BC=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B4=D0=BB=D1=8F=20CI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 3 + .gitea/workflows/build.yml | 36 ++++++++++++ .github/workflows/build.yml | 6 +- .gitignore | 4 ++ AGENTS.md | 6 +- scripts/send-telegram-notification.ps1 | 80 +++++++++++++++++++++++++- 6 files changed, 127 insertions(+), 8 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..7b33740 --- /dev/null +++ b/.env.example @@ -0,0 +1,3 @@ +BOT_TOKEN= +TG_CHAT_ID= +TG_THREAD_ID= diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 4f61b32..595be0b 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -13,6 +13,9 @@ jobs: build: runs-on: - win11 + env: + TG_CHAT_ID: ${{ secrets.TG_CHAT_ID }} + TG_THREAD_ID: ${{ secrets.TG_THREAD_ID }} defaults: run: @@ -50,6 +53,17 @@ jobs: New-Item -ItemType Directory -Path ".tools\\lslib" -Force | Out-Null New-Item -ItemType Directory -Path "build" -Force | Out-Null + - name: Notify Telegram about build start + if: startsWith(gitea.ref, 'refs/tags/v') + continue-on-error: true + env: + BOT_TOKEN: ${{ secrets.BOT_TOKEN }} + run: | + $ErrorActionPreference = "Stop" + $runUrl = "${{ gitea.server_url }}/${{ gitea.repository }}/actions/runs/${{ gitea.run_id }}" + $text = "⏳ Старт сборки релиза`nРепозиторий: ${{ gitea.repository }}`nТег: ${{ gitea.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: Download latest LSLib release run: | $ErrorActionPreference = "Stop" @@ -169,3 +183,25 @@ jobs: } Invoke-WebRequest -UseBasicParsing -Method Post -Uri "$apiBase/releases/$($release.id)/assets?name=$([uri]::EscapeDataString($assetName))" -Headers $uploadHeaders -ContentType "application/octet-stream" -InFile $zipPath + + - name: Notify Telegram about build success + if: success() && startsWith(gitea.ref, 'refs/tags/v') + continue-on-error: true + env: + BOT_TOKEN: ${{ secrets.BOT_TOKEN }} + run: | + $ErrorActionPreference = "Stop" + $releaseUrl = "${{ gitea.server_url }}/${{ gitea.repository }}/releases/tag/${{ gitea.ref_name }}" + $text = "🏁 Релиз собран успешно`nТег: ${{ gitea.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(gitea.ref, 'refs/tags/v') + continue-on-error: true + env: + BOT_TOKEN: ${{ secrets.BOT_TOKEN }} + run: | + $ErrorActionPreference = "Stop" + $runUrl = "${{ gitea.server_url }}/${{ gitea.repository }}/actions/runs/${{ gitea.run_id }}" + $text = "❌ Сборка релиза завершилась ошибкой`nТег: ${{ gitea.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/.github/workflows/build.yml b/.github/workflows/build.yml index 0075959..fc8cb04 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,10 +12,10 @@ permissions: jobs: build: runs-on: windows-latest - environment: TgBot + environment: Configure TgBot env: - TG_CHAT_ID: -1003975565934 - TG_THREAD_ID: 2 + TG_CHAT_ID: ${{ secrets.TG_CHAT_ID }} + TG_THREAD_ID: ${{ secrets.TG_THREAD_ID }} defaults: run: diff --git a/.gitignore b/.gitignore index db513d5..1d40aff 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,10 @@ build/ build-stage* .tools/ .cache/ +.env +.env.local +.env.* +!.env.example *.pak *.tmp *.temp diff --git a/AGENTS.md b/AGENTS.md index 600b3f7..c35f62d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -34,8 +34,8 @@ Approval/clarification: - Branch (`fix/*` or `feat/*`): ask once before the first file-changing task that may lead to commit; reuse decision for all subsequent tasks in same dialogue. After work in `fix/*` or `feat/*`: -1. merge changes directly into `main` and delete the source branch -2. create PR/MR targeting `main` +1. create PR/MR targeting `main` +2. merge changes into `main` and delete the source branch Push failure: - retry ≤2 times, 3s delay @@ -70,6 +70,8 @@ Forbidden: - CI: `.gitea/workflows/build.yml` - Glossary: `glossary/glossary.normalized.json` _(primary terminology reference)_ - Actions: `ACTIONS.md` +- Local env template: `.env.example` +- Local env file: `.env.local` - Upstream EN reference: `https://github.com/Yoonmoonsik/dnd55e/blob/main/Mods/DnD2024_897914ef-5c96-053c-44af-0be823f895fe/Localization/English/english.xml` --- diff --git a/scripts/send-telegram-notification.ps1 b/scripts/send-telegram-notification.ps1 index f4203cc..5cb28e1 100644 --- a/scripts/send-telegram-notification.ps1 +++ b/scripts/send-telegram-notification.ps1 @@ -1,12 +1,12 @@ [CmdletBinding()] param( - [Parameter(Mandatory = $true)] + [Parameter()] [string]$BotToken, - [Parameter(Mandatory = $true)] + [Parameter()] [string]$ChatId, - [Parameter(Mandatory = $true)] + [Parameter()] [string]$ThreadId, [Parameter(Mandatory = $true)] @@ -17,6 +17,80 @@ param( $ErrorActionPreference = "Stop" +function Import-DotEnvFile { + param( + [Parameter(Mandatory = $true)] + [string]$Path + ) + + if (-not (Test-Path -LiteralPath $Path)) { + return + } + + foreach ($line in [System.IO.File]::ReadAllLines($Path)) { + $trimmedLine = $line.Trim() + if (-not $trimmedLine -or $trimmedLine.StartsWith("#")) { + continue + } + + $separatorIndex = $trimmedLine.IndexOf("=") + if ($separatorIndex -lt 1) { + continue + } + + $name = $trimmedLine.Substring(0, $separatorIndex).Trim() + $value = $trimmedLine.Substring($separatorIndex + 1).Trim() + + if ( + ($value.StartsWith('"') -and $value.EndsWith('"')) -or + ($value.StartsWith("'") -and $value.EndsWith("'")) + ) { + $value = $value.Substring(1, $value.Length - 2) + } + + [System.Environment]::SetEnvironmentVariable($name, $value, "Process") + } +} + +function Resolve-Setting { + param( + [string]$ExplicitValue, + [Parameter(Mandatory = $true)] + [string]$EnvName + ) + + if (-not [string]::IsNullOrWhiteSpace($ExplicitValue)) { + return $ExplicitValue + } + + $envValue = [System.Environment]::GetEnvironmentVariable($EnvName, "Process") + if (-not [string]::IsNullOrWhiteSpace($envValue)) { + return $envValue + } + + return $null +} + +$repoRoot = [System.IO.Path]::GetFullPath((Join-Path $PSScriptRoot "..")) +$localEnvPath = Join-Path $repoRoot ".env.local" +Import-DotEnvFile -Path $localEnvPath + +$BotToken = Resolve-Setting -ExplicitValue $BotToken -EnvName "BOT_TOKEN" +$ChatId = Resolve-Setting -ExplicitValue $ChatId -EnvName "TG_CHAT_ID" +$ThreadId = Resolve-Setting -ExplicitValue $ThreadId -EnvName "TG_THREAD_ID" + +if ([string]::IsNullOrWhiteSpace($BotToken)) { + throw "Telegram bot token is required. Pass -BotToken or set BOT_TOKEN in .env.local." +} + +if ([string]::IsNullOrWhiteSpace($ChatId)) { + throw "Telegram chat id is required. Pass -ChatId or set TG_CHAT_ID in .env.local." +} + +if ([string]::IsNullOrWhiteSpace($ThreadId)) { + throw "Telegram thread id is required. Pass -ThreadId or set TG_THREAD_ID in .env.local." +} + $normalizedText = $Text. Replace("``r``n", "`r`n"). Replace("``n", "`n").