From 3428b56eef20cd24a3d6381864c9839985fb3b03 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Wed, 11 Nov 2026 00:05:15 -0800 Subject: [PATCH] ci: test on .NET 10 and .NET 11; publish to NuGet with trusted publishing The tests target net10.0 and net11.0, and a Build and Test workflow runs them on pull requests and on main. The expected generator output now uses ReplaceLineEndings(), so the test passes on a CRLF checkout instead of doubling the carriage return. The publish workflow is the trusted publishing setup the other package repos use: manual dispatch from main, the nuget environment, an OIDC login, and --skip-duplicate. The generator and annotations stay netstandard2.0 and keep their versions; nothing in the packages changes. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/publish.yml | 50 +++++++++++++++++++ .github/workflows/test.yml | 30 +++++++++++ .../CodeGeneratedEvents.Tests.csproj | 2 +- CodeGeneratedEvents.Tests/TestEvents.cs | 6 +-- 4 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..28574f2 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,50 @@ +name: Publish to NuGet + +# Trusted publishing: nuget.org trusts this repo + this workflow file (+ the "nuget" environment) +# and exchanges the job's GitHub OIDC token for a short-lived API key. No long-lived key is stored. +# Renaming this file or the environment breaks the nuget.org policy until it is updated to match. + +on: + workflow_dispatch: + +permissions: + contents: read + +jobs: + publish: + if: github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + environment: nuget + permissions: + contents: read + id-token: write + + env: + PACKAGE_DIR: ${{ github.workspace }}/packages + + steps: + - uses: actions/checkout@v7 + + - uses: actions/setup-dotnet@v6 + with: + dotnet-version: '11.0.x' + + # GeneratePackageOnBuild=true makes pack skip its build, packing an empty bin/ on a clean runner. + # Pack before logging in: the temporary key expires after an hour. + - name: Pack + run: | + dotnet pack CodeGeneratedEvents.Annotations/CodeGeneratedEvents.Annotations.csproj -c Release -p:GeneratePackageOnBuild=false -o "$PACKAGE_DIR" + dotnet pack CodeGeneratedEvents/CodeGeneratedEvents.csproj -c Release -p:GeneratePackageOnBuild=false -o "$PACKAGE_DIR" + + - name: NuGet login (OIDC) + id: login + uses: NuGet/login@v1 + with: + user: ${{ secrets.NUGET_USER }} + + - name: Push + run: > + dotnet nuget push "$PACKAGE_DIR/*.nupkg" + --api-key "${{ steps.login.outputs.NUGET_API_KEY }}" + --source https://api.nuget.org/v3/index.json + --skip-duplicate diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..4a16c64 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,30 @@ +name: Build and Test + +on: + push: + branches: [ main ] + pull_request: + +jobs: + build-and-test: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup .NET SDK + uses: actions/setup-dotnet@v4 + with: + dotnet-version: | + 10.0.x + 11.0.x + + - name: Restore dependencies + run: dotnet restore + + - name: Build + run: dotnet build -c Release --no-restore + + - name: Test + run: dotnet test -c Release --no-build --verbosity normal diff --git a/CodeGeneratedEvents.Tests/CodeGeneratedEvents.Tests.csproj b/CodeGeneratedEvents.Tests/CodeGeneratedEvents.Tests.csproj index 5737a6c..2ea3d8c 100644 --- a/CodeGeneratedEvents.Tests/CodeGeneratedEvents.Tests.csproj +++ b/CodeGeneratedEvents.Tests/CodeGeneratedEvents.Tests.csproj @@ -1,7 +1,7 @@ - net8.0 + net10.0;net11.0 enable enable diff --git a/CodeGeneratedEvents.Tests/TestEvents.cs b/CodeGeneratedEvents.Tests/TestEvents.cs index d4a8bd9..a9ec2af 100644 --- a/CodeGeneratedEvents.Tests/TestEvents.cs +++ b/CodeGeneratedEvents.Tests/TestEvents.cs @@ -45,7 +45,7 @@ public static void OnMyEvent2(string arg1, string arg2) } } - """.Replace("\n", Environment.NewLine).TrimStart(); + """.ReplaceLineEndings().TrimStart(); var source2 = """ @@ -60,7 +60,7 @@ public static partial class TestEvents2 public static partial void MyEvent(string arg1, string arg2); } - """.Replace("\n", Environment.NewLine).TrimStart(); + """.ReplaceLineEndings().TrimStart(); var expectedGeneratedCode = $$""" @@ -84,7 +84,7 @@ public static partial void MyEvent(string arg1, string arg2) } } - """.Replace("\n", Environment.NewLine).TrimStart(); + """.ReplaceLineEndings().TrimStart(); // Act var generatedCode = await GetGeneratedOutputAsync(generator, source1, source2);