Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion CodeGeneratedEvents.Tests/CodeGeneratedEvents.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net10.0;net11.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

Expand Down
6 changes: 3 additions & 3 deletions CodeGeneratedEvents.Tests/TestEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void OnMyEvent2(string arg1, string arg2)
}
}

""".Replace("\n", Environment.NewLine).TrimStart();
""".ReplaceLineEndings().TrimStart();

var source2 =
"""
Expand All @@ -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 =
$$"""
Expand All @@ -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);
Expand Down
Loading