SonarCloud #324
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: SonarCloud | |
on: | |
workflow_run: | |
workflows: [.NET] | |
types: [completed] | |
jobs: | |
QA: | |
name: Build and analyze | |
runs-on: windows-latest | |
if: github.event.workflow_run.conclusion == 'success' | |
steps: | |
- name: Download PR number artifact | |
if: github.event.workflow_run.event == 'pull_request' | |
uses: dawidd6/action-download-artifact@v2 | |
with: | |
workflow: Java CI | |
run_id: ${{ github.event.workflow_run.id }} | |
name: PR_NUMBER | |
- name: Read PR Number | |
if: github.event.workflow_run.event == 'pull_request' | |
id: pr_number | |
uses: juliangruber/read-file-action@v1 | |
with: | |
path: ./PR_NUMBER.txt | |
- name: Request GitHub API for PR data | |
if: github.event.workflow_run.event == 'pull_request' | |
uses: octokit/[email protected] | |
id: get_pr_data | |
with: | |
route: GET /repos/{full_name}/pulls/{number} | |
number: ${{ steps.pr_number.outputs.content }} | |
full_name: ${{ github.event.repository.full_name }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'oracle' | |
java-version: '17' | |
- uses: actions/checkout@v3 | |
with: | |
repository: ${{ github.event.workflow_run.head_repository.full_name }} | |
ref: ${{ github.event.workflow_run.head_branch }} | |
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis | |
- name: Checkout PR | |
if: github.event.workflow_run.event == 'pull_request' | |
run: | | |
git remote add upstream ${{ github.event.repository.clone_url }} | |
git fetch upstream | |
git checkout -B ${{ fromJson(steps.get_pr_data.outputs.data).base.ref }} upstream/${{ fromJson(steps.get_pr_data.outputs.data).base.ref }} | |
git checkout ${{ github.event.workflow_run.head_branch }} | |
git clean -ffdx && git reset --hard HEAD | |
- name: Cache SonarCloud packages | |
uses: actions/cache@v1 | |
with: | |
path: ~\sonar\cache | |
key: ${{ runner.os }}-sonar | |
restore-keys: ${{ runner.os }}-sonar | |
- name: Cache SonarCloud scanner | |
id: cache-sonar-scanner | |
uses: actions/cache@v1 | |
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' | |
shell: powershell | |
run: | | |
New-Item -Path .\.sonar\scanner -ItemType Directory | |
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner | |
- name: Install Dotnet Coverage | |
shell: powershell | |
run: dotnet tool install --global dotnet-coverage | |
- name: Sonar Scanner on PR | |
if: github.event.workflow_run.event == 'pull_request' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
shell: powershell | |
run: .\.sonar\scanner\dotnet-sonarscanner begin /k:"EvoEsports_EvoSC-sharp" /o:"evoesports" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml /d:sonar.scm.revision=${{ github.event.workflow_run.head_sha }} /d:sonar.pullrequest.key=${{ fromJson(steps.get_pr_data.outputs.data).number }} /d:sonar.pullrequest.branch=${{ fromJson(steps.get_pr_data.outputs.data).head.ref }} /d:sonar.pullrequest.base=${{ fromJson(steps.get_pr_data.outputs.data).base.ref }} | |
- name: Sonar Scanner on Push | |
if: github.event.workflow_run.event == 'push' && github.event.workflow_run.head_repository.full_name == github.event.repository.full_name | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
shell: powershell | |
run: .\.sonar\scanner\dotnet-sonarscanner begin /k:"EvoEsports_EvoSC-sharp" /o:"evoesports" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml | |
- name: Finish Sonarcloud And Upload Results | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
shell: powershell | |
run: | | |
dotnet build | |
dotnet-coverage collect 'dotnet test' -f xml -o 'coverage.xml' | |
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" |