-
Notifications
You must be signed in to change notification settings - Fork 19
/
build.proj
337 lines (281 loc) · 18.3 KB
/
build.proj
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Directories">
<!-- Top Level Directories -->
<RepoDirectory Condition=" '$(RepoDirectory)' == '' ">$(MSBuildThisFileDirectory.TrimEnd('\\'))</RepoDirectory>
<BinDirectory Condition=" '$(BinDirectory)' == '' ">$(RepoDirectory)\bin</BinDirectory>
<LibDirectory Condition=" '$(LibDirectory)' == '' ">$(RepoDirectory)\lib</LibDirectory>
<ScriptsDirectory Condition=" '$(ScriptsDirectory)' == '' ">$(RepoDirectory)\scripts</ScriptsDirectory>
<SrcDirectory Condition=" '$(SrcDirectory)' == '' ">$(RepoDirectory)\src</SrcDirectory>
<TestDirectory Condition=" '$(TestDirectory)' == '' ">$(RepoDirectory)\test</TestDirectory>
<TestStagingDirectory Condition=" '$(TestStagingDirectory)' == '' ">$(TestDirectory)\lib</TestStagingDirectory>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<!-- Configurations -->
<Configuration Condition=" '$(Configuration)' == '' ">debug</Configuration>
<!-- Options -->
<Official Condition=" '$(Official)' == '' ">false</Official>
<RunTests Condition=" '$(RunTests)' == '' ">false</RunTests>
<!--
Sideload builds and references the @microsoft/security-devops-azdevops-task-lib repo.
This requires it to be cloned to a parallel directory to the extension repo.
-->
<Sideload Condition=" '$(Sideload)' == '' ">false</Sideload>
<SideloadBuild Condition=" '$(SideloadBuild)' == '' ">true</SideloadBuild>
<NpmInstall Condition=" '$(NpmInstall)' == '' ">true</NpmInstall>
<ForceNpmInstall Condition=" '$(Official)' == 'true' ">true</ForceNpmInstall>
<ForceNpmInstall Condition=" '$(ForceNpmInstall)' == '' ">false</ForceNpmInstall>
<!-- Targets -->
<SkipCompileTsc Condition=" '$(SkipCompileTsc)' == '' ">false</SkipCompileTsc>
<SkipCompile Condition=" '$(SkipCompile)' == '' ">false</SkipCompile>
</PropertyGroup>
<PropertyGroup Label="BuildPaths">
<OutputDirectory Condition=" '$(OutputDirectory)' == '' ">$(BinDirectory)\$(Configuration)</OutputDirectory>
<StagingDirectory Condition=" '$(StagingDirectory)' == '' ">$(LibDirectory)\$(Configuration)</StagingDirectory>
<LibNodeModulesDirectory Condition= " '$(LibNodeModulesDirectory)' == '' ">$(LibDirectory)\node_modules</LibNodeModulesDirectory>
<RepoNodeModulesDirectory Condition= " '$(RepoNodeModulesDirectory)' == '' ">$(RepoDirectory)\node_modules</RepoNodeModulesDirectory>
</PropertyGroup>
<PropertyGroup Label="Scripts">
<PowerShellExe Condition=" '$(PowerShellExe)' == '' ">powershell.exe</PowerShellExe>
<GetExtensionVersionScriptPath>$(ScriptsDirectory)\Get-ExtensionVersion.ps1</GetExtensionVersionScriptPath>
<RollbackScriptPath>$(ScriptsDirectory)\Rollback.ps1</RollbackScriptPath>
<SetPublisherInfoScriptPath>$(ScriptsDirectory)\Set-PublisherInfo.ps1</SetPublisherInfoScriptPath>
</PropertyGroup>
<!-- Configurations -->
<PropertyGroup Condition=" '$(Configuration)' == 'debug' ">
<ExtensionManifestFileName>extension-manifest-debug.json</ExtensionManifestFileName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'release' ">
<ExtensionManifestFileName>extension-manifest.json</ExtensionManifestFileName>
</PropertyGroup>
<PropertyGroup>
<PublisherName Condition=" '$(Official)' == 'true' AND '$(PublisherName)' == '' ">debug</PublisherName>
<ExtensionManifestFilePath>$(SrcDirectory)\$(ExtensionManifestFileName)</ExtensionManifestFilePath>
<ExtensionIconFilePath>$(SrcDirectory)\icon.png</ExtensionIconFilePath>
<ExtensionReadmeFilePath>$(SrcDirectory)\extension-readme.md</ExtensionReadmeFilePath>
<ExtensionEulaFilePath>$(SrcDirectory)\extension-eula.md</ExtensionEulaFilePath>
<CopyEula>true</CopyEula>
<StagedExtensionManifestFilePath>$(StagingDirectory)\extension-manifest.json</StagedExtensionManifestFilePath>
<OutputExtensionFileName>microsoft-security-devops-azdevops</OutputExtensionFileName>
<OutputExtensionFilePath>$(OutputDirectory)\$(OutputExtensionFileName)</OutputExtensionFilePath>
<OutputExtensionFilePath Condition=" '$(Configuration)' == 'debug'">$(OutputExtensionFilePath)-debug</OutputExtensionFilePath>
</PropertyGroup>
<ItemGroup Label="BuildTasks">
<MicrosoftSecurityDevOpsV1 Include="MicrosoftSecurityDevOps">
<MajorVersion>v1</MajorVersion>
<Platform>Node</Platform>
</MicrosoftSecurityDevOpsV1>
</ItemGroup>
<ItemGroup Condition=" '$(Configuration)' == 'debug' ">
<!-- debug only contributions -->
</ItemGroup>
<ItemGroup>
<!-- contributions -->
<BuildTask Include="@(MicrosoftSecurityDevOpsV1)" />
</ItemGroup>
<Target Name="ValidateConfiguration">
<Error
Condition=" '$(Configuration)' != 'debug' AND '$(Configuration)' != 'release' "
Text="Invalid Configuration given: $(Configuration). Valid values are: debug, release" />
</Target>
<Target Name="Clean" DependsOnTargets="CleanTests">
<Message Text="Deleting staging directory: $(StagingDirectory)" />
<RemoveDir Directories="$(StagingDirectory)" Condition="Exists('$(StagingDirectory)')" />
<Message Text="Deleting output directory: $(OutputDirectory)" />
<RemoveDir Directories="$(OutputDirectory)" Condition="Exists('$(OutputDirectory)')" />
</Target>
<Target Name="CleanTests">
<ItemGroup>
<CompiledTestFiles Include="$(TestDirectory)\**\*.js" />
<CompiledTestFiles Include="$(TestDirectory)\**\*.js.map" />
</ItemGroup>
<Delete Files="@(CompiledTestFiles)" />
<RemoveDir Directories="$(TestStagingDirectory)" />
</Target>
<Target
Name="NpmInstall-RepoDirectory"
Inputs="$(RepoDirectory)"
Outputs="$(RepoNodeModulesDirectory)"
Condition=" '$(NpmInstall)' == 'true' AND ('$(ForceNpmInstall)' == 'true' OR EXISTS('$(RepoNodeModulesDirectory)') != 'true')">
<Message Text="Intstalling npm packages in repo directory: $(RepoDirectory)..." />
<Exec Command="npm install" WorkingDirectory="$(RepoDirectory)" />
</Target>
<Target
Name="CompileTsc"
Condition=" '$(SkipCompileTsc)' != 'true' ">
<Message Text="Compiling Microsoft Security DevOps for Azure DevOps Extension" />
<Exec Command="npx tsc --outDir "$(StagingDirectory)"" WorkingDirectory="$(SrcDirectory)" />
</Target>
<Target
Name="Compile"
DependsOnTargets="Clean;NpmInstall-RepoDirectory;CompileTsc"
Condition=" '$(SkipCompile)' != 'true' ">
<PropertyGroup>
<RepoPackageJsonFilePath>$(RepoDirectory)\package.json</RepoPackageJsonFilePath>
<SrcNpmrcFilePath>$(SrcDirectory)\.npmrc</SrcNpmrcFilePath>
</PropertyGroup>
<Copy SourceFiles="$(RepoPackageJsonFilePath)" DestinationFiles="$(LibDirectory)\package.json" />
<Copy SourceFiles="$(SrcNpmrcFilePath)" DestinationFiles="$(LibDirectory)\.npmrc" />
</Target>
<Target Name="CompileTests" DependsOnTargets="CleanTests;NpmInstall-RepoDirectory">
<Message Text="Compiling tests" />
<Exec Command="npx tsc --outDir "$(TestStagingDirectory)"" WorkingDirectory="$(TestDirectory)" />
</Target>
<Target
Name="NpmInstall-LibDirectory"
Inputs="$(LibDirectory)"
Outputs="$(LibDirectory)\node_modules"
Condition=" '$(NpmInstall)' == 'true' AND ('$(ForceNpmInstall)' == 'true' OR EXISTS('$(LibDirectory)\node_modules') != 'true') ">
<Message Text="Installing npm packages staging directory: $(StagingDirectory)..." />
<Exec Command="npm install --production" WorkingDirectory="$(StagingDirectory)" />
</Target>
<Target
Name="Sideload"
Condition=" '$(Sideload)' == 'true' ">
<PropertyGroup>
<TaskLibSrcDirectory>$(MSBuildThisFileDirectory)..\security-devops-azdevops-task-lib</TaskLibSrcDirectory>
<TaskLibDistDirectory>$(TaskLibSrcDirectory)\dist</TaskLibDistDirectory>
<TaskLibNodeModulesDirectory>$(LibNodeModulesDirectory)\@microsoft\security-devops-azdevops-task-lib</TaskLibNodeModulesDirectory>
</PropertyGroup>
<Message Text="Sideload mode enabled. Linking @microsoft/security-devops-azdevops-task-lib" />
<Error
Condition=" !Exists('$(TaskLibSrcDirectory)') "
Text="Could not find task lib repo directory: $(TaskLibSrcDirectory). Please clone the repo to a parallel directory to this extension repo. Repo homepage: https://github.com/microsoft/security-devops-azdevops-task-lib" />
<Message Condition=" '$(SideloadBuild)' == 'true' " Text="Building sideload project: npm run build" />
<Exec Condition=" '$(SideloadBuild)' == 'true' " Command="npm run build" WorkingDirectory="$(TaskLibSrcDirectory)" />
<Message Text="Remove existing task lib directory: $(TaskLibNodeModulesDirectory)" />
<RemoveDir Directories="$(TaskLibNodeModulesDirectory)" Condition=" Exists('$(TaskLibNodeModulesDirectory)') " />
<ItemGroup>
<TaskLibDistFiles Include="$(TaskLibDistDirectory)\**\*" />
</ItemGroup>
<Message Text="Copying sideload build..." />
<Copy
SourceFiles="@(TaskLibDistFiles)"
DestinationFiles="@(TaskLibDistFiles->'$(TaskLibNodeModulesDirectory)\%(RecursiveDir)%(Filename)%(Extension)')" />
</Target>
<Target Name="Stage" DependsOnTargets="NpmInstall-LibDirectory;Sideload">
<PropertyGroup>
<StagingNodeModulesBinDirectory>$(LibNodeModulesDirectory)\.bin</StagingNodeModulesBinDirectory>
<StagingPackageLockJsonFilePath>$(LibNodeModulesDirectory)\.package-lock.json</StagingPackageLockJsonFilePath>
</PropertyGroup>
<Message Text="Staging extension files to directory: $(StagingDirectory)" />
<RemoveDir Directories="$(StagingNodeModulesBinDirectory)" Condition=" Exists('$(StagingNodeModulesBinDirectory)') " />
<Delete Files="$(StagingPackageLockJsonFilePath)" Condition=" Exists('$(StagingPackageLockJsonFilePath)') " />
<Delete Files="$(RepoDirectory)/package-lock.json" Condition=" Exists('$(RepoDirectory)/package-lock.json') " />
<!-- Copy the Extension files -->
<Copy SourceFiles="$(ExtensionManifestFilePath)" DestinationFiles="$(StagedExtensionManifestFilePath)" />
<Copy SourceFiles="$(ExtensionIconFilePath)" DestinationFiles="$(StagingDirectory)\icon.png" />
<Copy SourceFiles="$(ExtensionReadmeFilePath)" DestinationFiles="$(StagingDirectory)\readme.md" />
<Copy SourceFiles="$(ExtensionEulaFilePath)" DestinationFiles="$(StagingDirectory)\eula.md" Condition=" '$(CopyEula)' == 'true' " />
</Target>
<Target
Name="Stage-BuildTask"
Inputs="@(BuildTask)"
Outputs="$(StagingDirectory)\%(BuildTask.Identity)\%(BuildTask.MajorVersion)"
AfterTargets="Stage">
<PropertyGroup>
<BuildTaskSourceFolder>$(SrcDirectory)\%(BuildTask.Identity)</BuildTaskSourceFolder>
<BuildTaskSourceFolder Condition=" '%(BuildTask.MajorVersion)' != '' ">$(BuildTaskSourceFolder)\%(BuildTask.MajorVersion)</BuildTaskSourceFolder>
<BuildTaskStagingFolder>$(StagingDirectory)\%(BuildTask.Identity)</BuildTaskStagingFolder>
<BuildTaskStagingFolder Condition=" '%(BuildTask.MajorVersion)' != '' ">$(BuildTaskStagingFolder)\%(BuildTask.MajorVersion)</BuildTaskStagingFolder>
<IconSourceFilePath Condition=" '%(BuildTask.IconPath)' == '' ">$(SrcDirectory)\icon.png</IconSourceFilePath>
<IconStagingFilePath>$(BuildTaskStagingFolder)\icon.png</IconStagingFilePath>
<InputMapPath>$(BuildTaskSourceFolder)\inputMap.json</InputMapPath>
</PropertyGroup>
<ItemGroup>
<!-- Node Build Tasks -->
<StagingNodeModuleFiles
Condition=" '%(BuildTask.Platform)' == 'Node' "
Include="$(LibNodeModulesDirectory)\**\*" />
<BuildTaskFiles
Condition=" '%(BuildTask.Platform)' == 'Node' "
Include="$(BuildTaskSourceFolder)\*.js" />
<BuildTaskFiles
Condition=" '%(BuildTask.Platform)' == 'Node' "
Include="$(BuildTaskSourceFolder)\task.json" />
<BuildTaskFiles
Condition=" '%(BuildTask.Platform)' == 'Node' And Exists('$(BuildTaskSourceFolder)\task.loc.json') "
Include="$(BuildTaskSourceFolder)\task.loc.json" />
<BuildTaskFiles
Condition=" '%(BuildTask.Platform)' == 'Node' "
Include="$(BuildTaskSourceFolder)\**\*.resjson" />
<BuildTaskFiles
Condition=" '%(BuildTask.Platform)' == 'Node' And Exists('$(InputMapPath)') "
Include="$(InputMapPath)" />
<BuildTaskFiles
Include="%(BuildTask.AdditionalFiles)" />
</ItemGroup>
<Message Text="Staging build task directory: %(BuildTask.Identity) %(BuildTask.MajorVersion)" />
<!-- Copy build task files -->
<Error
Condition=" '@(BuildTaskFiles->Count())' == 0 "
Text="BuildTaskFiles files were not found during staging." />
<Copy
SourceFiles="@(BuildTaskFiles)"
DestinationFiles="@(BuildTaskFiles->'$(BuildTaskStagingFolder)\%(RecursiveDir)%(Filename)%(Extension)')" />
<!-- Copy node_modules -->
<Error
Condition=" '%(BuildTask.Platform)' == 'Node' AND '@(StagingNodeModuleFiles->Count())' == 0 "
Text="StagingNodeModuleFiles files were not found during staging." />
<Copy
SourceFiles="@(StagingNodeModuleFiles)"
DestinationFiles="@(StagingNodeModuleFiles->'$(BuildTaskStagingFolder)\node_modules\%(RecursiveDir)%(Filename)%(Extension)')"
Condition=" '%(BuildTask.Platform)' == 'Node' " />
<!-- Copy build task icon, if one does not already exist -->
<Copy
SourceFiles="$(IconSourceFilePath)"
DestinationFiles="$(IconStagingFilePath)"
Condition=" !Exists('$(IconStagingFilePath)') " />
</Target>
<Target Name="CopyTestHelpers" DependsOnTargets="CompileTests;Stage-BuildTask">
<Message Text="Copy Test Helper files to: $(TestStagingDirectory)" />
<ItemGroup>
<TestHelperFiles Include="$(TestDirectory)\**\*.json" />
</ItemGroup>
<Copy SourceFiles="$(BuildTaskSourceFolder)\task.json" DestinationFiles="$(TestStagingDirectory)\task.json" />
<Copy SourceFiles="@(TestHelperFiles)" DestinationFolder="$(TestStagingDirectory)\%(RecursiveDir)" SkipUnchangedFiles="true" />
</Target>
<Target Name="Test" Condition=" '$(RunTests)' == 'true' " DependsOnTargets="CopyTestHelpers">
<Message Text="Compiling Microsoft Security DevOps for Azure DevOps Extension" />
<Exec Command="npx mocha **/*.tests.js" WorkingDirectory="$(TestStagingDirectory)" />
</Target>
<Target Name="Ext-Prep" Condition=" '$(Configuration)' == 'debug' ">
<Message Text="Updating publisher information..." />
<Exec Command=""$(PowerShellExe)" -NonInteractive -NoProfile -ExecutionPolicy Unrestricted -Command "& { & '$(SetPublisherInfoScriptPath)' -ManifestPath '$(StagedExtensionManifestFilePath)' -StagingDirectory '$(StagingDirectory)' -PublishersDirectory '$(PublishersDirectory)' -PublisherName '$(PublisherName)' } "" />
</Target>
<Target Name="Ext-GetVersion">
<Message Text="Getting extension version for output filename..." />
<Exec
Command=""$(PowerShellExe)" -NonInteractive -NoProfile -ExecutionPolicy Unrestricted -Command "& { $(GetExtensionVersionScriptPath) -FilePath '$(StagedExtensionManifestFilePath)' } ""
ConsoleToMSBuild="true" >
<Output TaskParameter="ConsoleOutput" PropertyName="EXTENSION_VERSION" />
</Exec>
</Target>
<Target Name="Ext-Build" DependsOnTargets="Ext-Prep;Ext-GetVersion">
<Message Text="Building DevOps extension..." />
<Exec
Command="npx tfx extension create --manifest-globs "$(StagedExtensionManifestFilePath)" --output-path "$(OutputExtensionFilePath).$(EXTENSION_VERSION).vsix""
WorkingDirectory="$(StagingDirectory)" />
</Target>
<Target Name="Build" DependsOnTargets="ValidateConfiguration;Compile;Stage;Test;Ext-Build"></Target>
<Target Name="Ext-GetRollbackVersion">
<Message Text="Getting rollback extension version..." />
<Exec
Command=""$(PowerShellExe)" -NonInteractive -NoProfile -ExecutionPolicy Unrestricted -Command "& { $(GetExtensionVersionScriptPath) -FilePath '$(StagedExtensionManifestFilePath)' } ""
ConsoleToMSBuild="true" >
<Output TaskParameter="ConsoleOutput" PropertyName="EXTENSION_ROLLBACK_VERSION" />
</Exec>
</Target>
<Target Name="Ext-PrepareRollback">
<Message Text="Preparing rollback extension..." />
<Exec
Command=""$(PowerShellExe)" -NonInteractive -NoProfile -ExecutionPolicy Unrestricted -Command "& { $(RollbackScriptPath) -ExtensionFilePath '$(StagedExtensionManifestFilePath)' -Configuration '$(Configuration)' } ""
ConsoleToMSBuild="true" />
</Target>
<Target Name="Rollback" DependsOnTargets="Ext-GetVersion;Ext-PrepareRollback;Ext-GetRollbackVersion">
<Message Text="Building DevOps rollback extension..." />
<Exec
Command="npx tfx extension create --manifest-globs "$(StagedExtensionManifestFilePath)" --output-path "$(OutputExtensionFilePath).$(EXTENSION_VERSION)-rollback-$(EXTENSION_ROLLBACK_VERSION).vsix""
WorkingDirectory="$(StagingDirectory)" />
</Target>
</Project>