name: Build Mod Package
on:
push:
tags:
- "v*"
workflow_dispatch:
permissions:
contents: write
jobs:
build:
runs-on: windows-latest
environment: Configure TgBot
env:
TG_CHAT_ID: ${{ secrets.TG_CHAT_ID }}
TG_THREAD_ID: ${{ secrets.TG_THREAD_ID }}
defaults:
run:
shell: pwsh
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Prepare workspace
run: |
$ErrorActionPreference = "Stop"
if (-not (Test-Path -LiteralPath "Mods\\DnD 5.5e AIO Russian\\Localization\\Russian\\russian.xml")) {
throw "Repository sources are not available in the runner workspace."
}
New-Item -ItemType Directory -Path ".tools\\lslib" -Force | Out-Null
New-Item -ItemType Directory -Path "build" -Force | Out-Null
- name: Resolve version tag
id: vars
run: |
$ErrorActionPreference = "Stop"
$versionTag = ""
$isPrerelease = "false"
if ($env:GITHUB_REF -like "refs/tags/v*") {
$versionTag = $env:GITHUB_REF_NAME
if ($versionTag -match '^v\d+\.\d+\.\d+-') {
$isPrerelease = "true"
}
}
"version_tag=$versionTag" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
"is_prerelease=$isPrerelease" | 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"
$release = Invoke-RestMethod -Uri "https://api.github.com/repos/Norbyte/lslib/releases/latest"
$asset = $release.assets | Where-Object { $_.name -match '\.zip$' } | Select-Object -First 1
if (-not $asset) {
throw "Could not find a downloadable LSLib zip asset in the latest release."
}
Invoke-WebRequest -UseBasicParsing -Uri $asset.browser_download_url -OutFile ".tools/lslib/lslib.zip"
Expand-Archive -LiteralPath ".tools/lslib/lslib.zip" -DestinationPath ".tools/lslib" -Force
- name: Build .pak
run: |
$ErrorActionPreference = "Stop"
$divine = Get-ChildItem -Path ".tools\\lslib" -Recurse -File |
Where-Object { $_.Name -ieq "Divine.exe" } |
Select-Object -First 1
if (-not $divine) {
throw "Divine.exe was not found in the downloaded LSLib release."
}
& ".\\scripts\\build.ps1" -DivinePath $divine.FullName -Workspace "${{ github.workspace }}" -VersionTag "${{ steps.vars.outputs.version_tag }}"
- name: Show build result
run: |
$ErrorActionPreference = "Stop"
$archiveBaseName = "DnD 5.5e AIO Russian"
if ($env:GITHUB_REF -like "refs/tags/v*") {
$archiveBaseName = "DnD 5.5e AIO Russian $env:GITHUB_REF_NAME"
}
$zipPath = [System.IO.Path]::GetFullPath((Join-Path "${{ github.workspace }}" "build/$archiveBaseName.zip"))
Get-ChildItem "build/DnD 5.5e AIO Russian.pak", "build/info.json", $zipPath |
Select-Object FullName, Length, LastWriteTime
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: bg3-dnd55e-russian-localization-${{ github.run_number }}
path: build/*
if-no-files-found: error
- name: Create or update GitHub release
if: startsWith(github.ref, 'refs/tags/v')
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$ErrorActionPreference = "Stop"
$tagName = "${{ github.ref_name }}"
$zipPath = Join-Path $env:GITHUB_WORKSPACE "build\\DnD 5.5e AIO Russian $tagName.zip"
$isPrerelease = "${{ steps.vars.outputs.is_prerelease }}" -eq "true"
if (-not (Test-Path -LiteralPath $zipPath)) {
throw "Release archive was not found at '$zipPath'."
}
gh release view $tagName --repo "${{ github.repository }}" *> $null
if ($LASTEXITCODE -ne 0) {
$args = @(
"release", "create", $tagName, $zipPath,
"--repo", "${{ github.repository }}",
"--title", $tagName,
"--notes", ""
)
if ($isPrerelease) {
$args += "--prerelease"
}
gh @args
}
else {
gh release upload $tagName $zipPath `
--repo "${{ github.repository }}" `
--clobber
$releaseId = gh release view $tagName `
--repo "${{ github.repository }}" `
--json id `
--jq ".id"
$releaseBodyPath = Join-Path $env:RUNNER_TEMP "release-body.json"
@{
name = $tagName
prerelease = $isPrerelease
} | ConvertTo-Json -Compress | Set-Content -LiteralPath $releaseBodyPath -Encoding utf8
gh api `
--method PATCH `
-H "Accept: application/vnd.github+json" `
"/repos/${{ github.repository }}/releases/$releaseId" `
--input $releaseBodyPath
}
- 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