test: add FormInputStateManager and AnnouncementService tests (+19 te… #131
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: 程式碼建置檢查 | |
| on: | |
| push: | |
| # 排除標籤推送,因為標籤通常會走發佈流程。 | |
| branches: | |
| - '**' | |
| tags-ignore: | |
| - 'v*' | |
| pull_request: | |
| branches: | |
| - main | |
| jobs: | |
| build-check: | |
| runs-on: windows-latest | |
| permissions: | |
| # 只需要讀取原始碼進行建置即可。 | |
| contents: read | |
| # 定義環境變數,方便統一管理。 | |
| env: | |
| DOTNET_MAJOR_VERSION: '10' | |
| # xUnit v3 MTP 的 coverage 輸出在 bin 輸出目錄的 TestResults 子目錄下。 | |
| COVERAGE_GLOB: tests/**/coverage.cobertura.xml | |
| REPORT_DIR: CoverageReport | |
| steps: | |
| - name: 簽出原始碼(Checkout) | |
| uses: actions/checkout@v6 | |
| - name: 安裝 .NET 環境 | |
| uses: actions/setup-dotnet@v5 | |
| with: | |
| # 使用 GitHub Actions 語法來讀取 env 變數。 | |
| dotnet-version: '${{ env.DOTNET_MAJOR_VERSION }}.x' | |
| # 啟用快取功能,加速 NuGet 套件還原。 | |
| cache: true | |
| # 同時涵蓋主專案與測試專案,確保 NuGet 套件快取完整。 | |
| cache-dependency-path: '**/*.csproj' | |
| - name: 執行專案建置(Build) | |
| working-directory: ./src/InputBox | |
| # 使用 --no-incremental 確保每次都是完整檢查,避免部分編譯遺漏錯誤。 | |
| run: dotnet build -c Release --no-incremental | |
| - name: 建置測試專案(Build Tests) | |
| working-directory: ./tests/InputBox.Tests | |
| run: dotnet build -c Release --no-incremental | |
| - name: 執行單元測試並收集覆蓋率(Test + Coverage) | |
| working-directory: ./tests/InputBox.Tests | |
| # xUnit v3 + MTP 原生模式(global.json test.runner=Microsoft.Testing.Platform)。 | |
| # --no-build 重用上一步的建置產出;coverage 輸出至 bin/Release 目錄下的 TestResults 子目錄。 | |
| run: | | |
| dotnet test -c Release --no-build ` | |
| --coverage ` | |
| --coverage-output-format cobertura ` | |
| --coverage-output coverage.cobertura.xml | |
| - name: 安裝 ReportGenerator 並產生覆蓋率報告 | |
| run: | | |
| dotnet tool install -g dotnet-reportgenerator-globaltool | |
| reportgenerator ` | |
| "-reports:${{ env.COVERAGE_GLOB }}" ` | |
| "-targetdir:${{ env.REPORT_DIR }}" ` | |
| "-reporttypes:Html;Cobertura;MarkdownSummaryGithub" | |
| - name: 寫入覆蓋率摘要至 GitHub Step Summary | |
| run: | | |
| Get-Content -Path "${{ env.REPORT_DIR }}/SummaryGithub.md" | | |
| Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append | |
| - name: 上傳覆蓋率報告(Artifact) | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: coverage-report | |
| path: ${{ env.REPORT_DIR }} | |
| if-no-files-found: error | |
| - name: 建置與測試成功通知 | |
| if: success() | |
| run: Write-Host "建置與測試全部通過!程式碼狀態良好。" |