Skip to content

Commit

Permalink
Update the build
Browse files Browse the repository at this point in the history
  • Loading branch information
charlessolar committed Jan 26, 2024
1 parent 8abc751 commit 41d7289
Show file tree
Hide file tree
Showing 17 changed files with 133 additions and 69 deletions.
22 changes: 21 additions & 1 deletion build.ps1
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
dotnet run --project cake/Build.csproj -- $args

Set-StrictMode -Version 3.0

# Set script to exit if a command fails
$ErrorActionPreference = "Stop"

# Set script to run cmdlets without confirmation
$ConfirmPreference = "None";

# Get the directory of the build script
$ScriptDir = Split-Path $MyInvocation.MyCommand.Path -Parent

# Check dotnet is installed
if (!(Get-Command "dotnet" -ErrorAction SilentlyContinue))
{
Write-Error "dotnet is not installed or could not be found"
exit 1
}

# Run the build application
dotnet run --project $ScriptDir/cake/Build.csproj -- $args
exit $LASTEXITCODE;
18 changes: 17 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
dotnet run --project ./cake/Build.csproj -- "$@"
#!/usr/bin/env bash

# Set script to exit if a command fails
set -eo pipefail

# Get the directory of the build script
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)

# Check dotnet is installed
if [ ! -x "$(command -v dotnet)" ]
then
echo "ERROR: dotnet is not installed or could not be found"
exit 1
fi

# Run the build application
dotnet run --project "$SCRIPT_DIR/cake/Build.csproj" -- "$@"
14 changes: 7 additions & 7 deletions cake/Build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
<None Remove="Helpers\nuget.config" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Cake.Coverlet" Version="3.0.2" />
<PackageReference Include="Cake.Coverlet" Version="3.0.4" />
<PackageReference Include="Cake.Curl" Version="4.1.0" />
<PackageReference Include="Cake.Docker" Version="1.1.2" />
<PackageReference Include="Cake.Frosting" Version="2.3.0" />
<PackageReference Include="Cake.Incubator" Version="7.0.0" />
<PackageReference Include="Cake.BuildSystems.Module" Version="4.2.0" />
<PackageReference Include="GitVersion.CommandLine" Version="5.11.1">
<PackageReference Include="Cake.Docker" Version="1.3.0" />
<PackageReference Include="Cake.Frosting" Version="4.0.0" />
<PackageReference Include="Cake.Incubator" Version="8.0.0" />
<PackageReference Include="Cake.BuildSystems.Module" Version="6.1.0" />
<PackageReference Include="GitVersion.CommandLine" Version="5.12.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="ReportGenerator" Version="5.1.12" />
<PackageReference Include="ReportGenerator" Version="5.2.0" />
</ItemGroup>
</Project>
6 changes: 6 additions & 0 deletions cake/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
global using System;
global using Cake.Common;
global using Cake.Common.IO;
global using Cake.Core;
global using Cake.Core.IO;
global using Cake.Frosting;
41 changes: 38 additions & 3 deletions cake/Helpers/Paths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Linq;
using System.Text;
using Cake.Incubator.Project;
using Cake.Core.Diagnostics;

