Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

Commit

Permalink
Improved build
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayPianikov committed Jul 7, 2024
1 parent bd6ec97 commit 8c130b3
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .run/Build.run.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Build" type="DotNetProject" factoryName=".NET Project">
<option name="EXE_PATH" value="$PROJECT_DIR$/Build/bin/Debug/net8.0/Build.exe" />
<option name="PROGRAM_PARAMETERS" value="-p:integrationTests=false -p:version=1.1.0-beta1" />
<option name="PROGRAM_PARAMETERS" value="-p:integrationTests=false -p:version=1.1.0-beta2" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="PASS_PARENT_ENVS" value="1" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
Expand Down
2 changes: 1 addition & 1 deletion Build/Build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CSharpInteractive" Version="1.0.9-beta6" />
<PackageReference Include="CSharpInteractive" Version="1.1.0-beta2" />
</ItemGroup>

</Project>
20 changes: 10 additions & 10 deletions Build/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
false)
};

Run(new DotNetToolRestore().WithShortName("Restoring tools"));
new DotNetToolRestore().WithShortName("Restoring tools").Run().EnsureSuccess();

new DotNetClean()
.WithProject(solutionFile)
Expand Down Expand Up @@ -134,7 +134,7 @@
.EnsureSuccess();

var dotCoverReportXml = Path.Combine(reportDir, "dotCover.xml");
Run(new DotNetCustom("dotCover", "report", $"--source={dotCoverSnapshot}", $"--output={dotCoverReportXml}", "--reportType=TeamCityXml").WithShortName("Generating the code coverage reports"));
new DotNetCustom("dotCover", "report", $"--source={dotCoverSnapshot}", $"--output={dotCoverReportXml}", "--reportType=TeamCityXml").WithShortName("Generating the code coverage reports").Run().EnsureSuccess();

