-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuildConfig.cake
79 lines (63 loc) · 2.55 KB
/
buildConfig.cake
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
#tool "nuget:?package=GitVersion.CommandLine"
#addin nuget:?package=Cake.Git
public class BuildConfig
{
public readonly string SrcDir = "./src/";
public readonly string TestDir = "./test/";
public readonly string ArtifactsDir = "./artifacts/";
public string Target { get; private set; }
public string SemVer { get; private set; }
public string Suffix { get; private set; }
public string Version { get; private set; }
public string Configuration { get; private set; }
public bool IsCiBuild { get; private set; }
public static BuildConfig Create(ICakeContext context, BuildSystem buildSystem)
{
return new BuildConfig(context, buildSystem);
}
private BuildConfig(ICakeContext context, BuildSystem buildSystem)
{
if (context == null)
throw new ArgumentNullException("context");
InitializeConfig(context, buildSystem);
}
private void InitializeConfig(ICakeContext context, BuildSystem buildSystem)
{
Target = context.Argument("target", BuildTasks.Default);
Configuration = context.Argument("configuration", Configurations.Release);
IsCiBuild = IsRunningOnAppVeyor(buildSystem);
var gitVersion = GetSemanticVersion(context);
Version = gitVersion.MajorMinorPatch;
SemVer = gitVersion.LegacySemVerPadded + gitVersion.BuildMetaDataPadded;
Suffix = gitVersion.PreReleaseLabel + gitVersion.PreReleaseNumber.PadLeft(3, '0') + gitVersion.BuildMetaDataPadded;
}
private bool IsRunningOnAppVeyor(BuildSystem buildSystem)
{
return buildSystem.AppVeyor.IsRunningOnAppVeyor;
}
private GitVersion GetSemanticVersion(ICakeContext context)
{
var gitVersionSettings = new GitVersionSettings(){
ArgumentCustomization = args => args.Append("/nofetch")
};
return context.GitVersion(gitVersionSettings);
}
}
public class BuildTasks
{
public static string UpdateVersion = "Update-Version";
public static string UpdateAppVeyor = "Update-AppVeyor";
public static string Clean = "Clean";
public static string Build = "Build";
public static string Test = "Test";
public static string Package = "Package";
public static string UploadArtifacts = "Upload-Artifacts";
public static string UploadTestResults = "Upload-TestResults";
public static string Publish = "Publish";
public static string Default = "Default";
}
public class Configurations
{
public static string Debug = "Debug";
public static string Release = "Release";
}