Skip to content

Commit e42a011

Browse files
committed
Logging to catch the error
1 parent eb82b9e commit e42a011

8 files changed

+138
-66
lines changed

Diff for: build/Build/Context.cs

+32-33
Original file line numberDiff line numberDiff line change
@@ -7,54 +7,53 @@
77

88
using Semver;
99

10-
namespace Build
10+
namespace Build;
11+
12+
public class Context : FrostingContext
1113
{
12-
public class Context : FrostingContext
14+
public Context(ICakeContext context)
15+
: base(context)
1316
{
14-
public Context(ICakeContext context)
15-
: base(context)
16-
{
17-
}
17+
}
1818

19-
public App App { get; } = new();
19+
public App App { get; } = new();
2020

21-
public General General { get; } = new();
21+
public General General { get; } = new();
2222

23-
public Tests Tests { get; } = new();
24-
}
23+
public Tests Tests { get; } = new();
24+
}
2525

26-
public class General
27-
{
28-
public string ArtifactsDir => ".artifacts";
26+
public class General
27+
{
28+
public string ArtifactsDir => ".artifacts";
2929

30-
public IList<string> ArtifactsToUploadToPipeline { get; } = new List<string>();
30+
public IList<string> ArtifactsToUploadToPipeline { get; } = new List<string>();
3131

32-
public SemVersion ArtifactVersion { get; set; }
32+
public SemVersion ArtifactVersion { get; set; }
3333

34-
public Branches CurrentBranch { get; set; }
34+
public Branches CurrentBranch { get; set; }
3535

36-
public string CurrentBranchName { get; set; }
36+
public string CurrentBranchName { get; set; }
3737

38-
public bool IsLocal { get; set; }
38+
public bool IsLocal { get; set; }
3939

40-
public string Name { get; } = "ModelBuilder";
40+
public string Name { get; } = "ModelBuilder";
4141

42-
public string SolutionName { get; } = "NA";
43-
}
42+
public string SolutionName { get; } = "NA";
43+
}
4444

45-
public class App
46-
{
47-
public const string PROJECT_NAME = "Commons.Builders.Model";
48-
public string BuildConfig { get; } = "Release";
45+
public class App
46+
{
47+
public const string PROJECT_NAME = "Commons.Builders.Model";
48+
public string BuildConfig { get; } = "Release";
4949

50-
public string MainProject { get; } = @$"src\{PROJECT_NAME}\{PROJECT_NAME}.csproj";
51-
}
50+
public string MainProject { get; } = @$"src\{PROJECT_NAME}\{PROJECT_NAME}.csproj";
51+
}
5252

53-
public class Tests
54-
{
55-
public const string TEST_NAME = "Commons.Builders.Model.Tests";
56-
public string TestProjectName { get; } = $"{TEST_NAME}";
53+
public class Tests
54+
{
55+
public const string TEST_NAME = "Commons.Builders.Model.Tests";
56+
public string TestProjectName { get; } = $"{TEST_NAME}";
5757

58-
public string TestProject { get; } = @$"tests\{TEST_NAME}\{TEST_NAME}.csproj";
59-
}
58+
public string TestProject { get; } = @$"tests\{TEST_NAME}\{TEST_NAME}.csproj";
6059
}

Diff for: build/Build/Flow/Flow.cs

+23-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
using Cake.Frosting;
22

3-
namespace Build {
4-
// [IsDependentOn(typeof(FormatCheck))]
5-
[IsDependentOn(typeof(NugetRestore))]
6-
[IsDependentOn(typeof(GenerateVersion))]
7-
[IsDependentOn(typeof(Build))]
8-
[IsDependentOn(typeof(RunTestsAndPublishResults))]
9-
[IsDependentOn(typeof(PublishApp))]
10-
[IsDependentOn(typeof(ZipArtifacts))]
11-
[IsDependentOn(typeof(UploadArtifactsToPipeline))]
12-
public partial class Default { }
13-
}
3+
namespace Build;
4+
5+
[IsDependentOn(typeof(NugetRestore))]
6+
[IsDependentOn(typeof(GenerateVersion))]
7+
[IsDependentOn(typeof(Build))]
8+
[IsDependentOn(typeof(RunTestsAndPublishResults))]
9+
[IsDependentOn(typeof(PublishApp))]
10+
[IsDependentOn(typeof(ZipArtifacts))]
11+
[IsDependentOn(typeof(UploadArtifactsToPipeline))]
12+
public partial class Default { }
13+
14+
[IsDependentOn(typeof(NugetRestore))]
15+
[IsDependentOn(typeof(GenerateVersion))]
16+
[IsDependentOn(typeof(Build))]
17+
[IsDependentOn(typeof(RunTestsAndPublishResults))]
18+
public partial class BuildAndTest { }
19+
20+
[IsDependentOn(typeof(NugetRestore))]
21+
[IsDependentOn(typeof(GenerateVersion))]
22+
[IsDependentOn(typeof(BuildNuGetPackage))]
23+
[IsDependentOn(typeof(GetNuGetPackagesFromArtifacts))]
24+
[IsDependentOn(typeof(UploadArtifactsToPipeline))]
25+
public partial class BuildPackage { }

Diff for: build/Build/Lifetime.cs

+19-18
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,32 @@
1010
using Cake.Core;
1111
using Cake.Frosting;
1212

