Skip to content

Commit

Permalink
Ready To run feature feature toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Feb 1, 2024
1 parent 2ba1eed commit 889ac90
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 15 deletions.
4 changes: 4 additions & 0 deletions starsky/.nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@
"type": "string"
}
},
"ReadyToRun": {
"type": "boolean",
"description": "Enable Ready to run builds"
},
"Root": {
"type": "string",
"description": "Root directory during build execution"
Expand Down
46 changes: 37 additions & 9 deletions starsky/build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,25 @@ string GetBranchName()
}
return branchName;
}

/// <summary>
/// Enable for Ready to run build
/// Only is combination is supported
/// @see: https://learn.microsoft.com/en-us/dotnet/core/deploying/ready-to-run
/// for build combinations, if not supported, it will auto skip
/// </summary>
/// <returns>true if explicit enabled</returns>
[Parameter("Enable Ready to run builds")]
readonly bool ReadyToRun;

/// <summary>
/// --ready-to-run
/// </summary>
/// <returns></returns>
public bool IsReadyToRunEnabled()
{
return ReadyToRun;
}

/// <summary>
/// Only the OS specific runtimes, so skip generic-netcore
Expand Down Expand Up @@ -140,6 +159,11 @@ List<string> GetRuntimesWithoutGeneric()
"starskythumbnailmetacli",
"starsky"
};

/// <summary>
/// Link to GeoCli.csproj
/// </summary>
const string GeoCliCsproj = "starskygeocli/starskygeocli.csproj";

/// <summary>
/// Npm and node are required for preflight checks and building frontend code
Expand Down Expand Up @@ -216,7 +240,10 @@ void ShowSettingsInfo()

Log.Information(NoDependencies ? "External dependencies: disabled" :
"External dependencies: enabled");


Log.Information(NoDependencies ? "External dependencies: disabled" :
"External dependencies: enabled");

if ( !string.IsNullOrEmpty(GetBranchName()) )
{
Log.Information("(Overwrite) Branch:");
Expand Down Expand Up @@ -262,9 +289,8 @@ void ShowSettingsInfo()
"starskytest/coverage-merge-sonarqube.xml");
DotnetGenericHelper.BuildNetCoreGenericCommand(Solution,Configuration);
DotnetTestHelper.TestNetCoreGenericCommand(Configuration,IsUnitTestDisabled());
DotnetGenericHelper.DownloadDependencies(Configuration,
"starskygeocli/starskygeocli.csproj",NoDependencies,
"generic-netcore");
DotnetGenericHelper.DownloadDependencies(Configuration, GeoCliCsproj
,NoDependencies, GenericRuntimeName);
MergeCoverageFiles.Merge(IsUnitTestDisabled());
SonarQube.SonarEnd(IsUnitTestDisabled(),NoSonar);
DotnetGenericHelper.PublishNetCoreGenericCommand(Configuration, IsPublishDisabled());
Expand All @@ -278,9 +304,9 @@ void ShowSettingsInfo()
{
DotnetGenericHelper.DownloadDependencies(Configuration,
"starskygeocli/starskygeocli.csproj",NoDependencies,
"generic-netcore");
GenericRuntimeName);
DotnetRuntimeSpecificHelper.CopyDependenciesFiles(NoDependencies,
"generic-netcore",GetRuntimesWithoutGeneric());
GenericRuntimeName,GetRuntimesWithoutGeneric());

});

Expand All @@ -307,12 +333,14 @@ void ShowSettingsInfo()

foreach ( var runtime in GetRuntimesWithoutGeneric() )
{
DotnetRuntimeSpecificHelper.BuildNetCoreCommand(Solution, Configuration, runtime);
DotnetRuntimeSpecificHelper.PublishNetCoreGenericCommand(Configuration, runtime);
DotnetRuntimeSpecificHelper.BuildNetCoreCommand(Solution, Configuration,
runtime, IsReadyToRunEnabled());
DotnetRuntimeSpecificHelper.PublishNetCoreGenericCommand(Configuration,
runtime, IsReadyToRunEnabled());
}

DotnetRuntimeSpecificHelper.CopyDependenciesFiles(NoDependencies,
"generic-netcore",GetRuntimesWithoutGeneric());
GenericRuntimeName,GetRuntimesWithoutGeneric());
});

// ReSharper disable once UnusedMember.Local
Expand Down
26 changes: 21 additions & 5 deletions starsky/build/helpers/DotnetRuntimeSpecificHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,25 @@ public static void CopyDependenciesFiles(bool noDependencies,
}

}

/// <summary>
/// Specific build for runtime
/// Runs the command: dotnet build
/// </summary>
/// <param name="solution">the solution file (sln)</param>
/// <param name="configuration">Config file</param>
/// <param name="runtime">which runtime e.g. linux-arm or osx-x64</param>
/// <param name="isReadyToRunEnabled">Is Ready To Run Enabled</param>
public static void BuildNetCoreCommand(Solution solution, Configuration
configuration, string runtime)
configuration, string runtime, bool isReadyToRunEnabled)
{
Log.Information("> dotnet build next for: solution: " + solution + " runtime: " + runtime);

var readyToRunArgument =
RuntimeIdentifier.IsReadyToRunSupported(runtime) && isReadyToRunEnabled
? "-p:PublishReadyToRun=true"
: "";

DotNetBuild(p => p
.SetProjectFile(solution)
// Implicit restore here, since .NET 8 self contained is disabled
Expand All @@ -127,6 +133,7 @@ public static void BuildNetCoreCommand(Solution solution, Configuration
.Add("/p:WarningLevel=0")
// SonarQube analysis is done in the generic build
.Add("/p:noSonar=true")
.Add(readyToRunArgument)
));
}

