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
15 changes: 4 additions & 11 deletions .expeditor/buildkite/artifact.habitat.test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# TODO: Set-StrictMode -Version Latest
$PSDefaultParameterValues['*:ErrorAction']='Stop'
$ErrorActionPreference = 'Stop'
$env:HAB_BLDR_CHANNEL = 'LTS-2024'
$env:HAB_REFRESH_CHANNEL = "LTS-2024"
$env:HAB_BLDR_CHANNEL = 'base-2025'
$env:HAB_REFRESH_CHANNEL = "base-2025"
$env:CHEF_LICENSE = 'accept-no-persist'
$env:HAB_LICENSE = 'accept-no-persist'
$Plan = 'knife'
Expand Down Expand Up @@ -80,15 +80,8 @@ Write-Host "+++ Testing $Plan"
Push-Location $project_root

try {
Write-Host "Running unit tests..."
hab pkg exec "${pkg_ident}" rake unit

If ($lastexitcode -ne 0) {
Write-Host "Rake unit tests failed!" -ForegroundColor Red
Exit $lastexitcode
} else {
Write-Host "Rake unit tests passed!" -ForegroundColor Green
}
$scriptPath = Join-Path $project_root "habitat/tests/test.ps1"
& $scriptPath $pkg_ident
}
finally {
# Ensure we always return to the original directory
Expand Down
32 changes: 16 additions & 16 deletions .expeditor/habitat-test.pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ steps:
environment:
- HAB_AUTH_TOKEN

# - label: ":windows: Validate Habitat Builds of Knife"
# commands:
# - .expeditor/buildkite/artifact.habitat.test.ps1
# expeditor:
# executor:
# docker:
# host_os: windows
# shell: ["powershell", "-Command"]
# image: rubydistros/windows-2019:3.1
# user: 'NT AUTHORITY\SYSTEM'
# environment:
# - HAB_AUTH_TOKEN
# - FORCE_FFI_YAJL=ext
# - EXPIRE_CACHE=true
# - CHEF_LICENSE=accept-no-persist
# - CHEF_LICENSE_SERVER=http://hosted-license-service-lb-8000-606952349.us-west-2.elb.amazonaws.com:8000/
- label: ":windows: Validate Habitat Builds of Knife"
commands:
- .expeditor/buildkite/artifact.habitat.test.ps1
expeditor:
executor:
docker:
host_os: windows
shell: ["powershell", "-Command"]
image: rubydistros/windows-2019:3.4
user: 'NT AUTHORITY\SYSTEM'
environment:
- HAB_AUTH_TOKEN
- FORCE_FFI_YAJL=ext
- EXPIRE_CACHE=true
- CHEF_LICENSE=accept-no-persist
- CHEF_LICENSE_SERVER=http://hosted-license-service-lb-8000-606952349.us-west-2.elb.amazonaws.com:8000/
14 changes: 11 additions & 3 deletions .expeditor/run_linux_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,22 @@ export LANG=C.UTF-8 LANGUAGE=C.UTF-8
export ARTIFACTORY_ENDPOINT="https://artifactory-internal.ps.chef.co/artifactory"
export ARTIFACTORY_USERNAME="REDACTED@chef.io"

ruby_version=$(ruby -e 'puts RUBY_VERSION')
echo "--- Detected Ruby version: $ruby_version"

# Fix bundler double load on Ruby 3.1 by installing compatible RubyGems + Bundler
if [[ "$ruby_version" == 3.1* ]]; then
echo "--- Installing RubyGems 3.6.9 for Ruby 3.1"
gem install rubygems-update -v 3.6.9
update_rubygems
fi

echo "--- Adding Artifactory gem source"
gem source -a "${ARTIFACTORY_ENDPOINT}/api/gems/omnibus-gems-local" || true

echo "--- Installing dependencies"
bundle config set --local path vendor/bundle
bundle config --local path vendor/bundle
bundle install --jobs=7 --retry=3

gem update --system

echo "+++ Running bundle exec task"
bundle exec $@
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ gem "knife", path: "."

# TODO: Once these gems are published to rubygems.org, we don't need to specify them in these conditions.
if RUBY_PLATFORM.match?(/mswin|mingw|windows/)
gem "appbundler"

# --- Windows: chef from vendor/cache, others from Artifactory ---

# Force Bundler to resolve chef from vendor/cache by declaring it without a source block
Expand Down
115 changes: 115 additions & 0 deletions habitat/plan.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
$ErrorActionPreference = "Stop"
$PSDefaultParameterValues['*:ErrorAction']='Stop'

$env:HAB_BLDR_CHANNEL = "base-2025"
$env:HAB_REFRESH_CHANNEL = "base-2025"
$pkg_name = "knife"
$pkg_origin = "chef"
$pkg_version = Get-Content "$PLAN_CONTEXT/../VERSION"
$pkg_maintainer = "The Chef Maintainers <humans@chef.io>"

$pkg_deps = @(
"core/ruby3_4-plus-devkit"
"core/git"
)
$pkg_bin_dirs = @("bin", "vendor/bin")
$project_root = (Resolve-Path "$PLAN_CONTEXT/../").Path

function pkg_version {
Get-Content "$SRC_PATH/VERSION"
}

function Invoke-Before {
Set-PkgVersion
}

function Invoke-SetupEnvironment {
Push-RuntimeEnv -IsPath GEM_PATH "$pkg_prefix/vendor"

Set-RuntimeEnv APPBUNDLER_ALLOW_RVM "true"
Set-RuntimeEnv FORCE_FFI_YAJL "ext"
Set-RuntimeEnv LANG "en_US.UTF-8"
Set-RuntimeEnv LC_CTYPE "en_US.UTF-8"
}

# Todo: Remove this function once the Chef gem is published with the correct name in Artifactory or rubygems.org.
function Handle-ArtifactoryChefGem {
Write-Host "--- Handling temporary Chef gem workaround from Artifactory"

$gem_source = "https://artifactory-internal.ps.chef.co/artifactory/api/gems/omnibus-gems-local"
$downloaded_path = "$env:TEMP\chef-19.1.36-universal-unknown.gem"
$corrected_path = "$env:TEMP\chef-19.1.36-universal-mingw-ucrt.gem"
$cache_path = "$project_root/vendor/cache"

Write-Host "--- Downloading Chef gem from Artifactory"
Invoke-WebRequest -Uri "$gem_source/gems/chef-19.1.36-universal-unknown.gem" -OutFile $downloaded_path -UseBasicParsing

Write-Host "--- Renaming gem file to correct platform"
Rename-Item -Path $downloaded_path -NewName (Split-Path $corrected_path -Leaf)

Write-Host "--- Moving gem to vendor/cache"
if (!(Test-Path $cache_path)) {
New-Item -ItemType Directory -Path $cache_path | Out-Null
}
Move-Item -Path $corrected_path -Destination "$cache_path/chef-19.1.36-universal-mingw-ucrt.gem" -Force
}

function Invoke-Build {
try {
$env:Path += ";C:\Program Files\Git\bin"
Push-Location $project_root
$env:GEM_HOME = "$HAB_CACHE_SRC_PATH/$pkg_dirname/vendor"

# Add only the chef gem manually
# Todo: Remove this function once the Chef gem is published with the correct name in Artifactory or rubygems.org.
Handle-ArtifactoryChefGem

Write-BuildLine " ** Configuring bundler for this build environment"
bundle config --local without integration deploy maintenance
bundle config --local jobs 4
bundle config --local retry 5
bundle config --local silence_root_warning 1

# Lock in Windows platform and avoid remote fetching
bundle lock --add-platform x64-mingw-ucrt
Write-BuildLine " ** Using bundler to retrieve the Ruby dependencies"
bundle install

gem build knife.gemspec
Write-BuildLine " ** Installing built gem"
gem install knife*.gem --no-document

If ($lastexitcode -ne 0) { Exit $lastexitcode }
} finally {
Pop-Location
}
}

function Invoke-Install {
Write-BuildLine "** Copy built & cached gems to install directory"
Copy-Item -Path "$HAB_CACHE_SRC_PATH/$pkg_dirname/*" -Destination $pkg_prefix -Recurse -Force -Exclude @(
"gem_make.out", "mkmf.log", "Makefile", "*/latest", "latest", "*/JSON-Schema-Test-Suite", "JSON-Schema-Test-Suite"
)

try {
Push-Location $pkg_prefix
bundle config --local gemfile $project_root/Gemfile
Write-BuildLine "** generating binstubs for knife"
Invoke-Expression -Command "appbundler.bat $project_root $pkg_prefix/bin knife"
If ($lastexitcode -ne 0) { Exit $lastexitcode }
} finally {
Pop-Location
}
}

function Invoke-After {
Remove-Item $pkg_prefix/vendor/cache -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item $pkg_prefix/vendor/doc -Recurse -Force -ErrorAction SilentlyContinue

Get-ChildItem $pkg_prefix/vendor/gems -Filter "spec" -Directory -Recurse -Depth 1 |
Where-Object { $_.FullName -notlike "*knife*" } |
Remove-Item -Recurse -Force

Get-ChildItem $pkg_prefix/vendor/gems -Include @("gem_make.out", "mkmf.log", "Makefile") -File -Recurse |
Remove-Item -Force
}
4 changes: 2 additions & 2 deletions habitat/plan.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Package metadata
export HAB_BLDR_CHANNEL="base-2025"
export HAB_REFRESH_CHANNEL="base-2025"
pkg_name=knife
ruby_pkg="core/ruby3_4"
pkg_origin=core
pkg_name="knife"
pkg_origin="chef"
pkg_description="knife is a command-line tool that provides an interface between a local chef-repo and the Chef Infra Server."
pkg_upstream_url=https://www.chef.io/
pkg_maintainer="The Habitat Maintainers <humans@habitat.sh>"
Expand Down
28 changes: 28 additions & 0 deletions habitat/tests/test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
$ErrorActionPreference = "Stop"

$project_root = (& git rev-parse --show-toplevel).Trim()
$pkg_ident = $args[0]

function Error {
param ([string]$message)
Write-Error "`nERROR: $message`n"
exit 1
}

if (-not $pkg_ident) {
Error "no hab package identity provided"
}

$package_version = ($pkg_ident -split '/')[2]

Set-Location $project_root
Write-Output "Testing $pkg_ident executables"
$version = (& hab pkg exec $pkg_ident knife -v).Trim()
Write-Output $version

$actual_version = ($version -replace '.*version: ([0-9]+\.[0-9]+\.[0-9]+).*', '$1')
Write-Output $actual_version

if ($actual_version -notlike "*$package_version*") {
Error "knife version is not the expected version. Expected '$package_version', got '$actual_version'"
}