-
Notifications
You must be signed in to change notification settings - Fork 0
Collapse file tree
Files
Search this repository(forward slash) forward slash/
/
Copy pathInvoke-LeanSERP-Build.ps1
More file actions
More file actions
Latest commit
422 lines (358 loc) · 7.69 KB
/
Copy pathInvoke-LeanSERP-Build.ps1
File metadata and controls
422 lines (358 loc) · 7.69 KB
You must be signed in to make or propose changes
More edit options
Edit and raw actions
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string]$BuilderPath,
[Parameter(Mandatory = $false)]
[string[]]$InputFile = @(),
[Parameter(Mandatory = $false)]
[string]$InputListFile = "",
[Parameter(Mandatory = $true)]
[string]$OutputDirectory,
[Parameter(Mandatory = $true)]
[string]$LogPath,
[Parameter(Mandatory = $false)]
[ValidateRange(1000, 1000000)]
[int]$ChunkSize = 250000,
[Parameter(Mandatory = $false)]
[switch]$KeepUnderscores,
[Parameter(Mandatory = $false)]
[switch]$KeepTemporaryFiles
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
function New-Utf8Writer {
param(
[Parameter(Mandatory = $true)]
[string]$Path,
[Parameter(Mandatory = $false)]
[bool]$Append = $false
)
return [System.IO.StreamWriter]::new(
$Path,
$Append,
[System.Text.UTF8Encoding]::new($false),
4096
)
}
function Write-LogHeader {
param(
[Parameter(Mandatory = $true)]
[System.IO.StreamWriter]$Writer,
[Parameter(Mandatory = $true)]
[string]$ResolvedBuilder,
[Parameter(Mandatory = $true)]
[string]$ResolvedOutput,
[Parameter(Mandatory = $true)]
[string[]]$ResolvedInputs,
[Parameter(Mandatory = $true)]
[DateTimeOffset]$StartedAt
)
$Writer.WriteLine(
"LeanSERP build runner started."
)
$Writer.WriteLine(
"Started UTC: " +
$StartedAt.ToString("o")
)
$Writer.WriteLine(
"Builder: " +
$ResolvedBuilder
)
$Writer.WriteLine(
"Output directory: " +
$ResolvedOutput
)
$Writer.WriteLine(
"Input files: " +
$ResolvedInputs.Count
)
foreach ($path in $ResolvedInputs) {
$Writer.WriteLine(
" " +
$path
)
}
$Writer.WriteLine(
"Chunk size: " +
$ChunkSize
)
$Writer.WriteLine(
"Keep underscores: " +
[string][bool]$KeepUnderscores
)
$Writer.WriteLine(
"Keep temporary files: " +
[string][bool]$KeepTemporaryFiles
)
$Writer.WriteLine("")
$Writer.Flush()
}
function Write-LogError {
param(
[Parameter(Mandatory = $true)]
[string]$Text
)
$writer = $null
try {
$writer =
New-Utf8Writer `
-Path $LogPath `
-Append $true
$writer.WriteLine("")
$writer.WriteLine(
"BUILD ERROR"
)
$writer.WriteLine(
$Text.TrimEnd()
)
$writer.Flush()
}
finally {
if ($null -ne $writer) {
$writer.Dispose()
}
}
}
function Write-LogFooter {
param(
[Parameter(Mandatory = $true)]
[DateTimeOffset]$StartedAt,
[Parameter(Mandatory = $true)]
$headerWriter =
New-Utf8Writer `
-Path $LogPath `
-Append $false
Write-LogHeader `
-Writer $headerWriter `
-ResolvedBuilder $resolvedBuilder `
-ResolvedOutput $resolvedOutput `
-ResolvedInputs $resolvedInputs.ToArray() `
-StartedAt $startedAt
}
finally {
if ($null -ne $headerWriter) {
$headerWriter.Dispose()
$headerWriter = $null
}
}
$parameters = @{
InputFile = $resolvedInputs.ToArray()
OutputDirectory = $resolvedOutput
ChunkSize = $ChunkSize
ProgressLogPath = $LogPath
}
if ($KeepUnderscores) {
$parameters["KeepUnderscores"] =
$true
}
if ($KeepTemporaryFiles) {
$parameters["KeepTemporaryFiles"] =
$true
}
try {
& $resolvedBuilder @parameters
if (-not $?) {
$exitCode = 1
}
}
catch {
$exitCode = 1
$errorText =
$_ |
Out-String
try {
Write-LogError `
-Text $errorText
}
catch {
}
Write-Error $errorText
}
finally {
try {
Write-LogFooter `
-StartedAt $startedAt `
-ExitCode $exitCode
}
catch {
}
}
if ($exitCode -ne 0) {
exit $exitCode
}
exit 0