From ecca70b270169b989abe8c856e8de8e8d5fb28d3 Mon Sep 17 00:00:00 2001 From: Alexis DRAI Date: Sat, 7 Jan 2023 14:20:41 +0100 Subject: [PATCH] :recycle: Implement CI --- .drone.yml | 44 +++++++++++++++++++++++++++++++++++++++++++ README.md | 4 +++- Tests/Tests.csproj | 28 +++++++++++++++++++++++++++ Tests/UnitTest1.cs | 23 ++++++++++++++++++++++ Tests/Usings.cs | 1 + cat_cafe/cat_cafe.sln | 8 +++++++- 6 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 .drone.yml create mode 100644 Tests/Tests.csproj create mode 100644 Tests/UnitTest1.cs create mode 100644 Tests/Usings.cs diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..faa4a68 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,44 @@ +kind: pipeline +type: docker +name: default + +trigger: + event: + - push + +steps: + - name: build + image: mcr.microsoft.com/dotnet/sdk:6.0 + commands: + - cd cat_cafe/ + - dotnet restore cat_cafe.sln + - dotnet build cat_cafe.sln -c Release --no-restore + - dotnet publish cat_cafe.sln -c Release --no-restore -o CI_PROJECT_DIR/build/release + + - name: tests + image: mcr.microsoft.com/dotnet/sdk:6.0 + commands: + - cd cat_cafe/ + - dotnet restore cat_cafe.sln + - dotnet test cat_cafe.sln --no-restore + depends_on: [build] + + # - name: code-analysis + # image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dronesonarplugin-dotnet6 + # commands: + # - cd cat_cafe/ + # - dotnet restore cat_cafe.sln + # - dotnet sonarscanner begin /k:"cat_cafe" /d:sonar.host.url=$${PLUGIN_SONAR_HOST} /d:sonar.coverageReportPaths="coveragereport/SonarQube.xml" /d:sonar.coverage.exclusions="Tests/**" /d:sonar.login=$${PLUGIN_SONAR_TOKEN} + # - dotnet build cat_cafe.sln -c Release --no-restore + # - dotnet test cat_cafe.sln --logger trx --no-restore /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura --collect "XPlat Code Coverage" + # - reportgenerator -reports:"**/coverage.cobertura.xml" -reporttypes:SonarQube -targetdir:"coveragereport" + # - dotnet publish cat_cafe.sln -c Release --no-restore -o CI_PROJECT_DIR/build/release + # - dotnet sonarscanner end /d:sonar.login=$${PLUGIN_SONAR_TOKEN} + # secrets: [ sonar_token ] + # settings: + # # accessible en ligne de commande par ${PLUGIN_SONAR_HOST} + # sonar_host: https://codefirst.iut.uca.fr/sonar/ + # # accessible en ligne de commande par ${PLUGIN_SONAR_TOKEN} + # sonar_token: + # from_secret: sonar_token + # depends_on: [tests] diff --git a/README.md b/README.md index 49db35a..a4204bb 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Build Status](https://codefirst.iut.uca.fr/api/badges/alexis.drai/cat_cafe/status.svg)](https://codefirst.iut.uca.fr/alexis.drai/cat_cafe) + # cat_cafe ## To contribute (workflow) @@ -6,7 +8,7 @@ We are using the feature branch workflow ([details here](https://www.atlassian.c ### 1 - Sync with the remote -Make sure you're working with the latest version of the project +Make sure you're working with the latest version of the project ``` git checkout master git fetch origin diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj new file mode 100644 index 0000000..17faa35 --- /dev/null +++ b/Tests/Tests.csproj @@ -0,0 +1,28 @@ + + + + net6.0 + enable + enable + + false + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + diff --git a/Tests/UnitTest1.cs b/Tests/UnitTest1.cs new file mode 100644 index 0000000..d834b5f --- /dev/null +++ b/Tests/UnitTest1.cs @@ -0,0 +1,23 @@ +using cat_cafe.Entities; + +namespace Tests +{ + public class UnitTest1 + { + [Fact] + public void Test1() + { + String name = "Margot"; + int id = 1337; + + Cat cat = new() + { + Id = id, + Name = name + }; + + Assert.Equal(name, cat.Name); + Assert.Equal(id, cat.Id); + } + } +} \ No newline at end of file diff --git a/Tests/Usings.cs b/Tests/Usings.cs new file mode 100644 index 0000000..8c927eb --- /dev/null +++ b/Tests/Usings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file diff --git a/cat_cafe/cat_cafe.sln b/cat_cafe/cat_cafe.sln index df444b8..aa8e7c0 100644 --- a/cat_cafe/cat_cafe.sln +++ b/cat_cafe/cat_cafe.sln @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.2.32616.157 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cat_cafe", "cat_cafe.csproj", "{CC02D05A-3817-4D0A-8766-3FEE0C90941B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "cat_cafe", "cat_cafe.csproj", "{CC02D05A-3817-4D0A-8766-3FEE0C90941B}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "..\Tests\Tests.csproj", "{674DDACC-DB0E-473B-81E2-E3CABB8CB65B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +17,10 @@ Global {CC02D05A-3817-4D0A-8766-3FEE0C90941B}.Debug|Any CPU.Build.0 = Debug|Any CPU {CC02D05A-3817-4D0A-8766-3FEE0C90941B}.Release|Any CPU.ActiveCfg = Release|Any CPU {CC02D05A-3817-4D0A-8766-3FEE0C90941B}.Release|Any CPU.Build.0 = Release|Any CPU + {674DDACC-DB0E-473B-81E2-E3CABB8CB65B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {674DDACC-DB0E-473B-81E2-E3CABB8CB65B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {674DDACC-DB0E-473B-81E2-E3CABB8CB65B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {674DDACC-DB0E-473B-81E2-E3CABB8CB65B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE -- 2.36.3