From c1572e24ed3d29a8ebbc77ed8c30518b9991ad17 Mon Sep 17 00:00:00 2001 From: Renan Carlos Pereira Date: Wed, 3 Jul 2024 21:15:44 +0100 Subject: [PATCH] Automate NuGet Package Creation and GitHub Release Process (#44) --- .github/workflows/dotnetcore-release.yml | 68 ++++++++++++++++++ .../RulesEngineBenchmark.csproj | 1 + demo/DemoApp/DemoApp.csproj | 1 + deployment/build-signed.ps1 | 1 + signing/RulesEngine-publicKey.snk | Bin 160 -> 596 bytes src/RulesEngine/Properties/AssemblyInfo.cs | 2 +- .../RulesEngine.UnitTest.csproj | 1 + 7 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/dotnetcore-release.yml diff --git a/.github/workflows/dotnetcore-release.yml b/.github/workflows/dotnetcore-release.yml new file mode 100644 index 00000000..681bc15d --- /dev/null +++ b/.github/workflows/dotnetcore-release.yml @@ -0,0 +1,68 @@ +name: Build and Publish NuGet Package + +on: + push: + tags: + - 'v*.*.*' + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup .NET Core + uses: actions/setup-dotnet@v2 + with: + dotnet-version: '8.0.x' + + - name: Restore dependencies + run: dotnet restore + + - name: Sign and Build Project + env: + SIGNING_KEY: ${{ secrets.SIGNING_KEY }} + run: | + pwsh -File ./deployment/build-signed.ps1 -csprojFilePath './src/RulesEngine/RulesEngine.csproj' -signingKey $SIGNING_KEY + + - name: Create NuGet package + run: | + # Extract version from the tag + VERSION=$(echo ${{ github.ref }} | sed 's/refs\/tags\/v//') + # Create the NuGet package with the version from the tag + dotnet pack --configuration Release --no-build --output ./nuget_packages /p:PackageVersion=$VERSION + + - name: Publish NuGet package to NuGet.org + env: + NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} + run: dotnet nuget push ./nuget_packages/*.nupkg -k $NUGET_API_KEY -s https://api.nuget.org/v3/index.json + + - name: Create source code zip + run: | + git archive -o source.zip HEAD + continue-on-error: true + + - name: Create source code tar + run: | + git archive -o source.tar.gz HEAD + continue-on-error: true + + - name: Upload artifacts + uses: actions/upload-artifact@v2 + with: + name: source-archives + path: | + source.zip + source.tar.gz + + - name: Create GitHub Release + uses: softprops/action-gh-release@v1 + with: + files: | + ./nuget_packages/*.nupkg + source.zip + source.tar.gz + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/benchmark/RulesEngineBenchmark/RulesEngineBenchmark.csproj b/benchmark/RulesEngineBenchmark/RulesEngineBenchmark.csproj index 45c7a272..92c37e77 100644 --- a/benchmark/RulesEngineBenchmark/RulesEngineBenchmark.csproj +++ b/benchmark/RulesEngineBenchmark/RulesEngineBenchmark.csproj @@ -3,6 +3,7 @@ Exe net8.0 + false diff --git a/demo/DemoApp/DemoApp.csproj b/demo/DemoApp/DemoApp.csproj index b570a1cb..912416d8 100644 --- a/demo/DemoApp/DemoApp.csproj +++ b/demo/DemoApp/DemoApp.csproj @@ -4,6 +4,7 @@ Exe net8.0 DemoApp.Program + false diff --git a/deployment/build-signed.ps1 b/deployment/build-signed.ps1 index b6c57b43..84460d2f 100644 --- a/deployment/build-signed.ps1 +++ b/deployment/build-signed.ps1 @@ -8,6 +8,7 @@ param( # sign and build the project $directory = Split-Path $csprojFilePath; $signKeyFile = Join-Path $directory "signKey.snk"; +$signKeyFile = [System.IO.Path]::GetFullPath($signKeyFile) $bytes = [Convert]::FromBase64String($signingKey) [IO.File]::WriteAllBytes($signKeyFile, $bytes) diff --git a/signing/RulesEngine-publicKey.snk b/signing/RulesEngine-publicKey.snk index 10341c93a5a5e47a0f6a5cebc30a6533b5a88d71..8bc1fb0f62cd2e7bc502e5df30a7442f8861b2a8 100644 GIT binary patch literal 596 zcmV-a0;~N80ssI2Bme+XQ$aES1ONa50096IEyoma`CUysy&Pep?Jv9pfYUOn29qpG z$wdn?8?J}0UwD})rB;G_ugzB~ZS=e8y!++b4 z4Kr<*T>I;b!wIFG!U%#SlfjzR&J28zN;1kt7Yk6rKSmEKPMxBl2`@NdZF!npMmr|IvblznW>-X7fRv zm1)a0)(u_~EEV_%h>k*GY@(H;<D z#V@f4GHI(7jmP+OnqZuH(3ay_4c{;M4>HG8# zTdCtms)cD1gjw?)q4qU?tLEV_ipRlghosgXjTePTrue ..\..\signing\RulesEngine-publicKey.snk True + false