Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .expeditor/build_gems.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ Write-Output "`r"


Write-Output "--- :muscle: cleanup, cleanup, everybody, everywhere: Deleting existing DLL's in the chef-powershell Directory and copying the newly compiled ones down"
$x64_bin_path = $("$project_root\chef-powershell\bin\ruby_bin_folder\AMD64")
$arch = if ($env:PROCESSOR_ARCHITECTURE) { $env:PROCESSOR_ARCHITECTURE } else { "AMD64" }
$x64_bin_path = $("$project_root\chef-powershell\bin\ruby_bin_folder\$arch")

if (Test-Path -PathType Container $x64_bin_path) {
Write-Output "My 64-bit path WAS found here : $x64_bin_path"
Expand Down
3 changes: 2 additions & 1 deletion .expeditor/manual_gem_release.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ if (-not $?) { throw "unable to install this build" }
Write-Output "`r"

Write-Output "--- :cleanup, cleanup, everybody, everywhere: Deleting existing DLL's in the chef-powershell Directory and copying the newly compiled ones down"
$x64_bin_path = $("$project_root/chef-powershell/bin/ruby_bin_folder/AMD64")
$arch = if ($env:PROCESSOR_ARCHITECTURE) { $env:PROCESSOR_ARCHITECTURE } else { "AMD64" }
$x64_bin_path = $("$project_root/chef-powershell/bin/ruby_bin_folder/$arch")

if (Test-Path -PathType Container $x64_bin_path) {
Get-ChildItem -Path $x64_bin_path -Recurse | Foreach-object { Remove-item -Recurse -path $_.FullName -Force }
Expand Down
30 changes: 23 additions & 7 deletions .expeditor/update_version.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,29 @@

$ErrorActionPreference = "Stop"

# get the contents of the gem version file
# Get the project root directory using git
$project_root = git rev-parse --show-toplevel
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to determine git repository root. Are you in a git repository?"
exit 1
}

# Convert Unix-style path to Windows path if necessary
$project_root = $project_root -replace '/', '\'

# Get the contents of the gem version file
$version_file = Join-Path $project_root "chef-powershell\lib\chef-powershell\version.rb"
if (-not (Test-Path $version_file)) {
Write-Error "Version file not found at: $version_file"
exit 1
}

try {
$project_root = Get-ChildItem -Path C:\ -Recurse | Where-Object { $_.PSIsContainer -eq $True -and $_.Name -like "*chef-powershell-shim*" } | % { $_.fullname } | select-object -First 1
$file = (Get-Content $("$project_root\chef-powershell\lib\chef-powershell\version.rb"))
$file = Get-Content $version_file
}
catch {
Write-Error "Failed to Get the Version from version.rb"
Write-Error "Failed to read the Version from version.rb: $_"
exit 1
}

# Use RegEx to get the Version Number and set it as a version datatype
Expand Down Expand Up @@ -48,10 +64,10 @@ else {

# Replace Old Version Number with New Version number in the file
try {
(Get-Content .\chef-powershell\lib\chef-powershell\version.rb) -replace $version, $NewVersion | Out-File .\chef-powershell\lib\chef-powershell\version.rb
(Get-Content $version_file) -replace $version, $NewVersion | Set-Content $version_file -Encoding UTF8
Write-Output "Updated Module Version from $Version to $NewVersion"
}
catch {
$_
Write-Error "failed to set file"
Write-Error "Failed to update version file: $_"
exit 1
}
3 changes: 2 additions & 1 deletion .github/workflows/gem-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ jobs:
. results/last_build.ps1
hab pkg install results/$pkg_artifact
$x64 = hab pkg path chef/chef-powershell-shim
$x64_bin_path = $("$project_root/chef-powershell/bin/ruby_bin_folder/AMD64")
$arch = if ($env:PROCESSOR_ARCHITECTURE) { $env:PROCESSOR_ARCHITECTURE } else { "AMD64" }
$x64_bin_path = $("$project_root/chef-powershell/bin/ruby_bin_folder/$arch")
if (Test-Path -PathType Container $x64_bin_path) {
Get-ChildItem -Path $x64_bin_path -Recurse | Foreach-object { Remove-item -Recurse -path $_.FullName -Force }
Copy-Item "$x64\bin\*" -Destination $x64_bin_path -Force -Recurse
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/manual-gem-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ jobs:
. results/last_build.ps1
hab pkg install results/$pkg_artifact
$x64 = hab pkg path chef/chef-powershell-shim
$x64_bin_path = $("$project_root/chef-powershell/bin/ruby_bin_folder/AMD64")
$arch = if ($env:PROCESSOR_ARCHITECTURE) { $env:PROCESSOR_ARCHITECTURE } else { "AMD64" }
$x64_bin_path = $("$project_root/chef-powershell/bin/ruby_bin_folder/$arch")
if (Test-Path -PathType Container $x64_bin_path) {
Get-ChildItem -Path $x64_bin_path -Recurse | Foreach-object { Remove-item -Recurse -path $_.FullName -Force }
Copy-Item "$x64\bin\*" -Destination $x64_bin_path -Force -Recurse
Expand Down
3 changes: 2 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ task :update_chef_powershell_dlls do

x64 = `hab pkg path chef/chef-powershell-shim`.chomp.tr("\\", "/")

target = File.join(__dir__, "chef-powershell", "bin", "ruby_bin_folder", "AMD64")
arch = ENV["PROCESSOR_ARCHITECTURE"] || "AMD64"
target = File.join(__dir__, "chef-powershell", "bin", "ruby_bin_folder", arch)
FileUtils.mkdir_p(target)

puts "Cleaning #{target}"
Expand Down
2 changes: 1 addition & 1 deletion chef-powershell/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ GEM
rspec-expectations (3.13.5)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.6)
rspec-mocks (3.13.7)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.6)
Expand Down
5 changes: 5 additions & 0 deletions chef-powershell/chef_dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ armv
Artifactory
Ashwini
askpass
assumeyes
auditd
auditpol
authz
Expand Down Expand Up @@ -249,6 +250,7 @@ haproxy
Harringon
Hashi
hashi
hawkey
hdiutil
Heartbleed
Heinemeier
Expand Down Expand Up @@ -294,6 +296,7 @@ Inno
inode
inodes
Inspec
installroot
Intune
ipsec
ipsecconf
Expand Down Expand Up @@ -661,6 +664,7 @@ tzdata
tzutil
UEFI
uids
ujson
ulimit
umask
umount
Expand Down Expand Up @@ -695,6 +699,7 @@ VCPU
Veertu
vendored
vendoring
versionstr
vgroot
virtconn
virtio
Expand Down
8 changes: 5 additions & 3 deletions chef-powershell/ext/chef-powershell/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ def find_chef_embedded_bin

def find_source_dlls
# Look for DLLs in the gem's bin directory structure
# They should be in bin/ruby_bin_folder/AMD64/
# They should be in bin/ruby_bin_folder/<ARCH>/
gem_bin_dir = File.expand_path("../../bin", __dir__)
arch = ENV["PROCESSOR_ARCHITECTURE"] || "AMD64"

possible_locations = [
File.join(gem_bin_dir, "ruby_bin_folder", "AMD64"),
File.join(gem_bin_dir, "ruby_bin_folder", arch),
gem_bin_dir,
]

Expand Down Expand Up @@ -108,8 +109,9 @@ def install_dlls
source_dir = find_source_dlls

unless source_dir
arch = ENV["PROCESSOR_ARCHITECTURE"] || "AMD64"
log "WARNING: Could not locate source DLL files in gem installation."
log "Expected location: bin/ruby_bin_folder/AMD64/"
log "Expected location: bin/ruby_bin_folder/#{arch}/"
log "DLL files will not be installed."
return
end
Expand Down
28 changes: 16 additions & 12 deletions chef-powershell/lib/chef-powershell/powershell_exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,23 @@ module PowerShellExec
# We don't want to move files around so we're setting the variable here to keep everything tidy.
# file_path = Gem.loaded_specs["chef-powershell"].full_gem_path + "/bin/ruby_bin_folder/#{ENV["PROCESSOR_ARCHITECTURE"]}/"
# ENV["CHEF_POWERSHELL_BIN"] = file_path
file_path = File.join(Gem.loaded_specs["chef-powershell"].full_gem_path, "bin", "ruby_bin_folder", ENV["PROCESSOR_ARCHITECTURE"] || "AMD64")
if File.directory?(file_path)
ENV["CHEF_POWERSHELL_BIN"] = file_path
else
# Habitat fallback: try locating the built package and use its bin directory
begin
hab_path = `hab pkg path chef/chef-powershell-shim 2>NUL`.strip
if hab_path != "" && File.directory?(hab_path)
candidate = File.join(hab_path, "bin")
ENV["CHEF_POWERSHELL_BIN"] = candidate if File.directory?(candidate)
gem_spec = Gem.loaded_specs["chef-powershell"]
if gem_spec
arch = ENV["PROCESSOR_ARCHITECTURE"] || "AMD64"
file_path = File.join(gem_spec.full_gem_path, "bin", "ruby_bin_folder", arch)
if File.directory?(file_path)
ENV["CHEF_POWERSHELL_BIN"] = file_path
else
# Habitat fallback: try locating the built package and use its bin directory
begin
hab_path = `hab pkg path chef/chef-powershell-shim 2>NUL`.strip
if hab_path != "" && File.directory?(hab_path)
candidate = File.join(hab_path, "bin")
ENV["CHEF_POWERSHELL_BIN"] = candidate if File.directory?(candidate)
end
rescue
# ignore habitat lookup failures
end
rescue
# ignore habitat lookup failures
end
end
# Run a command under PowerShell via a managed (.NET) API.
Expand Down
21 changes: 14 additions & 7 deletions chef-powershell/lib/chef-powershell/pwsh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,20 @@ class ChefPowerShell
class Pwsh < ChefPowerShell::PowerShell

def self.resolve_core_wrapper_dll
base = Gem.loaded_specs["chef-powershell"].full_gem_path
gem_spec = Gem.loaded_specs["chef-powershell"]
arch = ENV["PROCESSOR_ARCHITECTURE"] || "AMD64"
dll_path = File.join(base, "bin", "ruby_bin_folder", arch, "shared", "Microsoft.NETCore.App", "8.0.0", "Chef.PowerShell.Wrapper.Core.dll")
return dll_path if File.exist?(dll_path)

if gem_spec
base = gem_spec.full_gem_path
dll_path = File.join(base, "bin", "ruby_bin_folder", arch, "shared", "Microsoft.NETCore.App", "8.0.0", "Chef.PowerShell.Wrapper.Core.dll")
return dll_path if File.exist?(dll_path)
end

override = ENV["CHEF_POWERSHELL_BIN"]
candidate = override && File.join(override, "shared", "Microsoft.NETCore.App", "8.0.0", "Chef.PowerShell.Wrapper.Core.dll")
return candidate if candidate && File.exist?(candidate)

dll_path = gem_spec ? File.join(gem_spec.full_gem_path, "bin", "ruby_bin_folder", arch, "shared", "Microsoft.NETCore.App", "8.0.0", "Chef.PowerShell.Wrapper.Core.dll") : File.join("bin", "ruby_bin_folder", arch, "shared", "Microsoft.NETCore.App", "8.0.0", "Chef.PowerShell.Wrapper.Core.dll")
raise LoadError, "Pwsh Core wrapper DLL not found at #{dll_path}. Populate binaries via rake update_chef_powershell_dlls"
end

Expand Down Expand Up @@ -59,8 +64,12 @@ def exec(script, timeout: -1)
original_dotnet_root_x86 = ENV["DOTNET_ROOT(x86)"]

ENV["DOTNET_MULTILEVEL_LOOKUP"] = "0"
arch_root = File.join(Gem.loaded_specs["chef-powershell"].full_gem_path, "bin", "ruby_bin_folder", "AMD64")
ENV["DOTNET_ROOT"] = arch_root
gem_spec = Gem.loaded_specs["chef-powershell"]
if gem_spec
arch = ENV["PROCESSOR_ARCHITECTURE"] || "AMD64"
arch_root = File.join(gem_spec.full_gem_path, "bin", "ruby_bin_folder", arch)
ENV["DOTNET_ROOT"] = arch_root
end

@powershell_dll = self.class.resolve_core_wrapper_dll
super
Expand All @@ -78,8 +87,6 @@ def self.dll
# ensures that the correct architecture binaries are installed into the path.
# Also note that the version of pwsh is determined by which assemblies the dll was
# built with. To update powershell, those dependencies must be bumped.
@powershell_dll = Gem.loaded_specs["chef-powershell"].full_gem_path + "/bin/ruby_bin_folder/#{ENV["PROCESSOR_ARCHITECTURE"]}/shared/Microsoft.NETCore.App/8.0.0/Chef.PowerShell.Wrapper.Core.dll"
# @dll ||= @powershell_dll
@dll ||= resolve_core_wrapper_dll
end
end
Expand Down
2 changes: 1 addition & 1 deletion chef-powershell/lib/chef-powershell/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@

module ChefPowerShellModule
CHEFPOWERSHELL_ROOT = File.expand_path("..", __dir__)
VERSION = "18.6.5"
VERSION = "18.6.6"
end
8 changes: 6 additions & 2 deletions chef-powershell/spec/unit/powershell_exec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@
subject(:object) { powershell_mixin.new }

before do
file_path = Gem.loaded_specs["chef-powershell"].full_gem_path + "/bin/ruby_bin_folder/#{ENV["PROCESSOR_ARCHITECTURE"]}/"
ENV["CHEF_POWERSHELL_BIN"] = file_path
gem_spec = Gem.loaded_specs["chef-powershell"]
if gem_spec
arch = ENV["PROCESSOR_ARCHITECTURE"] || "AMD64"
file_path = File.join(gem_spec.full_gem_path, "bin", "ruby_bin_folder", arch)
ENV["CHEF_POWERSHELL_BIN"] = file_path
end
end

describe "#powershell_exec" do
Expand Down
Loading