Skip to content

Commit e4ef407

Browse files
Add new pre-commit hook for packer formatting (#55)
## Description This PR adds a new pre-commit hook for formatting packer HCL files. It also adds new test files for this hook. ## Verification steps - [x] Run `make test` and verify tests pass
1 parent 43c1059 commit e4ef407

5 files changed

Lines changed: 29 additions & 0 deletions

File tree

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ chmod +x taplo
102102
wget https://releases.hashicorp.com/terraform/1.9.8/terraform_1.9.8_linux_amd64.zip -O tf.zip
103103
unzip tf.zip
104104
rm tf.zip
105+
rm LICENSE.txt
106+
wget https://releases.hashicorp.com/packer/1.14.2/packer_1.14.2_linux_amd64.zip -O packer.zip
107+
unzip packer.zip
108+
rm packer.zip
105109

106110
# Create an empty file for the linters that need one for some reason
107111
touch /emptyfile

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The main hook that runs several code formatters in parallel:
2020
- [shfmt](https://github.com/mvdan/sh) v3.10.0 for Shell
2121
- [xsltproc](http://www.xmlsoft.org/xslt/xsltproc.html) from libxslt v10139 for XML
2222
- [terraform fmt](https://github.com/hashicorp/terraform) v1.9.8 for Terraform
23+
- [packer fmt](https://github.com/hashicorp/packer) v1.14.2 for Packer
2324
- [ClangFormat](https://clang.llvm.org/docs/ClangFormat.html) v18.1.8 for C++, Protobuf
2425
- [SVGO](https://github.com/svg/svgo) v3.3.2 for SVG
2526
- [Taplo](https://taplo.tamasfe.dev/) v0.9.3 for TOML

entry.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ const enum HookName {
8686
GradleDependenciesSorter = "gradle-dependencies-sorter",
8787
Isort = "isort",
8888
Ktfmt = "ktfmt",
89+
PackerFmt = "packer fmt",
8990
PrettierJs = "Prettier (JS)",
9091
PrettierNonJs = "Prettier (non-JS)",
9192
Ruff = "Ruff",
@@ -261,6 +262,11 @@ const HOOKS: Record<HookName, LockableHook> = {
261262
include: /\.kts?$/,
262263
runAfter: [HookName.Sed],
263264
}),
265+
[HookName.PackerFmt]: createLockableHook({
266+
action: sources => run("/packer", "fmt", ...sources),
267+
include: /\.pkr\.hcl$/,
268+
runAfter: [HookName.Sed],
269+
}),
264270
[HookName.PrettierJs]: createLockableHook({
265271
action: sources =>
266272
run(

test/after/hello.pkr.hcl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
build {
2+
provisioner "shell" {
3+
env = {
4+
PATH = local.shell_path
5+
HELLO_WORLD = var.hello_world
6+
}
7+
script = "scripts/hello-world.sh"
8+
}
9+
}

test/before/hello.pkr.hcl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
build {
2+
provisioner "shell" {
3+
env = {
4+
PATH = local.shell_path
5+
HELLO_WORLD = var.hello_world
6+
}
7+
script = "scripts/hello-world.sh"
8+
}
9+
}

0 commit comments

Comments
 (0)