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:
- main
workflow_dispatch:

jobs:
codecoverage:
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 EstateManagementUI.sln --source ${{ secrets.PUBLICFEEDURL }} --source ${{ secrets.PRIVATEFEED_URL }}

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

- name: Run Unit Tests
run: |
echo "ASPNETCORE_ENVIRONMENT are > ${ASPNETCORE_ENVIRONMENT}"
dotnet test EstateManagementUI.BlazorServer.Tests/EstateManagementUI.BlazorServer.Tests.csproj --settings .runsettings /p:CollectCoverage=true /p:Exclude="[xunit*]*" /p:ExcludeByAttribute="Obsolete" /p:ExcludeByAttribute="GeneratedCodeAttribute" /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 minimal GITHUB_TOKEN permissions for this workflow or job. Since the workflow only checks out code, builds, tests, and uploads coverage to Codacy (an external service), it only needs read access to repository contents. No repository writes (pushes, PR updates, etc.) are performed.

The best fix is to add a permissions block at the workflow root, right after name: Code Coverage, so it applies to all jobs (there is only codecoverage). Set contents: read as a minimal starting point in line with the CodeQL recommendation. No imports or additional methods are required; this is a pure YAML configuration change.

Concretely, in .github/workflows/codecoverage.yml, insert:

permissions:
  contents: read

between lines 1 and 3 (after the name line and before on:). This will ensure the GITHUB_TOKEN has only read access to repository contents during this workflow, without altering existing functionality.

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
@@ -1,5 +1,8 @@
 name: Code Coverage
 
+permissions:
+  contents: read
+
 on:
   push:
     # branches to consider in the event; optional, defaults to all
EOF
@@ -1,5 +1,8 @@
name: Code Coverage

permissions:
contents: read

on:
push:
# branches to consider in the event; optional, defaults to all
Copilot is powered by AI and may make mistakes. Always verify output.
47 changes: 0 additions & 47 deletions .github/workflows/nightlybuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,6 @@ jobs:
run: |
dotnet test EstateManagementUI.BlazorServer.Tests/EstateManagementUI.BlazorServer.Tests.csproj --settings .runsettings /p:CollectCoverage=true /p:Exclude="[xunit*]*" /p:ExcludeByAttribute="Obsolete" /p:ExcludeByAttribute="GeneratedCodeAttribute" /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


# chrometests:
# name: "Nightly Build - Chrome"
# env:
Expand Down Expand Up @@ -204,35 +189,3 @@ jobs:
# with:
# name: firefoxtracelogs
# path: /home/txnproc/trace/

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

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2.3.4

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

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

- name: Run Unit Tests
run: |
echo "ASPNETCORE_ENVIRONMENT are > ${ASPNETCORE_ENVIRONMENT}"
dotnet test EstateManagementUI.BlazorServer.Tests/EstateManagementUI.BlazorServer.Tests.csproj --settings .runsettings /p:CollectCoverage=true /p:Exclude="[xunit*]*" /p:ExcludeByAttribute="Obsolete" /p:ExcludeByAttribute="GeneratedCodeAttribute" /p:ExcludeByAttribute="ExcludeFromCodeCoverageAttribute" /p:CoverletOutput="../lcov1.info" /maxcpucount:1 /p:CoverletOutputFormat="lcov"

- name: Merge LCOV reports
run: |
sudo npm install -g lcov-result-merger
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
Loading