-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathget_diff_task.ps1
More file actions
122 lines (97 loc) · 3 KB
/
Copy pathget_diff_task.ps1
File metadata and controls
122 lines (97 loc) · 3 KB
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
param(
[Parameter(Mandatory = $false)]
[ValidateSet("auto", "all", "main", "test")]
[string]$Net = "auto",
[Parameter(Mandatory = $false)]
[string]$MetricsHost = $env:CKB_SYNC_METRICS_HOST,
[Parameter(Mandatory = $false)]
[switch]$NoFollowEnv
)
$ErrorActionPreference = "Continue"
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$taskLog = Join-Path $scriptDir "get_diff_task.log"
function Write-TaskLog {
param([string]$Message)
$line = "{0} {1}" -f (Get-Date).ToString("yyyy-MM-dd HH:mm:ss"), $Message
Add-Content -LiteralPath $taskLog -Encoding UTF8 -Value $line
}
function Get-ModeSequence {
$defaultSequence = @("1", "2")
$file = "mode_sequence.txt"
if (-not (Test-Path -LiteralPath $file)) {
return $defaultSequence
}
$content = Get-Content -LiteralPath $file | ForEach-Object {
$_ -replace '#.*$', ''
}
$modes = @(($content -join " ") -split '[,\s]+' |
ForEach-Object { $_.Trim() } |
Where-Object { $_ -in @("1", "2", "3", "4") })
if ($modes.Count -eq 0) {
return $defaultSequence
}
$sequence = New-Object System.Collections.Generic.List[string]
foreach ($modeValue in $modes) {
if (-not $sequence.Contains($modeValue)) {
[void]$sequence.Add($modeValue)
}
}
return @($sequence.ToArray())
}
function Get-NetFromEnv {
if (-not (Test-Path -LiteralPath "env.txt")) {
return $null
}
$modeSequence = @(Get-ModeSequence)
$envLines = @(Get-Content -LiteralPath "env.txt")
$mode = if ($envLines.Count -ge 1) { $envLines[0].Trim() } else { "" }
if ($modeSequence -notcontains $mode) {
$mode = $modeSequence[0]
}
switch ($mode) {
{ $_ -in @("1", "3") } { return "main" }
{ $_ -in @("2", "4") } { return "test" }
default { return $null }
}
}
function Resolve-Net {
param(
[string]$RequestedNet,
[bool]$FollowEnv
)
if ($RequestedNet -eq "all") {
return "all"
}
$envNet = Get-NetFromEnv
if ($envNet) {
if ($RequestedNet -eq "auto" -or ($FollowEnv -and $RequestedNet -ne $envNet)) {
return $envNet
}
}
if ($RequestedNet -eq "auto") {
return "all"
}
return $RequestedNet
}
try {
Set-Location -LiteralPath $scriptDir
$resolvedNet = Resolve-Net -RequestedNet $Net -FollowEnv:(-not $NoFollowEnv)
Write-TaskLog "start requested_net=$Net resolved_net=$resolvedNet follow_env=$(-not $NoFollowEnv)"
$scriptArgs = @{
Net = $resolvedNet
}
if (-not [string]::IsNullOrWhiteSpace($MetricsHost)) {
$scriptArgs.MetricsHost = $MetricsHost
}
$output = & (Join-Path $scriptDir "get_diff.ps1") @scriptArgs 2>&1
foreach ($line in $output) {
Write-TaskLog "$line"
}
$exitCode = if ($null -eq $LASTEXITCODE) { 0 } else { $LASTEXITCODE }
Write-TaskLog "done exit=$exitCode"
exit 0
}
catch {
Write-TaskLog "error: $($_.Exception.Message)"
exit 1
}