Skip to content

Commit 56a0595

Browse files
committed
Add workflow to publish .NET packages
1 parent d0da91b commit 56a0595

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Publish .NET Library to Package Repositories
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
8+
jobs:
9+
publish-prism:
10+
name: Build and publish Prism library to GitHub Packages and NuGet
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write
14+
actions: write
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up .NET environment
20+
uses: actions/setup-dotnet@v4
21+
with:
22+
dotnet-version: '6.0' # Adjust if using a different version
23+
24+
- name: Create Generated directory
25+
run: mkdir -p Generated
26+
27+
- name: Restore dependencies
28+
run: dotnet restore Prism.csproj
29+
30+
- name: Set Version
31+
run: |
32+
VERSION=${GITHUB_REF#refs/tags/}
33+
echo "VERSION=$VERSION" >> $GITHUB_ENV
34+
echo "MAJOR_VERSION=$(echo $VERSION | cut -d. -f1)" >> $GITHUB_ENV
35+
echo "MINOR_VERSION=$(echo $VERSION | cut -d. -f2)" >> $GITHUB_ENV
36+
37+
- name: Generate Version File
38+
run: |
39+
echo "namespace Polypheny.Prism { public static class Version { public const string Major = \"$MAJOR_VERSION\"; public const string Minor = \"$MINOR_VERSION\"; } }" > Generated/Version.cs
40+
# Assumes Generated directory is committed or added during build
41+
42+
- name: Build the project
43+
run: dotnet build Prism.csproj --no-restore -c Release -o ./Generated
44+
45+
- name: Test the project
46+
run: dotnet test Prism.csproj --no-build -c Release
47+
48+
- name: Pack the project
49+
run: dotnet pack Prism.csproj --no-build -c Release --output ./nupkgs
50+
51+
- name: Publish to GitHub Packages
52+
run: dotnet nuget push "./nupkgs/*.nupkg" --source "github" --skip-duplicate
53+
env:
54+
NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
56+
- name: Publish to NuGet
57+
run: dotnet nuget push "./nupkgs/*.nupkg" --source "nuget.org" --skip-duplicate
58+
env:
59+
NUGET_AUTH_TOKEN: ${{ secrets.NUGET_API_KEY }}

Prism.csproj

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<OutputType>Library</OutputType>
6+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
7+
<!-- Specify output directory for generated code -->
8+
<Protobuf_OutputDir>Generated</Protobuf_OutputDir>
9+
</PropertyGroup>
10+
11+
<!-- Add necessary package references -->
12+
<ItemGroup>
13+
<PackageReference Include="Google.Protobuf" Version="3.26.1" />
14+
<PackageReference Include="Grpc.Tools" Version="2.63.0">
15+
<PrivateAssets>all</PrivateAssets>
16+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
17+
</PackageReference>
18+
</ItemGroup>
19+
20+
<!-- Protobuf configurations -->
21+
<ItemGroup>
22+
<Protobuf Include="org/polypheny/prism/*.proto" OutputDir="$(Protobuf_OutputDir)" GrpcServices="None" />
23+
</ItemGroup>
24+
25+
</Project>

0 commit comments

Comments
 (0)