Sonarcloud quality gate #198
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: ci-sonarcloud | |
run-name: Sonarcloud quality gate | |
on: | |
workflow_run: | |
workflows: ["ci-integration-test"] | |
types: | |
- completed | |
jobs: | |
build-and-test: | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
runs-on: ubuntu-20.04 | |
# runs-on: windows-latest | |
steps: | |
- uses: actions/[email protected] | |
- name: Set status pending | |
run: | | |
curl \ | |
-X POST \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
${{ github.api_url }}/repos/${{ github.repository }}/statuses/${{ github.sha }} \ | |
-d '{"state":"pending","target_url":"${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}","description":"The quality gate is pending!","context":"continuous-integration/sonarcloud"}' | |
- name: Install zfs | |
run: | | |
sudo apt-get update | |
sudo apt install -y smartmontools | |
sudo apt install -y zfsutils-linux | |
which zfs | |
which zpool | |
which smartctl | |
which ls | |
which lsblk | |
sudo zpool status | |
- name: Setup .NET | |
uses: actions/[email protected] | |
with: | |
dotnet-version: 6.0.x | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'oracle' | |
# - name: Cache SonarCloud packages | |
# uses: actions/cache@v1 | |
# with: | |
# path: ~\sonar\cache | |
# key: ${{ runner.os }}-sonar | |
# restore-keys: ${{ runner.os }}-sonar | |
- name: Install SonarCloud scanners | |
run: | | |
dotnet tool install --global dotnet-sonarscanner | |
- name: Restore dependencies | |
run: | | |
dotnet nuget add source --username ${{ github.triggering_actor }} --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/bjornbouetsmith/index.json" | |
dotnet restore Source/ROOT.Zfs.sln | |
- name: Prepare sonarcloud | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
run: dotnet-sonarscanner begin /k:"bjornbouetsmith_ROOT.Zfs" /o:"bjornbouetsmith" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportsPaths=Source/ROOT.Zfs.Tests/coverage.opencover*.xml /d:sonar.qualitygate.wait=true | |
- name: Build | |
run: dotnet build Source/ROOT.Zfs.sln --no-restore --configuration Debug | |
- name: Unit Test | |
run: | | |
dotnet test Source/**/*.Tests.csproj --configuration Debug --verbosity normal --filter "TestCategory!=Integration" /p:AltCover=true /p:AltCoverReport="/home/runner/work/ROOT.Zfs/ROOT.Zfs/Source/ROOT.Zfs.Tests/coverage.opencover-unit.xml" /p:AltCoverAttributeFilter=ExcludeFromCodeCoverage /p:AltCoverVisibleBranches=true | |
- name: Integration Test | |
run: | | |
dotnet test Source/**/*.Tests.csproj --configuration Debug --verbosity normal --filter "TestCategory=Integration" /p:AltCover=true /p:AltCoverReport="/home/runner/work/ROOT.Zfs/ROOT.Zfs/Source/ROOT.Zfs.Tests/coverage.opencover-integration.xml" /p:AltCoverAttributeFilter=ExcludeFromCodeCoverage /p:AltCoverVisibleBranches=true | |
- name: Attach coverage xml | |
uses: actions/upload-artifact@v3 | |
with: | |
name: coverage-reports | |
path: /home/runner/work/ROOT.Zfs/ROOT.Zfs/Source/ROOT.Zfs.Tests/coverage.opencover*.xml | |
- name: Analyze with sonarcloud | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
run: dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" | |
- name: Set failed status | |
if: failure() | |
run: | | |
curl \ | |
-X POST \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
${{ github.api_url }}/repos/${{ github.repository }}/statuses/${{ github.sha }} \ | |
-d '{"state":"failure","target_url":"${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}","description":"The quality gate failed!","context":"continuous-integration/sonarcloud"}' | |
- name: Set success status | |
run: | | |
curl \ | |
-X POST \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
${{ github.api_url }}/repos/${{ github.repository }}/statuses/${{ github.sha }} \ | |
-d '{"state":"success","target_url":"${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}","description":"The quality gate succeeded!","context":"continuous-integration/sonarcloud"}' |