|
| 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 }} |
0 commit comments