if (TryGetCoverage(dotCoverReportXml, out coveragePercentage))
{
Expand All @@ -158,7 +158,7 @@
var uninstallTool = new DotNetCustom("tool", "uninstall", toolPackageId, "-g")
.WithShortName("Uninstalling tool");

if (uninstallTool.Run(_ => { } ) != 0)
if (uninstallTool.Run(_ => { } ).ExitCode != 0)
{
Warning($"{uninstallTool} failed.");
}
Expand All @@ -176,25 +176,25 @@
var installTool = new DotNetCustom("tool", "install", toolPackageId, "-g", "--version", packageVersion.ToString(), "--add-source", Path.Combine(outputDir, "CSharpInteractive.Tool"))
.WithShortName("Installing tool");

if (installTool.Run(output => WriteLine(output.Line)) != 0)
if (installTool.Run(output => WriteLine(output.Line)).ExitCode != 0)
{
Warning($"{installTool} failed.");
}

Run(new DotNetCustom("csi", "/?").WithShortName("Checking tool"));
new DotNetCustom("csi", "/?").WithShortName("Checking tool").Run().EnsureSuccess();

var uninstallTemplates = new DotNetCustom("new", "uninstall", templatesPackageId)
.WithShortName("Uninstalling template");

if (uninstallTemplates.Run(output => WriteLine(output.Line)) != 0)
if (uninstallTemplates.Run(output => WriteLine(output.Line)).ExitCode != 0)
{
Warning($"{uninstallTemplates} failed.");
}

var installTemplates = new DotNetCustom("new", "install", $"{templatesPackageId}::{packageVersion.ToString()}", "--nuget-source", templateOutputDir)
.WithShortName("Installing template");

Run(installTemplates.WithShortName(installTemplates.ShortName));
installTemplates.WithShortName(installTemplates.ShortName).Run().EnsureSuccess();

foreach (var framework in frameworks)
{
Expand All @@ -204,10 +204,10 @@
try
{
var sampleProjectDir = Path.Combine("Samples", "MySampleLib", "MySampleLib.Tests");
Run(new DotNetNew("build", $"--package-version={packageVersion}", "-T", framework, "--no-restore").WithWorkingDirectory(buildProjectDir).WithShortName($"Creating a new {sampleProjectName}"));
new DotNetNew("build", $"--package-version={packageVersion}", "-T", framework, "--no-restore").WithWorkingDirectory(buildProjectDir).WithShortName($"Creating a new {sampleProjectName}").Run().EnsureSuccess();
new DotNetBuild().WithProject(buildProjectDir).WithSources(defaultNuGetSource, Path.Combine(outputDir, "CSharpInteractive")).WithShortName($"Building the {sampleProjectName}").Build().EnsureSuccess();
Run(new DotNetRun().WithProject(buildProjectDir).WithNoBuild(true).WithWorkingDirectory(sampleProjectDir).WithShortName($"Running a build for the {sampleProjectName}"));
Run(new DotNetCustom("csi", Path.Combine(buildProjectDir, "Program.csx")).WithWorkingDirectory(sampleProjectDir).WithShortName($"Running a build as a C# script for the {sampleProjectName}"));
new DotNetRun().WithProject(buildProjectDir).WithNoBuild(true).WithWorkingDirectory(sampleProjectDir).WithShortName($"Running a build for the {sampleProjectName}").Run().EnsureSuccess();
new DotNetCustom("csi", Path.Combine(buildProjectDir, "Program.csx")).WithWorkingDirectory(sampleProjectDir).WithShortName($"Running a build as a C# script for the {sampleProjectName}").Run().EnsureSuccess();
}
finally
{
Expand Down
13 changes: 0 additions & 13 deletions Build/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,6 @@ public static string GetProperty(string name, string defaultProp, bool showWarni
return defaultProp;
}

public static void Run(ICommandLine commandLine)
{
var exitCode = commandLine.Run();
if (exitCode == 0)
{
return;
}

var startInfo = commandLine.GetStartInfo(GetService<IHost>());
Error($"{startInfo.ShortName} failed");
throw new OperationCanceledException();
}

public static bool TryGetCoverage(string dotCoverReportXml, out int coveragePercentage)
{
var dotCoverReportDoc = new XmlDocument();
Expand Down
5 changes: 5 additions & 0 deletions CSharpInteractive/Core/LogExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public static ILog<T> Error<T>(this ILog<T> log, ErrorId id, params string[] err

public static ILog<T> Error<T>(this ILog<T> log, ErrorId id, Exception error)
{
if (error is ProcessTerminationException)
{
return log;
}

log.Error(id, error.ToText());
return log;
}
Expand Down
7 changes: 7 additions & 0 deletions CSharpInteractive/Core/ProcessTerminationException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace CSharpInteractive.Core;

[Serializable]
internal class ProcessTerminationException(int exitCode): OperationCanceledException
{
public int ExitCode { get; } = exitCode;
}
13 changes: 10 additions & 3 deletions CSharpInteractive/Host.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,22 @@ private static void CurrentDomainOnUnhandledException(object sender, UnhandledEx
{
if (e.ExceptionObject is Exception error)
{
Root.Log.Error(ErrorId.Exception, error);
Root.Log.Error(ErrorId.Exception, error);
}
else
{
Root.Log.Error(ErrorId.Exception, [new Text(e.ExceptionObject.ToString() ?? "Unhandled exception.", Color.Error)]);
}

Finish();
System.Environment.Exit(1);

var exitCode = 1;
if (e.ExceptionObject is ProcessTerminationException processTermination)
{
exitCode = processTermination.ExitCode;
}

System.Environment.Exit(exitCode);
}
catch
{
Expand Down Expand Up @@ -136,7 +143,7 @@ public static T EnsureSuccess<T>(
Root.Log.Error(ErrorId.Build, $"{result}.");
if (failureExitCode.HasValue)
{
System.Environment.Exit(failureExitCode.Value);
throw new ProcessTerminationException(failureExitCode.Value);
}

return result;
Expand Down
21 changes: 15 additions & 6 deletions Samples/MySampleLib/Build/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,18 @@
.RunAsync()
.EnsureSuccess();

new DotNetTest()
.WithShortName("Tests")
.WithNoBuild(true)
.WithConfiguration(configuration)
.Build()
.EnsureSuccess();
await EunTestsAsync();

async Task EunTestsAsync()
{
await Task.Delay(100);

await new DotNetTest()
.WithShortName("Tests")
.WithNoBuild(true)
.WithConfiguration(configuration)
.BuildAsync()
.EnsureSuccess();

await Task.Delay(100);
}

0 comments on commit 8c130b3

Please sign in to comment.