This repository was archived by the owner on Dec 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathbuild.cake
149 lines (132 loc) · 3.82 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var solutionPath = "./AccessControlHelper.sln";
var srcProjects = GetFiles("./src/**/*.csproj");
var testProjects = GetFiles("./test/**/*.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(() =>
{
foreach(var project in srcProjects)
{
DotNetCoreRestore(project.FullPath);
}
});
Task("build")
.Description("Build")
.IsDependentOn("clean")
.IsDependentOn("restore")
.Does(() =>
{
var buildSetting = new DotNetCoreBuildSettings{
NoRestore = true,
Configuration = configuration
};
foreach(var project in srcProjects)
{
DotNetCoreBuild(project.FullPath, buildSetting);
}
});
Task("test")
.Description("Test")
.IsDependentOn("build")
.Does(() =>
{
var testSettings = new DotNetCoreTestSettings{
NoRestore = false,
Configuration = configuration
};
foreach(var project in testProjects)
{
DotNetCoreTest(project.FullPath, testSettings);
}
});
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 srcProjects)
{
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);