From 7092a8b09b204269bae009d3c162651ad0aff4ab Mon Sep 17 00:00:00 2001 From: Kaioru Date: Sun, 18 Aug 2024 20:08:17 +0800 Subject: [PATCH] Add pack and publish build targets --- .github/workflows/build.yml | 4 +- .nuke/build.schema.json | 10 +++ build/Build.Artifacts.Pack.cs | 18 +++++ build/Build.Artifacts.Publish.cs | 80 +++++++++++++++++++ build/Build.CI.GithubActions.cs | 9 +++ build/Build.cs | 19 +++-- src/app/Directory.Build.props | 6 -- .../packages.lock.json | 6 -- 8 files changed, 131 insertions(+), 21 deletions(-) create mode 100644 build/Build.Artifacts.Pack.cs create mode 100644 build/Build.Artifacts.Publish.cs create mode 100644 build/Build.CI.GithubActions.cs diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index feafc1f4c..e1fc8512c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,12 +9,12 @@ # # - To trigger manual generation invoke: # -# nuke --generate-configuration GitHubActions_build --host GitHubActions +# nuke --generate-configuration GitHubActions_Build --host GitHubActions # # # ------------------------------------------------------------------------------ -name: build +name: Build on: [push] diff --git a/.nuke/build.schema.json b/.nuke/build.schema.json index 184c799a9..05f7ebb68 100644 --- a/.nuke/build.schema.json +++ b/.nuke/build.schema.json @@ -73,11 +73,18 @@ "type": "string", "enum": [ "Clean", + "CleanArtifacts", "Compile", + "Pack", + "Publish", "Restore" ] } }, + "Solution": { + "type": "string", + "description": "Path to a solution file that is automatically loaded" + }, "Target": { "type": "array", "description": "List of targets to be invoked. Default is '{default_target}'", @@ -85,7 +92,10 @@ "type": "string", "enum": [ "Clean", + "CleanArtifacts", "Compile", + "Pack", + "Publish", "Restore" ] } diff --git a/build/Build.Artifacts.Pack.cs b/build/Build.Artifacts.Pack.cs new file mode 100644 index 000000000..98390c00e --- /dev/null +++ b/build/Build.Artifacts.Pack.cs @@ -0,0 +1,18 @@ +using Nuke.Common; +using Nuke.Common.IO; +using Nuke.Common.Tools.DotNet; + +partial class Build +{ + AbsolutePath OutputPkgDirectory => OutputDirectory / "packages"; + + Target Pack => d => d + .Produces(OutputPkgDirectory / "*.zip") + .Executes(() => + { + OutputPkgDirectory.CreateOrCleanDirectory(); + return DotNetTasks.DotNetPack(s => s + .SetConfiguration(Configuration) + .SetOutputDirectory(OutputPkgDirectory)); + }); +} diff --git a/build/Build.Artifacts.Publish.cs b/build/Build.Artifacts.Publish.cs new file mode 100644 index 000000000..ed0224ada --- /dev/null +++ b/build/Build.Artifacts.Publish.cs @@ -0,0 +1,80 @@ +using System.Collections.Generic; +using System.Linq; +using JetBrains.Annotations; +using Nuke.Common; +using Nuke.Common.IO; +using Nuke.Common.ProjectModel; +using Nuke.Common.Tools.DotNet; +using Nuke.Common.Tools.EntityFramework; + +partial class Build +{ + AbsolutePath OutputExeDirectory => OutputDirectory / "dist"; + + [CanBeNull] SolutionFolder SourceSolutionFolder => Solution?.GetSolutionFolder("src"); + [CanBeNull] SolutionFolder SourceAppSolutionFolder => SourceSolutionFolder?.GetSolutionFolder("app"); + [CanBeNull] SolutionFolder SourcePluginSolutionFolder => SourceSolutionFolder?.GetSolutionFolder("plugin"); + [CanBeNull] SolutionFolder SourceCommonSolutionFolder => SourceSolutionFolder?.GetSolutionFolder("common"); + + IEnumerable Runtimes => new[] + { + "win-x64", + "win-arm64", + "linux-x64", + "linux-arm64", + "osx-arm64" + }; + + Target Publish => d => d + .Produces(OutputExeDirectory / "*.zip") + .Executes(() => + { + OutputExeDirectory.CreateOrCleanDirectory(); + + if (SourceAppSolutionFolder?.Projects == null) return; + + foreach (var runtime in Runtimes) + { + var outputRuntimeDirectory = OutputExeDirectory / $"{runtime}"; + var outputRuntimePluginsDirectory = outputRuntimeDirectory / "plugins"; + + outputRuntimeDirectory.CreateOrCleanDirectory(); + + foreach (var project in SourceAppSolutionFolder.Projects) + { + DotNetTasks.DotNetPublish(s => s + .SetProject(project) + .SetConfiguration(Configuration) + .SetRuntime(runtime) + .SetPublishSingleFile(true) + .SetSelfContained(true) + .SetOutput(outputRuntimeDirectory)); + } + + if (SourceCommonSolutionFolder?.Projects != null) + foreach (var project in SourceCommonSolutionFolder.Projects) + { + if (project.Name.StartsWith("Edelstein.Common.Database.")) + { + var provider = project.Name.Split(".").Last().ToLower(); + + EntityFrameworkTasks.EntityFrameworkMigrationsScript(s => s + .SetProject(project) + .SetConfiguration(Configuration) + .SetOutput(outputRuntimeDirectory / $"db-migrate-{provider}.sql")); + } + } + + if (SourcePluginSolutionFolder?.Projects != null) + foreach (var project in SourcePluginSolutionFolder.Projects) + { + DotNetTasks.DotNetPublish(s => s + .SetProject(project) + .SetConfiguration(Configuration) + .SetOutput(outputRuntimePluginsDirectory / project.Name)); + } + + outputRuntimeDirectory.ZipTo(OutputExeDirectory / $"{outputRuntimeDirectory.Name}.zip"); + } + }); +} diff --git a/build/Build.CI.GithubActions.cs b/build/Build.CI.GithubActions.cs new file mode 100644 index 000000000..8b04a83f0 --- /dev/null +++ b/build/Build.CI.GithubActions.cs @@ -0,0 +1,9 @@ +using Nuke.Common.CI.GitHubActions; + +[GitHubActions( + "Build", + GitHubActionsImage.UbuntuLatest, + On = new[] { GitHubActionsTrigger.Push }, + InvokedTargets = new[] { nameof(Compile) } +)] +partial class Build; diff --git a/build/Build.cs b/build/Build.cs index de7ca2ddf..a2d0ad4ea 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -1,13 +1,9 @@ +using JetBrains.Annotations; using Nuke.Common; -using Nuke.Common.CI.GitHubActions; +using Nuke.Common.IO; +using Nuke.Common.ProjectModel; using Nuke.Common.Tools.DotNet; -[GitHubActions( - "build", - GitHubActionsImage.UbuntuLatest, - On = new[] { GitHubActionsTrigger.Push }, - InvokedTargets = new[] { nameof(Compile) } -)] partial class Build : NukeBuild { /// Support plugins are available for: @@ -21,9 +17,18 @@ partial class Build : NukeBuild [Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")] readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release; + [Solution] + readonly Solution Solution; + + AbsolutePath OutputDirectory => RootDirectory / "artifacts"; + Target Clean => d => d .Before(Restore) .Executes(() => DotNetTasks.DotNetClean()); + + Target CleanArtifacts => d => d + .Before(Restore) + .Executes(() => OutputDirectory.CreateOrCleanDirectory()); Target Restore => d => d .Executes(() => DotNetTasks.DotNetRestore()); diff --git a/src/app/Directory.Build.props b/src/app/Directory.Build.props index 9277c75ea..f9b0d0b11 100644 --- a/src/app/Directory.Build.props +++ b/src/app/Directory.Build.props @@ -6,10 +6,4 @@ Exe - - true - true - true - - \ No newline at end of file diff --git a/src/protocol/Edelstein.Protocol.Gameplay.Login/packages.lock.json b/src/protocol/Edelstein.Protocol.Gameplay.Login/packages.lock.json index f3c0122ce..4c3062b2d 100644 --- a/src/protocol/Edelstein.Protocol.Gameplay.Login/packages.lock.json +++ b/src/protocol/Edelstein.Protocol.Gameplay.Login/packages.lock.json @@ -923,12 +923,6 @@ "Microsoft.IO.RecyclableMemoryStream": "[3.0.1, )" } }, - "edelstein.protocol.plugin": { - "type": "Project", - "dependencies": { - "Edelstein.Protocol.Utilities": "[1.0.0, )" - } - }, "edelstein.protocol.utilities": { "type": "Project" },