优化(CodeInjectIncrementalSourceGenerator):增强代码健壮性 #6
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: Build and Publish NuGet Package | |
| on: | |
| push: | |
| branches: [ main, master ] | |
| paths: | |
| - 'src/**' | |
| - '.github/workflows/**' | |
| pull_request: | |
| branches: [ main, master ] | |
| paths: | |
| - 'src/**' | |
| env: | |
| DOTNET_VERSION: '8.0.x' | |
| PROJECT_PATH: 'src/CodeInject/CodeInject.csproj' | |
| SOURCE_GENERATOR_PATH: 'src/CodeInjectSourceGenerator/CodeInjectSourceGenerator.csproj' | |
| jobs: | |
| build-and-test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| - name: Restore dependencies | |
| run: dotnet restore src/CodeRegion.sln | |
| - name: Build Source Generator | |
| run: dotnet build ${{ env.SOURCE_GENERATOR_PATH }} --configuration Release --no-restore | |
| - name: Build project | |
| run: dotnet build ${{ env.PROJECT_PATH }} --configuration Release --no-restore | |
| - name: Run tests (if any) | |
| run: dotnet test src/ --configuration Release --no-build --verbosity normal --collect:"XPlat Code Coverage" | |
| continue-on-error: true | |
| - name: Pack NuGet package | |
| run: dotnet pack ${{ env.PROJECT_PATH }} --configuration Release --no-build --output ./packages | |
| - name: Upload NuGet package as artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: nuget-package | |
| path: ./packages/*.nupkg | |
| publish-nuget: | |
| needs: build-and-test | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') | |
| steps: | |
| - name: Download NuGet package artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: nuget-package | |
| path: ./packages | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| - name: Publish NuGet package | |
| run: | | |
| dotnet nuget push ./packages/*.nupkg \ | |
| --api-key ${{ secrets.NUGET_API_KEY }} \ | |
| --source https://api.nuget.org/v3/index.json \ | |
| --skip-duplicate | |
| env: | |
| NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} | |
| publish-github: | |
| needs: build-and-test | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') | |
| steps: | |
| - name: Download NuGet package artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: nuget-package | |
| path: ./packages | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| - name: Publish to GitHub Packages | |
| run: | | |
| dotnet nuget push ./packages/*.nupkg \ | |
| --api-key ${{ secrets.GITHUB_TOKEN }} \ | |
| --source https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json \ | |
| --skip-duplicate | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |