Derive mod version from release tag during build
Some checks failed
Build Mod Package / build (push) Failing after 11s
Some checks failed
Build Mod Package / build (push) Failing after 11s
This commit is contained in:
@@ -17,6 +17,34 @@ param(
|
|||||||
|
|
||||||
$ErrorActionPreference = "Stop"
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
|
function Convert-VersionTagToVersion64 {
|
||||||
|
param(
|
||||||
|
[string]$Tag,
|
||||||
|
[string]$FallbackVersion64
|
||||||
|
)
|
||||||
|
|
||||||
|
if (-not $Tag) {
|
||||||
|
return [int64]$FallbackVersion64
|
||||||
|
}
|
||||||
|
|
||||||
|
$normalized = $Tag
|
||||||
|
if ($normalized.StartsWith("v")) {
|
||||||
|
$normalized = $normalized.Substring(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($normalized -notmatch '^\d+(\.\d+){0,3}$') {
|
||||||
|
return [int64]$FallbackVersion64
|
||||||
|
}
|
||||||
|
|
||||||
|
$parts = $normalized.Split(".")
|
||||||
|
$numbers = @(0, 0, 0, 0)
|
||||||
|
for ($i = 0; $i -lt $parts.Length; $i++) {
|
||||||
|
$numbers[$i] = [int]$parts[$i]
|
||||||
|
}
|
||||||
|
|
||||||
|
return ([int64]$numbers[0] -shl 55) -bor ([int64]$numbers[1] -shl 47) -bor ([int64]$numbers[2] -shl 31) -bor [int64]$numbers[3]
|
||||||
|
}
|
||||||
|
|
||||||
$workspacePath = [System.IO.Path]::GetFullPath($Workspace)
|
$workspacePath = [System.IO.Path]::GetFullPath($Workspace)
|
||||||
$modsPath = Join-Path $workspacePath "Mods"
|
$modsPath = Join-Path $workspacePath "Mods"
|
||||||
$modPath = Join-Path $modsPath $ModFolder
|
$modPath = Join-Path $modsPath $ModFolder
|
||||||
@@ -31,6 +59,7 @@ if ($VersionTag) {
|
|||||||
}
|
}
|
||||||
$zipPath = Join-Path $buildPath "$archiveName.zip"
|
$zipPath = Join-Path $buildPath "$archiveName.zip"
|
||||||
$infoJsonPath = Join-Path $buildPath "info.json"
|
$infoJsonPath = Join-Path $buildPath "info.json"
|
||||||
|
$resolvedVersion64 = Convert-VersionTagToVersion64 -Tag $VersionTag -FallbackVersion64 $ModVersion64
|
||||||
|
|
||||||
if (-not (Test-Path -LiteralPath $DivinePath)) {
|
if (-not (Test-Path -LiteralPath $DivinePath)) {
|
||||||
$resolvedCommand = Get-Command $DivinePath -ErrorAction SilentlyContinue
|
$resolvedCommand = Get-Command $DivinePath -ErrorAction SilentlyContinue
|
||||||
@@ -67,6 +96,15 @@ if (Test-Path -LiteralPath $stagingRoot) {
|
|||||||
New-Item -ItemType Directory -Path $stagingPath -Force | Out-Null
|
New-Item -ItemType Directory -Path $stagingPath -Force | Out-Null
|
||||||
Copy-Item -LiteralPath $modsPath -Destination $stagingPath -Recurse
|
Copy-Item -LiteralPath $modsPath -Destination $stagingPath -Recurse
|
||||||
|
|
||||||
|
$stagedMetaPath = Join-Path $stagingPath "Mods\\$ModFolder\\meta.lsx"
|
||||||
|
if (-not (Test-Path -LiteralPath $stagedMetaPath)) {
|
||||||
|
throw "Staged meta.lsx was not found: '$stagedMetaPath'."
|
||||||
|
}
|
||||||
|
|
||||||
|
$stagedMetaContent = Get-Content -LiteralPath $stagedMetaPath -Raw
|
||||||
|
$stagedMetaContent = $stagedMetaContent -replace '(<attribute id="Version64" type="int64" value=")\d+("/>)', "`${1}$resolvedVersion64`${2}"
|
||||||
|
Set-Content -LiteralPath $stagedMetaPath -Value $stagedMetaContent -Encoding utf8
|
||||||
|
|
||||||
Write-Host "[build.ps1] Staged source tree:"
|
Write-Host "[build.ps1] Staged source tree:"
|
||||||
Get-ChildItem -Recurse $stagingPath | Select-Object FullName, Length | Format-Table -AutoSize
|
Get-ChildItem -Recurse $stagingPath | Select-Object FullName, Length | Format-Table -AutoSize
|
||||||
|
|
||||||
@@ -129,7 +167,7 @@ $infoJson = [ordered]@{
|
|||||||
Author = $ModAuthor
|
Author = $ModAuthor
|
||||||
Name = $ModName
|
Name = $ModName
|
||||||
Folder = $ModFolder
|
Folder = $ModFolder
|
||||||
Version = $ModVersion64
|
Version = [string]$resolvedVersion64
|
||||||
Description = $ModDescription
|
Description = $ModDescription
|
||||||
UUID = $ModUuid
|
UUID = $ModUuid
|
||||||
Created = $createdAt
|
Created = $createdAt
|
||||||
|
|||||||
Reference in New Issue
Block a user