Skip to content

Commit e5a06b2

Browse files
committed
Improve version resolution in build workflow
Enhanced the PowerShell script in build-and-release.yml to support MSBuild property token replacement (e.g., $(VersionSuffix), $(TimeStamp)) when extracting the version from Directory.Packages.props. Also deleted the legacy release.yml workflow, consolidating release logic into the updated build-and-release workflow.
1 parent e08caf5 commit e5a06b2

2 files changed

Lines changed: 27 additions & 369 deletions

File tree

‎.github/workflows/build-and-release.yml‎

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,34 @@ jobs:
4949
id: version
5050
shell: pwsh
5151
run: |
52+
$ErrorActionPreference = 'Stop'
5253
[xml]$xml = Get-Content -Raw "Directory.Packages.props"
53-
$v = $xml.Project.PropertyGroup.Version
54-
if (-not $v) { throw "Version not found in Directory.Packages.props" }
55-
echo "PKG_VERSION=$v" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
56-
echo "RELEASE_TAG=v$($v)" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
57-
Write-Host "Using version: $v"
54+
$pg = $xml.Project.PropertyGroup
55+
$versionTemplate = [string]$pg.Version
56+
if ([string]::IsNullOrWhiteSpace($versionTemplate)) { throw "Version not found in Directory.Packages.props" }
57+
# Build a property map from PropertyGroup
58+
$props = @{}
59+
foreach ($n in $pg.ChildNodes) {
60+
if ($n.NodeType -eq [System.Xml.XmlNodeType]::Element) {
61+
$props[$n.Name] = [string]$n.InnerText
62+
}
63+
}
64+
# Provide concrete TimeStamp replacement (UTC yyyyMMdd) if used
65+
$props['TimeStamp'] = (Get-Date -AsUTC).ToString('yyyyMMdd')
66+
# Replace $(Property) tokens (e.g., $(VersionSuffix), $(TimeStamp))
67+
$unresolved = New-Object System.Collections.Generic.List[string]
68+
$finalVersion = [regex]::Replace($versionTemplate, '\$\(([A-Za-z0-9_.-]+)\)', {
69+
param($m)
70+
$name = $m.Groups[1].Value
71+
if ($props.ContainsKey($name) -and -not [string]::IsNullOrWhiteSpace($props[$name])) { $props[$name] } else { $unresolved.Add($name) | Out-Null; '' }
72+
})
73+
if ($unresolved.Count -gt 0) { Write-Host "[warn] Unresolved version tokens -> $($unresolved -join ', '); replaced with empty string." }
74+
if ([string]::IsNullOrWhiteSpace($finalVersion)) { throw "Resolved version is empty" }
75+
"PKG_VERSION=$finalVersion" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
76+
"RELEASE_TAG=v$finalVersion" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
77+
"version=$finalVersion" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
78+
Write-Host "Version template: $versionTemplate"
79+
Write-Host "Final version: $finalVersion"
5880
5981
- name: Build frontend (Vite -> src/KoalaWiki/wwwroot)
6082
working-directory: ${{ env.FRONTEND_DIR }}

0 commit comments

Comments
 (0)