namespace Build.Helpers
{
Expand Down Expand Up @@ -55,6 +56,39 @@ string semVersion
// so that when we clean/zip we get ALLL builds
var binDir = info.OutputPaths[0].Combine("..");

// dont build "build" projects
if (info.HasPackage("Cake.Core") || info.HasPackage("Cake.Frosting"))
continue;

/*
* If you see this error in build:
*
* Exception: NullReferenceException: Object reference not set to an instance of an object.
at Cake.Incubator.StringExtensions.StringExtensions.EqualsIgnoreCase(String source, String value)
at Cake.Incubator.Project.ProjectParserExtensions.<>c.<IsDotNetCliTestProject>b__7_0(PackageReference x)
at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
at Cake.Incubator.Project.ProjectParserExtensions.IsDotNetCliTestProject(CustomProjectParserResult projectParserResult)
at Cake.Incubator.Project.ProjectParserExtensions.IsTestProject(CustomProjectParserResult projectParserResult)
at Build.Helpers.BuildPaths.GetPaths(BuildParameters context, String configuration, String semVersion) in D:\projects\Aggregates.NET\cake\Helpers\Paths.cs:line 78
at Build.Helpers.BuildParameters.Setup() in D:\projects\Aggregates.NET\cake\Helpers\Parameters.cs:line 194
at Build.BuildLifetime.Setup(BuildParameters parameters, ISetupContext context) in D:\projects\Aggregates.NET\cake\Program.cs:line 52
at Cake.Frosting.FrostingLifetime`1.Cake.Frosting.IFrostingSetup.Setup(ICakeContext context, ISetupContext info)
at Cake.Frosting.Internal.FrostingEngine`1.<ConfigureLifetime>b__14_0(ISetupContext info)
at Cake.Core.DefaultExecutionStrategy.PerformSetup(Action`1 action, ISetupContext context)
at Cake.Core.CakeEngine.PerformSetup(ICakeContext context, IExecutionStrategy strategy, CakeTask[] orderedTasks, String target, Stopwatch stopWatch, CakeReport report)
at Cake.Core.CakeEngine.RunTargetAsync(ICakeContext context, IExecutionStrategy strategy, ExecutionSettings settings)
Its because somewhere in your .csproj there is an "Update" package like this:
<ItemGroup>
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="8.0.0" />
</ItemGroup>
Change it to "Include" or remove
*
*
*/

if (context.FileExists(projectDir.CombineWithFilePath("./Dockerfile")))
{
output = "Docker";
Expand All @@ -66,11 +100,12 @@ string semVersion
}
if (info.IsTestProject())
{
if (!info.PackageReferences.Any(x => x.Name == "coverlet.collector"))
{
context.Log.Warning($"Assembly {info.AssemblyName} is a test project without \"coverlet.collector\" package. No coverage report possible");
}
output = "Test";
}
// dont build "build" projects
if (info.HasPackage("Cake.Core") || info.HasPackage("Cake.Frosting"))
continue;


binDirs.Add(binDir);
Expand Down
66 changes: 32 additions & 34 deletions cake/Program.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
using System.Threading.Tasks;
using Cake.Core;
using Cake.Core.Diagnostics;
using Cake.Frosting;
using Build.Extensions;
using Cake.Common.Build;
using Cake.Common.IO;
using System;
using Cake.Common.Xml;
using Build.Helpers;
using System.Linq;
Expand All @@ -18,15 +14,14 @@
using Cake.Coverlet;
using System.Collections.Generic;
using Cake.Common.Tools.ReportUnit;
using Cake.Core.IO;
using Cake.Common;
using Cake.Common.Build.AzurePipelines.Data;
using Cake.Common.Tools.DotNet.Test;
using Cake.Common.Tools.DotNet;
using Cake.Common.Tools.DotNet.Publish;
using Cake.Common.Tools.DotNet.Pack;
using Cake.Common.Tools.DotNet.Build;


namespace Build
{

Expand All @@ -52,54 +47,53 @@ public static void HandleToolMissingException(Exception e, string tool, ICakeCon
}
public sealed class BuildLifetime : FrostingLifetime<Helpers.BuildParameters>
{
public override void Setup(BuildParameters context)
public override void Setup(BuildParameters parameters, ISetupContext context)
{
context.Setup();
parameters.Setup();
context.Info("==============================================");
context.Info("==============================================");

context.Info("Calculated Semantic Version: {0} sha: {1}", context.Version.SemVersion, context.Version.Sha.Substring(0, 8));
context.Info("Calculated NuGet Version: {0}", context.Version.NuGet);
context.Info("Calculated Semantic Version: {0} sha: {1}", parameters.Version.SemVersion, parameters.Version.Sha.Substring(0, 8));
context.Info("Calculated NuGet Version: {0}", parameters.Version.NuGet);

context.Info("==============================================");
context.Info("==============================================");

context.Info("Solution: " + context.Solution);
context.Info("Target: " + context.Target);
context.Info("Configuration: " + context.BuildConfiguration);
context.Info("IsLocalBuild: " + context.IsLocalBuild);
context.Info("IsRunningOnUnix: " + context.IsRunningOnUnix);
context.Info("IsRunningOnWindows: " + context.IsRunningOnWindows);
context.Info("IsRunningOnVSTS: " + context.IsRunningOnVSTS);
context.Info("IsReleaseBuild: " + context.IsReleaseBuild);
context.Info("IsPullRequest: " + context.IsPullRequest);
context.Info("IsMaster: " + context.IsMaster + " Branch: " + context.Branch);
context.Info("BuildNumber: " + context.BuildNumber);
context.Info("Solution: " + parameters.Solution);
context.Info("Target: " + parameters.Target);
context.Info("Configuration: " + parameters.BuildConfiguration);
context.Info("IsLocalBuild: " + parameters.IsLocalBuild);
context.Info("IsRunningOnUnix: " + parameters.IsRunningOnUnix);
context.Info("IsRunningOnWindows: " + parameters.IsRunningOnWindows);
context.Info("IsRunningOnVSTS: " + parameters.IsRunningOnVSTS);
context.Info("IsReleaseBuild: " + parameters.IsReleaseBuild);
context.Info("IsPullRequest: " + parameters.IsPullRequest);
context.Info("IsMaster: " + parameters.IsMaster + " Branch: " + parameters.Branch);
context.Info("BuildNumber: " + parameters.BuildNumber);

// Increase verbosity?
if (context.IsReleaseBuild && (context.Log.Verbosity != Verbosity.Diagnostic))
if (parameters.IsReleaseBuild && (context.Log.Verbosity != Verbosity.Diagnostic))
{
context.Info("Increasing verbosity to diagnostic.");
context.Log.Verbosity = Verbosity.Diagnostic;
}

if (context.IsRunningOnVSTS)
if (parameters.IsRunningOnVSTS)
{
var commands = context.BuildSystem().AzurePipelines.Commands;
commands.UpdateBuildNumber(context.Version.SemVersion);
commands.AddBuildTag(context.Version.Sha.Substring(0, 8));
commands.AddBuildTag(context.Version.SemVersion);
commands.AddBuildTag(context.BuildConfiguration);
commands.UpdateBuildNumber(parameters.Version.SemVersion);
commands.AddBuildTag(parameters.Version.Sha.Substring(0, 8));
commands.AddBuildTag(parameters.Version.SemVersion);
commands.AddBuildTag(parameters.BuildConfiguration);
}


context.Info("Building version {0} {5} of {4} ({1}, {2}) using version {3} of Cake",
context.Version.SemVersion,
context.Configuration,
context.Target,
context.Version.CakeVersion,
context.Solution,
context.Version.Sha.Substring(0, 8));
parameters.Version.SemVersion,
parameters.Configuration,
parameters.Target,
parameters.Version.CakeVersion,
parameters.Solution,
parameters.Version.Sha.Substring(0, 8));
}

public override void Teardown(BuildParameters context, ITeardownContext info)
Expand All @@ -109,6 +103,10 @@ public override void Teardown(BuildParameters context, ITeardownContext info)
context.Log.Warning("This was not a successful build");
throw new CakeException("Publish task chain failed");
}
if (info.ThrownException != null)
{
context.Log.Error($"Exception: {info.ThrownException.GetType().Name}: {info.ThrownException.Message}\n{info.ThrownException.StackTrace}");
}
}
}
[TaskName("Clean")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@
</Compile>
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="8.0.0" />
</ItemGroup>


</Project>
3 changes: 2 additions & 1 deletion src/Aggregates.NET.EventStore/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@
"Microsoft.CSharp": "[4.7.0, )",
"Microsoft.Extensions.DependencyInjection.Abstractions": "[8.0.0, )",
"Microsoft.Extensions.Hosting.Abstractions": "[8.0.0, )",
"Microsoft.Extensions.Logging.Abstractions": "[8.0.0, )"
"Microsoft.Extensions.Logging.Abstractions": "[8.0.0, )",
"Microsoft.SourceLink.GitHub": "[8.0.0, )"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,5 @@
</Compile>
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="8.0.0" />
</ItemGroup>


</Project>
3 changes: 2 additions & 1 deletion src/Aggregates.NET.NServiceBus/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@
"Microsoft.CSharp": "[4.7.0, )",
"Microsoft.Extensions.DependencyInjection.Abstractions": "[8.0.0, )",
"Microsoft.Extensions.Hosting.Abstractions": "[8.0.0, )",
"Microsoft.Extensions.Logging.Abstractions": "[8.0.0, )"
"Microsoft.Extensions.Logging.Abstractions": "[8.0.0, )",
"Microsoft.SourceLink.GitHub": "[8.0.0, )"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
</Compile>
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="8.0.0" />
</ItemGroup>


</Project>
3 changes: 2 additions & 1 deletion src/Aggregates.NET.NewtonsoftJson/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@
"Microsoft.CSharp": "[4.7.0, )",
"Microsoft.Extensions.DependencyInjection.Abstractions": "[8.0.0, )",
"Microsoft.Extensions.Hosting.Abstractions": "[8.0.0, )",
"Microsoft.Extensions.Logging.Abstractions": "[8.0.0, )"
"Microsoft.Extensions.Logging.Abstractions": "[8.0.0, )",
"Microsoft.SourceLink.GitHub": "[8.0.0, )"
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/Aggregates.NET.Testing/Aggregates.NET.Testing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@
<ProjectReference Include="..\Aggregates.NET\Aggregates.NET.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="8.0.0" />
</ItemGroup>


</Project>
4 changes: 3 additions & 1 deletion src/Aggregates.NET.Testing/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,16 @@
"Microsoft.CSharp": "[4.7.0, )",
"Microsoft.Extensions.DependencyInjection.Abstractions": "[8.0.0, )",
"Microsoft.Extensions.Hosting.Abstractions": "[8.0.0, )",
"Microsoft.Extensions.Logging.Abstractions": "[8.0.0, )"
"Microsoft.Extensions.Logging.Abstractions": "[8.0.0, )",
"Microsoft.SourceLink.GitHub": "[8.0.0, )"
}
},
"aggregates.net.nservicebus": {
"type": "Project",
"dependencies": {
"Aggregates.NET": "[1.0.0, )",
"Microsoft.Extensions.DependencyInjection.Abstractions": "[8.0.0, )",
"Microsoft.SourceLink.GitHub": "[8.0.0, )",
"NServiceBus": "[8.1.6, )",
"NServiceBus.Callbacks": "[4.0.0, )",
"NServiceBus.Extensions.DependencyInjection": "[2.0.0, )",
Expand Down
3 changes: 0 additions & 3 deletions src/Aggregates.NET/Aggregates.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="8.0.0" />
</ItemGroup>


</Project>
4 changes: 2 additions & 2 deletions src/Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<Authors>Charles Solar</Authors>
<Company>Charles Solar</Company>
<Copyright>Copyright (c) 2023</Copyright>
<Copyright>Copyright (c) 2024</Copyright>
<PackageTags>CQRS ES event sourcing NServiceBus GetEventStore eventstore ddd</PackageTags>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/charlessolar/Aggregates.NET</RepositoryUrl>
Expand All @@ -34,7 +34,7 @@

</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All"/>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0"/>
</ItemGroup>
<ItemGroup>
<None Include="../../icon.png" Pack="true" PackagePath=""/>
Expand Down
2 changes: 1 addition & 1 deletion src/SharedAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[assembly: AssemblyProduct("Aggregates.NET")]
[assembly: AssemblyDescription(".NET event sourced domain driven design model via NServiceBus and EventStore")]
[assembly: AssemblyCopyright("Copyright © Charles Solar 2023")]
[assembly: AssemblyCopyright("Copyright © Charles Solar 2024")]
[assembly: AssemblyVersion("0.17.0.0")]
[assembly: AssemblyFileVersion("0.17.0.0")]
[assembly: AssemblyInformationalVersion("0.17.0.0")]
Expand Down

0 comments on commit 41d7289

Please sign in to comment.