diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml new file mode 100644 index 00000000..e580227f --- /dev/null +++ b/.github/workflows/pr-build.yml @@ -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 }}" diff --git a/Aplib.Core/SonarTest.cs b/Aplib.Core/SonarTest.cs new file mode 100644 index 00000000..6b871815 --- /dev/null +++ b/Aplib.Core/SonarTest.cs @@ -0,0 +1,9 @@ +using System; + +namespace Aplib.Core +{ + public class SonarTest + { + public void Main() => Console.WriteLine("Hello World!"); + } +} diff --git a/Aplib.Net.sln b/Aplib.Net.sln index b06a17f4..24528aa3 100644 --- a/Aplib.Net.sln +++ b/Aplib.Net.sln @@ -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 @@ -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 diff --git a/Aplib.Tests/Aplib.Tests.csproj b/Aplib.Tests/Aplib.Tests.csproj new file mode 100644 index 00000000..67ed265b --- /dev/null +++ b/Aplib.Tests/Aplib.Tests.csproj @@ -0,0 +1,29 @@ + + + + net8.0 + enable + enable + + false + true + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + diff --git a/Aplib.Tests/GlobalUsings.cs b/Aplib.Tests/GlobalUsings.cs new file mode 100644 index 00000000..8c927eb7 --- /dev/null +++ b/Aplib.Tests/GlobalUsings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file diff --git a/Aplib.Tests/SonarTest.cs b/Aplib.Tests/SonarTest.cs new file mode 100644 index 00000000..86f10414 --- /dev/null +++ b/Aplib.Tests/SonarTest.cs @@ -0,0 +1,13 @@ +namespace Aplib.Tests; + +public class SonarTest +{ + [Fact] + public void TestMain() + { + Core.SonarTest test = new(); + test.Main(); + + Assert.True(true); + } +} \ No newline at end of file