Skip to content

V6/contrib

V6/contrib #507

Workflow file for this run

name: SonarCloud
on:
push:
branches: [ contrib ]
paths:
- 'src/**'
- 'examples/**'
- 'Directory.Build.props'
- '.editorconfig'
- 'Nikcio.UHeadless.sln'
- 'nuget.config'
- '.github/workflows/sonar.yml'
pull_request_target:
branches: [ contrib ]
paths:
- 'src/**'
- 'examples/**'
- 'Directory.Build.props'
- '.editorconfig'
- 'Nikcio.UHeadless.sln'
- 'nuget.config'
- '.github/workflows/sonar.yml'
types: [opened, synchronize, reopened]
jobs:
authorize:
name: Authorize
environment:
${{ github.event_name == 'pull_request_target' &&
github.event.pull_request.head.repo.full_name != github.repository &&
'external' || 'internal' }}
runs-on: ubuntu-latest
steps:
- run: true
build:
needs: authorize
name: Build and analyze
runs-on: ubuntu-latest
steps:
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'zulu' # Alternative distribution options are available.
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
ref: ${{ github.event.pull_request.head.sha || github.ref }} # Ensures that the code being analyzed is the PR code.
- name: Cache SonarCloud packages
uses: actions/cache@v4
with:
path: ~/sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- 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
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
7.0.x
8.0.x
- uses: actions/cache@v4
id: cache-nuget-uheadless
with:
path: |
~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-uheadless
- name: Restore dependencies
run: dotnet restore
working-directory: ./
- name: Build and analyze (PR)
if: github.event_name == 'pull_request_target'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
run: |
./.sonar/scanner/dotnet-sonarscanner begin /k:"nikcio_Nikcio.UHeadless" /o:"nikcio" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportsPaths="**/TestResults/**/coverage.opencover.xml" /d:sonar.cs.vstest.reportsPaths="**/TestResults/*.trx" /d:sonar.pullrequest.key=${{ github.event.pull_request.number }}
dotnet build ./ --no-restore
dotnet test ./ --no-build --no-restore --logger trx --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
./.sonar/scanner/dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
- name: Build and analyze
if: github.event_name != 'pull_request_target'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
run: |
./.sonar/scanner/dotnet-sonarscanner begin /k:"nikcio_Nikcio.UHeadless" /o:"nikcio" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportsPaths="**/TestResults/**/coverage.opencover.xml" /d:sonar.cs.vstest.reportsPaths="**/TestResults/*.trx"
dotnet build ./ --no-restore
dotnet test ./ --no-build --no-restore --logger trx --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
./.sonar/scanner/dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"