Skip to content

Workflow file for this run

# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
name: Build and Analyze with SonarCloud
on:
push:
branches: [ "develop", "devon4net_github_actions" ]
pull_request:
branches: [ "develop", "devon4net_github_actions" ]
jobs:
build:
name: Build and analyze
runs-on: ubuntu-latest # Change to Ubuntu
steps:
- name: Set up JDK 17
uses: actions/setup-java@v3 # Update to the latest version
with:
java-version: 17
distribution: 'adopt' # Ubuntu uses AdoptOpenJDK
- uses: actions/checkout@v3 # Update to the latest version
with:
fetch-depth: 0
- name: Cache SonarCloud packages
uses: actions/cache@v3 # Update to the latest version
with:
path: ~/.sonar/cache # Change the path to the Linux format
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache SonarCloud scanner
id: cache-sonar-scanner
uses: actions/cache@v3 # Update to the latest version
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: Verify installed SonarCloud scanner
run: |
ls -la .sonar/scanner # List the contents of the scanner directory for debugging
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
./.sonar/scanner/dotnet-sonarscanner begin /k:"JosepFe_devon4net" /o:"josepfe" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io"
cd source
dotnet restore
dotnet build
./.sonar/scanner/dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"