-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbootstrap.ps1
144 lines (124 loc) · 5.88 KB
/
bootstrap.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
[CmdletBinding()]
param(
[Switch]$Force
)
if ($IsLinux -and $env:DOTNET_RUNNING_IN_CONTAINER) {
Write-Host -ForegroundColor Green 'We are running in a container, make sure we have permissions on all folders in the repo, to be able to build and run the application.'
$testOwnershipAndPermissions = ls -l $PSScriptRoot | Select-String bootstrap -Raw
if ($Force -or ($testOwnershipAndPermissions | Select-String root)) {
Write-Host "Making 'vscode' owner of all files in '$PSScriptRoot/' (recursive)."
sudo chown -R vscode:vscode $PSScriptRoot/
}
}
Write-Host -ForegroundColor Green 'Performing dotnet cleanup and setup..'
$env:DOTNET_NOLOGO = 'true'
dotnet restore
dotnet clean --verbosity minimal
try {
$ErrorActionPreference = 'stop'
Push-Location ./explainpowershell.analysisservice.tests/
dotnet restore
dotnet clean --verbosity minimal
Pop-Location
}
catch {
Write-Warning 'For a correct result, run this script from the root of the project.'
break
}
finally {
$ErrorActionPreference = 'continue'
}
Write-Host -ForegroundColor Green 'Checking PowerShell modules..'
$modules = 'Pester', 'Az.Storage', 'Posh-Git', 'Microsoft.PowerShell.UnixCompleters'
foreach ($module in $modules) {
if (($m = Get-Module -ListAvailable $module)) {
if (!$Force) {
continue
}
else {
Write-Host "Module '$module' version $($m.Version) already installed. Use -Force to update."
}
}
Write-Host -ForegroundColor Green "Install PowerShell module '$module'.."
Install-Module -Name $module -Force
}
Import-Module Posh-Git
if ($IsLinux) {
dotnet dev-certs https
Import-UnixCompleters
}
else {
dotnet dev-certs https --trust
}
Write-Host -ForegroundColor Green "Checking PowerShell '`$profile.CurrentUserAllHosts'.."
$commandsToAddToProfile = @(
'Import-Module Posh-Git',
'if ($isLinux) {'
' Set-PSReadLineOption -EditMode Windows'
' Set-PSReadLineKeyHandler -Chord tab -Function MenuComplete'
' Set-UnixCompleter -ShellType Bash'
' Import-UnixCompleters'
'}'
". $PSScriptRoot/explainpowershell.analysisservice.tests/Invoke-SyntaxAnalyzer.ps1"
". $PSScriptRoot/explainpowershell.analysisservice.tests/Get-HelpDatabaseData.ps1"
". $PSScriptRoot/explainpowershell.analysisservice.tests/Get-MetaData.ps1"
)
if ( !(Test-Path -Path $profile.CurrentUserAllHosts) ) {
New-Item -Path $profile.CurrentUserAllHosts -Force -ItemType file | Out-Null
}
$profileContents = Get-Content -Path $profile.CurrentUserAllHosts
if ($null -eq $profileContents -or
$profileContents.split("`n") -notcontains $commandsToAddToProfile[0]) {
Write-Host -ForegroundColor Green 'Add settings to PowerShell profile'
Add-Content -Path $profile.CurrentUserAllHosts -Value $commandsToAddToProfile
# Copy profile contents to VSCode profile too: Microsoft.VSCode_profile.ps1
Get-Content -Path $profile.CurrentUserAllHosts
| Set-Content -Path ($profile.CurrentUserAllHosts
| Split-Path -Parent
| Join-Path -ChildPath 'Microsoft.VSCode_profile.ps1') -Force
}
if ($Force -or -not [bool](Get-ChildItem -Path / -Filter 'about_Pwsh.help.txt' -Recurse -Depth 3 -ErrorAction SilentlyContinue)) {
Write-Host -ForegroundColor green 'Updating local PowerShell Help files..'
# The `-UICulture en-us` param is important, because at container build, this script is called, but the UICulture is
# `Invariant Culture` which results in no help available. Setting it to `en-us` manually makes sure we have updated help.
Update-Help -Force -ErrorAction SilentlyContinue -ErrorVariable updateErrors -UICulture en-us
if ($updateErrors) {
Write-Warning "$($updateErrors -join `"`n`")"
}
}
$fileName = "$PSScriptRoot/explainpowershell.helpcollector/help.about_articles.cache.user"
if ($Force -or !(Test-Path $fileName)) {
Write-Host -ForegroundColor green "Collecting about_.. article data and saving to cache file '$fileName'.."
./explainpowershell.helpcollector/aboutcollector.ps1
| ConvertTo-Json
| Set-Content -Path $fileName -Force
}
else {
Write-Host "Detected cache file '$fileName', skipping collecting about_.. data. Use '-Force' or remove cache file to refresh about_.. data."
}
Write-Host 'Writing about_.. help article data to local Azurite table..'
./explainpowershell.helpcollector/helpwriter.ps1 -HelpDataCacheFilename $fileName
Import-Module "$PSScriptRoot/explainpowershell.analysisservice.tests/testfiles/myTestModule.psm1"
$modulesToProcess = Get-Content "$PSScriptRoot/explainpowershell.metadata/defaultModules.json"
| ConvertFrom-Json
foreach ($module in $modulesToProcess) {
$fileName = "$PSScriptRoot/explainpowershell.helpcollector/help.$($module.Name).cache.user"
if ($Force -or !(Test-Path $fileName) -or ((Get-Item $fileName).Length -eq 0)) {
Write-Host -ForegroundColor Green "Collecting help data for module '$($module.Name)'.."
./explainpowershell.helpcollector/helpcollector.ps1 -ModulesToProcess $module
| ConvertTo-Json
| Out-File -path $fileName -Force:$Force
}
else {
Write-Host "Detected cache file '$fileName', skipping collecting help data. Use '-Force' or remove cache file to refresh help data."
}
Write-Host "Writing help for module '$($module.Name)' to local Azurite table.."
./explainpowershell.helpcollector/helpwriter.ps1 -HelpDataCacheFilename $fileName
if ($module.name -eq 'myTestModule') {
Remove-Module myTestModule
Import-Module "$PSScriptRoot/explainpowershell.analysisservice.tests/testfiles/myConflictingTestModule.psm1"
}
}
Write-Host -ForegroundColor Green 'Running tests to see if everything works'
& $PSScriptRoot/explainpowershell.analysisservice.tests/Start-AllBackendTests.ps1
Write-Host -ForegroundColor Green "Done. You now have the functions 'Get-HelpDatabaseData', 'Invoke-SyntaxAnalyzer' and 'Get-MetaData' available for ease of testing."