mirror of
https://github.com/tofuutils/pre-commit-opentofu.git
synced 2026-06-02 15:16:54 +02:00
Compare commits
5 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7067827cf3 | ||
|
|
9316d2989c | ||
|
|
b766f82b08 | ||
|
|
3f263a968c | ||
|
|
c9cd4a805d |
7 changed files with 41 additions and 17 deletions
8
.github/workflows/pre-commit.yaml
vendored
8
.github/workflows/pre-commit.yaml
vendored
|
|
@ -27,9 +27,13 @@ jobs:
|
||||||
sudo apt update && sudo apt install shellcheck
|
sudo apt update && sudo apt install shellcheck
|
||||||
|
|
||||||
- name: Install hadolint
|
- name: Install hadolint
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ github.token }}
|
||||||
run: |
|
run: |
|
||||||
curl -L "$(curl -s https://api.github.com/repos/hadolint/hadolint/releases/latest | grep -o -E -m 1 "https://.+?/hadolint-Linux-x86_64")" > hadolint \
|
gh release download v2.14.0 --repo hadolint/hadolint --pattern "hadolint-linux-x86_64"
|
||||||
&& chmod +x hadolint && sudo mv hadolint /usr/bin/
|
mv hadolint-linux-x86_64 hadolint
|
||||||
|
chmod +x hadolint
|
||||||
|
sudo mv hadolint /usr/bin/
|
||||||
# Need to success pre-commit fix push
|
# Need to success pre-commit fix push
|
||||||
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
|
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
|
||||||
with:
|
with:
|
||||||
|
|
|
||||||
11
CHANGELOG.md
11
CHANGELOG.md
|
|
@ -2,6 +2,15 @@
|
||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
## [2.4.1](https://github.com/tofuutils/pre-commit-opentofu/compare/v2.4.0...v2.4.1) (2026-06-01)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* initialize config_file_no_color variable ([b766f82](https://github.com/tofuutils/pre-commit-opentofu/commit/b766f82b087793f75b3ffa61eb22da80031455ce))
|
||||||
|
* typo fixes ([3f263a9](https://github.com/tofuutils/pre-commit-opentofu/commit/3f263a968cd776924c3d1f4981e0fbf1cd79ff4d))
|
||||||
|
* Update hadolint installation ([c9cd4a8](https://github.com/tofuutils/pre-commit-opentofu/commit/c9cd4a805d378516a24dac33278fa51deb98bf2e))
|
||||||
|
|
||||||
# [2.4.0](https://github.com/tofuutils/pre-commit-opentofu/compare/v2.3.0...v2.4.0) (2026-05-25)
|
# [2.4.0](https://github.com/tofuutils/pre-commit-opentofu/compare/v2.3.0...v2.4.0) (2026-05-25)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -48,7 +57,7 @@ All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
* spport .tofu files ([#6](https://github.com/tofuutils/pre-commit-opentofu/issues/6)) ([e059c58](https://github.com/tofuutils/pre-commit-opentofu/commit/e059c5859bceddf1ca018f55851f6940ad51f1c2))
|
* support .tofu files ([#6](https://github.com/tofuutils/pre-commit-opentofu/issues/6)) ([e059c58](https://github.com/tofuutils/pre-commit-opentofu/commit/e059c5859bceddf1ca018f55851f6940ad51f1c2))
|
||||||
|
|
||||||
# [2.0.0](https://github.com/tofuutils/pre-commit-opentofu/compare/v1.0.4...v2.0.0) (2024-09-25)
|
# [2.0.0](https://github.com/tofuutils/pre-commit-opentofu/compare/v1.0.4...v2.0.0) (2024-09-25)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -718,7 +718,7 @@ To replicate functionality in `tofu_docs` hook:
|
||||||
- --args=--config=__GIT_WORKING_DIR__/.tflint.hcl
|
- --args=--config=__GIT_WORKING_DIR__/.tflint.hcl
|
||||||
```
|
```
|
||||||
|
|
||||||
3. By default, pre-commit-opentofu performs directory switching into the OpenTofu modules for you. If you want to delgate the directory changing to the binary - this will allow tflint to determine the full paths for error/warning messages, rather than just module relative paths. *Note: this requires `tflint>=0.44.0`.* For example:
|
3. By default, pre-commit-opentofu performs directory switching into the OpenTofu modules for you. If you want to delegate the directory changing to the binary - this will allow tflint to determine the full paths for error/warning messages, rather than just module relative paths. *Note: this requires `tflint>=0.44.0`.* For example:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- id: tofu_tflint
|
- id: tofu_tflint
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,7 @@ function tofu_docs {
|
||||||
local -a -r files=("$@")
|
local -a -r files=("$@")
|
||||||
|
|
||||||
local -a paths
|
local -a paths
|
||||||
|
local config_file_no_color=""
|
||||||
|
|
||||||
local index=0
|
local index=0
|
||||||
local file_with_path
|
local file_with_path
|
||||||
|
|
|
||||||
|
|
@ -36,13 +36,14 @@ def main(argv=None):
|
||||||
args = parser.parse_args(argv)
|
args = parser.parse_args(argv)
|
||||||
|
|
||||||
dirs = []
|
dirs = []
|
||||||
|
seen_dirs = set()
|
||||||
for filename in args.filenames:
|
for filename in args.filenames:
|
||||||
if os.path.realpath(filename) not in dirs and (
|
if filename.endswith((".tf", ".tofu", ".tfvars")):
|
||||||
filename.endswith(".tf")
|
dir_path = os.path.dirname(filename)
|
||||||
or filename.endswith(".tofu")
|
dir_key = os.path.realpath(dir_path)
|
||||||
or filename.endswith(".tfvars")
|
if dir_key not in seen_dirs:
|
||||||
):
|
seen_dirs.add(dir_key)
|
||||||
dirs.append(os.path.dirname(filename))
|
dirs.append(dir_path)
|
||||||
|
|
||||||
retval = 0
|
retval = 0
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -128,12 +128,18 @@ function per_dir_hook_unique_part {
|
||||||
|
|
||||||
if [ "$retry_once_with_cleanup" != "true" ]; then
|
if [ "$retry_once_with_cleanup" != "true" ]; then
|
||||||
# tofu validate only
|
# tofu validate only
|
||||||
validate_output=$(tofu validate "${args[@]}" 2>&1)
|
if validate_output=$(tofu validate "${args[@]}" 2>&1); then
|
||||||
|
exit_code=0
|
||||||
|
else
|
||||||
exit_code=$?
|
exit_code=$?
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
# tofu validate, plus capture possible errors
|
# tofu validate, plus capture possible errors
|
||||||
validate_output=$(tofu validate -json "${args[@]}" 2>&1)
|
if validate_output=$(tofu validate -json "${args[@]}" 2>&1); then
|
||||||
|
exit_code=0
|
||||||
|
else
|
||||||
exit_code=$?
|
exit_code=$?
|
||||||
|
fi
|
||||||
|
|
||||||
# Match specific validation errors
|
# Match specific validation errors
|
||||||
local -i validate_errors_matched
|
local -i validate_errors_matched
|
||||||
|
|
@ -155,10 +161,13 @@ function per_dir_hook_unique_part {
|
||||||
return $exit_code
|
return $exit_code
|
||||||
}
|
}
|
||||||
|
|
||||||
validate_output=$(tofu validate "${args[@]}" 2>&1)
|
if validate_output=$(tofu validate "${args[@]}" 2>&1); then
|
||||||
|
exit_code=0
|
||||||
|
else
|
||||||
exit_code=$?
|
exit_code=$?
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if [ $exit_code -ne 0 ]; then
|
if [ $exit_code -ne 0 ]; then
|
||||||
common::colorify "red" "Validation failed: $dir_path"
|
common::colorify "red" "Validation failed: $dir_path"
|
||||||
|
|
|
||||||
|
|
@ -360,7 +360,7 @@ getopt() {
|
||||||
}
|
}
|
||||||
|
|
||||||
_getopt_resolve_abbrev() {
|
_getopt_resolve_abbrev() {
|
||||||
# Resolves an abbrevation from a list of possibilities.
|
# Resolves an abbreviation from a list of possibilities.
|
||||||
# If the abbreviation is unambiguous, echoes the expansion on stdout
|
# If the abbreviation is unambiguous, echoes the expansion on stdout
|
||||||
# and returns 0. If the abbreviation is ambiguous, prints a message on
|
# and returns 0. If the abbreviation is ambiguous, prints a message on
|
||||||
# stderr and returns 1. (For first parse this should convert to exit
|
# stderr and returns 1. (For first parse this should convert to exit
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue