-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.cake
184 lines (163 loc) · 5.57 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
///////////////////////////////////////////////////////////////////////////
// This is the main build file.
//
// The following targets are the prefered entrypoints:
// * Build
// * Publish
//
// You can call these targets by using the bootstrapper powershell script
// next to this file: ./build -target <target>
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
// Load additional cake addins
///////////////////////////////////////////////////////////////////////////
#addin Cake.Json
#addin Cake.Endpoint
#addin Cake.Npm
#addin Cake.DoInDirectory
///////////////////////////////////////////////////////////////////////////
// Load additional tools
///////////////////////////////////////////////////////////////////////////
#tool GitVersion.CommandLine
#tool OctopusTools
///////////////////////////////////////////////////////////////////////////
// Commandline argument handling
///////////////////////////////////////////////////////////////////////////
var target = Argument( "target", "Default" );
var configuration = Argument( "configuration", "Release" );
var framework = Argument( "framework", "netcoreapp1.1" );
///////////////////////////////////////////////////////////////////////////
// Project definition
///////////////////////////////////////////////////////////////////////////
FilePath webApiProject = "./src/webapi/webapi.csproj";
FilePath webApiTestProject = "./src/webapi.test/webapi.test.csproj";
DirectoryPath webAppProject = "./src/webapp";
///////////////////////////////////////////////////////////////////////////
// Constants, initial variables
///////////////////////////////////////////////////////////////////////////
DirectoryPath artifacts = "./artifacts";
GitVersion version = GitVersion();
var endpoints = DeserializeJsonFromFile<IEnumerable<Endpoint>>( "./endpoints.json" );
///////////////////////////////////////////////////////////////////////////
// Task: Clean
///////////////////////////////////////////////////////////////////////////
Task( "Clean" )
.Does( () =>
{
// clean artifacts folder
CleanDirectory( artifacts );
// clean webapp output folder
CleanDirectory( webAppProject.Combine( "dist" ) );
// clean webapi output folders
CleanDirectories( "./src/**/bin/" + configuration );
CleanDirectories( "./src/**/obj" );
} );
///////////////////////////////////////////////////////////////////////////
// Task: Restore
///////////////////////////////////////////////////////////////////////////
Task( "Restore" )
.Does( () =>
{
// run dotnet restore for webapi projects
DotNetCoreRestore( webApiProject.FullPath );
DotNetCoreRestore( webApiTestProject.FullPath );
// run npm install for webapp project
DoInDirectory( webAppProject, () =>
{
NpmInstall();
} );
} );
///////////////////////////////////////////////////////////////////////////
// Task: Build
///////////////////////////////////////////////////////////////////////////
Task( "Build" )
.IsDependentOn( "Clean" )
.IsDependentOn( "Restore" )
.Does( () =>
{
// run dotnet publish to build webapi output
DotNetCorePublish( webApiProject.FullPath, new DotNetCorePublishSettings
{
Configuration = configuration,
VersionSuffix = version.PreReleaseTag
} );
// run npm build to build bundled and minified webapp output
DoInDirectory( webAppProject, () =>
{
NpmRunScript( "build" );
} );
} );
///////////////////////////////////////////////////////////////////////////
// Task: Test
///////////////////////////////////////////////////////////////////////////
Task( "Test" )
.IsDependentOn( "Build" )
.Does( () =>
{
// run webapi tests via dotnet test
DotNetCoreTest( webApiTestProject.FullPath );
// run webapp tests via npm test
DoInDirectory( webAppProject, () =>
{
NpmRunScript( "test" );
} );
} );
///////////////////////////////////////////////////////////////////////////
// Task: Publish
///////////////////////////////////////////////////////////////////////////
Task( "Publish" )
.IsDependentOn( "Test" )
.Does( () =>
{
// orchestrate package contents for octopus packages
EndpointCreate( endpoints, new EndpointCreatorSettings()
{
TargetRootPath = artifacts.Combine( "publish" ).FullPath,
TargetPathPostFix = "." + version.NuGetVersion,
BuildConfiguration = configuration,
ZipTargetPath = false
} );
// iterate endpoints, postfix resulting packages and run octo pack
foreach( var endpoint in endpoints )
{
var publishPath = artifacts.Combine( "publish" ).Combine( endpoint.Id + "." + version.NuGetVersion );
var packageId = endpoint.Id + ".Deploy";
OctoPack( packageId, new OctopusPackSettings
{
BasePath = publishPath,
Description = endpoint.Id,
Title = packageId,
OutFolder = artifacts.Combine( "nuget" ),
Version = version.NuGetVersion
} );
}
} );
///////////////////////////////////////////////////////////////////////////
// Task: Run
///////////////////////////////////////////////////////////////////////////
Task( "Run" )
.IsDependentOn( "Restore" )
.Does( () =>
{
// start dotnet run task
var webApi = System.Threading.Tasks.Task.Factory.StartNew( () =>
{
DotNetCoreRun( webApiProject.GetFilename().ToString(), null, new DotNetCoreRunSettings
{
WorkingDirectory = webApiProject.GetDirectory().FullPath
} );
} );
// start npm run task
var webApp = System.Threading.Tasks.Task.Factory.StartNew( () =>
{
NpmRunScript( new NpmRunScriptSettings
{
ScriptName = "start",
WorkingDirectory = webAppProject.FullPath
} );
} );
System.Threading.Tasks.Task.WaitAll( webApi, webApp );
} );
Task( "Default" )
.IsDependentOn( "Build" );
RunTarget( target );