Skip to content

Commit

Permalink
Updated build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
flyingpie committed Oct 30, 2024
1 parent a77d7a9 commit 53d4a35
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 19 deletions.
4 changes: 4 additions & 0 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,12 @@
"CreateScoopManifest",
"CreateWinGetManifest",
"PublishDebug",
"PublishLinux64",
"PublishLinux64Aot",
"PublishLinux64FrameworkDependent",
"PublishLinux64SelfContained",
"PublishRelease",
"PublishWin64",
"PublishWin64Aot",
"PublishWin64FrameworkDependent",
"PublishWin64SelfContained",
Expand All @@ -107,10 +109,12 @@
"CreateScoopManifest",
"CreateWinGetManifest",
"PublishDebug",
"PublishLinux64",
"PublishLinux64Aot",
"PublishLinux64FrameworkDependent",
"PublishLinux64SelfContained",
"PublishRelease",
"PublishWin64",
"PublishWin64Aot",
"PublishWin64FrameworkDependent",
"PublishWin64SelfContained",
Expand Down
1 change: 1 addition & 0 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./src/build.ps1
3 changes: 3 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

./src/build.sh
56 changes: 37 additions & 19 deletions src/01-Build/NukeBuild/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,22 @@ public sealed class Build : NukeBuild
.Produces(PathToLinux64AotZip)
.Executes(() =>
{
var staging = StagingDirectory / "linux-x64_aot";
var st = StagingDirectory / "linux-x64_aot";
DotNetPublish(_ => _
.SetAssemblyVersion(AssemblyVersion)
.SetInformationalVersion(InformationalVersion)
.SetConfiguration(Configuration)
.SetProject(Solution._0_Host.Wtq_Host_Linux)
.SetOutput(staging)
.SetOutput(st)
.SetProperty("PublishAot", true)
.SetProperty("InvariantGlobalization", true)
.SetRuntime("linux-x64"));
staging.ZipTo(
// TODO: Remove unnecessary files.
st.ZipTo(
PathToLinux64AotZip,
filter: x => x.HasExtension(".exe", ".jsonc"),
compressionLevel: CompressionLevel.SmallestSize,
fileMode: System.IO.FileMode.CreateNew);
});
Expand All @@ -149,9 +150,10 @@ public sealed class Build : NukeBuild
.SetRuntime("linux-x64")
.SetSelfContained(false));
st.DeleteFilesExceptFor("wtq", "wtq.kwin.js");
st.ZipTo(
PathToLinux64FrameworkDependentZip,
filter: x => !x.HasExtension(".xml"),
compressionLevel: CompressionLevel.SmallestSize,
fileMode: System.IO.FileMode.CreateNew);
});
Expand All @@ -164,21 +166,22 @@ public sealed class Build : NukeBuild
.Produces(PathToLinux64SelfContainedZip)
.Executes(() =>
{
var staging = StagingDirectory / "linux-x64_self-contained";
var st = StagingDirectory / "linux-x64_self-contained";
DotNetPublish(_ => _
.SetAssemblyVersion(AssemblyVersion)
.SetInformationalVersion(InformationalVersion)
.SetConfiguration(Configuration)
.SetProject(Solution._0_Host.Wtq_Host_Linux)
.SetOutput(staging)
.SetOutput(st)
.SetPublishSingleFile(true)
.SetRuntime("linux-x64")
.SetSelfContained(true));
staging.ZipTo(
st.DeleteFilesExceptFor("wtq", "wtq.kwin.js");
st.ZipTo(
PathToLinux64SelfContainedZip,
filter: x => !x.HasExtension(".xml"),
compressionLevel: CompressionLevel.SmallestSize,
fileMode: System.IO.FileMode.CreateNew);
});
Expand All @@ -191,22 +194,23 @@ public sealed class Build : NukeBuild
.Produces(PathToWin64AotZip)
.Executes(() =>
{
var staging = StagingDirectory / "win-x64_aot";
var st = StagingDirectory / "win-x64_aot";
DotNetPublish(_ => _
.SetAssemblyVersion(AssemblyVersion)
.SetInformationalVersion(InformationalVersion)
.SetConfiguration(Configuration)
.SetFramework("net8.0-windows")
.SetProject(Solution._0_Host.Wtq_Host_Windows)
.SetOutput(staging)
.SetOutput(st)
.SetProperty("PublishAot", true)
.SetProperty("InvariantGlobalization", true)
.SetRuntime("win-x64"));
staging.ZipTo(
// TODO: Remove unnecessary files.
st.ZipTo(
PathToWin64AotZip,
filter: x => x.HasExtension(".exe", ".jsonc"),
compressionLevel: CompressionLevel.SmallestSize,
fileMode: System.IO.FileMode.CreateNew);
});
Expand All @@ -232,9 +236,10 @@ public sealed class Build : NukeBuild
.SetRuntime("win-x64")
.SetSelfContained(false));
st.DeleteFilesExceptFor("wtq.exe");
st.ZipTo(
PathToWin64FrameworkDependentZip,
filter: x => x.HasExtension(".exe", ".jsonc"),
compressionLevel: CompressionLevel.SmallestSize,
fileMode: System.IO.FileMode.CreateNew);
});
Expand All @@ -247,22 +252,23 @@ public sealed class Build : NukeBuild
.Produces(PathToWin64SelfContainedZip)
.Executes(() =>
{
var staging = StagingDirectory / "win-x64_self-contained";
var st = StagingDirectory / "win-x64_self-contained";
DotNetPublish(_ => _
.SetAssemblyVersion(AssemblyVersion)
.SetInformationalVersion(InformationalVersion)
.SetConfiguration(Configuration)
.SetFramework("net8.0-windows")
.SetProject(Solution._0_Host.Wtq_Host_Windows)
.SetOutput(staging)
.SetOutput(st)
.SetPublishSingleFile(true)
.SetRuntime("win-x64")
.SetSelfContained(true));
staging.ZipTo(
st.DeleteFilesExceptFor("wtq.exe");
st.ZipTo(
PathToWin64SelfContainedZip,
filter: x => x.HasExtension(".exe", ".jsonc"),
compressionLevel: CompressionLevel.SmallestSize,
fileMode: System.IO.FileMode.CreateNew);
});
Expand Down Expand Up @@ -375,16 +381,28 @@ await GitHubTasks
await GitHubTasks.GitHubClient.UploadReleaseAssetToGithub(ghRelease, PathToWin64SelfContainedZip);
});

