|
| 1 | +name: Build and Publish NuGet Packages |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, master ] |
| 6 | + tags: [ 'v*' ] |
| 7 | + pull_request: |
| 8 | + branches: [ main, master ] |
| 9 | + |
| 10 | +env: |
| 11 | + DOTNET_VERSION: '9.0.x' |
| 12 | + NUGET_SOURCE: 'https://api.nuget.org/v3/index.json' |
| 13 | + |
| 14 | +jobs: |
| 15 | + build-and-test: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Checkout code |
| 20 | + uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + fetch-depth: 0 # Required for GitVersion |
| 23 | + |
| 24 | + - name: Setup .NET |
| 25 | + uses: actions/setup-dotnet@v4 |
| 26 | + with: |
| 27 | + dotnet-version: ${{ env.DOTNET_VERSION }} |
| 28 | + |
| 29 | + - name: Install GitVersion |
| 30 | + uses: gittools/actions/gitversion/[email protected] |
| 31 | + with: |
| 32 | + versionSpec: '5.x' |
| 33 | + |
| 34 | + - name: Determine Version |
| 35 | + uses: gittools/actions/gitversion/[email protected] |
| 36 | + id: gitversion |
| 37 | + |
| 38 | + - name: Display Version |
| 39 | + run: | |
| 40 | + echo "Version: ${{ steps.gitversion.outputs.semVer }}" |
| 41 | + echo "NuGetVersionV2: ${{ steps.gitversion.outputs.nuGetVersionV2 }}" |
| 42 | +
|
| 43 | + - name: Restore dependencies for core projects |
| 44 | + run: | |
| 45 | + dotnet restore EightBot.Orbit.Core/EightBot.Orbit.Core.csproj |
| 46 | + dotnet restore EightBot.Orbit.Client/EightBot.Orbit.Client.csproj |
| 47 | + dotnet restore EightBot.Orbit.Server/EightBot.Orbit.Server.csproj |
| 48 | + dotnet restore EightBot.Orbit.Server.Web/EightBot.Orbit.Server.Web.csproj |
| 49 | + dotnet restore EightBot.Orbit.Tests/EightBot.Orbit.Tests.csproj |
| 50 | +
|
| 51 | + - name: Build core projects |
| 52 | + run: | |
| 53 | + dotnet build EightBot.Orbit.Core/EightBot.Orbit.Core.csproj --configuration Release --no-restore /p:Version=${{ steps.gitversion.outputs.assemblySemVer }} /p:PackageVersion=${{ steps.gitversion.outputs.nuGetVersionV2 }} |
| 54 | + dotnet build EightBot.Orbit.Client/EightBot.Orbit.Client.csproj --configuration Release --no-restore /p:Version=${{ steps.gitversion.outputs.assemblySemVer }} /p:PackageVersion=${{ steps.gitversion.outputs.nuGetVersionV2 }} |
| 55 | + dotnet build EightBot.Orbit.Server/EightBot.Orbit.Server.csproj --configuration Release --no-restore /p:Version=${{ steps.gitversion.outputs.assemblySemVer }} /p:PackageVersion=${{ steps.gitversion.outputs.nuGetVersionV2 }} |
| 56 | + dotnet build EightBot.Orbit.Server.Web/EightBot.Orbit.Server.Web.csproj --configuration Release --no-restore /p:Version=${{ steps.gitversion.outputs.assemblySemVer }} /p:PackageVersion=${{ steps.gitversion.outputs.nuGetVersionV2 }} |
| 57 | + dotnet build EightBot.Orbit.Tests/EightBot.Orbit.Tests.csproj --configuration Release --no-restore |
| 58 | +
|
| 59 | + - name: Run tests |
| 60 | + continue-on-error: true |
| 61 | + run: dotnet test EightBot.Orbit.Tests/EightBot.Orbit.Tests.csproj --configuration Release --no-build --verbosity normal --filter "FullyQualifiedName~OrbitClientTests" |
| 62 | + |
| 63 | + - name: Pack NuGet packages |
| 64 | + run: | |
| 65 | + dotnet pack EightBot.Orbit.Core/EightBot.Orbit.Core.csproj --configuration Release --no-build --output ./artifacts /p:PackageVersion=${{ steps.gitversion.outputs.nuGetVersionV2 }} |
| 66 | + dotnet pack EightBot.Orbit.Client/EightBot.Orbit.Client.csproj --configuration Release --no-build --output ./artifacts /p:PackageVersion=${{ steps.gitversion.outputs.nuGetVersionV2 }} |
| 67 | + dotnet pack EightBot.Orbit.Server/EightBot.Orbit.Server.csproj --configuration Release --no-build --output ./artifacts /p:PackageVersion=${{ steps.gitversion.outputs.nuGetVersionV2 }} |
| 68 | + dotnet pack EightBot.Orbit.Server.Web/EightBot.Orbit.Server.Web.csproj --configuration Release --no-build --output ./artifacts /p:PackageVersion=${{ steps.gitversion.outputs.nuGetVersionV2 }} |
| 69 | +
|
| 70 | + - name: Upload NuGet packages as artifacts |
| 71 | + uses: actions/upload-artifact@v4 |
| 72 | + with: |
| 73 | + name: nuget-packages |
| 74 | + path: ./artifacts/*.nupkg |
| 75 | + |
| 76 | + outputs: |
| 77 | + version: ${{ steps.gitversion.outputs.nuGetVersionV2 }} |
| 78 | + |
| 79 | + publish: |
| 80 | + needs: build-and-test |
| 81 | + runs-on: ubuntu-latest |
| 82 | + if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')) |
| 83 | + |
| 84 | + steps: |
| 85 | + - name: Download NuGet packages |
| 86 | + uses: actions/download-artifact@v4 |
| 87 | + with: |
| 88 | + name: nuget-packages |
| 89 | + path: ./artifacts |
| 90 | + |
| 91 | + - name: Setup .NET |
| 92 | + uses: actions/setup-dotnet@v4 |
| 93 | + with: |
| 94 | + dotnet-version: ${{ env.DOTNET_VERSION }} |
| 95 | + |
| 96 | + - name: Publish to NuGet (Release) |
| 97 | + if: startsWith(github.ref, 'refs/tags/') |
| 98 | + run: | |
| 99 | + for package in ./artifacts/*.nupkg; do |
| 100 | + echo "Publishing $package to NuGet..." |
| 101 | + dotnet nuget push "$package" --api-key ${{ secrets.EIGHTBOT_NUGET_APIKEY }} --source ${{ env.NUGET_SOURCE }} --skip-duplicate |
| 102 | + done |
| 103 | +
|
| 104 | + - name: Publish to NuGet (Prerelease) |
| 105 | + if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' |
| 106 | + run: | |
| 107 | + for package in ./artifacts/*.nupkg; do |
| 108 | + echo "Publishing $package to NuGet as prerelease..." |
| 109 | + dotnet nuget push "$package" --api-key ${{ secrets.EIGHTBOT_NUGET_APIKEY }} --source ${{ env.NUGET_SOURCE }} --skip-duplicate |
| 110 | + done |
| 111 | +
|
| 112 | + create-release: |
| 113 | + needs: [build-and-test, publish] |
| 114 | + runs-on: ubuntu-latest |
| 115 | + if: startsWith(github.ref, 'refs/tags/') |
| 116 | + |
| 117 | + steps: |
| 118 | + - name: Checkout code |
| 119 | + uses: actions/checkout@v4 |
| 120 | + |
| 121 | + - name: Download NuGet packages |
| 122 | + uses: actions/download-artifact@v4 |
| 123 | + with: |
| 124 | + name: nuget-packages |
| 125 | + path: ./artifacts |
| 126 | + |
| 127 | + - name: Create GitHub Release |
| 128 | + uses: softprops/action-gh-release@v1 |
| 129 | + with: |
| 130 | + files: ./artifacts/*.nupkg |
| 131 | + generate_release_notes: true |
| 132 | + draft: false |
| 133 | + prerelease: false |
| 134 | + env: |
| 135 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments