From f119f0924ebce620e32e3fa9206df85738e12924 Mon Sep 17 00:00:00 2001 From: Sonu Saha <98935583+ahasunos@users.noreply.github.com> Date: Sun, 1 Oct 2023 08:12:26 +0530 Subject: [PATCH] Fix Habitat package pipeline for inspec-4 (#6747) * HAB: Add an exception to trust the workdir Signed-off-by: Sonu Saha * Updating powershell script as equivalent to shell script for hab Signed-off-by: Sonu Saha --------- Signed-off-by: Sonu Saha --- .../buildkite/artifact.habitat.test.ps1 | 40 +++++++++++++++++-- .expeditor/buildkite/artifact.habitat.test.sh | 24 +++++++++++ 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/.expeditor/buildkite/artifact.habitat.test.ps1 b/.expeditor/buildkite/artifact.habitat.test.ps1 index b97c50c13..410b256fc 100755 --- a/.expeditor/buildkite/artifact.habitat.test.ps1 +++ b/.expeditor/buildkite/artifact.habitat.test.ps1 @@ -30,13 +30,41 @@ finally { Write-Host "--- Generating fake origin key" 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" $project_root = "$(git rev-parse --show-toplevel)" 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" hab pkg install -b $project_root/results/$pkg_artifact @@ -56,4 +84,10 @@ Write-Host "+++ Testing $Plan" Push-Location $project_root/test/artifact 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." diff --git a/.expeditor/buildkite/artifact.habitat.test.sh b/.expeditor/buildkite/artifact.habitat.test.sh index b930a4224..79da5f649 100755 --- a/.expeditor/buildkite/artifact.habitat.test.sh +++ b/.expeditor/buildkite/artifact.habitat.test.sh @@ -6,7 +6,28 @@ export HAB_ORIGIN='ci' export PLAN='inspec' export CHEF_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)" +echo "The value for project_root is: $project_root" + export HAB_NONINTERACTIVE=true export HAB_NOCOLORING=true export HAB_STUDIO_SECRET_HAB_NONINTERACTIVE=true @@ -46,6 +67,9 @@ if [ -f ./results/last_build.env ]; then fi echo "+++ Installing ${pkg_ident:?is undefined}" +echo "++++" +echo $project_root +echo "+++" hab pkg install -b "${project_root:?is undefined}/results/${pkg_artifact:?is undefined}" echo "--- Removing world readability from /usr/local/bundle"