forked from shinyorg/shiny
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuildContext.cs
86 lines (66 loc) · 2.94 KB
/
BuildContext.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
75
76
77
78
79
80
81
82
83
84
85
86
using Cake.Frosting;
using Cake.Git;
using Cake.Common;
using Cake.Common.Build;
using Cake.Core;
using Cake.Core.IO;
using Cake.Core.Diagnostics;
using Cake.GitVersioning;
namespace ShinyBuild;
public class BuildContext : FrostingContext
{
public BuildContext(ICakeContext context) : base(context)
{
#if DEBUG
//walk backwards until git directory found -that's root
if (!context.GitIsValidRepository(context.Environment.WorkingDirectory))
{
var dir = new DirectoryPath(".");
while (!context.GitIsValidRepository(dir))
dir = new DirectoryPath(Directory.GetParent(dir.FullPath).FullName);
context.Environment.WorkingDirectory = dir;
}
#endif
this.Branch = context.GitBranchCurrent(".");
this.ReleaseVersion = this.GitVersioningGetVersion().NuGetPackageVersion;
this.Log.Information("NUGET PACKAGE VERSION: " + this.ReleaseVersion);
}
public string ReleaseVersion { get; }
//public bool UseXamarinPreview => this.HasArgumentOrEnvironment("UseXamarinPreview");
public string GitHubSecretToken => this.ArgumentOrEnvironment<string>("GITHUB_TOKEN");
public string OperatingSystemString => this.Environment.Platform.Family == PlatformFamily.Windows ? "WINDOWS_NT" : "MAC";
public string MsBuildConfiguration => this.ArgumentOrEnvironment("configuration", Constants.DefaultBuildConfiguration);
public string NugetApiKey => this.ArgumentOrEnvironment<string>("NugetApiKey");
public bool AllowNugetUploadFailures => this.ArgumentOrEnvironment("AllowNugetUploadFailures", false);
public GitBranch Branch { get; }
public T ArgumentOrEnvironment<T>(string name, T defaultValue = default)
=> this.HasArgument(name) ? this.Argument<T>(name) : this.EnvironmentVariable<T>(name, defaultValue);
public bool HasArgumentOrEnvironment(string name)
=> this.HasArgument(name) || this.HasEnvironmentVariable(name);
public string ArtifactDirectory
{
get
{
if (this.IsRunningInCI)
return this.GitHubActions().Environment.Workflow.Workspace + "/artifacts";
return System.IO.Path.Combine(this.Environment.WorkingDirectory.FullPath, "artifacts");
}
}
public bool IsReleaseBranch => this.Branch.FriendlyName.ToLower().StartsWith("v");
public bool IsPullRequest =>
this.IsRunningInCI &&
this.GitHubActions().Environment.PullRequest.IsPullRequest;
public bool IsRunningInCI
=> this.GitHubActions()?.IsRunningOnGitHubActions ?? false;
public bool IsNugetDeployBranch
{
get
{
if (this.IsPullRequest)
return false;
var bn = this.Branch.FriendlyName.ToLower();
return bn.Equals("main") || bn.Equals("master") || bn.Equals("preview") || bn.StartsWith("v");
}
}
public bool IsDocsDeployBranch => this.IsNugetDeployBranch && !this.IsPullRequest;
}