Update dependencies and add code coverage workflow#233
Conversation
Updated NuGet package versions across all projects, including Shared, DomainDrivenDesign, EventStore, MediatR, SecurityService.Client, TransactionProcessor.Client, and NUnit. Added a GitHub Actions workflow (codecoverage.yml) to build, run tests with coverage, merge LCOV reports, and upload results to Codacy. No application logic changes were made.
| name: "Code Coverage" | ||
| env: | ||
| ASPNETCORE_ENVIRONMENT: "Production" | ||
|
|
||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v2.3.4 | ||
|
|
||
| - name: Restore Nuget Packages | ||
| run: dotnet restore CallbackHandler.sln --source ${{ secrets.PUBLICFEEDURL }} --source ${{ secrets.PRIVATEFEED_URL }} | ||
|
|
||
| - name: Build Code | ||
| run: dotnet build CallbackHandler.sln --configuration Release | ||
|
|
||
| - name: Run Unit Tests | ||
| run: | | ||
| echo "ASPNETCORE_ENVIRONMENT are > ${ASPNETCORE_ENVIRONMENT}" | ||
| dotnet test "CallbackHandler.BusinessLogic.Tests\CallbackHandler.BusinessLogic.Tests.csproj" /p:CollectCoverage=true /p:Exclude="[xunit*]*" /p:ExcludeByAttribute="Obsolete" /p:ExcludeByAttribute="GeneratedCodeAttribute" /p:ExcludeByAttribute="CompilerGeneratedAttribute" /p:ExcludeByAttribute="ExcludeFromCodeCoverageAttribute" /p:CoverletOutput="../lcov1.info" /maxcpucount:1 /p:CoverletOutputFormat="lcov" | ||
| dotnet test "CallbackHandler.CallbackMessageAggregate.Tests\CallbackHandler.CallbackMessageAggregate.Tests.csproj" /p:CollectCoverage=true /p:Exclude="[xunit*]*" /p:ExcludeByAttribute="Obsolete" /p:ExcludeByAttribute="GeneratedCodeAttribute" /p:ExcludeByAttribute="CompilerGeneratedAttribute" /p:ExcludeByAttribute="ExcludeFromCodeCoverageAttribute" /p:CoverletOutput="../lcov2.info" /maxcpucount:1 /p:CoverletOutputFormat="lcov" | ||
| dotnet test "CallbackHandler.Tests\CallbackHandler.Tests.csproj" /p:CollectCoverage=true /p:Exclude="[xunit*]*" /p:ExcludeByAttribute="Obsolete" /p:ExcludeByAttribute="GeneratedCodeAttribute" /p:ExcludeByAttribute="CompilerGeneratedAttribute" /p:ExcludeByAttribute="ExcludeFromCodeCoverageAttribute" /p:CoverletOutput="../lcov3.info" /maxcpucount:1 /p:CoverletOutputFormat="lcov" | ||
|
|
||
| - name: Install LCOV merger | ||
| run: npm install -g lcov-result-merger | ||
|
|
||
| - name: Merge LCOV reports | ||
| run: | | ||
| mkdir -p coverage | ||
| lcov-result-merger "*.info" > lcov.info | ||
|
|
||
| - name: Upload merged coverage to Codacy | ||
| uses: codacy/codacy-coverage-reporter-action@v1 | ||
| with: | ||
| project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} | ||
| coverage-reports: ./lcov.info |
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 2 months ago
To fix the issue, explicitly restrict GITHUB_TOKEN permissions for this workflow to the minimum needed. The job only checks out code, restores/builds/tests, and uploads coverage to Codacy; it does not need to write to the repository or interact with issues/PRs. Therefore, setting contents: read (and nothing else) at the workflow level is sufficient and preserves existing behavior.
The best minimal fix is to add a permissions: block at the top (root) of .github/workflows/codecoverage.yml, directly under the name: line and before the on: section:
- This applies to all jobs in the workflow (currently just
codecoverage). - It limits the
GITHUB_TOKENto read-only repository contents, which is enough foractions/checkoutand does not impact the usage of secrets or external services like Codacy.
Concretely:
-
Edit
.github/workflows/codecoverage.yml. -
Insert:
permissions: contents: read
after line 1 (
name: Code Coverage) and before theon:block (line 3 onwards). -
No imports or additional methods are required; this is purely a YAML configuration change.
| @@ -1,4 +1,6 @@ | ||
| name: Code Coverage | ||
| permissions: | ||
| contents: read | ||
|
|
||
| on: | ||
| push: |
Replaced manual registration of IMediator and specific IRequestHandlers with AddMediatR, auto-registering all handlers from the relevant assembly. This streamlines service setup and reduces maintenance overhead.
Updated NuGet package versions across all projects, including Shared, DomainDrivenDesign, EventStore, MediatR, SecurityService.Client, TransactionProcessor.Client, and NUnit. Added a GitHub Actions workflow (codecoverage.yml) to build, run tests with coverage, merge LCOV reports, and upload results to Codacy. No application logic changes were made.
closes #232
closes #231