Expand All @@ -136,11 +143,14 @@ public static void BuildNetCoreCommand(Solution solution, Configuration
/// </summary>
/// <param name="configuration">Release</param>
/// <param name="runtime">runtime identifier</param>
public static void PublishNetCoreGenericCommand(Configuration configuration, string runtime)
/// <param name="isReadyToRunEnabled">Is Ready To Run Enabled</param>
public static void PublishNetCoreGenericCommand(Configuration configuration,
string runtime, bool isReadyToRunEnabled)
{
foreach ( var publishProject in Build.PublishProjectsList )
{
Log.Information(">> next publishProject: " + publishProject + " runtime: " + runtime);
Log.Information(">> next publishProject: " +
publishProject + " runtime: " + runtime);

var publishProjectFullPath = Path.Combine(
WorkingDirectory.GetSolutionParentFolder(),
Expand All @@ -149,7 +159,12 @@ public static void PublishNetCoreGenericCommand(Configuration configuration, str
var outputFullPath = Path.Combine(
WorkingDirectory.GetSolutionParentFolder(),
runtime);


var readyToRunArgument =
RuntimeIdentifier.IsReadyToRunSupported(runtime) && isReadyToRunEnabled
? "-p:PublishReadyToRun=true"
: "";

DotNetPublish(p => p
.SetConfiguration(configuration)
.EnableNoRestore()
Expand All @@ -163,6 +178,7 @@ public static void PublishNetCoreGenericCommand(Configuration configuration, str
.SetProcessArgumentConfigurator(args =>
args.Add("/p:noSonar=true")
.Add($"/p:OverwriteRuntimeIdentifier={runtime}")
.Add(readyToRunArgument)
)
);
}
Expand Down
64 changes: 63 additions & 1 deletion starsky/build/helpers/RuntimeIdentifier.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Serilog;

namespace helpers;

Expand All @@ -26,4 +27,65 @@ public static string GetCurrentRuntimeIdentifier()

return $"{os}-{architecture}";
}

/// <summary>
/// SDK-platform Supported target platforms
/// Windows X64 Windows (X86, X64, Arm64), Linux (X64, Arm32, Arm64), macOS (X64, Arm64)
/// win-x64 - supports: win-x86, win-x64, win-arm64, linux-x64, linux-arm, linux-arm64, osx-x64, osx-arm64
/// Windows X86 Windows (X86), Linux (Arm32)
/// win-x86 - supports: win-x86, linux-arm
/// Linux X64 Linux (X64, Arm32, Arm64), macOS (X64, Arm64)
/// linux-x64 - supports linux-x64, linux-arm, linux-arm64, osx-x64, osx-arm64
/// Linux Arm32 Linux Arm32
/// linux-arm, supports linux-arm
/// Linux Arm64 Linux (X64, Arm32, Arm64), macOS (X64, Arm64)
/// linux-arm64 supports linux-x64, linux-arm, linux-arm64, osx-x64, osx-arm64
/// macOS X64 Linux (X64, Arm32, Arm64), macOS (X64, Arm64)
/// osx-x64 supports linux-x64, linux-arm, linux-arm64, osx-x64, osx-arm64
/// macOS Arm64 Linux (X64, Arm32, Arm64), macOS (X64, Arm64)
/// osx-arm64 supports linux-x64, linux-arm, linux-arm64, osx-x64, osx-arm64
///
/// @see: https://learn.microsoft.com/en-us/dotnet/core/deploying/ready-to-run
/// </summary>
static readonly Dictionary<string, List<string>> SupportedPlatforms = new()
{
{ "win-x64",
[
"win-x86", "win-x64", "win-arm64", "linux-x64", "linux-arm",
"linux-arm64", "osx-x64", "osx-arm64"
]
},
{ "win-x86", ["win-x86", "linux-arm"] },
{ "linux-x64",
["linux-x64", "linux-arm", "linux-arm64", "osx-x64", "osx-arm64"]
},
{ "linux-arm", ["linux-arm"] },
{ "linux-arm64",
["linux-x64", "linux-arm", "linux-arm64", "osx-x64", "osx-arm64"]
},
{ "osx-x64",
["linux-x64", "linux-arm", "linux-arm64", "osx-x64", "osx-arm64"]
},
{ "osx-arm64",
["linux-x64", "linux-arm", "linux-arm64", "osx-x64", "osx-arm64"]
}
};

public static bool IsReadyToRunSupported(string toRuntimeIdentifier)
{
var currentIdentifier = GetCurrentRuntimeIdentifier();
return IsReadyToRunSupported(currentIdentifier, toRuntimeIdentifier);
}

static bool IsReadyToRunSupported(string currentIdentifier, string toRuntimeIdentifier)
{
if (SupportedPlatforms.TryGetValue(currentIdentifier, out var supportedTargets))
{
return supportedTargets.Contains(toRuntimeIdentifier);
}

// Handle unsupported currentIdentifier
Log.Error($"Unsupported currentIdentifier: {currentIdentifier}");
return false;
}
}

0 comments on commit 889ac90

Please sign in to comment.