From 5d01d8e50e5bdba15d70b306139064f16a058c0c Mon Sep 17 00:00:00 2001 From: Doug Gerard Date: Mon, 13 Apr 2026 20:56:54 -0600 Subject: [PATCH] Add GitHub Actions workflow with tag-driven NuGet publishing Build and test on PRs and master pushes. NuGet pack and push only on version tags (v*). Version is derived from the tag name. Co-Authored-By: Claude Opus 4.6 (1M context) --- .github/workflows/build-and-publish.yml | 48 +++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 .github/workflows/build-and-publish.yml diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/build-and-publish.yml new file mode 100644 index 0000000..41a57bc --- /dev/null +++ b/.github/workflows/build-and-publish.yml @@ -0,0 +1,48 @@ +name: Build and Publish + +on: + push: + branches: [master] + tags: ['v*'] + pull_request: + branches: [master] + +jobs: + build: + runs-on: windows-latest + + steps: + - uses: actions/checkout@v4 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '10.x' + + - name: Determine version + id: version + shell: pwsh + run: | + if ($env:GITHUB_REF -like 'refs/tags/v*') { + $version = $env:GITHUB_REF -replace 'refs/tags/v', '' + } else { + $version = "0.0.0-ci.${{ github.run_number }}" + } + echo "PackageVersion=$version" >> $env:GITHUB_ENV + Write-Host "Version: $version" + + - name: Restore + run: dotnet restore + + - name: Build + run: dotnet build --configuration Release --no-restore -p:PackageVersion=${{ env.PackageVersion }} + + - name: Test + run: dotnet test tests/CodeStructure.Analyzers.Tests/CodeStructure.Analyzers.Tests.csproj --configuration Release --no-build + + - name: Pack + run: dotnet pack CodeStructure.Analyzers/CodeStructure.Analyzers.csproj --configuration Release --no-build --output ./nupkg -p:PackageVersion=${{ env.PackageVersion }} + + - name: Push to NuGet + if: startsWith(github.ref, 'refs/tags/v') + run: dotnet nuget push ./nupkg/*.nupkg --api-key ${{ secrets.CodeStructureNuGetKey }} --source https://api.nuget.org/v3/index.json --skip-duplicate