1+ # !/usr/bin/env powershell
2+
3+ # Requires -Version 5
4+ # https://stackoverflow.com/questions/9948517
5+ # TODO: Set-StrictMode -Version Latest
6+ $PSDefaultParameterValues [' *:ErrorAction' ]= ' Stop'
7+ $ErrorActionPreference = ' Stop'
8+ $env: HAB_BLDR_CHANNEL = " LTS-2024"
9+ $env: HAB_REFRESH_CHANNEL = " LTS-2024"
10+ $env: HAB_ORIGIN = ' ci'
11+ $env: CHEF_LICENSE = ' accept-no-persist'
12+ $env: HAB_LICENSE = ' accept-no-persist'
13+ $Plan = ' chef-cli'
14+
15+ Write-Host " --- system details"
16+ $Properties = ' Caption' , ' CSName' , ' Version' , ' BuildType' , ' OSArchitecture'
17+ Get-CimInstance Win32_OperatingSystem | Select-Object $Properties | Format-Table - AutoSize
18+
19+ Write-Host " --- Installing the version of Habitat required"
20+
21+ function Stop-HabProcess {
22+ $habProcess = Get-Process hab - ErrorAction SilentlyContinue
23+ if ($habProcess ) {
24+ Write-Host " Stopping hab process..."
25+ Stop-Process - Name hab - Force
26+ }
27+ }
28+
29+ # Installing Habitat
30+ function Install-Habitat {
31+ Write-Host " Downloading and installing Habitat..."
32+ Invoke-Expression ((New-Object System.Net.WebClient).DownloadString(' https://raw.githubusercontent.com/habitat-sh/habitat/main/components/hab/install.ps1' ))
33+ }
34+
35+ try {
36+ hab -- version
37+ }
38+ catch {
39+ Set-ExecutionPolicy Bypass - Scope Process - Force
40+
41+ Stop-HabProcess
42+
43+ # Remove the existing hab.exe if it exists and if you have permissions
44+ $habPath = " C:\ProgramData\Habitat\hab.exe"
45+ if (Test-Path $habPath ) {
46+ Write-Host " Attempting to remove existing hab.exe..."
47+ Remove-Item $habPath - Force - ErrorAction SilentlyContinue
48+ if (Test-Path $habPath ) {
49+ Write-Host " Failed to remove hab.exe, re-running script with elevated permissions."
50+ Start-Process powershell - Verb runAs - ArgumentList " -NoProfile -ExecutionPolicy Bypass -File `" $PSCommandPath `" "
51+ exit
52+ }
53+ }
54+
55+ Install-Habitat
56+ }
57+ finally {
58+ Write-Host " :habicat: I think I have the version I need to build."
59+ }
60+
61+
62+ Write-Host " --- Generating fake origin key"
63+ hab origin key generate $env: HAB_ORIGIN
64+
65+ Write-Host " --- Building $Plan "
66+ $project_root = " $ ( git rev- parse -- show-toplevel ) "
67+ Set-Location $project_root
68+
69+ $env: DO_CHECK = $true ; hab pkg build .
70+
71+ . $project_root / results/ last_build.ps1
72+
73+ Write-Host " --- Installing $pkg_ident /$pkg_artifact "
74+ hab pkg install - b $project_root / results/ $pkg_artifact
75+
76+ Write-Host " +++ Testing $Plan "
77+
78+ Push-Location $project_root
79+
80+ try {
81+ Write-Host " Running unit tests..."
82+ habitat/ tests/ test.ps1 $pkg_ident
83+ }
84+ finally {
85+ # Ensure we always return to the original directory
86+ Pop-Location
87+ }
0 commit comments