fix: prevent analyzer self-injection cycle #130
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 | |
| on: | |
| push: | |
| branches: | |
| - "main" | |
| pull_request: | |
| concurrency: | |
| group: ci-${{ github.ref }} | |
| cancel-in-progress: false | |
| env: | |
| DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 | |
| DOTNET_NOLOGO: true | |
| NUGET_DIRECTORY: ${{ github.workspace}}/artifacts | |
| defaults: | |
| run: | |
| shell: pwsh | |
| jobs: | |
| lint_config: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: actions/setup-dotnet@v5 | |
| - run: dotnet run --project=tools/ConfigFilesGenerator/ConfigFilesGenerator.csproj | |
| compute_version: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| package_version: ${{ steps.compute-version.outputs.package_version }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: actions/setup-dotnet@v5 | |
| - id: compute-version | |
| run: | | |
| try | |
| { | |
| # Match version like 1.1.X or 1.0.X | |
| $(Invoke-WebRequest "https://www.nuget.org/api/v2/package/ANcpLua.NET.Sdk/").BaseResponse.RequestMessage.RequestUri -match "ANcpLua\.net\.sdk\.(\d+)\.(\d+)\.(\d+)\.nupkg" | |
| $Major = [int]$Matches.1 | |
| $Minor = [int]$Matches.2 | |
| $Patch = [int]$Matches.3 + 1 | |
| $NewVersion = "$Major.$Minor.$Patch" | |
| } | |
| catch | |
| { | |
| $NewVersion = "1.1.3" | |
| } | |
| Write-Host "New version: $NewVersion" | |
| "package_version=$NewVersion" >> $env:GITHUB_OUTPUT | |
| create_nuget: | |
| needs: [compute_version] | |
| runs-on: windows-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| submodules: true | |
| - uses: actions/setup-dotnet@v5 | |
| - run: ./build.ps1 -Version ${{ needs.compute_version.outputs.package_version }} | |
| - uses: actions/upload-artifact@v6 | |
| with: | |
| name: nuget | |
| if-no-files-found: error | |
| retention-days: 3 | |
| path: "${{ env.NUGET_DIRECTORY }}/*.nupkg" | |
| test: | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| runs-on: [ubuntu-latest, windows-latest, macos-latest] | |
| runs-on: ${{ matrix.runs-on }} | |
| needs: [create_nuget, compute_version] | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: actions/download-artifact@v7 | |
| with: | |
| name: nuget | |
| path: ${{ env.NUGET_DIRECTORY }} | |
| - uses: actions/setup-dotnet@v5 | |
| - run: Get-ChildItem "${{ env.NUGET_DIRECTORY }}/*" -Recurse | |
| - run: dotnet --info | |
| - run: dotnet nuget locals all --clear | |
| - run: dotnet test --project tests/ANcpLua.Sdk.Tests/ANcpLua.Sdk.Tests.csproj --report-xunit-trx --report-github --results-directory test_results | |
| env: | |
| CI: true | |
| NUGET_DIRECTORY: ${{ env.NUGET_DIRECTORY }} | |
| PACKAGE_VERSION: ${{ needs.compute_version.outputs.package_version }} | |
| - uses: actions/upload-artifact@v6 | |
| if: always() | |
| with: | |
| name: test_results_${{ matrix.runs-on }} | |
| path: test_results | |
| deploy: | |
| runs-on: ubuntu-latest | |
| needs: [create_nuget, lint_config, test, compute_version] | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - uses: actions/download-artifact@v7 | |
| with: | |
| name: nuget | |
| path: ${{ env.NUGET_DIRECTORY }} | |
| - uses: actions/setup-dotnet@v5 | |
| - name: Must Publish Packages | |
| id: has_changes | |
| run: | | |
| $PreviousTag = git describe --tags --abbrev=0 2>$null | |
| if ($PreviousTag) { | |
| Write-Host "Previous tag: $PreviousTag" | |
| $Changes = git diff --name-only $PreviousTag HEAD -- '*.nuspec' 'src/**/*' 'eng/**/*' | |
| } else { | |
| Write-Host "No previous tag found, checking all files" | |
| $Changes = $true | |
| } | |
| if ($Changes) { | |
| Write-Host "Changes: $Changes" | |
| echo "has_changes=true" >> $env:GITHUB_OUTPUT | |
| exit 0 | |
| } else { | |
| Write-Host "No changes detected in .nuspec or src/ files" | |
| echo "has_changes=false" >> $env:GITHUB_OUTPUT | |
| exit 0 | |
| } | |
| - name: Publish NuGet packages | |
| if: ${{ steps.has_changes.outputs.has_changes == 'true' && github.ref == 'refs/heads/main' }} | |
| env: | |
| NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} | |
| run: | | |
| Write-Host "Publishing to NuGet.org" | |
| $files = Get-ChildItem "${{ env.NUGET_DIRECTORY }}/*" -Recurse -Include *.nupkg | |
| foreach ($file in $files) { | |
| Write-Host "Pushing: $($file.Name)" | |
| & dotnet nuget push "$($file.FullName)" --api-key "$env:NUGET_API_KEY" --source https://api.nuget.org/v3/index.json --skip-duplicate | |
| } | |
| - run: gh release create "${{ needs.compute_version.outputs.package_version }}" --generate-notes | |
| if: ${{ steps.has_changes.outputs.has_changes == 'true' && github.ref == 'refs/heads/main' }} | |
| env: | |
| GH_TOKEN: ${{ github.token }} |