13-
namespace Build
13+
namespace Build;
14+
15+
public sealed class Lifetime : FrostingLifetime<Context>
1416
{
15-
public sealed class Lifetime : FrostingLifetime<Context>
17+
public override void Setup(Context context, ISetupContext info)
1618
{
17-
public override void Setup(Context context, ISetupContext info)
18-
{
19-
context.Information("Setting things up...");
19+
context.Information("Setting things up...");
2020

21-
context.CleanDirectory(context.General.ArtifactsDir.AsDirectoryPath());
21+
context.CleanDirectory(context.General.ArtifactsDir.AsDirectoryPath());
22+
context.Information("Cleaned directory");
2223

23-
context.General.IsLocal = context.BuildSystem().IsLocalBuild;
24+
context.General.IsLocal = context.BuildSystem().IsLocalBuild;
25+
context.Information("Determined if local build");
2426

25-
SetBranchInContext(context);
27+
SetBranchInContext(context);
2628

27-
context.Information(string.Join(Environment.NewLine, context.Environment.GetEnvironmentVariables()));
28-
}
29+
context.Information(string.Join(Environment.NewLine, context.Environment.GetEnvironmentVariables()));
30+
}
2931

30-
public override void Teardown(Context context, ITeardownContext info) =>
31-
context.Information("Tearing things down...");
32+
public override void Teardown(Context context, ITeardownContext info) =>
33+
context.Information("Tearing things down...");
3234

33-
private void SetBranchInContext(Context context)
34-
{
35-
string branchName = context.GitVersion(new GitVersionSettings { NoFetch = true }).BranchName.ToLower();
36-
context.General.CurrentBranchName = branchName;
37-
context.General.CurrentBranch = new BranchService().GetBranch(branchName);
38-
}
35+
private void SetBranchInContext(Context context)
36+
{
37+
string branchName = context.GitVersion(new GitVersionSettings { NoFetch = true }).BranchName.ToLower();
38+
context.General.CurrentBranchName = branchName;
39+
context.General.CurrentBranch = new BranchService().GetBranch(branchName);
3940
}
4041
}

Diff for: build/Build/Targets/BuildAndTest.cs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
using Cake.Frosting;
2+
3+
namespace Build;
4+
5+
public partial class BuildAndTest : FrostingTask<Context> { }

Diff for: build/Build/Targets/BuildPackage.cs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
using Cake.Frosting;
2+
3+
namespace Build;
4+
5+
public partial class BuildPackage : FrostingTask<Context> { }

Diff for: build/Build/Tasks/BuildNuGetPackage.cs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Build.Common.Enums;
2+
using Cake.Common.Tools.DotNet;
3+
using Cake.Frosting;
4+
using System.IO;
5+
6+
namespace Build;
7+
8+
public sealed class BuildNuGetPackage : FrostingTask<Context>
9+
{
10+
public override void Run(Context context)
11+
{
12+
string versionPrefix, versionSuffix;
13+
var version = context.General.ArtifactVersion;
14+
15+
if (!context.General.IsLocal && context.General.CurrentBranch == Branches.Main)
16+
{
17+
versionPrefix = $"{version.Major}.{version.Minor}.{version.Patch}";
18+
versionSuffix = string.Empty;
19+
}
20+
else
21+
{
22+
versionPrefix = $"{version.Major}.{version.Minor}.{version.Patch}";
23+
versionSuffix = $"{version.Prerelease}-{version.Build}";
24+
}
25+
context.DotNetPack(Path.Combine(context.Environment.WorkingDirectory.FullPath, context.App.MainProject),
26+
new Cake.Common.Tools.DotNet.Pack.DotNetPackSettings()
27+
{
28+
Configuration = context.App.BuildConfig,
29+
OutputDirectory = "./.artifacts",
30+
VersionSuffix = versionSuffix
31+
});
32+
}
33+
}

Diff for: build/Build/Tasks/GenerateVersion.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ public override void Run(Context context)
2222
var buildPropertiesPath = context.Environment.WorkingDirectory.FullPath + "/Directory.Build.Props";
2323
string assemblyVersion = "0.0.0";
2424
//TODO: Read version from msbuild to include Directory.Build.Props settings correctly
25-
26-
// context.XmlPeek(
27-
// Path.Combine(context.Environment.WorkingDirectory.FullPath, context.App.MainProject),
28-
// "//AssemblyVersion");
25+
assemblyVersion = context.XmlPeek(buildPropertiesPath, "//AssemblyVersion");
2926
context.Information($"Found {assemblyVersion} as assembly version in csproj file.");
3027
_context = context;
3128
IArtifactVersionService versionService = new ArtifactVersionService(new BranchService());

Diff for: build/Build/Tasks/GetNuGetPackagesFromArtifacts.cs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.IO;
2+
3+
using Cake.Common.Diagnostics;
4+
using Cake.Frosting;
5+
6+
namespace Build;
7+
8+
public class GetNuGetPackagesFromArtifacts : FrostingTask<Context>
9+
{
10+
/// <summary>Runs the task using the specified context.</summary>
11+
/// <param name="context">The context.</param>
12+
public override void Run(Context context)
13+
{
14+
context.Information("Found the following package files:");
15+
foreach (string file in Directory.GetFiles(".artifacts", "*.nupkg"))
16+
{
17+
context.Information(file);
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)