Fix Habitat package pipeline for inspec-4 (#6747)

* HAB: Add an exception to trust the workdir

Signed-off-by: Sonu Saha <sonu.saha@progress.com>

* Updating powershell script as equivalent to shell script for hab

Signed-off-by: Sonu Saha <sonu.saha@progress.com>

---------

Signed-off-by: Sonu Saha <sonu.saha@progress.com>
This commit is contained in:
Sonu Saha 2023-10-01 08:12:26 +05:30 committed by GitHub
parent 3375644d2a
commit f119f0924e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 3 deletions

View file

@ -30,13 +30,41 @@ finally {
Write-Host "--- Generating fake origin key" Write-Host "--- Generating fake origin key"
hab origin key generate $env:HAB_ORIGIN hab origin key generate $env:HAB_ORIGIN
# Find the key file
$HAB_CI_KEY = Get-ChildItem -Path C:\hab\cache\keys\$env:HAB_ORIGIN*.pub | Select-Object -ExpandProperty FullName
# Export the HAB_CI_KEY environment variable
$Env:HAB_CI_KEY = $HAB_CI_KEY
if (Test-Path -Path $HAB_CI_KEY) {
# Import the key if it exists
$keyContents = Get-Content -Path $HAB_CI_KEY
$keyContents | ForEach-Object { hab origin key import - } # Use '-' to accept input from the pipeline
}
else {
Write-Host "$HAB_CI_KEY not found"
Get-ChildItem -Path $env:USERPROFILE\.hab\cache\keys
Get-ChildItem -Path $project_root\hab\cache\keys
Get-ChildItem -Path C:\hab
Exit 1
}
Write-Host "--- Building $Plan" Write-Host "--- Building $Plan"
$project_root = "$(git rev-parse --show-toplevel)" $project_root = "$(git rev-parse --show-toplevel)"
Set-Location $project_root Set-Location $project_root
$env:DO_CHECK=$true; hab pkg build . $env:DO_CHECK = $true
hab pkg build .
. $project_root/results/last_build.ps1 if ($LASTEXITCODE -ne 0) {
Write-Host "Package build failed."
}
try {
. $project_root/results/last_build.ps1
} catch {
Write-Host "Error running last_build.ps1: $_"
}
Write-Host "--- Installing $pkg_ident/$pkg_artifact" Write-Host "--- Installing $pkg_ident/$pkg_artifact"
hab pkg install -b $project_root/results/$pkg_artifact hab pkg install -b $project_root/results/$pkg_artifact
@ -56,4 +84,10 @@ Write-Host "+++ Testing $Plan"
Push-Location $project_root/test/artifact Push-Location $project_root/test/artifact
rake rake
If ($lastexitcode -ne 0) { Exit $lastexitcode }
# Check the test result and handle any errors
if ($LASTEXITCODE -ne 0) {
Write-Host "Tests failed. Exit code: $LASTEXITCODE"
}
Write-Host "--- Script completed successfully."

View file

@ -6,7 +6,28 @@ export HAB_ORIGIN='ci'
export PLAN='inspec' export PLAN='inspec'
export CHEF_LICENSE="accept-no-persist" export CHEF_LICENSE="accept-no-persist"
export HAB_LICENSE="accept-no-persist" export HAB_LICENSE="accept-no-persist"
echo "--- checking if git is installed"
if ! command -v git &> /dev/null; then
echo "Git is not installed. Installing Git..."
sudo yum install -y git
else
echo "Git is already installed."
git --version
fi
echo "--- add an exception for this directory since detected dubious ownership in repository at /workdir"
git config --global --add safe.directory /workdir
echo "--- git status for this workdir"
git status
echo "--- ruby version"
ruby -v
export project_root="$(git rev-parse --show-toplevel)" export project_root="$(git rev-parse --show-toplevel)"
echo "The value for project_root is: $project_root"
export HAB_NONINTERACTIVE=true export HAB_NONINTERACTIVE=true
export HAB_NOCOLORING=true export HAB_NOCOLORING=true
export HAB_STUDIO_SECRET_HAB_NONINTERACTIVE=true export HAB_STUDIO_SECRET_HAB_NONINTERACTIVE=true
@ -46,6 +67,9 @@ if [ -f ./results/last_build.env ]; then
fi fi
echo "+++ Installing ${pkg_ident:?is undefined}" echo "+++ Installing ${pkg_ident:?is undefined}"
echo "++++"
echo $project_root
echo "+++"
hab pkg install -b "${project_root:?is undefined}/results/${pkg_artifact:?is undefined}" hab pkg install -b "${project_root:?is undefined}/results/${pkg_artifact:?is undefined}"
echo "--- Removing world readability from /usr/local/bundle" echo "--- Removing world readability from /usr/local/bundle"