From 933ec6acd6f1d95c71b611ff29f2c856c10867de Mon Sep 17 00:00:00 2001 From: John Nye Date: Fri, 5 Jul 2024 13:17:41 +0100 Subject: [PATCH] Setup Github Actions to push nuget --- .github/workflows/main.yml | 136 ++++++++++++++---- BuildNugetPackage.ps1 | 2 + .../NinjaNye.SearchExtensions.csproj | 2 +- 3 files changed, 111 insertions(+), 29 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index adbfb5f..d0bc6f1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,34 +1,114 @@ -name: Publish SearchExtensions package to NuGet +name: Publish to NuGet on: - push: + release: + types: [published] branches: - - main - tags: - - "v[0-9]+.[0-9]+.[0-9]+" + - main -jobs: - build-and-publish: +jobs: + build-and-test: runs-on: ubuntu-latest - + defaults: + run: + working-directory: NinjaNye.SearchExtensions steps: - - uses: actions/checkout@v2 - - - name: Go to project directory - run: cd NinjaNye.SearchExtensions - - - name: Restore dependencies - run: dotnet restore - - - name: Build - run: dotnet build --configuration Release --no-restore - - - name: Test - run: dotnet test --no-restore --verbosity normal - -# - name: Pack -# run: dotnet pack --configuration Release --no-build --output ../../nupkgs -# -# - name: Push to NuGet -# run: dotnet nuget push ../../nupkgs/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{secrets.NUGET_API_KEY}} --skip-duplicate -# if: startsWith(github.ref, 'refs/tags/v') + - uses: actions/checkout@v4 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '8.x' + + - name: Restore dependencies + run: dotnet restore + + - name: Build + run: dotnet build --configuration Release --no-restore + + - name: Test + run: dotnet test --verbosity minimal + + deploy_searchextensions: + needs: [build-and-test] + runs-on: ubuntu-latest + defaults: + run: + working-directory: NinjaNye.SearchExtensions + steps: + - uses: actions/checkout@v4 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '8.x' + + - name: Get version + id: get_version + run: echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT + + - name: Pack + run: dotnet pack NinjaNye.SearchExtensions.csproj -c Release -p:PackageVersion=${{ steps.get_version.outputs.VERSION }} --output nuget-packages + + - name: Log + run: ls -al ./nuget-packages + + - name: Push to NuGet + run: dotnet nuget push ./nuget-packages/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{secrets.NUGET_API_KEY}} --skip-duplicate + + deploy_levenshtein: + needs: [build-and-test] + runs-on: ubuntu-latest + defaults: + run: + working-directory: NinjaNye.SearchExtensions.Levenshtein + steps: + - uses: actions/checkout@v4 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '8.x' + + - name: Get version + id: get_version + run: echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT + + - name: Log + run: ls -al . + + - name: Pack + run: dotnet pack NinjaNye.SearchExtensions.Levenshtein.csproj -c Release -p:PackageVersion=${{ steps.get_version.outputs.VERSION }} --output nuget-packages + + - name: Log + run: ls -al ./nuget-packages + + - name: Push to NuGet + run: dotnet nuget push ./nuget-packages/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{secrets.NUGET_API_KEY}} --skip-duplicate + + deploy_soundex: + needs: [build-and-test] + runs-on: ubuntu-latest + defaults: + run: + working-directory: NinjaNye.SearchExtensions.Soundex + steps: + - uses: actions/checkout@v4 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '8.x' + + - name: Get version + id: get_version + run: echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT + + - name: Pack + run: dotnet pack NinjaNye.SearchExtensions.Soundex.csproj -c Release -p:PackageVersion=${{ steps.get_version.outputs.VERSION }} --output nuget-packages + + - name: Log + run: ls -al ./nuget-packages + + - name: Push to NuGet + run: dotnet nuget push ./nuget-packages/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{secrets.NUGET_API_KEY}} --skip-duplicate diff --git a/BuildNugetPackage.ps1 b/BuildNugetPackage.ps1 index 277b17c..578efbe 100644 --- a/BuildNugetPackage.ps1 +++ b/BuildNugetPackage.ps1 @@ -6,3 +6,5 @@ dotnet pack -c Release -o . cd ..\NinjaNye.SearchExtensions.Soundex\ dotnet pack -c Release -o . + +cd ../ \ No newline at end of file diff --git a/NinjaNye.SearchExtensions/NinjaNye.SearchExtensions.csproj b/NinjaNye.SearchExtensions/NinjaNye.SearchExtensions.csproj index 94931c8..adb02bd 100644 --- a/NinjaNye.SearchExtensions/NinjaNye.SearchExtensions.csproj +++ b/NinjaNye.SearchExtensions/NinjaNye.SearchExtensions.csproj @@ -1,7 +1,7 @@ - netstandard1.0;netstandard2.1;net481;net8.0 + net8.0;netstandard1.0;netstandard2.1;net481 A collection of extension methods to IQueryable and IEnumerable that enable easy searching and ranking. Searches can be performed against multiple properties and support a wide range of types 4.0.0.3 https://ninjanye.github.io/SearchExtensions/