2020-02-11 23:24:27 +00:00
|
|
|
# https://stackoverflow.com/questions/9948517
|
2020-02-13 20:42:41 +00:00
|
|
|
# TODO: Set-StrictMode -Version Latest
|
2020-02-11 23:24:27 +00:00
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$PSDefaultParameterValues['*:ErrorAction']='Stop'
|
|
|
|
|
2019-07-11 04:53:55 +00:00
|
|
|
$pkg_name="inspec"
|
2019-10-17 03:25:54 +00:00
|
|
|
$pkg_origin="chef"
|
|
|
|
$pkg_version=$(Get-Content "$PLAN_CONTEXT/../VERSION")
|
2019-09-17 00:46:35 +00:00
|
|
|
$pkg_revision="1"
|
2019-07-11 04:53:55 +00:00
|
|
|
$pkg_description="InSpec is an open-source testing framework for infrastructure
|
|
|
|
with a human- and machine-readable language for specifying compliance,
|
|
|
|
security and policy requirements."
|
|
|
|
$pkg_upstream_url="https://www.inspec.io/"
|
2019-10-17 03:25:54 +00:00
|
|
|
$pkg_maintainer="The Chef Maintainers <humans@chef.io>"
|
2019-07-11 04:53:55 +00:00
|
|
|
$pkg_license=('Apache-2.0')
|
2019-09-17 00:46:35 +00:00
|
|
|
|
2019-07-11 04:53:55 +00:00
|
|
|
$pkg_deps=@(
|
2023-01-03 14:57:01 +00:00
|
|
|
"chef/ruby31-plus-devkit"
|
|
|
|
"core/git"
|
2019-07-11 04:53:55 +00:00
|
|
|
)
|
2019-09-17 23:52:31 +00:00
|
|
|
$pkg_bin_dirs=@("bin"
|
|
|
|
"vendor/bin")
|
2019-09-17 00:46:35 +00:00
|
|
|
$project_root= (Resolve-Path "$PLAN_CONTEXT/../").Path
|
|
|
|
|
|
|
|
function Invoke-SetupEnvironment {
|
|
|
|
Push-RuntimeEnv -IsPath GEM_PATH "$pkg_prefix/vendor"
|
2019-07-11 04:53:55 +00:00
|
|
|
|
2019-09-17 00:46:35 +00:00
|
|
|
Set-RuntimeEnv APPBUNDLER_ALLOW_RVM "true" # prevent appbundler from clearing out the carefully constructed runtime GEM_PATH
|
2019-11-01 18:10:49 +00:00
|
|
|
Set-RuntimeEnv FORCE_FFI_YAJL "ext"
|
2019-09-17 00:46:35 +00:00
|
|
|
Set-RuntimeEnv LANG "en_US.UTF-8"
|
|
|
|
Set-RuntimeEnv LC_CTYPE "en_US.UTF-8"
|
2019-07-11 04:53:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function Invoke-Build {
|
2019-09-17 00:46:35 +00:00
|
|
|
try {
|
2023-01-03 14:57:01 +00:00
|
|
|
$env:Path += ";c:\\Program Files\\Git\\bin"
|
2019-09-17 00:46:35 +00:00
|
|
|
Push-Location $project_root
|
|
|
|
$env:GEM_HOME = "$HAB_CACHE_SRC_PATH/$pkg_dirname/vendor"
|
|
|
|
|
|
|
|
Write-BuildLine " ** Configuring bundler for this build environment"
|
|
|
|
bundle config --local without integration deploy maintenance
|
|
|
|
bundle config --local jobs 4
|
2019-11-01 18:10:49 +00:00
|
|
|
bundle config --local retry 5
|
|
|
|
bundle config --local silence_root_warning 1
|
2019-09-17 00:46:35 +00:00
|
|
|
|
|
|
|
Write-BuildLine " ** Using bundler to retrieve the Ruby dependencies"
|
|
|
|
bundle install
|
2020-02-10 21:27:05 +00:00
|
|
|
If ($lastexitcode -ne 0) { Exit $lastexitcode }
|
2019-09-17 00:46:35 +00:00
|
|
|
Write-BuildLine " ** Running the inspec 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
|
2020-02-10 21:27:05 +00:00
|
|
|
If ($lastexitcode -ne 0) { Exit $lastexitcode }
|
2019-09-17 00:46:35 +00:00
|
|
|
} finally {
|
|
|
|
Pop-Location
|
|
|
|
}
|
2019-07-11 04:53:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function Invoke-Install {
|
2019-09-17 00:46:35 +00:00
|
|
|
Write-BuildLine "** Copy built & cached gems to install directory"
|
2020-02-13 20:44:12 +00:00
|
|
|
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")
|
2019-09-17 00:46:35 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
Push-Location $pkg_prefix
|
|
|
|
bundle config --local gemfile $project_root/Gemfile
|
2020-02-10 21:27:05 +00:00
|
|
|
foreach($gem in ("inspec-core", "inspec", "inspec-bin")) {
|
2019-09-17 00:46:35 +00:00
|
|
|
Write-BuildLine "** generating binstubs for $gem with precise version pins"
|
|
|
|
Invoke-Expression -Command "appbundler.bat $project_root $pkg_prefix/bin $gem"
|
2020-02-10 21:27:05 +00:00
|
|
|
If ($lastexitcode -ne 0) { Exit $lastexitcode }
|
2019-09-17 00:46:35 +00:00
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
Pop-Location
|
|
|
|
# forget about the build bundle config
|
|
|
|
Remove-Item $pkg_prefix/.bundle -Recurse -Force
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function Invoke-After {
|
|
|
|
# We don't need the cache of downloaded .gem files ...
|
|
|
|
Remove-Item $pkg_prefix/vendor/cache -Recurse -Force
|
|
|
|
# We don't need the gem docs.
|
|
|
|
Remove-Item $pkg_prefix/vendor/doc -Recurse -Force
|
|
|
|
# We don't need to ship the test suites for every gem dependency,
|
|
|
|
# only inspec's for package verification.
|
|
|
|
Get-ChildItem $pkg_prefix/vendor/gems -Filter "spec" -Directory -Recurse -Depth 1 `
|
|
|
|
| Where-Object -FilterScript { $_.FullName -notlike "*inspec*" } `
|
|
|
|
| Remove-Item -Recurse -Force
|
2019-11-01 18:10:49 +00:00
|
|
|
# Remove the byproducts of compiling gems with extensions
|
|
|
|
Get-ChildItem $pkg_prefix/vendor/gems -Include @("gem_make.out", "mkmf.log", "Makefile") -File -Recurse `
|
|
|
|
| Remove-Item -Force
|
2019-09-17 00:46:35 +00:00
|
|
|
}
|