-
Notifications
You must be signed in to change notification settings - Fork 1
/
Utilities.ps1
106 lines (96 loc) · 2.93 KB
/
Utilities.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
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
Function IsolateRestore {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[string]$RootDirectory
)
Write-Host "The root directory is $RootDirectory"
$gpf = Join-Path $RootDirectory -ChildPath "gpf"
$httpCache = Join-Path $RootDirectory -ChildPath "httpCache"
$pluginLogs = Join-Path $RootDirectory -ChildPath "plugin-logs"
Write-Host "Setting the global packages folder to $gpf"
$env:NUGET_PACKAGES=$gpf
Write-Host "Setting the http cache to $httpCache"
$env:NUGET_HTTP_CACHE_PATH=$httpCache
Write-Host "Enabling the plugins loggings"
$Env:NUGET_PLUGIN_ENABLE_LOG='true'
Write-Host "Setting the plugin log directory to $pluginLogs"
$Env:NUGET_PLUGIN_LOG_DIRECTORY_PATH=$pluginLogs
Write-Host "Creating the plugin logs path."
New-Item -Path $pluginLogs
# https://docs.microsoft.com/en-us/nuget/consume-packages/managing-the-global-packages-and-cache-folders
# https://github.com/NuGet/Home/wiki/Plugin-Diagnostic-Logging
}
Function CompareFiles {
[CmdletBinding()]
param(
[string]$file1,
[string]$file2
)
if((Get-FileHash $file1).hash -ne (Get-FileHash $file2).hash){
Write-Host "Files are the same".
} else {
Write-Host "Files are different."
}
}
Function Remove-OrphanedLocalBranches() {
@(git branch -vv) | findstr ": gone]" | findstr /V "\*" | %{$_.Split(' ')[2];} | findstr /V "^release" | % { git branch -D $_}
}
Function Invoke-TestsWithFilter
{
<#
.SYNOPSIS
Restores, Builds and runs tests.
.DESCRIPTION
Restores, Builds and runs tests using dotnet and filtering of scope.
.EXAMPLE
Run-TestsWithFilter TestMethodName -restore -build
.EXAMPLE
Run-TestsWithFilter TestMethodName -b
.PARAMETER filter
The filter to be passed to dotnet test --filter option. No filter will run all tests.
.PARAMETER restore
Restores the project before running tests.
.PARAMETER build
Builds the project before running tests.
#>
[CmdletBinding()]
param
(
[Alias('f')]
[string]$filter,
[Alias('r')]
[switch]$restore,
[Alias('b')]
[switch]$build
)
if ($restore)
{
Write-Host "msbuild /v:m /m /t:restore"
& msbuild /v:m /m /t:restore
}
if ($build)
{
Write-Host "msbuild /v:m /m"
& msbuild /v:m /m
}
if ([string]::IsNullOrEmpty($filter))
{
Write-Host "dotnet test --no-build --no-restore"
& dotnet test --no-build --no-restore
}
else
{
Write-Host "dotnet test --no-build --no-restore --filter DisplayName~$filter"
& dotnet test --no-build --no-restore --filter DisplayName~$filter
}
}
Function Invoke-Expression
{
param
(
[string]$expression
)
Write-Host "$expression"
Invoke-Expression $expression
}