Skip to content

Commit

Permalink
Add pack and publish build targets
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaioru committed Aug 18, 2024
1 parent e8d04d8 commit 7092a8b
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
#
# - To trigger manual generation invoke:
#
# nuke --generate-configuration GitHubActions_build --host GitHubActions
# nuke --generate-configuration GitHubActions_Build --host GitHubActions
#
# </auto-generated>
# ------------------------------------------------------------------------------

name: build
name: Build

on: [push]

Expand Down
10 changes: 10 additions & 0 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,29 @@
"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}'",
"items": {
"type": "string",
"enum": [
"Clean",
"CleanArtifacts",
"Compile",
"Pack",
"Publish",
"Restore"
]
}
Expand Down
18 changes: 18 additions & 0 deletions build/Build.Artifacts.Pack.cs
Original file line number Diff line number Diff line change
@@ -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));
});
}
80 changes: 80 additions & 0 deletions build/Build.Artifacts.Publish.cs
Original file line number Diff line number Diff line change
@@ -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<string> 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");
}
});
}
9 changes: 9 additions & 0 deletions build/Build.CI.GithubActions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Nuke.Common.CI.GitHubActions;

[GitHubActions(
"Build",
GitHubActionsImage.UbuntuLatest,
On = new[] { GitHubActionsTrigger.Push },
InvokedTargets = new[] { nameof(Compile) }
)]
partial class Build;
19 changes: 12 additions & 7 deletions build/Build.cs
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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());
Expand Down
6 changes: 0 additions & 6 deletions src/app/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,4 @@
<OutputType>Exe</OutputType>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Release'">
<PublishReadyToRun>true</PublishReadyToRun>
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>true</SelfContained>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down

0 comments on commit 7092a8b

Please sign in to comment.