mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-05 17:49:40 +00:00
Added the current CPU architecture to the metadata (#402)
This commit is contained in:
1 parent
c715b38f41
commit
b153b9c4e9
16 files changed
+177
-71
No files matched your search
@@ -1,7 +1,7 @@
|
||||
using System.Diagnostics;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using Build.Tools;
|
||||
using SharedTools;
|
||||
|
||||
namespace Build.Commands;
|
||||
|
||||
@@ -77,9 +77,11 @@ public sealed partial class UpdateMetadataCommands
|
||||
foreach (var rid in rids)
|
||||
{
|
||||
Console.WriteLine("==============================");
|
||||
Console.Write($"- Start .NET build for '{rid.ToName()}' ...");
|
||||
await this.ReadCommandOutput(pathApp, "dotnet", $"clean --configuration release --runtime {rid.ToName()}");
|
||||
var dotnetBuildOutput = await this.ReadCommandOutput(pathApp, "dotnet", $"publish --configuration release --runtime {rid.ToName()} --disable-build-servers --force");
|
||||
await this.UpdateArchitecture(rid);
|
||||
|
||||
Console.Write($"- Start .NET build for '{rid.AsMicrosoftRid()}' ...");
|
||||
await this.ReadCommandOutput(pathApp, "dotnet", $"clean --configuration release --runtime {rid.AsMicrosoftRid()}");
|
||||
var dotnetBuildOutput = await this.ReadCommandOutput(pathApp, "dotnet", $"publish --configuration release --runtime {rid.AsMicrosoftRid()} --disable-build-servers --force");
|
||||
var dotnetBuildOutputLines = dotnetBuildOutput.Split([global::System.Environment.NewLine], StringSplitOptions.RemoveEmptyEntries);
|
||||
var foundIssue = false;
|
||||
foreach (var buildOutputLine in dotnetBuildOutputLines)
|
||||
@@ -125,7 +127,7 @@ public sealed partial class UpdateMetadataCommands
|
||||
|
||||
if (string.IsNullOrWhiteSpace(tauriSidecarArtifactName))
|
||||
{
|
||||
Console.WriteLine($"- Error: Unsupported rid '{rid.ToName()}'.");
|
||||
Console.WriteLine($"- Error: Unsupported rid '{rid.AsMicrosoftRid()}'.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -139,7 +141,7 @@ public sealed partial class UpdateMetadataCommands
|
||||
_ => "mindworkAIStudio",
|
||||
};
|
||||
|
||||
var dotnetPublishedPath = Path.Combine(pathApp, "bin", "release", Environment.DOTNET_VERSION, rid.ToName(), "publish", dotnetArtifactFilename);
|
||||
var dotnetPublishedPath = Path.Combine(pathApp, "bin", "release", Environment.DOTNET_VERSION, rid.AsMicrosoftRid(), "publish", dotnetArtifactFilename);
|
||||
var finalDestination = Path.Combine(dotnetArtifactPath, tauriSidecarArtifactName);
|
||||
|
||||
if(File.Exists(dotnetPublishedPath))
|
||||
@@ -235,6 +237,19 @@ public sealed partial class UpdateMetadataCommands
|
||||
await File.WriteAllTextAsync(changelogCodePath, changelogCode, Environment.UTF8_NO_BOM);
|
||||
}
|
||||
|
||||
private async Task UpdateArchitecture(RID rid)
|
||||
{
|
||||
const int ARCHITECTURE_INDEX = 9;
|
||||
|
||||
var pathMetadata = Environment.GetMetadataPath();
|
||||
var lines = await File.ReadAllLinesAsync(pathMetadata, Encoding.UTF8);
|
||||
Console.Write("- Updating architecture ...");
|
||||
lines[ARCHITECTURE_INDEX] = rid.AsMicrosoftRid();
|
||||
|
||||
await File.WriteAllLinesAsync(pathMetadata, lines, Environment.UTF8_NO_BOM);
|
||||
Console.WriteLine(" done.");
|
||||
}
|
||||
|
||||
private async Task UpdateProjectCommitHash()
|
||||
{
|
||||
const int COMMIT_HASH_INDEX = 8;
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
using Build.Tools;
|
||||
|
||||
using SharedTools;
|
||||
|
||||
namespace Build.Commands;
|
||||
|
||||
public sealed class UpdateWebAssetsCommand
|
||||
@@ -19,7 +21,7 @@ public sealed class UpdateWebAssetsCommand
|
||||
|
||||
var rid = Environment.GetRidsForCurrentOS().First();
|
||||
var cwd = Environment.GetAIStudioDirectory();
|
||||
var contentPath = Path.Join(cwd, "bin", "release", Environment.DOTNET_VERSION, rid.ToName(), "publish", "wwwroot", "_content");
|
||||
var contentPath = Path.Join(cwd, "bin", "release", Environment.DOTNET_VERSION, rid.AsMicrosoftRid(), "publish", "wwwroot", "_content");
|
||||
var isMudBlazorDirectoryPresent = Directory.Exists(Path.Join(contentPath, "MudBlazor"));
|
||||
if (!isMudBlazorDirectoryPresent)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using SharedTools;
|
||||
|
||||
namespace Build.Tools;
|
||||
|
||||
public static class Environment
|
||||
@@ -7,7 +9,7 @@ public static class Environment
|
||||
public const string DOTNET_VERSION = "net9.0";
|
||||
public static readonly Encoding UTF8_NO_BOM = new UTF8Encoding(false);
|
||||
|
||||
private static readonly Dictionary<RID, string> ALL_RIDS = Enum.GetValues<RID>().Select(rid => new KeyValuePair<RID, string>(rid, rid.ToName())).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
|
||||
private static readonly Dictionary<RID, string> ALL_RIDS = Enum.GetValues<RID>().Select(rid => new KeyValuePair<RID, string>(rid, rid.AsMicrosoftRid())).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
|
||||
|
||||
public static bool IsWorkingDirectoryValid()
|
||||
{
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
namespace Build.Tools;
|
||||
|
||||
public static class RIDExtensions
|
||||
{
|
||||
public static string ToName(this RID rid) => rid switch
|
||||
{
|
||||
RID.WIN_X64 => "win-x64",
|
||||
RID.WIN_ARM64 => "win-arm64",
|
||||
|
||||
RID.LINUX_X64 => "linux-x64",
|
||||
RID.LINUX_ARM64 => "linux-arm64",
|
||||
|
||||
RID.OSX_X64 => "osx-x64",
|
||||
RID.OSX_ARM64 => "osx-arm64",
|
||||
|
||||
_ => string.Empty,
|
||||
};
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Reflection;
|
||||
|
||||
using AIStudio.Tools.Metadata;
|
||||
using AIStudio.Tools.Rust;
|
||||
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
namespace AIStudio;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Assembly)]
|
||||
public class MetaDataAttribute(
|
||||
string version,
|
||||
string buildTime,
|
||||
uint buildNum,
|
||||
string dotnetSdkVersion,
|
||||
string dotnetVersion,
|
||||
string rustVersion,
|
||||
string mudBlazorVersion,
|
||||
string tauriVersion,
|
||||
string appCommitHash
|
||||
) : Attribute
|
||||
{
|
||||
public string BuildTime { get; } = buildTime;
|
||||
|
||||
public string Version { get; } = version;
|
||||
|
||||
public uint BuildNum { get; } = buildNum;
|
||||
|
||||
public string DotnetVersion { get; } = dotnetVersion;
|
||||
|
||||
public string DotnetSdkVersion { get; } = dotnetSdkVersion;
|
||||
|
||||
public string RustVersion { get; } = rustVersion;
|
||||
|
||||
public string MudBlazorVersion { get; } = mudBlazorVersion;
|
||||
|
||||
public string TauriVersion { get; } = tauriVersion;
|
||||
|
||||
public string AppCommitHash { get; } = appCommitHash;
|
||||
}
|
||||
@@ -78,6 +78,7 @@
|
||||
<MetaMudBlazorVersion>$([System.String]::Copy( $(Metadata) ).Split( ';' )[ 6 ])</MetaMudBlazorVersion>
|
||||
<MetaTauriVersion>$([System.String]::Copy( $(Metadata) ).Split( ';' )[ 7 ])</MetaTauriVersion>
|
||||
<MetaAppCommitHash>$([System.String]::Copy( $(Metadata) ).Split( ';' )[ 8 ])</MetaAppCommitHash>
|
||||
<MetaArchitecture>$([System.String]::Copy( $(Metadata) ).Split( ';' )[ 9 ])</MetaArchitecture>
|
||||
|
||||
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
|
||||
|
||||
@@ -87,7 +88,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AssemblyAttribute Include="AIStudio.MetaDataAttribute">
|
||||
<AssemblyAttribute Include="AIStudio.Tools.Metadata.MetaData">
|
||||
<_Parameter1>$(MetaVersion)</_Parameter1>
|
||||
<_Parameter2>$(MetaBuildTime)</_Parameter2>
|
||||
<_Parameter3>$(MetaBuild)</_Parameter3>
|
||||
@@ -99,6 +100,9 @@
|
||||
<_Parameter8>$(MetaTauriVersion)</_Parameter8>
|
||||
<_Parameter9>$(MetaAppCommitHash)</_Parameter9>
|
||||
</AssemblyAttribute>
|
||||
<AssemblyAttribute Include="AIStudio.Tools.Metadata.MetaDataArchitecture">
|
||||
<_Parameter1>$(MetaArchitecture)</_Parameter1>
|
||||
</AssemblyAttribute>
|
||||
</ItemGroup>
|
||||
|
||||
</Target>
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
using System.Reflection;
|
||||
|
||||
using AIStudio.Tools.Metadata;
|
||||
using AIStudio.Tools.Rust;
|
||||
using AIStudio.Tools.Services;
|
||||
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
using SharedTools;
|
||||
|
||||
namespace AIStudio.Pages;
|
||||
|
||||
public partial class About : ComponentBase
|
||||
@@ -20,6 +23,7 @@ public partial class About : ComponentBase
|
||||
|
||||
private static readonly Assembly ASSEMBLY = Assembly.GetExecutingAssembly();
|
||||
private static readonly MetaDataAttribute META_DATA = ASSEMBLY.GetCustomAttribute<MetaDataAttribute>()!;
|
||||
private static readonly MetaDataArchitecture META_DATA_ARCH = ASSEMBLY.GetCustomAttribute<MetaDataArchitecture>()!;
|
||||
|
||||
private static string VersionDotnetRuntime => $"Used .NET runtime: v{META_DATA.DotnetVersion}";
|
||||
|
||||
@@ -27,7 +31,7 @@ public partial class About : ComponentBase
|
||||
|
||||
private static string VersionRust => $"Used Rust compiler: v{META_DATA.RustVersion}";
|
||||
|
||||
private static string VersionApp => $"MindWork AI Studio: v{META_DATA.Version} (commit {META_DATA.AppCommitHash}, build {META_DATA.BuildNum})";
|
||||
private static string VersionApp => $"MindWork AI Studio: v{META_DATA.Version} (commit {META_DATA.AppCommitHash}, build {META_DATA.BuildNum}, {META_DATA_ARCH.Architecture.ToRID().ToUserFriendlyName()})";
|
||||
|
||||
private static string BuildTime => $"Build time: {META_DATA.BuildTime}";
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// ReSharper disable ClassNeverInstantiated.Global
|
||||
namespace AIStudio.Tools.Metadata;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Assembly)]
|
||||
public class MetaDataArchitecture(string architecture) : Attribute
|
||||
{
|
||||
public string Architecture => architecture;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// ReSharper disable ClassNeverInstantiated.Global
|
||||
namespace AIStudio.Tools.Metadata;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Assembly)]
|
||||
public class MetaDataAttribute(
|
||||
string version,
|
||||
string buildTime,
|
||||
uint buildNum,
|
||||
string dotnetSdkVersion,
|
||||
string dotnetVersion,
|
||||
string rustVersion,
|
||||
string mudBlazorVersion,
|
||||
string tauriVersion,
|
||||
string appCommitHash
|
||||
) : Attribute
|
||||
{
|
||||
public string BuildTime => buildTime;
|
||||
|
||||
public string Version => version;
|
||||
|
||||
public uint BuildNum => buildNum;
|
||||
|
||||
public string DotnetVersion => dotnetVersion;
|
||||
|
||||
public string DotnetSdkVersion => dotnetSdkVersion;
|
||||
|
||||
public string RustVersion => rustVersion;
|
||||
|
||||
public string MudBlazorVersion => mudBlazorVersion;
|
||||
|
||||
public string TauriVersion => tauriVersion;
|
||||
|
||||
public string AppCommitHash => appCommitHash;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Build.Tools;
|
||||
namespace SharedTools;
|
||||
|
||||
public enum RID
|
||||
{
|
||||
@@ -0,0 +1,46 @@
|
||||
namespace SharedTools;
|
||||
|
||||
public static class RIDExtensions
|
||||
{
|
||||
public static string AsMicrosoftRid(this RID rid) => rid switch
|
||||
{
|
||||
RID.WIN_X64 => "win-x64",
|
||||
RID.WIN_ARM64 => "win-arm64",
|
||||
|
||||
RID.LINUX_X64 => "linux-x64",
|
||||
RID.LINUX_ARM64 => "linux-arm64",
|
||||
|
||||
RID.OSX_X64 => "osx-x64",
|
||||
RID.OSX_ARM64 => "osx-arm64",
|
||||
|
||||
_ => string.Empty,
|
||||
};
|
||||
|
||||
public static string ToUserFriendlyName(this RID rid) => rid switch
|
||||
{
|
||||
RID.WIN_X64 => "Windows x64",
|
||||
RID.WIN_ARM64 => "Windows ARM64",
|
||||
|
||||
RID.LINUX_X64 => "Linux x64",
|
||||
RID.LINUX_ARM64 => "Linux ARM64",
|
||||
|
||||
RID.OSX_X64 => "macOS x64",
|
||||
RID.OSX_ARM64 => "macOS ARM64",
|
||||
|
||||
_ => "unknown",
|
||||
};
|
||||
|
||||
public static RID ToRID(this string rid) => rid switch
|
||||
{
|
||||
"win-x64" => RID.WIN_X64,
|
||||
"win-arm64" => RID.WIN_ARM64,
|
||||
|
||||
"linux-x64" => RID.LINUX_X64,
|
||||
"linux-arm64" => RID.LINUX_ARM64,
|
||||
|
||||
"osx-x64" => RID.OSX_X64,
|
||||
"osx-arm64" => RID.OSX_ARM64,
|
||||
|
||||
_ => RID.NONE,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user