Skip to content

SonarCloud

SonarCloud #1411

Workflow file for this run

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
name: SonarCloud
on:
workflow_dispatch:
push:
branches:
- master
paths: # Exclude anything that isn't the main solution (docs, images, website, etc.)
- '.github/workflows/sonar.yml'
- 'src/**'
- '.build/dependencies.props'
- '.build/TestReferences.Common.*'
- '**/TestTargetFramework.*'
- '*.sln'
- '**/Directory.Build.*'
- '!src/docs/**'
- '!**/*.md'
- '!**/*.txt'
schedule:
- cron: '36 12 * * *' # 12:36 PM UTC, daily (picked an odd start time to try to avoid competing for agents with other projects)
jobs:
build:
if: github.repository == 'apache/lucenenet' # Don't run on forks
name: Build and analyze
runs-on: windows-latest
env:
DOTNET_NOLOGO: 1
DOTNET_CLI_TELEMETRY_OPTOUT: 1
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
BUILD_FOR_ALL_TEST_TARGET_FRAMEWORKS: 'true'
steps:
- name: Setup .NET 8 SDK
uses: actions/setup-dotnet@v5
with:
dotnet-version: '8.0.x'
- name: Set up JDK 21
uses: actions/setup-java@v5
with:
distribution: 'zulu'
java-version: '21'
- uses: actions/checkout@v6
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- 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'
shell: pwsh
run: |
$dir = '.\.sonar\scanner'
if (!(Test-Path $dir)) { New-Item -Path $dir -ItemType Directory }
dotnet tool update dotnet-sonarscanner --tool-path $dir
- name: Cache NuGet Packages
uses: actions/cache@v4
with:
# '**/*.*proj' includes .csproj, .vbproj, .fsproj, msbuildproj, etc.
# '**/*.props' includes Directory.Packages.props, Directory.Build.props and Dependencies.props
# '**/*.targets' includes Directory.Build.targets
# '**/*.sln' and '*.sln' ensure root solution files are included (minimatch glitch for file extension .sln)
# 'global.json' included for SDK version changes
key: nuget-${{ runner.os }}-${{ env.BUILD_FOR_ALL_TEST_TARGET_FRAMEWORKS }}-${{ hashFiles('**/*.*proj', '**/*.props', '**/*.targets', '**/*.sln', '*.sln', 'global.json') }}
path: ${{ env.NUGET_PACKAGES }}
- name: Restore dependencies
run: dotnet restore /p:TestFrameworks=${{ env.BUILD_FOR_ALL_TEST_TARGET_FRAMEWORKS }}
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
shell: pwsh
run: |
.\.sonar\scanner\dotnet-sonarscanner begin /k:"apache_lucenenet" /o:"apache" /d:sonar.token="${{ secrets.SONARCLOUD_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io"
dotnet build --no-restore /p:TestFrameworks=${{ env.BUILD_FOR_ALL_TEST_TARGET_FRAMEWORKS }}
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONARCLOUD_TOKEN }}"