-
Notifications
You must be signed in to change notification settings - Fork 120
/
Compile.ps1
356 lines (346 loc) · 19.1 KB
/
Compile.ps1
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
Param(
[string]$MSBuildPath="C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\MSBuild.exe",
[string]$Target="",
[string]$CustomVersion="",
[string]$NuGet="",
[string]$Config="Debug",
[switch]$AutoVersion,
[switch]$ProjectSpecificOutputs,
[switch]$AcceptanceTesting,
[switch]$UITesting,
[switch]$Server,
[switch]$Studio,
[switch]$Release,
[switch]$Web,
[switch]$RegenerateSpecFlowFeatureFiles,
[switch]$InContainer,
[string]$GitCredential
)
$KnownSolutionFiles = "Dev\AcceptanceTesting.sln",
"Dev\UITesting.sln",
"Dev\Server.sln",
"Dev\Studio.sln",
"Dev\Release.sln",
"Dev\Web.sln"
$NoSolutionParametersPresent = !($AcceptanceTesting.IsPresent) -and !($UITesting.IsPresent) -and !($Server.IsPresent) -and !($Studio.IsPresent) -and !($Release.IsPresent) -and !($Web.IsPresent) -and !($RegenerateSpecFlowFeatureFiles.IsPresent)
if ($Target -ne "") {
$Target = "/t:" + $Target
}
#find script
if ("$PSScriptRoot" -eq "" -or $PSScriptRoot -eq $null) {
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
}
if (!($InContainer.IsPresent)) {
#Find Local NuGet
if ("$NuGet" -eq "" -or !(Test-Path "$NuGet" -ErrorAction SilentlyContinue)) {
$NuGetCommand = Get-Command NuGet -ErrorAction SilentlyContinue
if ($NuGetCommand) {
$NuGet = $NuGetCommand.Path
}
}
if (("$NuGet" -eq "" -or !(Test-Path "$NuGet" -ErrorAction SilentlyContinue)) -and (Test-Path "$env:windir")) {
wget "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -OutFile "$env:windir\nuget.exe"
$NuGet = "$env:windir\nuget.exe"
}
if ("$NuGet" -eq "" -or !(Test-Path "$NuGet" -ErrorAction SilentlyContinue)) {
Write-Host NuGet not found. Download from: https://dist.nuget.org/win-x86-commandline/latest/nuget.exe to: c:\windows\nuget.exe. If you do not have permission to create c:\windows\nuget.exe use the -NuGet switch.
sleep 10
exit 1
}
#Find Local Compiler
if (!(Test-Path "$MSBuildPath" -ErrorAction SilentlyContinue)) {
$GetMSBuildCommand = Get-Command MSBuild -ErrorAction SilentlyContinue
if ($GetMSBuildCommand) {
$MSBuildPath = $GetMSBuildCommand.Path
}
}
if ($MSBuildPath -ne $null -and !(Test-Path "$MSBuildPath" -ErrorAction SilentlyContinue)) {
$GetvswhereCommand = Get-Command vswhere -ErrorAction SilentlyContinue
if ($GetvswhereCommand) {
$VswherePath = $GetvswhereCommand.Path
} else {
if (Test-Path "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe") {
$VswherePath = "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe"
} else {
&"$NuGet" install vswhere -ExcludeVersion -NonInteractive -OutputDirectory "$env:windir"
$VswherePath = "$env:windir\vswhere\tools\vswhere.exe"
}
}
[xml]$GetMSBuildPath = &$VswherePath -latest -requires Microsoft.Component.MSBuild -version 15.0 -format xml
if ($GetMSBuildPath -ne $null) {
$MSBuildPath = $GetMSBuildPath.instances.instance.installationPath + "\MSBuild\15.0\Bin\MSBuild.exe"
}
}
if (!(Test-Path "$MSBuildPath" -ErrorAction SilentlyContinue)) {
if (Test-Path $MSBuildPath.Replace("Enterprise", "Professional")) {
$MSBuildPath = $MSBuildPath.Replace("Enterprise", "Professional")
}
if (Test-Path $MSBuildPath.Replace("Enterprise", "Community")) {
$MSBuildPath = $MSBuildPath.Replace("Enterprise", "Community")
}
if (Test-Path $MSBuildPath.Replace("Enterprise", "BuildTools")) {
$MSBuildPath = $MSBuildPath.Replace("Enterprise", "BuildTools")
}
if ("$env:MSBuildPath" -ne "" -and (Test-Path "$env:MSBuildPath")) {
$MSBuildPath = $env:MSBuildPath
}
}
if (!(Test-Path "$MSBuildPath" -ErrorAction SilentlyContinue)) {
$env:MSBuildPath = Read-Host 'Please enter the path to MSBuild.exe. For example: C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\MSBuild.exe. Or change the value of the MSBuildPath environment variable to be the path to MSBuild.exe'
if ("$env:MSBuildPath" -ne "" -and (Test-Path "$env:MSBuildPath")) {
$MSBuildPath = $env:MSBuildPath
[System.Environment]::SetEnvironmentVariable("MSBuildPath", $MSBuildPath, "Machine")
} else {
Write-Host MSBuild not found. Download from: https://aka.ms/vs/15/release/vs_buildtools.exe
sleep 10
exit 1
}
}
}
#Version
$GitCommitID = git -C "$PSScriptRoot" rev-parse HEAD
if ($AutoVersion.IsPresent -or $CustomVersion -ne "") {
Write-Host Writing C# and F# versioning files...
if ($GitCredential -ne "") {
git -C "$PSScriptRoot" remote set-url origin https://[email protected]/warewolf/warewolf
}
# Get all the latest version tags from server repo.
git -C "$PSScriptRoot" fetch --all --tags -f
# Generate informational version.
# (from git commit id and time)
$GitCommitTimeObject = git -C "$PSScriptRoot" show -s --format="%ct" $GitCommitID
if (($GitCommitTimeObject[0]).ToString().length -gt 1){
$GitCommitTimeString = $GitCommitTimeObject[0]
} else {
$GitCommitTimeString = $GitCommitTimeObject
}
if ([string]::IsNullOrEmpty($GitCommitTimeString)) {
Write-Host Cannot resolve time of commit `"$GitCommitID`".
} else {
write-host Resolved time of commit `"$GitCommitID`" as `"$GitCommitTimeString`".
$GitCommitTimeDouble = [Double]$GitCommitTimeString
$origin = New-Object -Type DateTime -ArgumentList 1970, 1, 1, 0, 0, 0, 0
$GitCommitTime = $origin.AddSeconds($GitCommitTimeDouble)
}
$GitBranchName = git -C "$PSScriptRoot" rev-parse --abbrev-ref HEAD
if ($CustomVersion -ne "") {
$FullVersionString = "$CustomVersion"
} else {
# Check if this version already tagged.
$FullVersionString = git -C "$PSScriptRoot" tag --points-at HEAD
if (-not [string]::IsNullOrEmpty($FullVersionString)) {
$FullVersionString = $FullVersionString.Trim()
$MultiTags = $FullVersionString.Split("\n")
if ($MultiTags.Count -gt 1) {
# This commit has more than one tag, using first tag
Write-Host This commit has more than one tags as `"$FullVersionString`".
$FullVersionString = $MultiTags[-1]
Write-Host Using last tag as `"$FullVersionString`".
}
# This version is already tagged.
Write-Host You are up to date with version `"$FullVersionString`".
} else {
# This version is not already tagged.
Write-Host This version is not tagged, generating new tag...
# Get last known version
$AllTags = git -C "$PSScriptRoot" tag -l --sort=-creatordate --merged
foreach ($element in $AllTags) {
$dotCount = $element.Split('.').Count - 1
if ($dotCount -eq 3) {
$FullVersionString = $element
break
}
}
if ([string]::IsNullOrEmpty($FullVersionString) -or $dotCount -ne 3) {
Write-Host No local tags found in git history.
exit 1
} else {
$FullVersionString = $FullVersionString.Trim()
# Make new version from last known version.
Write-Host Last version was `"$FullVersionString`". Generating next version...
do {
# Increment build number.
[int]$NewBuildNumber = $FullVersionString.Split(".")[3]
if ($NewBuildNumber -eq $null)
{
$NewBuildNumber = 0
}
else
{
$NewBuildNumber++
}
$FullVersionString = $FullVersionString.Split(".")[0] + "." + $FullVersionString.Split(".")[1] + "." + $FullVersionString.Split(".")[2] + "." + $NewBuildNumber
Write-Host Next version would be `"$FullVersionString`". Checking against Origin repo...
# Check tag against origin
$originTag = git -C "$PSScriptRoot" ls-remote --tags origin $FullVersionString
if ($originTag.length -ne 0) {
Write-Host Origin has tag `"$originTag`".
} else {
Write-Host Double checking with hard coded integration manager repo...
# Check tag against hard coded integration manager repo
$originTag = git -C "$PSScriptRoot" ls-remote --tags "https://gitlab.com/warewolf/warewolf" $FullVersionString
if ($originTag.length -ne 0) {
Write-Host Hard coded integration manager repo has tag `"$originTag`".
} else {
Write-Host Double checking with hard coded blessed repo...
# Check tag against hard coded blessed repo
$originTag = git -C "$PSScriptRoot" ls-remote --tags "https://github.com/Warewolf-ESB/Warewolf" $FullVersionString
if ($originTag.length -ne 0) {
Write-Host Hard coded blessed repo has tag `"$originTag`".
}
}
}
} while ($originTag.length -ne 0)
}
# New (unique) version has been generated.
Write-Host Origin has confirmed version `"$FullVersionString`" is OK.
}
}
# Write version files
$CSharpVersionFile = "$PSScriptRoot\Dev\AssemblyCommonInfo.cs"
Write-Host Writing C Sharp version file to `"$CSharpVersionFile`" as...
$CSharpVersionFileContents = @"
using System.Reflection;
using System.Runtime.CompilerServices;
#pragma warning disable CC0021 // Use nameof
[assembly: AssemblyCompany(@"Warewolf")]
[assembly: AssemblyProduct(@"Warewolf")]
#pragma warning restore CC0021 // Use nameof
[assembly: AssemblyCopyright(@"Copyright Warewolf
"@ + (Get-Date).year + @"
")]
[assembly: AssemblyVersion(@"
"@ + $FullVersionString + @"
")]
[assembly: AssemblyInformationalVersion(@"
"@ + $GitCommitTime + " " + $GitCommitID + " " + $GitBranchName + @"
")]
[assembly: InternalsVisibleTo("Dev2.Runtime.Tests")]
[assembly: InternalsVisibleTo("Dev2.Runtime.WebServer.Tests")]
[assembly: InternalsVisibleTo("Dev2.Studio.Core.Tests")]
[assembly: InternalsVisibleTo("Dev2.TaskScheduler.Wrappers")]
[assembly: InternalsVisibleTo("Dev2.Infrastructure.Tests")]
[assembly: InternalsVisibleTo("Warewolf.Studio.ViewModels.Tests")]
[assembly: InternalsVisibleTo("Warewolf.QueueWorker.Tests")]
[assembly: InternalsVisibleTo("Dev2.Data.Tests")]
[assembly: InternalsVisibleTo("Warewolf.Tools.Specs")]
[assembly: InternalsVisibleTo("Warewolf.Common.Framework48.Tests")]
[assembly: InternalsVisibleTo("Warewolf.Storage.Tests")]
[assembly: InternalsVisibleTo("Warewolf.UIBindingTests.ComDll")]
[assembly: InternalsVisibleTo("Warewolf.UIBindingTests.PluginSource")]
[assembly: InternalsVisibleTo("Dev2.Utils.Tests")]
[assembly: InternalsVisibleTo("Warewolf.Core.Tests")]
[assembly: InternalsVisibleTo("Dev2.Common.Tests")]
[assembly: InternalsVisibleTo("Dev2.Activities.Tests")]
[assembly: InternalsVisibleTo("Dev2.Activities.Designers.Tests")]
[assembly: InternalsVisibleTo("Dev2.CustomControls.Tests")]
[assembly: InternalsVisibleTo("Dev2.Activities.Specs")]
[assembly: InternalsVisibleTo("Dev2.Integration.Tests")]
[assembly: InternalsVisibleTo("Warewolf.HangfireServer.Tests")]
"@
Write-Host $CSharpVersionFileContents
$CSharpVersionFileContents | Out-File -LiteralPath $CSharpVersionFile -Encoding utf8 -Force
Write-Host C Sharp version file written to `"$CSharpVersionFile`".
$FSharpVersionFile = "$PSScriptRoot\Dev\AssemblyCommonInfo.fs"
Write-Host Writing F Sharp version file to `"$FSharpVersionFile`" as...
$FSharpVersionFileContents = @"
namespace Warewolf.FSharp
namespace Warewolf.FSharp
open System.Reflection;
#nowarn
[<assembly: AssemblyCompany(@"Warewolf")>]
[<assembly: AssemblyProduct(@"Warewolf")>]
[<assembly: AssemblyCopyright(@"Copyright Warewolf
"@ + (Get-Date).year + @"
")>]
[<assembly: AssemblyVersion(@"
"@ + $FullVersionString + @"
")>]
do()
"@
Write-Host $FSharpVersionFileContents
$FSharpVersionFileContents | Out-File -LiteralPath $FSharpVersionFile -Encoding utf8 -Force
Write-Host F Sharp version file written to `"$FSharpVersionFile`".
Write-Host Warewolf version written successfully! For more info about Warewolf versioning see: http://warewolf.io/ESB-blog/artefact-sharing-efficient-ci/
}
if ($RegenerateSpecFlowFeatureFiles.IsPresent) {
&"nuget.exe" "restore" "$PSScriptRoot\Dev\AcceptanceTesting.sln"
if ($LASTEXITCODE -ne 0) {
sleep 30
exit 1
}
foreach ($ProjectDir in ((Get-ChildItem "$PSScriptRoot\Dev\*Specs") + (Get-ChildItem "$PSScriptRoot\Dev\Warewolf.UIBindingTests.*"))) {
$FullPath = $ProjectDir.FullName
$ProjectName = $ProjectDir.Name
if (Test-Path "$FullPath\$ProjectName.csproj") {
&"$env:userprofile\.nuget\packages\specflow\2.3.2\tools\specflow.exe" "generateAll" "$FullPath\$ProjectName.csproj" "/force" "/verbose"
} else {
Write-Warning -Message "Project file not found in folder $FullPath`nExpected it to be $FullPath\$ProjectName.csproj"
}
}
foreach ($FeatureFile in (Get-ChildItem "$PSScriptRoot\Dev\**\*.feature.cs")) {
(Get-Content $FeatureFile).replace('TestCategoryAttribute("MSTest:DeploymentItem:', 'DeploymentItem("').replace('DeploymentItem("Warewolf_Studio.exe")', 'DeploymentItem("Warewolf Studio.exe")') | Set-Content $FeatureFile
}
}
#Compile Solutions
foreach ($SolutionFile in $KnownSolutionFiles) {
if (Test-Path "$PSScriptRoot\$SolutionFile") {
$GetSolutionFileInfo = Get-Item "$PSScriptRoot\$SolutionFile"
$SolutionFileName = $GetSolutionFileInfo.Name
$SolutionFileExtension = $GetSolutionFileInfo.Extension
$OutputFolderName = $SolutionFileName.TrimEnd("." + $SolutionFileExtension).TrimEnd("2")
if ((Get-Variable "$OutputFolderName*" -ValueOnly).IsPresent.Length -gt 1) {
$SolutionParameterIsPresent = (Get-Variable "$OutputFolderName*" -ValueOnly).IsPresent[0]
} else {
$SolutionParameterIsPresent = (Get-Variable "$OutputFolderName*" -ValueOnly).IsPresent
}
if ($SolutionParameterIsPresent -or $NoSolutionParametersPresent) {
if ($OutputFolderName -eq "Webs") {
npm install --add-python-to-path='true' --global --production windows-build-tools
}
if ($OutputFolderName -eq "AcceptanceTesting" -and !($ProjectSpecificOutputs.IsPresent)) {
&"$NuGet" install Microsoft.TestPlatform -ExcludeVersion -NonInteractive -OutputDirectory "$PSScriptRoot\Bin\$OutputFolderName" -Version "17.2.0"
}
if ($ProjectSpecificOutputs.IsPresent) {
$OutputProperty = ""
} else {
$OutputProperty = "/property:OutDir=$PSScriptRoot\Bin\$OutputFolderName"
}
if (!($InContainer.IsPresent)) {
&"$MSBuildPath" "$PSScriptRoot\$SolutionFile" "/p:Platform=`"Any CPU`";Configuration=`"$Config`"" "/maxcpucount" "/nodeReuse:false" "/restore" $OutputProperty $Target
} else {
docker run -t -m 4g -v "$PSScriptRoot":"C:\Build" registry.gitlab.com/warewolf/msbuild "C:\Build\$SolutionFile" "/p:Platform=`"Any CPU`";Configuration=`"$Config`"$NugetPackVersion" "/maxcpucount" "/nodeReuse:false" "/restore" $OutputProperty $Target
}
if ($LASTEXITCODE -ne 0) {
Write-Host Build failed. Check your pending changes. If you do not have any pending changes then you can try running 'dev\scorch.bat' to thoroughly clean your workspace. Compiling Warewolf requires at at least MSBuild 15.0, download from: https://aka.ms/vs/15/release/vs_buildtools.exe and FSharp 4.0, download from http://download.microsoft.com/download/9/1/2/9122D406-F1E3-4880-A66D-D6C65E8B1545/FSharp_Bundle.exe
exit 1
}
if (!($ProjectSpecificOutputs.IsPresent) -and ($Target -eq "/t:Debug" -or $Target -eq "")) {
if (Test-Path "$PSScriptRoot\Bin\$OutputFolderName\SQLite.Interop.dll") {
Remove-Item -Path "$PSScriptRoot\Bin\$OutputFolderName\SQLite.Interop.dll" -Force
}
if (Test-Path "$env:userprofile\.nuget\packages\mstest.testadapter\2.1.2\build\_common\Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll") {
Copy-Item -Path "$env:userprofile\.nuget\packages\mstest.testadapter\2.1.2\build\_common\Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll" -Destination "$PSScriptRoot\Bin\$OutputFolderName\Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll" -Force
}
if (Test-Path "$env:userprofile\.nuget\packages\mstest.testadapter\2.1.2\build\_common\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll") {
Copy-Item -Path "$env:userprofile\.nuget\packages\mstest.testadapter\2.1.2\build\_common\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll" -Destination "$PSScriptRoot\Bin\$OutputFolderName\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll" -Force
}
if (Test-Path "$env:userprofile\.nuget\packages\mstest.testadapter\2.1.2\build\_common\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.dll") {
Copy-Item -Path "$env:userprofile\.nuget\packages\mstest.testadapter\2.1.2\build\_common\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.dll" -Destination "$PSScriptRoot\Bin\$OutputFolderName\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.dll" -Force
}
if (Test-Path "$env:userprofile\.nuget\packages\mstest.testadapter\2.1.2\build\_common\Microsoft.VisualStudio.TestPlatform.TestFramework.dll") {
Copy-Item -Path "$env:userprofile\.nuget\packages\mstest.testadapter\2.1.2\build\_common\Microsoft.VisualStudio.TestPlatform.TestFramework.dll" -Destination "$PSScriptRoot\Bin\$OutputFolderName\Microsoft.VisualStudio.TestPlatform.TestFramework.dll" -Force
}
Copy-Item -Path "$PSScriptRoot\Dev\Resources - Release" -Destination "$PSScriptRoot\Bin\$OutputFolderName" -Force -Recurse
Copy-Item -Path "$PSScriptRoot\Dev\Resources - ServerTests" -Destination "$PSScriptRoot\Bin\$OutputFolderName" -Force -Recurse
Copy-Item -Path "$PSScriptRoot\Dev\Resources - UITests" -Destination "$PSScriptRoot\Bin\$OutputFolderName" -Force -Recurse
Copy-Item -Path "$PSScriptRoot\Dev\Resources - Load" -Destination "$PSScriptRoot\Bin\$OutputFolderName" -Force -Recurse
if (!(Test-Path "$PSScriptRoot\Bin\$OutputFolderName\_PublishedWebsites\Dev2.Web")) {
Copy-Item -Path "$PSScriptRoot\Dev\Dev2.Web2" "$PSScriptRoot\Bin\$OutputFolderName\_PublishedWebsites\Dev2.Web" -Force -Recurse
}
Copy-Item -Path "$PSScriptRoot\Dev\.run\Job Shortcuts" "$PSScriptRoot\Bin\$OutputFolderName\Job Shortcuts" -Force -Recurse
}
}
}
}
exit 0