-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Lifetime.cs
74 lines (62 loc) · 3.49 KB
/
Lifetime.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using Cake.Common;
using Cake.Common.Build;
using Cake.Common.Diagnostics;
using Cake.Frosting;
using Cake.Core.Diagnostics;
using Cake.Core;
public class Lifetime : FrostingLifetime<Context>
{
public override void Setup(Context context, ISetupContext setupContext)
{
context.Target = context.Argument("target", "Default");
context.Configuration = context.Argument("configuration", "Release");
context.ForceVersion = context.Argument<string>("forceVersion", "0.0.0");
context.FormatCode = context.Argument("formatCode", false);
context.Artifacts = "./packaging/";
// Build system information.
var buildSystem = context.BuildSystem();
context.IsLocalBuild = buildSystem.IsLocalBuild;
context.GitHubActions = buildSystem.GitHubActions.IsRunningOnGitHubActions;
if (context.GitHubActions)
{
context.IsPullRequest = buildSystem.GitHubActions.Environment.PullRequest.IsPullRequest;
context.IsOriginalRepo = StringComparer.OrdinalIgnoreCase.Equals("octokit/octokit.net", buildSystem.GitHubActions.Environment.Workflow.Repository);
context.IsMainBranch = StringComparer.OrdinalIgnoreCase.Equals("main", buildSystem.GitHubActions.Environment.Workflow.Ref);
}
// Force publish?
context.ForcePublish = context.Argument<bool>("forcepublish", false);
// Setup projects.
context.Projects = new Project[]
{
new Project { Name = "Octokit", Path = "./Octokit/Octokit.csproj", Publish = true },
new Project { Name = "Octokit.Reactive", Path = "./Octokit.Reactive/Octokit.Reactive.csproj", Publish = true },
new Project { Name = "Octokit.Tests", Path = "./Octokit.Tests/Octokit.Tests.csproj", UnitTests = true },
new Project { Name = "Octokit.Tests.Conventions", Path = "./Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj", ConventionTests = true },
new Project { Name = "Octokit.Tests.Integration", Path = "./Octokit.Tests.Integration/Octokit.Tests.Integration.csproj", IntegrationTests = true }
};
context.GitVersionToolPath = ToolInstaller.DotNetToolInstall(context, "GitVersion.Tool", "5.12.0", "dotnet-gitversion");
ToolInstaller.DotNetToolInstall(context, "coverlet.console", "1.7.2", "coverlet");
// Calculate semantic version.
context.Version = context.ForceVersion != "0.0.0" ? new BuildVersion(context.ForceVersion, null, null) : BuildVersion.Calculate(context);
context.Version.Prefix = context.Argument<string>("version", context.Version.Prefix);
context.Version.Suffix = context.Argument<string>("suffix", context.Version.Suffix);
context.Information("Version: {0}", context.Version.Prefix);
context.Information("Version suffix: {0}", context.Version.Suffix);
context.Information("Configuration: {0}", context.Configuration);
context.Information("Target: {0}", context.Target);
context.Information("GitHub Actions: {0}", context.GitHubActions);
}
private static string GetEnvironmentValueOrArgument(Context context, string environmentVariable, string argumentName)
{
var arg = context.EnvironmentVariable(environmentVariable);
if (string.IsNullOrWhiteSpace(arg))
{
arg = context.Argument<string>(argumentName, null);
}
return arg;
}
public override void Teardown(Context context, ITeardownContext info)
{
}
}