mirror of https://github.com/hashicorp/terraform
Add goimports as a check to the Github commit actions (#31432)
* Add goimports as a check to the Github commit actions * check diff against main instead of last commit * goimports should fix the problems * fix up conditionals and wildcard matching * specify origin/main in diff * fetch main branch when checkout * back to origin mainpull/31408/head
parent
7b4a5513a9
commit
afd273d636
@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Check goimports
|
||||
echo "==> Checking the code complies with goimports requirements..."
|
||||
target_files=$(git diff --name-only origin/main | grep "\.go")
|
||||
|
||||
if [[ -z ${target_files} ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
goimports_files=$(goimports -w -l -local github.com/hashicorp/terraform/ ${target_files})
|
||||
if [[ -n ${goimports_files} ]]; then
|
||||
echo 'goimports needs running on the following files:'
|
||||
echo "${goimports_files}"
|
||||
echo "You can use the command and flags \`goimports -w -l -local github.com/hashicorp/terraform/\` to reformat the code"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exit 0
|
||||
Loading…
Reference in new issue