private Target PublishDebug => _ => _
private Target PublishLinux64 => _ => _
.DependsOn(Clean)
.DependsOn(PublishLinux64FrameworkDependent)
.DependsOn(PublishLinux64SelfContained)
.Executes();

private Target PublishWin64 => _ => _
.DependsOn(Clean)
.DependsOn(PublishWin64FrameworkDependent)
.DependsOn(PublishWin64SelfContained)
.Triggers(CreateScoopManifest)
.Triggers(CreateWinGetManifest)
.Executes();

private Target PublishDebug => _ => _
.DependsOn(Clean)
.DependsOn(PublishLinux64)
.DependsOn(PublishWin64)
.Triggers(CreateScoopManifest)
.Triggers(CreateWinGetManifest)
.Executes();

[SuppressMessage("Major Code Smell", "S1144:Unused private types or members should be removed", Justification = "MvdO: Invoked manually.")]
private Target PublishRelease => _ => _
.DependsOn(Clean)
Expand Down
25 changes: 25 additions & 0 deletions src/01-Build/NukeBuild/NukeExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using Nuke.Common.IO;
using Octokit;
using Serilog;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Text;
Expand All @@ -11,6 +14,28 @@ public static partial class NukeExtensions
{
private static readonly string ApplicationOctetStream = "application/octet-stream";

/// <summary>
/// Deletes all files under the specified <paramref name="path"/>, except for any <paramref name="excludes"/>.
/// </summary>
public static void DeleteFilesExceptFor(this AbsolutePath path, params string[] excludes)
{
var wl = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
foreach (var ex in excludes)
{
wl.Add(ex);
}

foreach (var f in path.GetFiles())
{
if (wl.Contains(f.Name))
{
continue;
}

f.DeleteFile();
}
}

public static async Task<string> GetChangeLogEntryAsync(
string path,
string ver)
Expand Down

0 comments on commit 53d4a35

Please sign in to comment.