Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/codecoverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Code Coverage

on:
push:
# branches to consider in the event; optional, defaults to all
branches:
- master
workflow_dispatch:

jobs:
build:
name: "Code Coverage"
env:
ASPNETCORE_ENVIRONMENT: "Production"

runs-on: ubuntu-latest

steps:
- uses: actions/[email protected]

- name: Restore Nuget Packages
run: dotnet restore SecurityService.sln --source ${{ secrets.PUBLICFEEDURL }} --source ${{ secrets.PRIVATEFEED_URL }}

- name: Build Code
run: dotnet build SecurityService.sln --configuration Release

- name: Run Unit Tests
run: |
echo "ASPNETCORE_ENVIRONMENT are > ${ASPNETCORE_ENVIRONMENT}"
dotnet test "SecurityService.UnitTests\SecurityService.UnitTests.csproj" /p:ExcludeByFile="\SecurityService\Views\**\*.cshtml" /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"

- 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
Comment on lines +12 to +44

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

Copilot Autofix

AI 2 months ago

To fix the problem, explicitly declare restricted GITHUB_TOKEN permissions in the workflow. The least-privilege baseline for a workflow that only checks out code and runs tests is contents: read at the workflow or job level. No steps in the shown job require write access to the repo, so we can safely limit permissions to read-only.

The best fix without changing existing functionality is to add a permissions: block under the jobs: root (so it applies to this and any future jobs) or directly under the build: job. Since there is currently only one job, either is fine; adding at the job level makes the change tightly scoped. Concretely, in .github/workflows/codecoverage.yml, add:

    permissions:
      contents: read

just under build: (and before name:) with correct indentation. No imports, methods, or other definitions are needed; YAML structure is the only change.

Suggested changeset 1
.github/workflows/codecoverage.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/codecoverage.yml b/.github/workflows/codecoverage.yml
--- a/.github/workflows/codecoverage.yml
+++ b/.github/workflows/codecoverage.yml
@@ -9,6 +9,8 @@
 
 jobs:  
   build:
+    permissions:
+      contents: read
     name: "Code Coverage"
     env:
         ASPNETCORE_ENVIRONMENT: "Production"
EOF
@@ -9,6 +9,8 @@

jobs:
build:
permissions:
contents: read
name: "Code Coverage"
env:
ASPNETCORE_ENVIRONMENT: "Production"
Copilot is powered by AI and may make mistakes. Always verify output.
42 changes: 1 addition & 41 deletions .github/workflows/nightlybuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -286,44 +286,4 @@ jobs:
# title: Investigate Nightly Build Failure - Edge UI
# token: ${{secrets.GITHUB_TOKEN}}
# labels: nightlybuild
# body: Url is ${{env.action_url}}

codecoverage:
name: "Nightly Build - Code Coverage"
env:
ASPNETCORE_ENVIRONMENT: "Production"

runs-on: ubuntu-latest

steps:
- uses: actions/[email protected]

- name: Install NET 9
uses: actions/[email protected]
with:
dotnet-version: '9.0.x'

- name: Restore Nuget Packages
run: dotnet restore SecurityService.sln --source ${{ secrets.PUBLICFEEDURL }} --source ${{ secrets.PRIVATEFEED_URL }}

- name: Build Code
run: dotnet build SecurityService.sln --configuration Release

- name: Run Unit Tests
run: |
echo "ASPNETCORE_ENVIRONMENT are > ${ASPNETCORE_ENVIRONMENT}"
dotnet test "SecurityService.UnitTests\SecurityService.UnitTests.csproj" /p:ExcludeByFile="\SecurityService\Views\**\*.cshtml" /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"

- 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
# body: Url is ${{env.action_url}}
Loading