generated from abdes/asap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.ps1
68 lines (60 loc) · 1.65 KB
/
init.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
#!/usr/bin/env pwsh
# Based on: https://github.com/dotnet/Nerdbank.GitVersioning/blob/main/init.ps1
<#
.SYNOPSIS
Installs dependencies required to build and test the projects in this
repository.
.DESCRIPTION
This does not require elevation, as the SDK and runtimes are installed to a
per-user location.
.PARAMETER NoPreCommitHooks
Skips the installation of pre-commit (https://pre-commit.com/) and its
hooks.
#>
[CmdletBinding(SupportsShouldProcess = $true)]
Param (
[Parameter()]
[switch]$NoPreCommitHooks,
[Parameter()]
[switch]$Help
)
if ($Help) {
Get-Help $MyInvocation.MyCommand.Definition
exit
}
# Environment variables and Path that can be propagated via a temp file to a
# caller script.
#
# For example: $EnvVars['KEY'] = "VALUE"
#
$EnvVars = @{}
$PrependPath = @()
$HeaderColor = 'Green'
$ToolsDirectory = "$PSScriptRoot\tools"
# Check if the pre-commit hooks were already installed in the repo.
$lockFile = ".pre-commit.installed.lock";
$preCommitInstalled = Test-Path -Path $lockFile
if (!$NoPreCommitHooks -and !$preCommitInstalled -and $PSCmdlet.ShouldProcess("pip install", "pre-commit")) {
Write-Host "Installing pre-commit and its hooks" -ForegroundColor $HeaderColor
New-Item $lockFile
pip install pre-commit
if ($LASTEXITCODE -ne 0) {
Exit $LASTEXITCODE
}
pre-commit install
if ($LASTEXITCODE -ne 0) {
Exit $LASTEXITCODE
}
Write-Host ""
}
Push-Location $PSScriptRoot
try {
& "$ToolsDirectory/Set-EnvVars.ps1" -Variables $EnvVars -PrependPath $PrependPath | Out-Null
}
catch {
Write-Error $error[0]
exit $lastexitcode
}
finally {
Pop-Location
}