Добавлены локальный env и Telegram-уведомления для CI

This commit is contained in:
2026-04-11 20:03:24 +03:00
parent af1fd046d4
commit 8f8233ab0b
6 changed files with 127 additions and 8 deletions

3
.env.example Normal file
View File

@@ -0,0 +1,3 @@
BOT_TOKEN=
TG_CHAT_ID=
TG_THREAD_ID=

View File

@@ -13,6 +13,9 @@ jobs:
build: build:
runs-on: runs-on:
- win11 - win11
env:
TG_CHAT_ID: ${{ secrets.TG_CHAT_ID }}
TG_THREAD_ID: ${{ secrets.TG_THREAD_ID }}
defaults: defaults:
run: run:
@@ -50,6 +53,17 @@ jobs:
New-Item -ItemType Directory -Path ".tools\\lslib" -Force | Out-Null New-Item -ItemType Directory -Path ".tools\\lslib" -Force | Out-Null
New-Item -ItemType Directory -Path "build" -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 = "⏳ <b>Старт сборки релиза</b>`n<b>Репозиторий:</b> <code>${{ gitea.repository }}</code>`n<b>Тег:</b> <code>${{ gitea.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 -DisableNotification
- name: Download latest LSLib release - name: Download latest LSLib release
run: | run: |
$ErrorActionPreference = "Stop" $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 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 = "🏁 <b>Релиз собран успешно</b>`n<b>Тег:</b> <code>${{ gitea.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(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 = "❌ <b>Сборка релиза завершилась ошибкой</b>`n<b>Тег:</b> <code>${{ gitea.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

View File

@@ -12,10 +12,10 @@ permissions:
jobs: jobs:
build: build:
runs-on: windows-latest runs-on: windows-latest
environment: TgBot environment: Configure TgBot
env: env:
TG_CHAT_ID: -1003975565934 TG_CHAT_ID: ${{ secrets.TG_CHAT_ID }}
TG_THREAD_ID: 2 TG_THREAD_ID: ${{ secrets.TG_THREAD_ID }}
defaults: defaults:
run: run:

4
.gitignore vendored
View File

@@ -2,6 +2,10 @@ build/
build-stage* build-stage*
.tools/ .tools/
.cache/ .cache/
.env
.env.local
.env.*
!.env.example
*.pak *.pak
*.tmp *.tmp
*.temp *.temp

View File

@@ -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. - 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/*`: After work in `fix/*` or `feat/*`:
1. merge changes directly into `main` and delete the source branch 1. create PR/MR targeting `main`
2. create PR/MR targeting `main` 2. merge changes into `main` and delete the source branch
Push failure: Push failure:
- retry ≤2 times, 3s delay - retry ≤2 times, 3s delay
@@ -70,6 +70,8 @@ Forbidden:
- CI: `.gitea/workflows/build.yml` - CI: `.gitea/workflows/build.yml`
- Glossary: `glossary/glossary.normalized.json` _(primary terminology reference)_ - Glossary: `glossary/glossary.normalized.json` _(primary terminology reference)_
- Actions: `ACTIONS.md` - 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` - Upstream EN reference: `https://github.com/Yoonmoonsik/dnd55e/blob/main/Mods/DnD2024_897914ef-5c96-053c-44af-0be823f895fe/Localization/English/english.xml`
--- ---

View File

@@ -1,12 +1,12 @@
[CmdletBinding()] [CmdletBinding()]
param( param(
[Parameter(Mandatory = $true)] [Parameter()]
[string]$BotToken, [string]$BotToken,
[Parameter(Mandatory = $true)] [Parameter()]
[string]$ChatId, [string]$ChatId,
[Parameter(Mandatory = $true)] [Parameter()]
[string]$ThreadId, [string]$ThreadId,
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
@@ -17,6 +17,80 @@ param(
$ErrorActionPreference = "Stop" $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. $normalizedText = $Text.
Replace("``r``n", "`r`n"). Replace("``r``n", "`r`n").
Replace("``n", "`n"). Replace("``n", "`n").