Repository navigation
Expand file tree
/
Copy pathReviewBranch.psm1
More file actions
128 lines (99 loc) · 3.89 KB
/
Copy pathReviewBranch.psm1
File metadata and controls
128 lines (99 loc) · 3.89 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
123
124
125
126
127
128
function CSH-ReviewBranch {
param (
[string]$folder,
[string]$pathToTestingRepo,
[switch]$skipValidation = $true,
[switch]$xml = $false
)
$repositoryRoot = Join-Path $PSScriptRoot ".."
$csProjectPath = Join-Path $repositoryRoot "Src/CSharpier.Cli/CSharpier.Cli.csproj"
$csharpierDllPath = Join-Path $repositoryRoot "Src/CSharpier.Cli/bin/release/net11.0/CSharpier.dll"
$location = Get-Location
Set-Location $repositoryRoot
if (!$pathToTestingRepo) {
$pathToTestingRepo = Join-Path $PSScriptRoot "../../csharpier-repos"
}
if ($folder -ne $null) {
$pathToTestingRepo = Join-Path $pathToTestingRepo $folder
}
if (!(Test-Path $pathToTestingRepo)) {
Write-Output "No directory found at $($pathToTestingRepo)."
Write-Output "Please checkout out https://github.com/belav/csharpier-repos there or supply -pathToTestingRepo"
return
}
$ErrorActionPreference = "Stop"
$branch = & git branch --show-current
if ($branch -eq "main") {
Write-Output "You must be on the branch you want to test. You are currently on main"
return
}
$preBranch = "pre-" + $branch
$postBranch = "post-" + $branch
if ($folder -ne $null) {
$preBranch += "-" + $folder
$postBranch += "-" + $folder
}
Set-Location $pathToTestingRepo
& git reset --hard *> $null
& git pull
try {
& git checkout $postBranch 2>&1
}
catch { }
$postBranchOutput = (git status 2>&1) | Out-String
$firstRun = -not $postBranchOutput.Contains("On branch $postBranch")
$skipValidationParam = ""
if ($skipValidation -eq $true) {
$skipValidationParam = "--skip-validation"
}
if ($firstRun) {
Set-Location $repositoryRoot
& git checkout main #2>&1 | Out-String
CSH-BuildProject -doNotExit
if ($lastExitCode -gt 0) {
return
}
Set-Location $pathToTestingRepo
& git checkout main
& git reset --hard
& git checkout -b $preBranch
if ($xml) {
Add-Content -Path "$pathToTestingRepo/.csharpierignore" -Value "**/*.cs"
} else {
Add-Content -Path "$pathToTestingRepo/.csharpierignore" -Value "**/*.config"
Add-Content -Path "$pathToTestingRepo/.csharpierignore" -Value "**/*.csproj"
Add-Content -Path "$pathToTestingRepo/.csharpierignore" -Value "**/*.props"
Add-Content -Path "$pathToTestingRepo/.csharpierignore" -Value "**/*.slnx"
Add-Content -Path "$pathToTestingRepo/.csharpierignore" -Value "**/*.targets"
Add-Content -Path "$pathToTestingRepo/.csharpierignore" -Value "**/*.xaml"
Add-Content -Path "$pathToTestingRepo/.csharpierignore" -Value "**/*.xml"
}
dotnet $csharpierDllPath format . $skipValidationParam --no-cache
# there is some weirdness with a couple files with #if where
# they need to be formatted twice to get them stable
# it isn't worth fixing in csharpier, because it only really affects this
dotnet $csharpierDllPath format . $skipValidationParam
& git add -A
& git commit -m "Before $branch"
& git push --set-upstream origin $preBranch
}
Set-Location $repositoryRoot
git checkout $branch
CSH-BuildProject
Set-Location $pathToTestingRepo
if ($firstRun) {
& git checkout -b $postBranch
} else {
& git checkout $postBranch
}
dotnet $csharpierDllPath format . $skipValidationParam --no-cache
& git add -A
& git commit -m "After $branch"
& git push --set-upstream origin $postBranch
if ($firstRun) {
$newPr = & gh pr create --base $preBranch --head $postBranch --title "Testing $branch $folder" --body ""
Write-Output $newPr
}
Set-Location $location
}
Export-ModuleMember -Function CSH-*