mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-09-14 20:43:38 +00:00
Some checks are pending
Build and Release / Determine run mode (push) Waiting to run
Build and Release / Sync Flatpak repo (push) Blocked by required conditions
Build and Release / Collect Flatpak artifacts (push) Blocked by required conditions
Build and Release / Verify (push) Waiting to run
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions
149 lines
5.4 KiB
C#
149 lines
5.4 KiB
C#
using System.Runtime.InteropServices;
|
|
|
|
using SharedTools;
|
|
|
|
namespace Build.Tools;
|
|
|
|
public static class Environment
|
|
{
|
|
public const string DOTNET_VERSION = "net9.0";
|
|
public const string BUILD_OFFLINE_ENVIRONMENT_VARIABLE = "AI_STUDIO_BUILD_OFFLINE";
|
|
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.AsMicrosoftRid())).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
|
|
|
|
public static bool IsWorkingDirectoryValid()
|
|
{
|
|
var currentDirectory = Directory.GetCurrentDirectory();
|
|
var mainFile = Path.Combine(currentDirectory, "Program.cs");
|
|
var projectFile = Path.Combine(currentDirectory, "Build Script.csproj");
|
|
|
|
if (!currentDirectory.EndsWith("Build", StringComparison.Ordinal) || !File.Exists(mainFile) || !File.Exists(projectFile))
|
|
{
|
|
Console.WriteLine("The current directory is not a valid working directory for the build script. Go to the /app/Build directory within the git repository.");
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public static string GetAIStudioDirectory()
|
|
{
|
|
var currentDirectory = Directory.GetCurrentDirectory();
|
|
var directory = Path.Combine(currentDirectory, "..", "MindWork AI Studio");
|
|
return Path.GetFullPath(directory);
|
|
}
|
|
|
|
public static string GetTestsDirectory()
|
|
{
|
|
var currentDirectory = Directory.GetCurrentDirectory();
|
|
var directory = Path.Combine(currentDirectory, "..", "Tests");
|
|
return Path.GetFullPath(directory);
|
|
}
|
|
|
|
/// <summary>
|
|
/// The root of the git repository, which is what a path in a report is written relative to.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// GitHub resolves the file of an annotation against the checkout, not against wherever a tool
|
|
/// happened to run. An absolute path of somebody's machine would therefore land the annotation
|
|
/// nowhere, without saying so.
|
|
/// </remarks>
|
|
public static string GetRepositoryDirectory()
|
|
{
|
|
var currentDirectory = Directory.GetCurrentDirectory();
|
|
var directory = Path.Combine(currentDirectory, "..", "..");
|
|
return Path.GetFullPath(directory);
|
|
}
|
|
|
|
public static string GetRustRuntimeDirectory()
|
|
{
|
|
var currentDirectory = Directory.GetCurrentDirectory();
|
|
var directory = Path.Combine(currentDirectory, "..", "..", "runtime");
|
|
return Path.GetFullPath(directory);
|
|
}
|
|
|
|
public static string GetMetadataPath()
|
|
{
|
|
var currentDirectory = Directory.GetCurrentDirectory();
|
|
var directory = Path.Combine(currentDirectory, "..", "..", "metadata.txt");
|
|
return Path.GetFullPath(directory);
|
|
}
|
|
|
|
public static bool IsOfflineBuildRequested(bool offlineOption)
|
|
{
|
|
if (offlineOption)
|
|
return true;
|
|
|
|
var environmentValue = global::System.Environment.GetEnvironmentVariable(BUILD_OFFLINE_ENVIRONMENT_VARIABLE);
|
|
return environmentValue?.Trim().ToLowerInvariant() switch
|
|
{
|
|
"1" or "true" or "yes" or "on" => true,
|
|
_ => false,
|
|
};
|
|
}
|
|
|
|
public static string? GetOS()
|
|
{
|
|
if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
return "windows";
|
|
|
|
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
return "linux";
|
|
|
|
if(RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
|
return "darwin";
|
|
|
|
Console.WriteLine($"Error: Unsupported OS '{RuntimeInformation.OSDescription}'");
|
|
return null;
|
|
}
|
|
|
|
public static IEnumerable<RID> GetRidsForCurrentOS()
|
|
{
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
return ALL_RIDS.Where(rid => rid.Value.StartsWith("win-", StringComparison.Ordinal)).Select(n => n.Key);
|
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
|
return ALL_RIDS.Where(rid => rid.Value.StartsWith("osx-", StringComparison.Ordinal)).Select(n => n.Key);
|
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
return ALL_RIDS.Where(rid => rid.Value.StartsWith("linux-", StringComparison.Ordinal)).Select(n => n.Key);
|
|
|
|
Console.WriteLine($"Error: Unsupported OS '{RuntimeInformation.OSDescription}'");
|
|
return [];
|
|
}
|
|
|
|
public static RID GetCurrentRid()
|
|
{
|
|
var arch = RuntimeInformation.ProcessArchitecture;
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
return arch switch
|
|
{
|
|
Architecture.X64 => RID.WIN_X64,
|
|
Architecture.Arm64 => RID.WIN_ARM64,
|
|
|
|
_ => RID.NONE,
|
|
};
|
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
|
return arch switch
|
|
{
|
|
Architecture.X64 => RID.OSX_X64,
|
|
Architecture.Arm64 => RID.OSX_ARM64,
|
|
|
|
_ => RID.NONE,
|
|
};
|
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
return arch switch
|
|
{
|
|
Architecture.X64 => RID.LINUX_X64,
|
|
Architecture.Arm64 => RID.LINUX_ARM64,
|
|
|
|
_ => RID.NONE,
|
|
};
|
|
|
|
Console.WriteLine($"Error: Unsupported OS '{RuntimeInformation.OSDescription}'");
|
|
return RID.NONE;
|
|
}
|
|
} |