Skip to content

Commit 46967ab

Browse files
authored
ci(nuget): allow auto or explicit package version in workflow (#440)
Add flexible version management to NuGet workflow: - New `version` input parameter with default "latest" for workflow dispatch - Auto-generate date-based version (yyyy.MM.dd.0) when "latest" is specified - Validate version format follows X.Y.Z.W pattern - Dynamically set package version in .csproj before building This enables both automatic versioning and explicit version control.
1 parent 5a1ed6d commit 46967ab

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

.github/workflows/nuget.yml

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ on:
88
required: true
99
type: boolean
1010
default: true
11+
version:
12+
description: 'Package version (defaults to auto-generated date-based version)'
13+
required: false
14+
type: string
15+
default: 'latest'
1116
schedule:
1217
- cron: '21 3 * * 1' # 3:21 AM UTC every Monday
1318

@@ -36,11 +41,26 @@ jobs:
3641
}
3742
shell: pwsh
3843

44+
- name: Package information
45+
id: package-info
46+
run: |
47+
$Version = '${{ github.event.inputs.version }}'
48+
if ($Version -eq '' -or $Version -eq 'latest') {
49+
$Version = (Get-Date -Format "yyyy.MM.dd") + ".0"
50+
}
51+
52+
if ($Version -notmatch '^\d+\.\d+\.\d+\.\d+$') {
53+
throw "Invalid version format. Expected X.Y.Z.W, got: $Version"
54+
}
55+
56+
echo "Computed package version: $Version"
57+
echo "package-version=$Version" >> $Env:GITHUB_OUTPUT
58+
shell: pwsh
59+
3960
- name: Get version
4061
id: get-version
4162
run: |
42-
$CsprojXml = [Xml] (Get-Content .\ffi\dotnet\Devolutions.Picky\Devolutions.Picky.csproj)
43-
$ProjectVersion = $CsprojXml.Project.PropertyGroup.Version | Select-Object -First 1
63+
$ProjectVersion = '${{ steps.package-info.outputs.package-version }}'
4464
$PackageVersion = $ProjectVersion -Replace "^(\d+)\.(\d+)\.(\d+).(\d+)$", "`$1.`$2.`$3"
4565
echo "project-version=$ProjectVersion" >> $Env:GITHUB_OUTPUT
4666
echo "package-version=$PackageVersion" >> $Env:GITHUB_OUTPUT
@@ -270,7 +290,7 @@ jobs:
270290

271291
build-managed:
272292
name: Managed build
273-
needs: [build-universal]
293+
needs: [preflight, build-universal]
274294
runs-on: windows-2022
275295

276296
steps:
@@ -297,6 +317,18 @@ jobs:
297317
Get-ChildItem * -Recurse
298318
shell: pwsh
299319

320+
- name: Set package version
321+
run: |
322+
$Version = '${{ needs.preflight.outputs.project-version }}'
323+
$CsprojPath = '.\ffi\dotnet\Devolutions.Picky\Devolutions.Picky.csproj'
324+
325+
$Content = Get-Content $CsprojPath -Raw
326+
$Content = $Content -replace '<Version>[\d\.]+</Version>', "<Version>$Version</Version>"
327+
Set-Content -Path $CsprojPath -Value $Content
328+
329+
echo "Package version set to: $Version"
330+
shell: pwsh
331+
300332
- name: Build picky (managed)
301333
run: |
302334
dotnet build .\ffi\dotnet\Devolutions.Picky\Devolutions.Picky.csproj -c Release

ffi/dotnet/Devolutions.Picky/Devolutions.Picky.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<Company>Devolutions</Company>
66
<Description>Bindings to Rust picky native library</Description>
77
<LangVersion>latest</LangVersion>
8-
<Version>2025.10.9.0</Version>
8+
<Version>0.0.0.0</Version>
99
<ImplicitUsings>disable</ImplicitUsings>
1010
<Nullable>enable</Nullable>
1111
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

0 commit comments

Comments
 (0)