Skip to content

Commit

Permalink
Add Sonarcloud (#3)
Browse files Browse the repository at this point in the history
* Create pr-build.yml

* Change to build to ubuntu

* Build dotnet command earlier.

* Go back to windows

* Don't run the tests

We don't have to run the tests, as the tests are not ready yet (there are no tests)

* Bump up version of dotnet

* Reset pipeline

🙏 🙏 🙏

* Create Main.cs

* feat: add testing framework

* fix: collect code coverage

* fix: use dotnet-coverage

* Make individual tasks

* fix: multiline command

* Just write hello world for the test

* Rename main file

* Conform to Guido

* style: conform to Quake

Co-authored-by: Quake <74355598+QuakeEye@users.noreply.github.com>

---------

Co-authored-by: Quake <74355598+QuakeEye@users.noreply.github.com>
  • Loading branch information
joachimdekker and QuakeEye authored Feb 19, 2024
1 parent b1a0549 commit 0771315
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 1 deletion.
66 changes: 66 additions & 0 deletions .github/workflows/pr-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: SonarCloud
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
name: Build .NET and Analyse with SonarCloud
runs-on: windows-latest
steps:
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'zulu'
- uses: actions/checkout@v3
- 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: Install Coverage Tool
shell: powershell
run: |
dotnet tool install --global dotnet-coverage
- name: Prepare SonarCloud analysis
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: powershell
run: >
.\.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
- name: Build the project
shell: powershell
run: |
dotnet build --no-incremental
- name: Test the project
shell: powershell
run: |
dotnet-coverage collect "dotnet test" -f xml -o "coverage.xml"
- name: Run SonarCloud analysis
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: powershell
run: |
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
9 changes: 9 additions & 0 deletions Aplib.Core/SonarTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace Aplib.Core
{
public class SonarTest
{
public void Main() => Console.WriteLine("Hello World!");
}
}
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>
<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
{
[Fact]
public void TestMain()
{
Core.SonarTest test = new();
test.Main();

Assert.True(true);
}
}

0 comments on commit 0771315

Please sign in to comment.