From a8c065db5701aa0ee0aa193778ff7267042e034b Mon Sep 17 00:00:00 2001 From: Carl Sixsmith Date: Wed, 7 Aug 2024 12:20:55 +0100 Subject: [PATCH] Local building solutions - remove build project because we are using github actions - add powershell script that replicates the github actions locally --- LocalPublish.ps1 | 42 ++++++++++++++++++++++++++++++++++++++++++ build/Build.csproj | 11 ----------- build/BuildContext.cs | 16 ---------------- build/BuildTask.cs | 19 ------------------- build/CleanTask.cs | 22 ---------------------- build/Default.cs | 8 -------- build/Program.cs | 13 ------------- build/PublishTask.cs | 21 --------------------- build/RestoreTask.cs | 18 ------------------ build/TestTask.cs | 20 -------------------- cats.sln | 8 +------- 11 files changed, 43 insertions(+), 155 deletions(-) create mode 100644 LocalPublish.ps1 delete mode 100644 build/Build.csproj delete mode 100644 build/BuildContext.cs delete mode 100644 build/BuildTask.cs delete mode 100644 build/CleanTask.cs delete mode 100644 build/Default.cs delete mode 100644 build/Program.cs delete mode 100644 build/PublishTask.cs delete mode 100644 build/RestoreTask.cs delete mode 100644 build/TestTask.cs diff --git a/LocalPublish.ps1 b/LocalPublish.ps1 new file mode 100644 index 00000000..8fdb8ca1 --- /dev/null +++ b/LocalPublish.ps1 @@ -0,0 +1,42 @@ + +# step one build the project + +#remove the publish fodler + +$sourcePath = ".\publish\*" +$destinationPath = ".\publish\build-artifacts.zip" +$publishPath = ".\publish" + +if(Test-Path $publishPath) { + Write-Host "Cleaning publish path" + Remove-Item -Recurse $publishPath +} + +Write-Host "Restoring nuget packages" -ForegroundColor Green +dotnet restore + +Write-Host "Restoring tools" -ForegroundColor Green +dotnet tool restore + +Write-Host "Building" -ForegroundColor Green +dotnet build --configuration Release --no-restore + +Write-Host "Running unit tests" -ForegroundColor Green +dotnet test --configuration Release --no-build --verbosity normal + +Write-Host "Publishing package" -ForegroundColor Green +dotnet publish --no-build --configuration Release --output $publishPath + +Write-Host "Generting indempotent migration script" -ForegroundColor Green +dotnet ef migrations script --no-build --configuration Release --project src/Migrators/Migrators.MSSQL/Migrators.MSSQL.csproj --startup-project src/Server.UI/Server.UI.csproj --context Cfo.Cats.Infrastructure.Persistence.ApplicationDbContext --idempotent -o ./publish/Migration.sql + +Write-Host "Compressing artifacts" -ForegroundColor Green +Compress-Archive -Path $sourcePath -DestinationPath $destinationPath + +Write-Host "Cleaning publish folder" -ForegroundColor Green + +Get-ChildItem -Path $publishPath -Exclude "build-artifacts.zip" | ForEach-Object { + if ($_.FullName -ne $destinationPath) { + Remove-Item -Recurse -Force $_.FullName + } +} \ No newline at end of file diff --git a/build/Build.csproj b/build/Build.csproj deleted file mode 100644 index aa5b1fe1..00000000 --- a/build/Build.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - Exe - net8.0 - $(MSBuildProjectDirectory) - true - - - - - \ No newline at end of file diff --git a/build/BuildContext.cs b/build/BuildContext.cs deleted file mode 100644 index fc1a76b6..00000000 --- a/build/BuildContext.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Cake.Common; -using Cake.Core; -using Cake.Frosting; - -namespace Build; - -public class BuildContext : FrostingContext -{ - public string MsBuildConfiguration { get; set; } - - public BuildContext(ICakeContext context) - : base(context) - { - MsBuildConfiguration = context.Argument("configuration", "Release"); - } -} \ No newline at end of file diff --git a/build/BuildTask.cs b/build/BuildTask.cs deleted file mode 100644 index 5571750b..00000000 --- a/build/BuildTask.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Cake.Common.Tools.DotNet; -using Cake.Common.Tools.DotNet.Build; -using Cake.Frosting; - -namespace Build; - -[TaskName("Build")] -[IsDependentOn(typeof(RestoreTask))] -public sealed class BuildTask : FrostingTask -{ - public override void Run(BuildContext context) - { - context.DotNetBuild("../cats.sln", new DotNetBuildSettings - { - Configuration = context.MsBuildConfiguration, - NoRestore = true - }); - } -} \ No newline at end of file diff --git a/build/CleanTask.cs b/build/CleanTask.cs deleted file mode 100644 index 7773bf09..00000000 --- a/build/CleanTask.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Cake.Common.IO; -using Cake.Frosting; - -namespace Build; - -[TaskName("Clean")] -public sealed class CleanTask : FrostingTask -{ - public override void Run(BuildContext context) - { - // clean any existing publishing output - context.CleanDirectories("../publish"); - - context.CleanDirectory($"../src/Server.Ui/bin/{context.MsBuildConfiguration}"); - context.CleanDirectory($"../src/Server/bin/{context.MsBuildConfiguration}"); - context.CleanDirectory($"../src/Migrators/Migrators.MSSQL/bin/{context.MsBuildConfiguration}"); - context.CleanDirectory($"../src/Migrators/Migrators.SqLite/bin/{context.MsBuildConfiguration}"); - context.CleanDirectory($"../src/Infrastructure/bin/{context.MsBuildConfiguration}"); - context.CleanDirectory($"../src/Application/bin/{context.MsBuildConfiguration}"); - context.CleanDirectory($"../src/Domain/bin/{context.MsBuildConfiguration}"); - } -} \ No newline at end of file diff --git a/build/Default.cs b/build/Default.cs deleted file mode 100644 index f8b09507..00000000 --- a/build/Default.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Cake.Frosting; - -namespace Build; - -[IsDependentOn(typeof(PublishTask))] -public sealed class Default : FrostingTask -{ -} \ No newline at end of file diff --git a/build/Program.cs b/build/Program.cs deleted file mode 100644 index 8f5344f0..00000000 --- a/build/Program.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Cake.Frosting; - -namespace Build; - -public static class Program -{ - public static int Main(string[] args) - { - return new CakeHost() - .UseContext() - .Run(args); - } -} \ No newline at end of file diff --git a/build/PublishTask.cs b/build/PublishTask.cs deleted file mode 100644 index 5832fbcf..00000000 --- a/build/PublishTask.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Cake.Common.Tools.DotNet; -using Cake.Common.Tools.DotNet.Publish; -using Cake.Frosting; - -namespace Build; - -[TaskName("Publish")] -[IsDependentOn(typeof(TestTask))] -public sealed class PublishTask : FrostingTask -{ - public override void Run(BuildContext context) - { - context.DotNetPublish("../src/Server.UI/Server.UI.csproj", new DotNetPublishSettings() - { - NoBuild = true, // we are dependent on the build task - NoRestore = true, - Configuration = context.MsBuildConfiguration, - OutputDirectory = "../publish/Server.Ui" - }); - } -} \ No newline at end of file diff --git a/build/RestoreTask.cs b/build/RestoreTask.cs deleted file mode 100644 index bc83bdc4..00000000 --- a/build/RestoreTask.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Cake.Common.Tools.DotNet; -using Cake.Common.Tools.DotNet.Restore; -using Cake.Frosting; - -namespace Build; - -[TaskName("Restore")] -[IsDependentOn(typeof(CleanTask))] -public class RestoreTask : FrostingTask -{ - public override void Run(BuildContext context) - { - context.DotNetRestore("../cats.sln", new DotNetRestoreSettings() - { - - }); - } -} \ No newline at end of file diff --git a/build/TestTask.cs b/build/TestTask.cs deleted file mode 100644 index 4cb14cc4..00000000 --- a/build/TestTask.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Cake.Common.Tools.DotNet; -using Cake.Common.Tools.DotNet.Test; -using Cake.Frosting; - -namespace Build; - -[TaskName("Test")] -[IsDependentOn(typeof(BuildTask))] -public sealed class TestTask : FrostingTask -{ - public override void Run(BuildContext context) - { - context.DotNetTest("../cats.sln", new DotNetTestSettings - { - Configuration = context.MsBuildConfiguration, - NoBuild = true, - Loggers = ["nunit;LogFilePath=TestResult.xml"] - }); - } -} \ No newline at end of file diff --git a/cats.sln b/cats.sln index 40f77b8a..552c521a 100644 --- a/cats.sln +++ b/cats.sln @@ -1,4 +1,4 @@ -Microsoft Visual Studio Solution File, Format Version 12.00 +Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.0.31903.59 MinimumVisualStudioVersion = 10.0.40219.1 @@ -27,8 +27,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_SolutionItems", "_Solution README.md = README.md EndProjectSection EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Build", "build\Build.csproj", "{7CC5B8A2-2122-4907-B970-FD7A3EEA1C4C}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{62ABFE2F-D4F3-4E44-AA07-20D679B04CF3}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Application.UnitTests", "test\Application.UnitTests\Application.UnitTests.csproj", "{2FC2E6B9-5186-4A39-A2CC-0975ED2AEC1E}" @@ -61,10 +59,6 @@ Global {A7B309FF-FFA9-4290-B982-46DA80D0E0DF}.Debug|Any CPU.Build.0 = Debug|Any CPU {A7B309FF-FFA9-4290-B982-46DA80D0E0DF}.Release|Any CPU.ActiveCfg = Release|Any CPU {A7B309FF-FFA9-4290-B982-46DA80D0E0DF}.Release|Any CPU.Build.0 = Release|Any CPU - {7CC5B8A2-2122-4907-B970-FD7A3EEA1C4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7CC5B8A2-2122-4907-B970-FD7A3EEA1C4C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7CC5B8A2-2122-4907-B970-FD7A3EEA1C4C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7CC5B8A2-2122-4907-B970-FD7A3EEA1C4C}.Release|Any CPU.Build.0 = Release|Any CPU {2FC2E6B9-5186-4A39-A2CC-0975ED2AEC1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {2FC2E6B9-5186-4A39-A2CC-0975ED2AEC1E}.Debug|Any CPU.Build.0 = Debug|Any CPU {2FC2E6B9-5186-4A39-A2CC-0975ED2AEC1E}.Release|Any CPU.ActiveCfg = Release|Any CPU