Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Sonarcloud #3

Merged
merged 17 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/pr-build.yml
SilasPeters marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: SonarCloud
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
name: Build and analyze
runs-on: windows-latest
steps:
- name: Set up JDK 17
joachimdekker marked this conversation as resolved.
Show resolved Hide resolved
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'zulu' # Alternative distribution options are available.
joachimdekker marked this conversation as resolved.
Show resolved Hide resolved
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
joachimdekker marked this conversation as resolved.
Show resolved Hide resolved
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~\sonar\cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache SonarCloud scanner
id: cache-sonar-scanner
uses: actions/cache@v3
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: |
dotnet tool install --global dotnet-coverage
.\.sonar\scanner\dotnet-sonarscanner begin /k:"team-zomsa_aplib.net" /o:"team-zomsa" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml
dotnet build --no-incremental
dotnet-coverage collect "dotnet test" -f xml -o "coverage.xml"
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
21 changes: 21 additions & 0 deletions Aplib.Core/Main.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;

namespace Aplib.Core
{
public class SonarTest
joachimdekker marked this conversation as resolved.
Show resolved Hide resolved
{
public void Main()
{
Console.WriteLine("Hello World!");
int i = 0;

while (i < 10)
{
Console.WriteLine(i);
i++;
}
joachimdekker marked this conversation as resolved.
Show resolved Hide resolved

Console.WriteLine("i is 1");
joachimdekker marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
8 changes: 7 additions & 1 deletion Aplib.Net.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34525.116
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aplib.Core", "Aplib.Core\Aplib.Core.csproj", "{0ED50CC0-F90F-44D4-830E-2F3BACE040EC}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aplib.Core", "Aplib.Core\Aplib.Core.csproj", "{0ED50CC0-F90F-44D4-830E-2F3BACE040EC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aplib.Tests", "Aplib.Tests\Aplib.Tests.csproj", "{67D4F6C5-758D-489F-A100-8B259B2158D2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -15,6 +17,10 @@ Global
{0ED50CC0-F90F-44D4-830E-2F3BACE040EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0ED50CC0-F90F-44D4-830E-2F3BACE040EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0ED50CC0-F90F-44D4-830E-2F3BACE040EC}.Release|Any CPU.Build.0 = Release|Any CPU
{67D4F6C5-758D-489F-A100-8B259B2158D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{67D4F6C5-758D-489F-A100-8B259B2158D2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{67D4F6C5-758D-489F-A100-8B259B2158D2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{67D4F6C5-758D-489F-A100-8B259B2158D2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
29 changes: 29 additions & 0 deletions Aplib.Tests/Aplib.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
joachimdekker marked this conversation as resolved.
Show resolved Hide resolved
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Aplib.Core\Aplib.Core.csproj" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions Aplib.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Xunit;
13 changes: 13 additions & 0 deletions Aplib.Tests/SonarTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Aplib.Tests;

public class SonarTest
joachimdekker marked this conversation as resolved.
Show resolved Hide resolved
{
[Fact]
public void TestMain()
{
Core.SonarTest test = new();
test.Main();

Assert.True(true);
}
}
Loading