Skip to content

build(deps): Bump coverlet.collector from 6.0.3 to 6.0.4 #69

build(deps): Bump coverlet.collector from 6.0.3 to 6.0.4

build(deps): Bump coverlet.collector from 6.0.3 to 6.0.4 #69

name: 'SonarCloud and Mutation Tests'
on:
workflow_dispatch: # To can dispatch manually
push: # First pipeline to run when deploy a new version
branches:
- main
paths:
- "src/**" # Only run when exists changes in source code
- "tests/**" # Only run when exists changes in tests code
pull_request:
types: [opened, reopened, edited, synchronize]
branches:
- main
env:
FRAMEWORK_VERSION: 'net9.0'
PROJECT_FILE: 'PowerUtils.Text.csproj'
TEST_PROJECT_PATH: 'tests/PowerUtils.Text.Tests/PowerUtils.Text.Tests.csproj'
permissions:
pull-requests: write # To can create a comment with the results
jobs:
sonar-scanner:
name: "Sonar Scanner and Mutation Tests"
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: actions/checkout@v4.2.2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: "Define branch name for Stryker"
run: |
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "STRYKER_BRANCH=main" >> $GITHUB_ENV
else
echo "STRYKER_BRANCH=${{ github.head_ref }}-${{ github.run_number }}" >> $GITHUB_ENV
fi
- name: "Display branch name for Stryker"
run: echo "Stryker branch is '${{ env.STRYKER_BRANCH }}'"
- name: "Setup .NET"
uses: actions/setup-dotnet@v4.2.0
with:
global-json-file: 'global.json'
# Hack reasons:
# - The last version of the `xunit.runner.visualstudio` doesn't generate the report for some OLD SDK versions like .net 5
# - The Stryker versions after 4.0.0 is not compatible with net7.0
- name: "Replace TargetFrameworks"
run: |
find . -type f -name "*.csproj" -exec sed -i 's/<TargetFrameworks>.*<\/TargetFrameworks>/<TargetFrameworks>${{ env.FRAMEWORK_VERSION }}<\/TargetFrameworks>/g' {} +
- name: "Set up JDK"
uses: actions/setup-java@v4.6.0
with:
distribution: 'adopt'
java-version: '17'
- name: "Restore .NET Tools"
run: dotnet tool restore
- name: "Create cache directory"
run: mkdir -p ~/sonar/cache
- name: "Cache SonarCloud packages"
uses: actions/cache@v4
with:
path: ~/sonar/cache
key: ${{ runner.os }}-sonar-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-sonar-
${{ runner.os }}-
- name: "Cache SonarCloud scanner"
id: cache-sonar-scanner
uses: actions/cache@v4
with:
path: ./.sonar/scanner
key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner
- name: "Install SonarCloud scanner"
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
run: |
mkdir -p ./.sonar/scanner
dotnet tool update dotnet-sonarscanner --tool-path ./.sonar/scanner
dotnet tool update dotnet-coverage --tool-path ./.sonar/scanner
- name: "Run Stryker"
run: |
dotnet stryker \
-tp ${{ env.TEST_PROJECT_PATH }} \
-p ${{ env.PROJECT_FILE }} \
--reporter json \
--reporter markdown \
--reporter progress \
--reporter dashboard --dashboard-api-key ${{ secrets.STRYKER_API_KEY }} \
--version ${{ env.STRYKER_BRANCH }} \
-O ${{ github.workspace }}/mutations
- name: "Convert report to Sonar"
run: jq -f tests/mutation-report-to-sonar.jq '${{ github.workspace }}/mutations/reports/mutation-report.json' > '${{ github.workspace }}/mutations/reports/mutation-sonar.json'
- name: "Comment PR"
uses: actions/github-script@v7.0.1
if: github.event_name == 'pull_request'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { issue: { number: issue_number }, repo: { owner, repo } } = context;
const message = `🚀 **Stryker report generated** 🚀
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2F${{ github.repository_owner }}%2F${{ github.event.repository.name }}%2F${{ env.STRYKER_BRANCH }})](https://dashboard.stryker-mutator.io/reports/github.com/${{ github.repository_owner }}/${{ github.event.repository.name }}/${{ env.STRYKER_BRANCH }})
To more details: https://dashboard.stryker-mutator.io/reports/github.com/${{ github.repository_owner }}/${{ github.event.repository.name }}/${{ env.STRYKER_BRANCH }}`;
github.rest.issues.createComment({
issue_number,
owner,
repo,
body: message
});
- name: "Publish report"
run: |
cat $(find ${{ github.workspace }}/mutations/reports/* -name "*.md") > $GITHUB_STEP_SUMMARY
- name: "Build and analyze"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: pwsh
run: |
./.sonar/scanner/dotnet-sonarscanner begin /k:"${{ secrets.SONAR_PROJECT_KEY }}" /o:"${{ secrets.SONAR_ORGANIZATION }}" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml /d:sonar.projectBaseDir="$(pwd)" /d:sonar.externalIssuesReportPaths="${{ github.workspace }}/mutations/reports/mutation-sonar.json"
dotnet build -c Release --no-incremental
./.sonar/scanner/dotnet-coverage collect "dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover -c Release --no-restore --no-build" -f xml -o "coverage.xml"
./.sonar/scanner/dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"