diff options
author | tpowell-progress <104777878+tpowell-progress@users.noreply.github.com> | 2023-01-19 07:14:33 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-19 10:14:33 -0500 |
commit | 7a807aa02da45fd74967817010a6a974af1b3307 (patch) | |
tree | 5cf9e1e492d68ffa339990b524648090f8f7a16f | |
parent | f6d0ca5889da3a6c7f3126802aa1a9ada7e48987 (diff) | |
download | chef-7a807aa02da45fd74967817010a6a974af1b3307.tar.gz |
Fix Chef 16 Habitat Test pipeline (#13514)
* refactoring the hab powershell script to ensure habitat gets installed. Backport from chef-18
* test script for habitat
* Packaged actions for habitat test into habitat-test.ps1
* pass package value from yml
* Handle error return values in habitat-test.ps1
Signed-off-by: Thomas Powell <powell@progress.com>
Co-authored-by: John <john.mccrae@progress.com>
-rw-r--r-- | .expeditor/habitat-test.pipeline.yml | 6 | ||||
-rw-r--r-- | .expeditor/scripts/ensure-minimum-viable-hab.ps1 | 22 | ||||
-rw-r--r-- | .expeditor/scripts/habitat-test.ps1 | 15 |
3 files changed, 34 insertions, 9 deletions
diff --git a/.expeditor/habitat-test.pipeline.yml b/.expeditor/habitat-test.pipeline.yml index 859d4eb1f1..836f9c91f4 100644 --- a/.expeditor/habitat-test.pipeline.yml +++ b/.expeditor/habitat-test.pipeline.yml @@ -35,15 +35,13 @@ steps: - label: ":windows: Validate Habitat Builds of Chef Infra" commands: - - powershell -File ./.expeditor/scripts/ensure-minimum-viable-hab.ps1 - - 'Write-Host "--- :hammer_and_wrench: Installing $EXPEDITOR_PKG_IDENTS_CHEFINFRACLIENTX86_64WINDOWS"' - - hab pkg install $EXPEDITOR_PKG_IDENTS_CHEFINFRACLIENTX86_64WINDOWS - - powershell -File ./habitat/tests/test.ps1 -PackageIdentifier $EXPEDITOR_PKG_IDENTS_CHEFINFRACLIENTX86_64WINDOWS + - .expeditor/scripts/habitat-test.ps1 $EXPEDITOR_PKG_IDENTS_CHEFINFRACLIENTX86_64WINDOWS expeditor: executor: windows: privileged: true single-use: true + shell: ["powershell", "-Command"] # Wait for the package testing to succeed before promoting whatever was tested. - wait diff --git a/.expeditor/scripts/ensure-minimum-viable-hab.ps1 b/.expeditor/scripts/ensure-minimum-viable-hab.ps1 index 716de60cf8..5d1bf1f54b 100644 --- a/.expeditor/scripts/ensure-minimum-viable-hab.ps1 +++ b/.expeditor/scripts/ensure-minimum-viable-hab.ps1 @@ -1,9 +1,21 @@ -[Version]$hab_version = (hab --version).split(" ")[1].split("/")[0] -if ($hab_version -lt [Version]"0.85.0" ) { +Write-Host "--- :habicat: Verifying that Hab is installed and updating as necessary" +try { + [Version]$hab_version = (hab --version).split(" ")[1].split("/")[0] + if ($hab_version -lt [Version]"0.85.0" ) { + Write-Host "--- :habicat: Installing the version of Habitat required" + Set-ExecutionPolicy Bypass -Scope Process -Force + Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/habitat-sh/habitat/main/components/hab/install.ps1')) + if (-not $?) { throw "Hab version is older than 0.85 and could not update it." } + } + else { + Write-Host "--- :habicat: :thumbsup: Minimum required version of Habitat already installed" + } +} +catch { + # This install fails if Hab isn't on the path when we check for the version. This ensures it is installed Write-Host "--- :habicat: Installing the version of Habitat required" Set-ExecutionPolicy Bypass -Scope Process -Force Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/habitat-sh/habitat/main/components/hab/install.ps1')) - if (-not $?) { throw "Hab version is older than 0.85 and could not update it." } -} else { - Write-Host "--- :habicat: :thumbsup: Minimum required version of Habitat already installed" } +Write-Host "--- :habicat: Refreshing the Path" +$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User") + ";C:\ProgramData\Habitat;" diff --git a/.expeditor/scripts/habitat-test.ps1 b/.expeditor/scripts/habitat-test.ps1 new file mode 100644 index 0000000000..824cbf94b5 --- /dev/null +++ b/.expeditor/scripts/habitat-test.ps1 @@ -0,0 +1,15 @@ +$ErrorActionPreference = 'Stop' + +$ScriptRoute = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($PSScriptRoot, "ensure-minimum-viable-hab.ps1")) +& "$ScriptRoute" +# . ./scripts/ensure-minimum-viable-hab.ps1 +Write-Host "--- Installing $EXPEDITOR_PKG_IDENTS_CHEFINFRACLIENTX86_64WINDOWS" +$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User") +hab pkg install $EXPEDITOR_PKG_IDENTS_CHEFINFRACLIENTX86_64WINDOWS + +if (-not $?) { throw "Unable to install $EXPEDITOR_PKG_IDENTS_CHEFINFRACLIENTX86_64WINDOWS" } + +. ./habitat/tests/test.ps1 -PackageIdentifier $EXPEDITOR_PKG_IDENTS_CHEFINFRACLIENTX86_64WINDOWS + +if (-not $?) { throw "Habitat tests failed" } + |