Publish Nuget Packages #87
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish Nuget Packages | |
| on: | |
| workflow_dispatch: | |
| jobs: | |
| build-test-publish: | |
| name: Build, Test & Publish | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: '8.0.x' | |
| - name: Get current version | |
| id: version | |
| run: | | |
| VERSION=$(grep -oP '(?<=<Version>)[^<]+' src/GenerativeAI/GenerativeAI.csproj | head -1) | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| - 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 | |
| continue-on-error: true | |
| - name: Pack (src projects only) | |
| run: | | |
| for project in src/**/*.csproj; do | |
| dotnet pack "$project" -c Release --no-build -o ./nupkgs | |
| done | |
| - name: Publish to NuGet.org | |
| run: dotnet nuget push "./nupkgs/*.nupkg" --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_KEY }} --skip-duplicate | |
| - name: Publish to GitHub Packages | |
| run: | | |
| dotnet nuget add source "https://nuget.pkg.github.com/gunpal5/index.json" --name github --username gunpal5 --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text | |
| dotnet nuget push "./nupkgs/*.nupkg" --source github --skip-duplicate | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: v${{ steps.version.outputs.version }} | |
| name: v${{ steps.version.outputs.version }} | |
| generate_release_notes: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Bump version for next release | |
| id: bump | |
| uses: vers-one/dotnet-project-version-updater@v1.7 | |
| with: | |
| file: | | |
| "**/*.csproj", "**/*.nuspec", "**/AssemblyInfo.cs" | |
| version: bump-build | |
| - name: Commit version bump | |
| run: | | |
| git config user.name "Gunpal Jain" | |
| git config user.email "gunpal5@gmail.com" | |
| git add . | |
| git commit -m "Bump version to v${{ steps.bump.outputs.newVersion }}" | |
| git push |