diff options
author | Christopher A. Snapp <csnapp@chef.io> | 2020-09-24 09:48:58 -0600 |
---|---|---|
committer | Christopher A. Snapp <csnapp@chef.io> | 2020-11-17 10:38:18 -0700 |
commit | 966e477784a47483bf156213ba140a225a2a7834 (patch) | |
tree | 07f31da3f7d94e47d55eaaa8154136dfe8515c8e | |
parent | 7bc1bf55c1f2807c05898fb5b371119ff90b5f04 (diff) | |
download | chef-csnapp/fix_habk2.tar.gz |
Update windows habitat plancsnapp/fix_habk2
Signed-off-by: Christopher A. Snapp <csnapp@chef.io>
-rw-r--r-- | habitat/plan.ps1 | 22 | ||||
-rw-r--r-- | habitat/tests/spec.ps1 | 9 | ||||
-rw-r--r-- | habitat/tests/test.pester.ps1 | 17 |
3 files changed, 40 insertions, 8 deletions
diff --git a/habitat/plan.ps1 b/habitat/plan.ps1 index 719f5e7a5a..5462ff56ff 100644 --- a/habitat/plan.ps1 +++ b/habitat/plan.ps1 @@ -13,6 +13,7 @@ $pkg_bin_dirs=@( $pkg_deps=@( "core/cacerts" "chef/ruby-plus-devkit" + "chef/chef-powershell-shim" ) function Invoke-Begin { @@ -44,6 +45,7 @@ function Invoke-Download() { try { Push-Location (Resolve-Path "$PLAN_CONTEXT/../").Path git archive --format=zip --output="${HAB_CACHE_SRC_PATH}/${pkg_filename}" HEAD + if (-not $?) { throw "unable to create archive of source" } } finally { Pop-Location } @@ -62,6 +64,7 @@ function Invoke-Prepare { Write-BuildLine " ** Configuring bundler for this build environment" bundle config --local without server docgen maintenance pry travis integration ci chefstyle + if (-not $?) { throw "unable to configure bundler to restrict gems to be installed" } bundle config --local jobs 4 bundle config --local retry 5 bundle config --local silence_root_warning 1 @@ -74,20 +77,29 @@ function Invoke-Build { try { Push-Location "${HAB_CACHE_SRC_PATH}/${pkg_dirname}" + $env:_BUNDER_WINDOWS_DLLS_COPIED = "1" + Write-BuildLine " ** Using bundler to retrieve the Ruby dependencies" - bundle install - Write-BuildLine " ** Running the chef project's 'rake install' to install the path-based gems so they look like any other installed gem." - bundle exec rake install # this needs to be 'bundle exec'd because a Rakefile makes reference to Bundler - Write-BuildLine " ** Also 'rake install' any gem sourced as a git reference." + bundle install --jobs=3 --retry=3 + if (-not $?) { throw "unable to install gem dependencies" } + Write-BuildLine " ** 'rake install' any gem sourced as a git reference so they'll look like regular gems." foreach($git_gem in (Get-ChildItem "$env:GEM_HOME/bundler/gems")) { try { Push-Location $git_gem - Write-BuildLine " -- and $git_gem too" + Write-BuildLine " -- installing $git_gem" rake install # this needs to NOT be 'bundle exec'd else bundler complains about dev deps not being installed + if (-not $?) { throw "unable to install $git_gem as a plain old gem" } } finally { Pop-Location } } + Write-BuildLine " ** Running the chef project's 'rake install' to install the path-based gems so they look like any other installed gem." + bundle exec rake install # this needs to be 'bundle exec'd because a Rakefile makes reference to Bundler + if (-not $?) { + Write-Warning " -- That didn't work. Let's try again." + bundle exec rake install # this needs to be 'bundle exec'd because a Rakefile makes reference to Bundler + if (-not $?) { throw "unable to install the gems that live in directories within this repo" } + } } finally { Pop-Location } diff --git a/habitat/tests/spec.ps1 b/habitat/tests/spec.ps1 index ab1656b221..6cbdd406c2 100644 --- a/habitat/tests/spec.ps1 +++ b/habitat/tests/spec.ps1 @@ -10,8 +10,15 @@ $chef_gem_root = (hab pkg exec $PackageIdentifier gem.cmd which chef | Split-Pat try { Push-Location $chef_gem_root $env:PATH = "C:\hab\bin;$env:PATH" + + # Put chef's GEM_PATH in the machine environment so that the windows service + # tests will be able to consume the win32-service gem + $pkgEnv = hab pkg env $PackageIdentifier + $gemPath = $pkgEnv | Where-Object { $_.StartsWith("`$env:GEM_PATH=") } + SETX GEM_PATH $($gemPath.Split("=")[1]) /m + hab pkg binlink --force $PackageIdentifier - /hab/bin/rspec --format progress --tag ~executables --tag ~choco_installed spec/functional + /hab/bin/rspec --format documentation --tag ~executables --tag ~choco_installed spec/functional if (-not $?) { throw "functional testing failed"} } finally { Pop-Location diff --git a/habitat/tests/test.pester.ps1 b/habitat/tests/test.pester.ps1 index a5f665c9de..56f31e9a2f 100644 --- a/habitat/tests/test.pester.ps1 +++ b/habitat/tests/test.pester.ps1 @@ -12,8 +12,21 @@ Describe "chef-infra-client" { $? | Should be $true } + <# + At some point hab's argument parsing changed and it started interpreting the trailing `--version` as being + an argument passed to hab instead of an argument to the command passed to `hab pkg exec`. + + Powershell 5.1 and 7 appear to differ in how they treat following arguments as well, such that these two + versions of the command fail in powershell 5.1 (which is currently what is running in the windows machines + in Buildkite) but pass in powershell 7 (which is currently what is running in a stock Windows 10 VM). + + $the_version = (hab pkg exec $PackageIdentifier chef-client.bat '--version' | Out-String).split(':')[1].Trim() + $the_version = (hab pkg exec $PackageIdentifier chef-client.bat --version | Out-String).split(':')[1].Trim() + + This version of the command passes in powershell 5.1 but fails in powershell 7. + #> It "is the expected version" { - $the_version = (hab pkg exec $PackageIdentifier chef-client.bat --version | Out-String).split(':')[1].Trim() + $the_version = (hab pkg exec $PackageIdentifier chef-client.bat -- --version | Out-String).split(':')[1].Trim() $the_version | Should be $PackageVersion } } @@ -52,4 +65,4 @@ Describe "chef-infra-client" { $? | Should be $true } } -}
\ No newline at end of file +} |