add readme #17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Generate bindings and publish Interop | |
| name: Generate bindings and publish Interop | |
| # Trigger workflow on push to any branch and manual dispatch | |
| on: | |
| push: | |
| branches: | |
| - '**' | |
| workflow_dispatch: | |
| jobs: | |
| generate-and-publish: | |
| runs-on: windows-latest | |
| steps: | |
| # Check out the source code from repository | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| # Set up .NET 8 SDK for build and packaging | |
| - name: Setup .NET SDK | |
| uses: actions/setup-dotnet@v3 | |
| with: | |
| dotnet-version: '10.x' | |
| # Download dependencies and generate interop bindings via ClangSharp | |
| - name: Download dependencies & generate bindings | |
| shell: pwsh | |
| run: | | |
| cd generation | |
| ./Download.ps1 | |
| dotnet tool restore | |
| dotnet ClangSharpPInvokeGenerator "@GenerateOpenSlide.rsp" | |
| # Update project version with valid NuGet version string (4-segment, all parts ≤65535) | |
| - name: Update csproj version with valid build number | |
| shell: pwsh | |
| run: | | |
| # Define path to the target csproj file | |
| $csprojPath = 'src/OpenSlideSharp.Interop/OpenSlideSharp.Interop.csproj' | |
| # Validate csproj file exists | |
| if (-not (Test-Path $csprojPath)) { | |
| Write-Error "Project file not found at path: $csprojPath" | |
| exit 1 | |
| } | |
| # Load XML project file and preserve whitespace formatting | |
| $xmlDoc = New-Object System.Xml.XmlDocument | |
| $xmlDoc.PreserveWhitespace = $true | |
| $xmlDoc.Load($csprojPath) | |
| # Select PropertyGroup with Version node or first PropertyGroup as fallback | |
| $propertyGroup = $xmlDoc.SelectSingleNode("//PropertyGroup[Version]") ?? $xmlDoc.SelectSingleNode("//PropertyGroup[1]") | |
| if (-not $propertyGroup) { | |
| Write-Error "No valid PropertyGroup found in project file" | |
| exit 1 | |
| } | |
| # Get existing Version node or create new one if missing | |
| $versionNode = $propertyGroup.SelectSingleNode("Version") | |
| if (-not $versionNode) { | |
| $versionNode = $xmlDoc.CreateElement("Version") | |
| $propertyGroup.AppendChild($versionNode) | Out-Null | |
| } | |
| # Generate valid NuGet version: Major.Minor.DaysSinceBaseDate.RunNumber | |
| # All parts ≤ 65535 to comply with NuGet version rules | |
| $baseDate = Get-Date "2025-01-01" | |
| $currentDate = Get-Date | |
| $daysSinceBase = ($currentDate - $baseDate).Days | |
| $buildRunNumber = $env:GITHUB_RUN_NUMBER | |
| $validVersion = "1.0.$daysSinceBase.$buildRunNumber" | |
| # Update version and save changes to csproj | |
| $versionNode.InnerText = $validVersion | |
| $xmlDoc.Save($csprojPath) | |
| Write-Host "Successfully updated project version to: $validVersion" | |
| # Build project - NuGet package auto-generated via GeneratePackageOnBuild in csproj | |
| - name: Build project & generate NuGet package | |
| run: | | |
| dotnet build src/OpenSlideSharp.Interop/OpenSlideSharp.Interop.csproj -c Release --no-incremental | |
| # Push NuGet packages to NuGet.org ONLY when running on main branch | |
| - name: Push package to NuGet.org | |
| if: github.ref == 'refs/heads/master' | |
| shell: pwsh | |
| run: | | |
| # Find all generated nupkg files (exclude symbol packages) | |
| $nugetPackages = Get-ChildItem -Recurse -Filter "*.nupkg" | Where-Object { $_.Name -notmatch "\.symbols\." } | |
| # Push each package to NuGet.org with skip duplicate option | |
| foreach ($package in $nugetPackages) { | |
| dotnet nuget push $package.FullName ` | |
| --api-key ${{ secrets.NUGET_API_KEY }} ` | |
| --source https://api.nuget.org/v3/index.json ` | |
| --skip-duplicate | |
| } |