-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathEditorServicesCommandSuite.build.ps1
229 lines (183 loc) · 7.04 KB
/
EditorServicesCommandSuite.build.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#requires -Module InvokeBuild -Version 5.1
[CmdletBinding()]
param(
[Parameter()]
[ValidateSet('Debug', 'Release')]
[string] $Configuration = 'Debug',
[Parameter()]
[string] $Framework = 'netstandard2.0',
[Parameter()]
[switch] $Force
)
$ModuleName = 'EditorServicesCommandSuite'
$Culture = 'en-US'
$ShouldAnalyze = $false
$ShouldTest = $true
$FailOnError = @{
ErrorAction = [System.Management.Automation.ActionPreference]::Stop
}
$Silent = @{
ErrorAction = [System.Management.Automation.ActionPreference]::Ignore
WarningAction = [System.Management.Automation.ActionPreference]::Ignore
}
$Manifest = Test-ModuleManifest -Path "$PSScriptRoot/module/$ModuleName.psd1" @Silent
$Version = $Manifest.Version
$PowerShellPath = "$PSScriptRoot/module"
$CSharpPath = "$PSScriptRoot/src"
$ReleasePath = "$PSScriptRoot/Release/$ModuleName/$Version"
$DocsPath = "$PSScriptRoot/docs"
$TestPath = "$PSScriptRoot/test/$ModuleName.Tests"
$ToolsPath = "$PSScriptRoot/tools"
$HasDocs = Test-Path $DocsPath/$Culture/*.md
$HasTests = Test-Path $TestPath/*
$IsUnix = $PSEdition -eq 'Core' -and -not $IsWindows
function InvokeWithPSModulePath([scriptblock] $Action) {
$oldPSModulePath = $env:PSModulePath
try {
$env:PSModulePath = Join-Path (Split-Path $pwsh.Path) -ChildPath 'Modules'
. $Action
} finally {
$env:PSModulePath = $oldPSModulePath
}
}
task Clean {
if (Test-Path $ReleasePath) {
Remove-Item $ReleasePath -Recurse
}
New-Item -ItemType Directory $ReleasePath | Out-Null
}
task BuildDocs -If { $HasDocs } {
New-ExternalHelp -Path $DocsPath/$Culture -OutputPath $ReleasePath/$Culture | Out-Null
}
task AssertDependencies AssertPowerShellCore, AssertRequiredModules, AssertDotNet, AssertPSES, AssertPSRL
task AssertPowerShellCore {
$script:pwsh = $pwsh = Get-Command pwsh @Silent
if ($pwsh) {
return
}
if ($Force.IsPresent) {
choco install powershell-core --version 7.0.0 -y
} else {
choco install powershell-core --verison 7.0.0
}
$script:pwsh = Get-Command $env:ProgramFiles/PowerShell/7/pwsh.exe @FailOnError
}
task AssertRequiredModules {
$assertRequiredModule = Get-Command $ToolsPath/AssertRequiredModule.ps1 @FailOnError
& $assertRequiredModule platyPS -RequiredVersion 0.14.0 -Force:$Force.IsPresent
}
task AssertDotNet {
$script:dotnet = & $ToolsPath/GetDotNet.ps1 -Unix:$IsUnix
}
task AssertPSES {
& "$ToolsPath/AssertPSES.ps1"
}
task AssertPSRL {
& "$ToolsPath/AssertPSRL.ps1"
}
task AssertPSResGen {
# Download the ResGen tool used by PowerShell core internally. This will need to be replaced
# when the dotnet cli gains support for it.
# The SHA in the uri's are for the 6.0.2 release commit.
if (-not (Test-Path $ToolsPath/ResGen)) {
New-Item -ItemType Directory $ToolsPath/ResGen | Out-Null
}
if (-not (Test-Path $ToolsPath/ResGen/Program.cs)) {
$programUri = 'https://raw.githubusercontent.com/PowerShell/PowerShell/36b71ba39e36be3b86854b3551ef9f8e2a1de5cc/src/ResGen/Program.cs'
Invoke-WebRequest $programUri -OutFile $ToolsPath/ResGen/Program.cs @FailOnError
}
if (-not (Test-Path $ToolsPath/ResGen/ResGen.csproj)) {
$projUri = 'https://raw.githubusercontent.com/PowerShell/PowerShell/36b71ba39e36be3b86854b3551ef9f8e2a1de5cc/src/ResGen/ResGen.csproj'
Invoke-WebRequest $projUri -OutFile $ToolsPath/ResGen/ResGen.csproj @FailOnError
}
}
task ResGenImpl {
Push-Location $CSharpPath/$ModuleName
try {
& $dotnet run --project $ToolsPath/ResGen/ResGen.csproj
} finally {
Pop-Location
}
}
task BuildManaged {
& $dotnet publish --framework $Framework --configuration $Configuration --verbosity q -nologo
}
task BuildRefactorModule {
$dllToImport = "$CSharpPath/$ModuleName/bin/$Configuration/$Framework/publish/$ModuleName.dll"
$script = {
Add-Type -Path '{0}'
[EditorServicesCommandSuite.Internal.CommandSuite]::WriteRefactorModule('{1}')
}.ToString() -f $dllToImport, "$ReleasePath/$ModuleName.RefactorCmdlets.cdxml"
$encodedScript = [convert]::ToBase64String(
[System.Text.Encoding]::Unicode.GetBytes($script))
if ('Core' -eq $PSEdition) {
InvokeWithPSModulePath {
& $pwsh -NoProfile -EncodedCommand $encodedScript
}
} else {
powershell -NoProfile -ExecutionPolicy Bypass -EncodedCommand $encodedScript
}
}
task CopyToRelease {
"$ModuleName.psm1", "$ModuleName.psd1", "$ModuleName.format.ps1xml" | ForEach-Object {
Join-Path $PowerShellPath -ChildPath $PSItem |
Copy-Item -Destination $ReleasePath -Recurse
}
$srcBase = "$CSharpPath/$ModuleName"
Copy-Item "$srcBase/bin/$Configuration/$Framework/publish/EditorServicesCommandSuite.*" -Destination $ReleasePath
Copy-Item "$srcBase.EditorServices/bin/$Configuration/$Framework/publish/EditorServicesCommandSuite.*" -Destination $ReleasePath
Copy-Item "$srcBase.EditorServices/bin/$Configuration/$Framework/publish/*.dll" -Destination $ReleasePath
$psrlReleaseItems =
'EditorServicesCommandSuite.*',
'System.Buffers.dll',
'System.Memory.dll',
'System.Numerics.Vectors.dll',
'System.Runtime.CompilerServices.Unsafe.dll',
'System.Collections.Immutable.dll'
foreach ($releaseItem in $psrlReleaseItems) {
Copy-Item "$srcBase.PSReadLine/bin/$Configuration/$Framework/publish/$releaseItem" -Destination $ReleasePath
}
}
task Analyze -If { $ShouldAnalyze } {
Invoke-ScriptAnalyzer -Path $ReleasePath -Settings $PSScriptRoot/ScriptAnalyzerSettings.psd1 -Recurse
}
task DoTest {
Push-Location $TestPath
try {
& $dotnet restore -nologo --verbosity quiet
InvokeWithPSModulePath {
& $dotnet test `
--framework netcoreapp3.1 `
--configuration Test `
--logger "trx;LogFileName=$PSScriptRoot/TestResults/results.trx" `
-nologo
}
} finally {
Pop-Location
}
}
task DoInstall {
$installBase = $Home
if ($profile) {
$installBase = $profile | Split-Path
}
$installPath = "$installBase/Modules/$ModuleName/$Version"
if (-not (Test-Path $installPath)) {
$null = New-Item $installPath -ItemType Directory
}
Copy-Item -Path $ReleasePath/* -Destination $installPath -Force -Recurse
}
task DoPublish {
if (-not (Test-Path $env:USERPROFILE/.PSGallery/apikey.xml)) {
throw 'Could not find PSGallery API key!'
}
$apiKey = (Import-Clixml $env:USERPROFILE/.PSGallery/apikey.xml).GetNetworkCredential().Password
Publish-Module -Name $ReleasePath -NuGetApiKey $apiKey -Confirm
}
task ResGen -Jobs AssertDotNet, AssertPSResGen, ResGenImpl
task Build -Jobs Clean, AssertDependencies, ResGen, BuildManaged, BuildRefactorModule, CopyToRelease, BuildDocs
task Test -Jobs Build, DoTest
task PrePublish -Jobs Test
task Install -Jobs Test, DoInstall
task Publish -Jobs Test, DoPublish
task . Build