Skip to content

Commit 0d78b1a

Browse files
committed
Implement dynamic package versioning and update CI/CD workflow for NuGet packaging
1 parent c01152d commit 0d78b1a

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

.github/workflows/build.yml

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,29 @@ jobs:
158158
- name: Restore dependencies
159159
run: dotnet restore
160160

161+
- name: Determine Version
162+
id: version
163+
run: |
164+
# Get the latest git tag or use 1.0.0 as default
165+
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v1.0.0")
166+
167+
# Remove 'v' prefix if present
168+
VERSION=${LATEST_TAG#v}
169+
170+
# If not on a tag, add pre-release suffix with commit count and short SHA
171+
if ! git describe --exact-match --tags HEAD >/dev/null 2>&1; then
172+
COMMITS_SINCE_TAG=$(git rev-list --count ${LATEST_TAG}..HEAD 2>/dev/null || echo "0")
173+
SHORT_SHA=$(git rev-parse --short HEAD)
174+
VERSION="${VERSION}-alpha.${COMMITS_SINCE_TAG}+${SHORT_SHA}"
175+
fi
176+
echo "version=${VERSION}" >> $GITHUB_OUTPUT
177+
echo "📦 Determined version: ${VERSION}"
178+
161179
- name: Build (Release) for packaging
162180
run: dotnet build src/NLWebNet --configuration Release --no-restore --verbosity minimal
163181

164182
- name: Pack NuGet package
165-
run: dotnet pack src/NLWebNet --configuration Release --no-build --output ./packages
183+
run: dotnet pack src/NLWebNet --configuration Release --no-build --output ./packages -p:PackageVersion=${{ steps.version.outputs.version }}
166184

167185
- name: Upload package artifacts
168186
uses: actions/upload-artifact@v4
@@ -172,6 +190,9 @@ jobs:
172190
retention-days: 30
173191

174192
- name: Validate NuGet Package
175-
uses: NuGetPackageExplorer/ValidatePackage@v1
176-
with:
177-
packagePath: ./packages/NLWebNet.1.0.0-alpha.nupkg
193+
run: |
194+
echo "📦 Validating NuGet package..."
195+
dotnet tool install --global dotnet-validate --version 0.0.1-preview.537
196+
PACKAGE_FILE=$(find ./packages -name "*.nupkg" | head -n 1)
197+
echo "Validating package: $PACKAGE_FILE"
198+
dotnet validate package local "$PACKAGE_FILE"

doc/todo.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ The demo application is now fully functional with a modern .NET 9 Blazor Web App
5050
-**CI/CD Testing Fix**: Updated GitHub Actions workflow to gracefully handle missing test projects and prevent build failures
5151
-**CI/CD Packaging Fix**: Added Release build step to package-validation job to ensure NuGet DLL is available for packaging
5252
-**CI/CD Symbol Generation**: Fixed NuGet package validation by adding proper symbol generation, deterministic builds, and Source Link integration
53+
-**Dynamic Package Versioning**: Implemented Git-based semantic versioning with automatic pre-release numbering for CI builds
5354

5455
The next phase focuses on implementing the core NLWeb library functionality.
5556

src/NLWebNet/NLWebNet.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
<Nullable>enable</Nullable>
44
<ImplicitUsings>enable</ImplicitUsings>
55
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
6-
7-
<!-- Package Metadata -->
6+
<!-- Package Metadata -->
87
<PackageId>NLWebNet</PackageId>
9-
<PackageVersion>1.0.0-alpha</PackageVersion>
8+
<PackageVersion Condition="'$(PackageVersion)' == ''">1.0.0-dev</PackageVersion>
109
<Authors>NLWebNet Contributors</Authors>
1110
<Description>A .NET library implementing the NLWeb protocol for natural language web interfaces</Description>
1211
<PackageProjectUrl>https://github.com/microsoft/NLWeb</PackageProjectUrl>

0 commit comments

Comments
 (0)