-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlint.ps1
More file actions
87 lines (74 loc) · 2.13 KB
/
Copy pathlint.ps1
File metadata and controls
87 lines (74 loc) · 2.13 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
#!/usr/bin/env pwsh
[CmdletBinding()]
param(
[switch] $Check,
[switch] $ChangedOnly,
[string] $ChangedBase = "origin/main",
[switch] $NoRestore
)
$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest
Set-Location $PSScriptRoot
function Invoke-Step {
param(
[Parameter(Mandatory=$true)][string] $Name,
[Parameter(Mandatory=$true)][scriptblock] $Command
)
Write-Host "lint: $Name"
& $Command
if ($LASTEXITCODE -ne 0) {
throw "$Name failed with exit code $LASTEXITCODE"
}
}
function Get-ChangedCSharpFiles {
param([string] $Base)
$files = @()
$diffArgs = @("diff", "--name-only", "--diff-filter=ACMRT", "$Base...HEAD")
$output = & git @diffArgs 2>$null
if ($LASTEXITCODE -ne 0) {
$diffArgs = @("diff", "--name-only", "--diff-filter=ACMRT", "$Base..HEAD")
$output = & git @diffArgs 2>$null
}
if ($LASTEXITCODE -ne 0 -or -not $output) {
return @()
}
foreach ($file in @($output)) {
if ($file -match '\.cs$' -and
$file -notmatch '(^|/)(bin|obj|build|release|stage)(/|$)') {
$files += $file
}
}
return $files
}
Invoke-Step -Name "workflow script syntax" -Command {
./.github/scripts/Test-WorkflowSyntax.ps1
./.github/scripts/Test-UpdateChangelog.ps1
./.github/scripts/Test-GenerateReleaseNotes.ps1
./.github/scripts/Test-ReleaseVersionSequence.ps1
./.github/scripts/Test-NightlyBetaPlan.ps1
}
if (-not $NoRestore) {
Invoke-Step -Name "restore" -Command {
dotnet restore VRCInventoryManager.slnx
}
}
$formatArgs = @("format", "VRCInventoryManager.slnx", "--verbosity", "minimal")
if ($NoRestore) {
$formatArgs += "--no-restore"
}
if ($Check) {
$formatArgs += "--verify-no-changes"
}
if ($ChangedOnly) {
$changedCSharp = @(Get-ChangedCSharpFiles -Base $ChangedBase)
if ($changedCSharp.Count -eq 0) {
Write-Host "lint: no changed C# files to format-check."
exit 0
}
$formatArgs += "--include"
$formatArgs += $changedCSharp
}
Invoke-Step -Name "dotnet format" -Command {
dotnet @formatArgs
}
Write-Host "lint: passed."