Skip to content

Run tests and publish the test report to SonarQube

Notifications You must be signed in to change notification settings

warrenbrasil/sonar-qube

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 

Repository files navigation

Warren - Run Tests and SonarQube Analysis 🧪

This action is responsible for running tests and publish the test resport to SonarQube.

Prerequisites

Before using this action, please be sure that all tests projects have the following dependencies installed and updated to at least the latest stable version

  • xunit
  • xunit.runner.visualstudio
  • Microsoft.NET.Test.Sdk
  • coverlet.collector
  • coverlet.msbuild
  • GitHubActionsTestLogger

Inputs

sonar-token

Required: SonarQube token

sonar-host-url

Required: SonarQube URL

sonar-project-key

Required: SonarQube project key

To get the SonarQube project key go to SonarQube, find or setup your project, then click on Project Information at the top right corner. The Project Key will be found at drawer window that should be opened on you right.

sonar-organization

Required: SonarQube organization name

pull-request

Required: Boolean to change behavior of dotnet-sonarscanner for pull requests

branch-name

Required: when pull-request input parameter is set to false Optional: when pull-request input parameter is set to true

Branch name to be displayed on SonarQube.

pull-request-number

Required: when pull-request input parameter is set to true Optional: when pull-request input parameter is set to false

The number of the pull request

pull-request-base

Required: when pull-request input parameter is set to true Optional: when pull-request input parameter is set to false

The target branch name from the pull request

pull-request-head

Required: when pull-request input parameter is set to true Optional: when pull-request input parameter is set to false

The target source name from the pull request

solution

Optional: Solution file name without the .sln extension (do not use with project input parameter)

project

Optional: The path of test project to be tested (do not use with solution input parameter)

⚠️ the parameters solution and project are optional for you to choose one to use, but you MUST choose one ⚠️

code-exclusions

Optional: The matching path for code that should be excluded from coverage (absolute, relative and pattern paths are acceptable)

quality-gate-wait

Optional: Poll to SonarQube instance until the Quality Gate status is available (default is true)

verbosity

Optional: Verbosity level for dotnet test command (default is m)

Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]

enable-dotnet-restore

Optional: Runs dotnet restore before runs dotnet test. (default is true)

dotnet-restore-flags

Optional: Add flags to dotnet restore command. (defaults is no flags)

Full flags list is available here

enable-dotnet-build

Optional: Runs dotnet build --no-restore before runs dotnet test. (default is true)

dotnet-build-flags

Optional: Add flags to dotnet build command. (default is --no-restore)

Full flags list is available here

dotnet-test-flags

Optional: Add flags for dotnet test command. (default is --no-build --no-restore).

Full flags list is available here.

Usage

Using for push on long-lived branches:

- name: Warren - Run Tests and SonarQube Analysis
  uses: warrenbrasil/sonar-qube@v2
  with:
    sonar-token: ${{ secrets.SONAR_TOKEN }}
    sonar-host-url: ${{ secrets.SONAR_HOST_URL }}
    sonar-project-key: warrenbrasil_my-repo-sonar-key
    sonar-organization: myorg
    solution: Warren.Core.MyRepo
    pull-request: false
    branch-name: ${{ github.head_ref || github.ref_name }}

Using for pull requests:

- name: Warren - Run Tests and SonarQube Analysis
  uses: warrenbrasil/sonar-qube@v3
  with:
    sonar-token: ${{ secrets.SONAR_TOKEN }}
    sonar-host-url: ${{ secrets.SONAR_HOST_URL }}
    sonar-project-key: warrenbrasil_my-repo-sonar-key
    sonar-organization: myorg
    solution: Warren.Core.MyRepo
    pull-request: true
    pull-request-number: ${{ github.event.pull_request.number }}
    pull-request-base: ${{ github.event.pull_request.base.ref }}
    pull-request-head: ${{ github.event.pull_request.head.ref }}

Using with file code exclusions:

- name: Warren - Run Tests and SonarQube Analysis
  uses: warrenbrasil/sonar-qube@v3
  with:
    sonar-token: ${{ secrets.SONAR_TOKEN }}
    sonar-host-url: ${{ secrets.SONAR_HOST_URL }}
    sonar-project-key: myorg_my-project-key
    sonar-organization: myorg
    solution: Warren.Core.MyRepo
    code-exclusions: "tests/Warren.Core.MyRepo.Fixtures/**/*.cs"
    pull-request: false
    branch-name: ${{ github.head_ref || github.ref_name }}

Using with multiline file code exclusions:

- name: Warren - Run Tests and SonarQube Analysis
  uses: warrenbrasil/sonar-qube@v3
  with:
    sonar-token: ${{ secrets.SONAR_TOKEN }}
    sonar-host-url: ${{ secrets.SONAR_HOST_URL }}
    sonar-project-key: myorg_my-project-key
    sonar-organization: myorg
    solution: Warren.Core.MyRepo
    code-exclusions: >-
      tests/Warren.Core.MyRepo.Fixtures/**/*.cs,
      src/Warren.Core.MyRepo.Services/**/*.cs
    pull-request: false
    branch-name: ${{ github.head_ref || github.ref_name }}

Using with dotnet restore, dotnet build and dotnet test flags:

- name: Warren - Run Tests and SonarQube Analysis
  uses: warrenbrasil/sonar-qube@v3
  with:
    sonar-token: ${{ secrets.SONAR_TOKEN }}
    sonar-host-url: ${{ secrets.SONAR_HOST_URL }}
    sonar-project-key: myorg_my-project-key
    sonar-organization: myorg
    solution: Warren.Core.MyRepo
    pull-request: false
    branch-name: ${{ github.head_ref || github.ref_name }}
    dotnet-restore-flags: --no-cache
    dotnet-build-flags: --configuration Release
    dotnet-test-flags: --configuration Release