-
Notifications
You must be signed in to change notification settings - Fork 292
/
Copy pathsetup.ps1
137 lines (117 loc) · 3.95 KB
/
setup.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
<#
.DESCRIPTION
This script checks the development environment for required tools and configurations.
#>
# Enable error handling
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
# Check for required JDKs
function TestJvm {
param ($JavaHomeName, $ExpectedJavaVersion)
if (-not (Test-Path "env:$JavaHomeName")) {
Write-Host "❌ $JavaHomeName is not set. Please set $JavaHomeName to refer to a JDK $ExpectedJavaVersion installation." -ForegroundColor Red
exit 1
}
else {
$javaHome = Get-Item "env:$JavaHomeName" | Select-Object -ExpandProperty Value
try {
# try to handle differences between PowerShell 7 and Windows PowerShell 5
$ErrorActionPreference = 'Continue'
$javaVersionOutput = & "$javaHome\bin\java.exe" -version 2>&1
}
catch {
Write-Host "❌ Error running `"$javaHome\bin\java.exe -version`". Please check that $JavaHomeName is set to a JDK $ExpectedJavaVersion installation."
exit 1
}
finally {
$ErrorActionPreference = 'Stop'
}
if ($javaVersionOutput[0] -notmatch "version `"$ExpectedJavaVersion") {
Write-Host "❌ $JavaHomeName is set to $javaHome, but it does not refer to a JDK $ExpectedJavaVersion installation." -ForegroundColor Red
exit 1
}
else {
Write-Host "✅ $JavaHomeName is set to $javaHome."
}
}
}
Write-Host 'ℹ️ Checking required JVM:'
if (Test-Path 'env:JAVA_HOME') {
TestJvm 'JAVA_HOME' '1.8'
}
TestJvm 'JAVA_8_HOME' '1.8'
TestJvm 'JAVA_11_HOME' '11'
TestJvm 'JAVA_17_HOME' '17'
TestJvm 'JAVA_21_HOME' '21'
# GraalVM cannot currently be installed due to license change in October 2024 for GraalVM 17.0.13 and later.
# TestJvm 'JAVA_GRAALVM17_HOME' '17'
# Check for required commands (e.g., git, docker)
function TestCommand {
param ($command)
if (Get-Command $command -ErrorAction SilentlyContinue) {
Write-Host "✅ The $command command line is installed."
}
else {
Write-Host "❌ The $command command line is missing. Please install $command." -ForegroundColor Red
exit 1
}
}
function Get-FileHashMD5 {
param ($file)
return (Get-FileHash -Path $file -Algorithm MD5).Hash
}
function TestHook {
param ($hookName)
$hookChecksum = Get-FileHashMD5 ".githooks/$hookName"
$hooksPath = (git config core.hooksPath) -or '.git/hooks'
if ((Test-Path ".git/hooks/$hookName") -and (Get-FileHashMD5 ".git/hooks/$hookName" -eq $hookChecksum)) {
Write-Host "✅ $hookName hook is installed in repository."
}
elseif ((Test-Path "$hooksPath/$hookName") -and (Get-FileHashMD5 "$hooksPath/$hookName" -eq $hookChecksum)) {
Write-Host "✅ $hookName hook is installed in git hooks path."
}
else {
Write-Host "🟨 $hookName hook was not found (optional but recommended)."
}
}
function TestGitConfig {
param ($configName, $expectedValue)
$actualValue = git config $configName
if ($actualValue -eq $expectedValue) {
Write-Host "✅ git config $configName is set to $expectedValue."
}
elseif (-not $actualValue) {
Write-Host "❌ git config $configName is not set. Please set it to $expectedValue." -ForegroundColor Red
}
else {
Write-Host "🟨 git config $configName is set to $actualValue (expected: $expectedValue)."
}
}
Write-Host 'ℹ️ Checking git configuration:'
TestCommand 'git'
TestHook 'pre-commit'
TestGitConfig 'submodule.recurse' 'true'
# Check Docker environment
function TestDockerServer {
try {
# try to handle differences between PowerShell 7 and Windows PowerShell 5
$ErrorActionPreference = 'Continue'
docker info *> $null
if ($LASTEXITCODE -eq 0) {
Write-Host "✅ The Docker server is running."
}
else {
Write-Host "🟨 The Docker server is not running. Please start it to run all tests."
}
}
catch {
Write-Host "❌ Error running `"docker info *> $null`"."
exit 1
}
finally {
$ErrorActionPreference = 'Stop'
}
}
Write-Host 'ℹ️ Checking Docker environment:'
TestCommand 'docker'
TestDockerServer