This repository has been archived by the owner on Dec 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.cake
126 lines (110 loc) · 3.35 KB
/
build.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var solutionPath = "./WeihanLi.DataProtection.sln";
var srcProjects = GetFiles("./src/**/*.csproj");
var packProjects = GetFiles("./src/**/*.csproj");
var artifacts = "./artifacts/packages";
var isWindowsAgent = (EnvironmentVariable("Agent_OS") ?? "Windows_NT") == "Windows_NT";
var branchName = EnvironmentVariable("BUILD_SOURCEBRANCHNAME") ?? "local";
void PrintBuildInfo(){
Information($@"branch:{branchName}, agentOs={EnvironmentVariable("Agent_OS")}
BuildID:{EnvironmentVariable("BUILD_BUILDID")},BuildNumber:{EnvironmentVariable("BUILD_BUILDNUMBER")},BuildReason:{EnvironmentVariable("BUILD_REASON")}
");
}
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup(ctx =>
{
// Executed BEFORE the first task.
Information("Running tasks...");
PrintBuildInfo();
});
Teardown(ctx =>
{
// Executed AFTER the last task.
Information("Finished running tasks.");
});
///////////////////////////////////////////////////////////////////////////////
// TASKS
///////////////////////////////////////////////////////////////////////////////
Task("clean")
.Description("Clean")
.Does(() =>
{
var deleteSetting = new DeleteDirectorySettings()
{
Force = true,
Recursive = true
};
if (DirectoryExists(artifacts))
{
DeleteDirectory(artifacts, deleteSetting);
}
});
Task("restore")
.Description("Restore")
.Does(() =>
{
DotNetCoreRestore(solutionPath);
});
Task("build")
.Description("Build")
.IsDependentOn("clean")
.IsDependentOn("restore")
.Does(() =>
{
var buildSetting = new DotNetCoreBuildSettings{
NoRestore = true,
Configuration = configuration
};
DotNetCoreBuild(solutionPath, buildSetting);
});
Task("pack")
.Description("Pack package")
.IsDependentOn("build")
.Does(() =>
{
var settings = new DotNetCorePackSettings
{
Configuration = configuration,
OutputDirectory = artifacts,
VersionSuffix = "",
NoRestore = true,
NoBuild = true
};
if(branchName != "master"){
settings.VersionSuffix = $"preview-{DateTime.UtcNow:yyyyMMdd-HHmmss}";
}
foreach (var project in packProjects)
{
DotNetCorePack(project.FullPath, settings);
}
PublishArtifacts();
});
bool PublishArtifacts(){
if(!isWindowsAgent){
return false;
}
if(branchName == "master" || branchName == "preview")
{
var pushSetting =new DotNetCoreNuGetPushSettings
{
Source = EnvironmentVariable("Nuget__SourceUrl") ?? "https://api.nuget.org/v3/index.json",
ApiKey = EnvironmentVariable("Nuget__ApiKey")
};
var packages = GetFiles($"{artifacts}/*.nupkg");
foreach(var package in packages)
{
DotNetCoreNuGetPush(package.FullPath, pushSetting);
}
return true;
}
return false;
}
Task("Default")
.IsDependentOn("pack");
RunTarget(target);