Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass arguments to Packer #37

Merged
merged 2 commits into from
Sep 10, 2024
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
2 changes: 2 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
name: Packer Format
description: This hook runs `packer fmt` on appropriate files.
entry: hooks/packer_fmt.sh
args:
- -check
language: script
files: \.pkr(?:vars)?\.hcl$
pass_filenames: true
20 changes: 18 additions & 2 deletions hooks/packer_fmt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,26 @@ if [ -z "$(command -v packer)" ]; then
exit 1
fi

args=()
files=()

while (("$#")); do
case "$1" in
-*)
args+=("$1")
shift
;;
*)
files+=("$1")
shift
;;
esac
done

error=0

for file in "$@"; do
if ! packer fmt -check "$file"; then
for file in "${files[@]}"; do
if ! packer fmt "${args[@]}" "$file"; then
error=1
echo
echo "Failed path: $file"
Expand Down
20 changes: 18 additions & 2 deletions hooks/packer_validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,26 @@ if [ -z "$(command -v packer)" ]; then
exit 1
fi

args=()
files=()

while (("$#")); do
case "$1" in
-*)
args+=("$1")
shift
;;
*)
files+=("$1")
shift
;;
esac
done

error=0

for file in "$@"; do
if ! packer validate "$file"; then
for file in "${files[@]}"; do
if ! packer validate "${args[@]}" "$file"; then
error=1
echo
echo "Failed path: $file"
Expand Down
Loading