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
|
# Setup Script =================================================================
# Helpers ----------------------------------------------------------------------
function Write-Log {
param(
[Parameter(Mandatory = $true)][string] $Message,
[ValidateSet("INF", "WRN", "ERR")][string] $Level = "INF"
)
$colors = @{ INF = "Blue"; WRN = "Yellow"; ERR = "Red" }
Write-Host $Level -ForegroundColor $colors[$Level] -NoNewline
Write-Host " $Message"
}
# Step 1: Check tools availability ---------------------------------------------
$Tools = @("git", "terraform", "terraform-docs", "tflint", "python")
$MissingTools = @()
foreach ($Tool in $Tools) {
if (-not (Get-Command $Tool -ErrorAction SilentlyContinue)) {
$MissingTools += $Tool
}
}
if ($MissingTools.Count -gt 0) {
Write-Log "Missing tool$(if ($MissingTools.Count -gt 1) { 's' }): $($MissingTools -join ', ')" -Level ERR
exit 1
}
# Step 2: Setup git hooks ------------------------------------------------------
git rev-parse --is-inside-work-tree 2>&1 | Out-Null
if ($LASTEXITCODE -ne 0) {
Write-Log "Does not appear to be a git repository." -Level ERR
Write-Log "Skipping git hooks configuration." -Level WRN
}
else {
git config core.hooksPath hooks
Write-Log "Git hooks configured."
}
|