Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
ci: Setup Sonarcloud Analysis (#223)
* Updating packages and installing new ones for sonarcloud

Signed-off-by: Leonardo Ferreira <index.xp@gmail.com>

* ci: Added workflow that builds, tests and analyse on sonarcloud

Signed-off-by: Leonardo Ferreira <index.xp@gmail.com>
  • Loading branch information
Leonardo-Ferreira committed Nov 16, 2021
1 parent 4158812 commit 3c91830
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/sonar.yml
@@ -0,0 +1,63 @@
name: sonarbuild
on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
name: Build
runs-on: windows-latest
steps:
- name: Setup .NET Core 3.1.x SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.x

- name: Setup .NET 5.0.x SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x

- name: Setup .NET 6.0.x SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x

- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 1.11
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- 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: Build and analyze
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:"${{ secrets.SONAR_PROJECT_KEY }}" /o:"${{ secrets.SONAR_CASBIN_ORG_NAME }}" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportsPaths="${{ GITHUB.WORKSPACE }}\**\coverage*.opencover.xml" /d:sonar.cs.vstest.reportsPaths="${{ GITHUB.WORKSPACE }}\**\*.trx" /d:sonar.verbose=true
dotnet build -c Release
dotnet test -c Release --logger trx -r test-results --collect:"XPlat Code Coverage" /p:CollectCoverage=true /p:CoverletOutputFormat=opencover -f net5 -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=json,cobertura,lcov,teamcity,opencover
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"
13 changes: 11 additions & 2 deletions NetCasbin.UnitTest/NetCasbin.UnitTest.csproj
Expand Up @@ -8,13 +8,18 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.0.3">
<PackageReference Include="coverlet.collector" Version="3.1.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="OpenCover" Version="4.7.1221" />
<PackageReference Include="coverlet.msbuild" Version="3.1.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand All @@ -24,6 +29,10 @@
<ProjectReference Include="..\NetCasbin\NetCasbin.csproj" />
</ItemGroup>

<ItemGroup>
<None Remove="OpenCover" />
<None Remove="coverlet.msbuild" />
</ItemGroup>
<ItemGroup>
<None Update="examples\abac_model.conf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down

0 comments on commit 3c91830

Please sign in to comment.