Fix code quality check #5
Workflow file for this run
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: CI | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| pull_request: | |
| branches: [ main, develop ] | |
| workflow_dispatch: | |
| env: | |
| DOTNET_VERSION: '9.0.x' | |
| CONFIGURATION: Release | |
| jobs: | |
| build-and-test: | |
| name: Build and Test | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| os: [ubuntu-latest, windows-latest, macos-latest] | |
| fail-fast: false | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| - name: Restore dependencies | |
| run: dotnet restore | |
| - name: Build solution | |
| run: dotnet build --configuration ${{ env.CONFIGURATION }} --no-restore | |
| - name: Run tests | |
| run: | | |
| cd TUnit.AutoFixture.UnitTests/bin/${{ env.CONFIGURATION }}/net10.0 | |
| dotnet exec TUnit.AutoFixture.UnitTests.dll | |
| - name: Upload test results | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: test-results-${{ matrix.os }} | |
| path: '**/TestResults/**/*' | |
| retention-days: 7 | |
| code-quality: | |
| name: Code Quality Checks | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| - name: Restore dependencies | |
| run: dotnet restore | |
| - name: Build with warnings as errors | |
| run: dotnet build --configuration ${{ env.CONFIGURATION }} --no-restore /p:TreatWarningsAsErrors=true | |
| - name: Check for warnings | |
| run: | | |
| BUILD_OUTPUT=$(dotnet build --configuration ${{ env.CONFIGURATION }} --no-restore 2>&1) | |
| # Check for actual warning lines (e.g., "warning CS1234:" or "warning:"), not the summary | |
| if echo "$BUILD_OUTPUT" | grep -E "warning [A-Z]+[0-9]+:" | grep -v "0 Warning(s)"; then | |
| echo "Build contains warnings!" | |
| echo "$BUILD_OUTPUT" | grep -E "warning [A-Z]+[0-9]+:" | |
| exit 1 | |
| else | |
| echo "No warnings found - build is clean!" | |
| fi | |
| pack: | |
| name: Pack NuGet Packages | |
| runs-on: ubuntu-latest | |
| needs: [build-and-test, code-quality] | |
| if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| - name: Restore dependencies | |
| run: dotnet restore | |
| - name: Build solution | |
| run: dotnet build --configuration ${{ env.CONFIGURATION }} --no-restore | |
| - name: Pack TUnit.AutoFixture | |
| run: dotnet pack TUnit.AutoFixture/TUnit.AutoFixture.csproj --configuration ${{ env.CONFIGURATION }} --no-build --output ./artifacts | |
| - name: Pack TUnit.AutoFixture.NSubstitute | |
| run: dotnet pack TUnit.AutoFixture.NSubstitute/TUnit.AutoFixture.NSubstitute.csproj --configuration ${{ env.CONFIGURATION }} --no-build --output ./artifacts | |
| - name: Upload NuGet packages | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: nuget-packages | |
| path: ./artifacts/*.nupkg | |
| retention-days: 30 | |
| publish: | |
| name: Publish to NuGet | |
| runs-on: ubuntu-latest | |
| needs: pack | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| environment: production | |
| steps: | |
| - name: Download artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: nuget-packages | |
| path: ./artifacts | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| - name: Push to NuGet | |
| run: dotnet nuget push "./artifacts/*.nupkg" --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate | |
| create-release: | |
| name: Create GitHub Release | |
| runs-on: ubuntu-latest | |
| needs: publish | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' && startsWith(github.event.head_commit.message, 'Release v') | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Extract version from commit message | |
| id: version | |
| run: | | |
| VERSION=$(echo "${{ github.event.head_commit.message }}" | sed -n 's/Release v\([0-9.]*\).*/\1/p') | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| - name: Download artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: nuget-packages | |
| path: ./artifacts | |
| - name: Create Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: v${{ steps.version.outputs.version }} | |
| name: Release v${{ steps.version.outputs.version }} | |
| body_path: RELEASE_NOTES.md | |
| files: ./artifacts/*.nupkg | |
| draft: false | |
| prerelease: false | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |