Skip to content

Commit

Permalink
Adjust how packer validate is called
Browse files Browse the repository at this point in the history
Break out the `packer validate` call so we can:
- Disable errexit for _just_ the `packer validate` call so every path
  has an attempt at validation.
- Get the output of the `packer validate` call so that if there is a
  non-zero exit code we can output that along with the path being
  validated.
  • Loading branch information
mcdonnnj committed Dec 17, 2024
1 parent 3363211 commit d47f8c2
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions hooks/packer_validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@ set -o nounset
set -o errexit
set -o pipefail

function packer_validate() {
local exit_code=0

packer init . > /dev/null

# Allow us to get output if the validation fails
set +o errexit
validate_output=$(packer validate "${ARGS[@]}" . 2>&1)
exit_code=$?
set -o errexit

if [[ $exit_code -ne 0 ]]; then
echo "Validation failed in $path"
echo -e "$validate_output"
fi

return $exit_code
}

if [ -z "$(command -v packer)" ]; then
echo "packer is required"
exit 1
Expand All @@ -24,8 +43,7 @@ for path in "${UNIQUE_PATHS[@]}"; do
# Check each path in parallel
{
pushd "$path" > /dev/null
packer init . > /dev/null
packer validate "${ARGS[@]}" .
packer_validate
} &
pids+=("$!")
done
Expand Down

0 comments on commit d47f8c2

Please sign in to comment.