From 564bcebbe74715568522a585c96ea67007cd9b71 Mon Sep 17 00:00:00 2001 From: Cesar Aguirre Date: Wed, 17 Jul 2024 12:30:06 -0500 Subject: [PATCH 1/3] Add coverlet.collector to test projects --- tests/FunctionalTests/FunctionalTests.csproj | 4 ++++ tests/IntegrationTests/IntegrationTests.csproj | 4 ++++ tests/UnitTests/UnitTests.csproj | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/tests/FunctionalTests/FunctionalTests.csproj b/tests/FunctionalTests/FunctionalTests.csproj index e703b4d5..5573b3fb 100644 --- a/tests/FunctionalTests/FunctionalTests.csproj +++ b/tests/FunctionalTests/FunctionalTests.csproj @@ -14,6 +14,10 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/tests/IntegrationTests/IntegrationTests.csproj b/tests/IntegrationTests/IntegrationTests.csproj index 0923dc66..c35f0f79 100644 --- a/tests/IntegrationTests/IntegrationTests.csproj +++ b/tests/IntegrationTests/IntegrationTests.csproj @@ -6,6 +6,10 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/tests/UnitTests/UnitTests.csproj b/tests/UnitTests/UnitTests.csproj index c2d6e0c8..7a9fb76a 100644 --- a/tests/UnitTests/UnitTests.csproj +++ b/tests/UnitTests/UnitTests.csproj @@ -9,6 +9,10 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + From 2f8f921f5f8fc6a415d495442369f67141334a8a Mon Sep 17 00:00:00 2001 From: Cesar Aguirre Date: Wed, 17 Jul 2024 13:07:14 -0500 Subject: [PATCH 2/3] Update test action and add comment action --- .github/workflows/comment-on-pr.yml | 44 +++++++++++++++++++++++++++++ .github/workflows/dotnetcore.yml | 40 ++++++++++++++++++++++++-- 2 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/comment-on-pr.yml diff --git a/.github/workflows/comment-on-pr.yml b/.github/workflows/comment-on-pr.yml new file mode 100644 index 00000000..e81f5559 --- /dev/null +++ b/.github/workflows/comment-on-pr.yml @@ -0,0 +1,44 @@ +name: Comment on the Pull Request + +# read-write repo token +# See: https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ +on: + workflow_run: + workflows: ["eShopOnWeb Build and Test"] + types: + - completed + +jobs: + comment: + runs-on: ubuntu-latest + + # Only comment on the PR if this is a PR event + if: github.event.workflow_run.event == 'pull_request' + + steps: + - name: Get the PR Number artifact + uses: dawidd6/action-download-artifact@v3 + with: + workflow: ${{ github.event.workflow_run.workflow_id }} + workflow_conclusion: "" + name: pr-number + + - name: Read PR Number into GitHub environment variables + run: echo "PR_NUMBER=$(cat pr-number.txt)" >> $GITHUB_ENV + + - name: Confirm the PR Number (Debugging) + run: echo $PR_NUMBER + + - name: Get the code coverage results file + uses: dawidd6/action-download-artifact@v3 + with: + workflow: ${{ github.event.workflow_run.workflow_id }} + workflow_conclusion: "" + name: code-coverage-results + + - name: Add Coverage PR Comment + uses: marocchino/sticky-pull-request-comment@v2 + with: + number: ${{ env.PR_NUMBER }} + recreate: true + path: code-coverage-results.md diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 3a83f967..118be4be 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -17,6 +17,42 @@ jobs: - name: Build with dotnet run: dotnet build ./eShopOnWeb.sln --configuration Release - + + # See https://josh-ops.com/posts/github-code-coverage/ + # Add coverlet.collector nuget package to test project - 'dotnet add package coverlet - name: Test with dotnet - run: dotnet test ./eShopOnWeb.sln --configuration Release + run: dotnet test ./eShopOnWeb.sln --no-restore --verbosity normal --collect:"XPlat Code Coverage" --logger trx --results-directory coverage + + - name: Copy Coverage To Predictable Location + run: find coverage -type f -name coverage.cobertura.xml -exec cp -p {} coverage/coverage.cobertura.xml \; + + - name: Code Coverage Summary Report + uses: irongut/CodeCoverageSummary@v1.3.0 + with: + filename: coverage/coverage.cobertura.xml + badge: true + format: 'markdown' + output: 'both' + + - name: Upload code coverage results artifact + uses: actions/upload-artifact@v4 + if: success() || failure() + with: + name: code-coverage-results + path: code-coverage-results.md + retention-days: 1 + + - name: Save the PR number in an artifact + if: github.event_name == 'pull_request' && (success() || failure()) + shell: bash + env: + PR_NUMBER: ${{ github.event.number }} + run: echo $PR_NUMBER > pr-number.txt + + - name: Upload the PR number + uses: actions/upload-artifact@v4 + if: github.event_name == 'pull_request' && (success() || failure()) + with: + name: pr-number + path: ./pr-number.txt + retention-days: 1 \ No newline at end of file From 5810e5c9056c084ccc736418551438f66eda5762 Mon Sep 17 00:00:00 2001 From: Cesar Aguirre Date: Wed, 17 Jul 2024 13:30:36 -0500 Subject: [PATCH 3/3] Add comment-on-pr.yml to solution files --- eShopOnWeb.sln | 1 + 1 file changed, 1 insertion(+) diff --git a/eShopOnWeb.sln b/eShopOnWeb.sln index e878f9a7..0d7592d7 100755 --- a/eShopOnWeb.sln +++ b/eShopOnWeb.sln @@ -28,6 +28,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution docker-compose.override.yml = docker-compose.override.yml docker-compose.yml = docker-compose.yml .github\workflows\dotnetcore.yml = .github\workflows\dotnetcore.yml + .github\workflows\comment-on-pr.yml = .github\workflows\comment-on-pr.yml README.md = README.md EndProjectSection EndProject