forked from SteeltoeOSS/Steeltoe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleanupcode.ps1
44 lines (36 loc) · 1.89 KB
/
cleanupcode.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
#Requires -Version 7.0
# This script reformats (part of) the codebase to make it compliant with our coding guidelines.
param(
# Git branch name or base commit hash to reformat only the subset of changed files. Omit for all files.
[string] $revision
)
function VerifySuccessExitCode {
if ($LastExitCode -ne 0) {
throw "Command failed with exit code $LastExitCode."
}
}
dotnet tool restore
VerifySuccessExitCode
dotnet restore src
VerifySuccessExitCode
if ($revision) {
$headCommitHash = git rev-parse HEAD
VerifySuccessExitCode
$baseCommitHash = git rev-parse $revision
VerifySuccessExitCode
if ($baseCommitHash -eq $headCommitHash) {
Write-Output "Running code cleanup on staged/unstaged files."
dotnet regitlint -s src/Steeltoe.All.sln --print-command --skip-tool-check --max-runs=5 --jb --dotnetcoresdk=$(dotnet --version) --jb-profile="Steeltoe Full Cleanup" --jb --properties:Configuration=Release --jb --properties:NuGetAudit=false --jb --verbosity=WARN -f staged,modified
VerifySuccessExitCode
}
else {
Write-Output "Running code cleanup on commit range $baseCommitHash..$headCommitHash, including staged/unstaged files."
dotnet regitlint -s src/Steeltoe.All.sln --print-command --skip-tool-check --max-runs=5 --jb --dotnetcoresdk=$(dotnet --version) --jb-profile="Steeltoe Full Cleanup" --jb --properties:Configuration=Release --jb --properties:NuGetAudit=false --jb --verbosity=WARN -f staged,modified,commits -a $headCommitHash -b $baseCommitHash
VerifySuccessExitCode
}
}
else {
Write-Output "Running code cleanup on all files."
dotnet regitlint -s src/Steeltoe.All.sln --print-command --skip-tool-check --jb --dotnetcoresdk=$(dotnet --version) --jb-profile="Steeltoe Full Cleanup" --jb --properties:Configuration=Release --jb --properties:NuGetAudit=false --jb --verbosity=WARN
VerifySuccessExitCode
}