Skip to content

Commit cf7ba50

Browse files
authored
Merge branch 'master' into MaxymVlasov-patch-1
2 parents 17fc1a8 + 8931c65 commit cf7ba50

19 files changed

+319
-123
lines changed

.git-blame-ignore-revs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# `git blame` master ignore list.
2+
#
3+
# This file contains a list of git hashes of revisions to be ignored
4+
# by `git blame`. These revisions are considered "unimportant" in
5+
# that they are unlikely to be what you are interested in when blaming.
6+
# They are typically expected to be formatting-only changes.
7+
#
8+
# It can be used for `git blame` using `--ignore-revs-file` or by
9+
# setting `blame.ignoreRevsFile` in the `git config`[1].
10+
#
11+
# Ignore these commits when reporting with blame. Calling
12+
#
13+
# git blame --ignore-revs-file .git-blame-ignore-revs
14+
#
15+
# will tell `git blame` to ignore changes made by these revisions when
16+
# assigning blame, as if the change never happened.
17+
#
18+
# You can enable this as a default for your local repository by
19+
# running
20+
#
21+
# git config blame.ignoreRevsFile .git-blame-ignore-revs
22+
#
23+
# This will probably be automatically picked by your IDE
24+
# (VSCode+GitLens and JetBrains products are confirmed to do this).
25+
#
26+
# Important: if you are switching to a branch without this file,
27+
# `git blame` will fail with an error.
28+
#
29+
# GitHub also excludes the commits listed below from its "Blame"
30+
# views[2][3].
31+
#
32+
# [1]: https://git-scm.com/docs/git-blame#Documentation/git-blame.txt-blameignoreRevsFile
33+
# [2]: https://github.blog/changelog/2022-03-24-ignore-commits-in-the-blame-view-beta/
34+
# [3]: https://docs.github.com/en/repositories/working-with-files/using-files/viewing-a-file#ignore-commits-in-the-blame-view
35+
#
36+
# Guidelines:
37+
# - Only large (generally automated) reformatting or renaming PRs
38+
# should be added to this list. Do not put things here just because
39+
# you feel they are trivial or unimportant. If in doubt, do not put
40+
# it on this list.
41+
# - When adding a single revision, use inline comment to link relevant
42+
# issue/PR. Alternatively, paste the commit title instead.
43+
# Example:
44+
# d4a8b7307acc2dc8a8833ccfa65426ad28b3ffc9 # https://github.com/sanitizers/octomachinery/issues/1
45+
# - When adding multiple revisions (like a bulk of work over many
46+
# commits), organize them in blocks. Precede each such block with a
47+
# comment starting with the word "START", followed by a link to the
48+
# relevant issue or PR. Add a similar comment after the last block
49+
# line but use the word "END", followed by the same link.
50+
# Alternatively, add or augment the link with a text motivation and
51+
# description of work performed in each commit.
52+
# After each individual commit in the block, add an inline comment
53+
# with the commit title line.
54+
# Example:
55+
# # START https://github.com/sanitizers/octomachinery/issues/1
56+
# 6f0bd2d8a1e6cd2e794cd39976e9756e0c85ac66 # Bulk-replace smile emojis with unicorns
57+
# d53974df11dbc22cbea9dc7dcbc9896c25979a27 # Replace double with single quotes
58+
# ... <rest of the list>
59+
# # END https://github.com/sanitizers/octomachinery/issues/1
60+
# - Only put full 40-character hashes on this list (not short hashes
61+
# or any other revision reference).
62+
# - Append to the bottom of the file, regardless of the chronological
63+
# order of the revisions. Revisions within blocks should be in
64+
# chronological order from oldest to newest.
65+
# - Because you must use a hash, you need to append to this list in a
66+
# follow-up PR to the actual reformatting PR that you are trying to
67+
# ignore. This approach helps avoid issues with arbitrary rebases
68+
# and squashes while the pull request is in progress.
69+
70+
23928fbf8511697c915c3231977ee254bd3fa0c2 # chore(linters): Apply ruff-format

.github/CONTRIBUTING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Notes for contributors
22

3+
* [Configure `git blame` to ignore formatting commits](#configure-git-blame-to-ignore-formatting-commits)
34
* [Run and debug hooks locally](#run-and-debug-hooks-locally)
45
* [Run hook performance test](#run-hook-performance-test)
56
* [Run via BASH](#run-via-bash)
@@ -15,6 +16,10 @@
1516
* [Contributing to Python code](#contributing-to-python-code)
1617
* [Run tests in your fork](#run-tests-in-your-fork)
1718

19+
## Configure `git blame` to ignore formatting commits
20+
21+
This project uses `.git-blame-ignore-revs` to exclude formatting-related commits from `git blame` history. To configure your local `git blame` to ignore these commits, refer to the [.git-blame-ignore-revs](/.git-blame-ignore-revs) file for details.
22+
1823
## Run and debug hooks locally
1924

2025
```bash

.github/workflows/pre-commit.yaml

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -47,48 +47,41 @@ jobs:
4747
)"
4848
> hadolint
4949
&& chmod +x hadolint && sudo mv hadolint /usr/bin/
50-
# Need to success pre-commit fix push
50+
# Needed for pre-commit fix push to succeed
5151
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
5252
with:
5353
fetch-depth: 0
5454
ref: ${{ github.event.pull_request.head.sha }}
55+
# Needed to trigger pre-commit workflow on autofix commit. Guide:
56+
# https://web.archive.org/web/20210731173012/https://github.community/t/required-check-is-expected-after-automated-push/187545/
57+
ssh-key: ${{ secrets.GHA_AUTOFIX_COMMIT_KEY }}
5558
# Skip terraform_tflint which interferes to commit pre-commit auto-fixes
5659
- uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
5760
with:
5861
python-version: '3.13'
62+
5963
- name: Execute pre-commit
60-
uses: pre-commit/action@9b88afc9cd57fd75b655d5c71bd38146d07135fe # v2.0.3
64+
uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
6165
env:
62-
SKIP: no-commit-to-branch,hadolint
66+
SKIP: no-commit-to-branch
6367
with:
64-
token: ${{ secrets.GITHUB_TOKEN }}
6568
extra_args: >-
6669
--color=always
6770
--show-diff-on-failure
68-
--files ${{ steps.file_changes.outputs.files }}
69-
# Run only skipped checks
70-
- name: Execute pre-commit check that have no auto-fixes
71-
if: always()
72-
uses: pre-commit/action@9b88afc9cd57fd75b655d5c71bd38146d07135fe # v2.0.3
73-
env:
74-
SKIP: >-
75-
check-added-large-files,
76-
check-merge-conflict,
77-
check-vcs-permalinks,
78-
forbid-new-submodules,
79-
no-commit-to-branch,
80-
end-of-file-fixer,
81-
trailing-whitespace,
82-
check-yaml,
83-
check-merge-conflict,
84-
check-executables-have-shebangs,
85-
check-case-conflict,mixed-line-ending,
86-
detect-aws-credentials,
87-
detect-private-key,
88-
shfmt,
89-
shellcheck,
71+
--files ${{ steps.file_changes.outputs.files}}
72+
73+
# Needed to trigger pre-commit workflow on autofix commit
74+
- name: Push fixes
75+
if: failure()
76+
uses: EndBug/add-and-commit@a94899bca583c204427a224a7af87c02f9b325d5 # v9.1.4
9077
with:
91-
extra_args: >-
92-
--color=always
93-
--show-diff-on-failure
94-
--files ${{ steps.file_changes.outputs.files }}
78+
# Determines the way the action fills missing author name and email.
79+
# Three options are available:
80+
# - github_actor -> UserName <[email protected]>
81+
# - user_info -> Your Display Name <[email protected]>
82+
# - github_actions -> github-actions <email associated with the github logo>
83+
# Default: github_actor
84+
default_author: github_actor
85+
# The message for the commit.
86+
# Default: 'Commit from GitHub Actions (name of the workflow)'
87+
message: '[pre-commit] Autofix violations'

.pre-commit-config.yaml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ repos:
4343

4444
# Detect hardcoded secrets
4545
- repo: https://github.com/gitleaks/gitleaks
46-
rev: v8.24.0
46+
rev: v8.24.2
4747
hooks:
4848
- id: gitleaks
4949

5050
# Dockerfile
5151
- repo: https://github.com/hadolint/hadolint
52-
rev: v2.12.1-beta
52+
rev: v2.13.1-beta
5353
hooks:
5454
- id: hadolint
5555

@@ -66,7 +66,7 @@ repos:
6666
- --implicit_start
6767

6868
- repo: https://github.com/adrienverge/yamllint.git
69-
rev: v1.36.2
69+
rev: v1.37.0
7070
hooks:
7171
- id: yamllint
7272
types:
@@ -77,7 +77,7 @@ repos:
7777

7878
# JSON5
7979
- repo: https://github.com/pre-commit/mirrors-prettier
80-
rev: v3.1.0
80+
rev: v4.0.0-alpha.8
8181
hooks:
8282
- id: prettier
8383
# https://prettier.io/docs/en/options.html#parser
@@ -98,6 +98,14 @@ repos:
9898
- id: shellcheck
9999

100100
# Python
101+
- repo: https://github.com/astral-sh/ruff-pre-commit
102+
rev: v0.11.4
103+
hooks:
104+
- id: ruff
105+
args:
106+
- --fix
107+
- id: ruff-format
108+
101109
- repo: https://github.com/pre-commit/mirrors-mypy.git
102110
rev: v1.15.0
103111
hooks:

.pre-commit-hooks.yaml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
entry: hooks/infracost_breakdown.sh
55
language: script
66
require_serial: true
7-
files: \.(tf(vars)?|hcl)$
7+
files: \.(tf|tofu|tfvars|hcl)$
88
exclude: \.terraform/.*$
99

1010
- id: terraform_fmt
@@ -13,7 +13,7 @@
1313
Rewrites all Terraform configuration files to a canonical format.
1414
entry: hooks/terraform_fmt.sh
1515
language: script
16-
files: (\.tf|\.tfvars)$
16+
files: \.(tf|tofu|tfvars)$
1717
exclude: \.terraform/.*$
1818

1919
- id: terraform_docs
@@ -24,7 +24,7 @@
2424
require_serial: true
2525
entry: hooks/terraform_docs.sh
2626
language: script
27-
files: (\.tf|\.terraform\.lock\.hcl)$
27+
files: \.(tf|tofu|terraform\.lock\.hcl)$
2828
exclude: \.terraform/.*$
2929

3030
- id: terraform_docs_without_aggregate_type_defaults
@@ -35,7 +35,7 @@
3535
require_serial: true
3636
entry: hooks/terraform_docs.sh
3737
language: script
38-
files: (\.tf)$
38+
files: \.(tf|tofu)$
3939
exclude: \.terraform/.*$
4040

4141
- id: terraform_docs_replace
@@ -44,7 +44,7 @@
4444
require_serial: true
4545
entry: python -Im pre_commit_terraform replace-docs
4646
language: python
47-
files: (\.tf)$
47+
files: \.(tf|tofu)$
4848
exclude: \.terraform/.*$
4949

5050
- id: terraform_validate
@@ -53,7 +53,7 @@
5353
require_serial: true
5454
entry: hooks/terraform_validate.sh
5555
language: script
56-
files: \.(tf(vars)?|terraform\.lock\.hcl)$
56+
files: \.(tf|tofu|tfvars|terraform\.lock\.hcl)$
5757
exclude: \.terraform/.*$
5858

5959
- id: terraform_providers_lock
@@ -71,7 +71,7 @@
7171
require_serial: true
7272
entry: hooks/terraform_tflint.sh
7373
language: script
74-
files: (\.tf|\.tfvars)$
74+
files: \.(tf|tofu|tfvars)$
7575
exclude: \.terraform/.*$
7676

7777
- id: terragrunt_fmt
@@ -114,7 +114,7 @@
114114
Static analysis of Terraform templates to spot potential security issues.
115115
require_serial: true
116116
entry: hooks/terraform_tfsec.sh
117-
files: \.tf(vars)?$
117+
files: \.(tf|tofu|tfvars)$
118118
language: script
119119

120120
- id: terraform_trivy
@@ -123,7 +123,7 @@
123123
Static analysis of Terraform templates to spot potential security issues.
124124
require_serial: true
125125
entry: hooks/terraform_trivy.sh
126-
files: \.tf(vars)?$
126+
files: \.(tf|tofu|tfvars)$
127127
language: script
128128

129129
- id: checkov
@@ -133,7 +133,7 @@
133133
language: python
134134
pass_filenames: false
135135
always_run: false
136-
files: \.tf$
136+
files: \.(tf|tofu)$
137137
exclude: \.terraform/.*$
138138
require_serial: true
139139

@@ -143,7 +143,7 @@
143143
entry: hooks/terraform_checkov.sh
144144
language: script
145145
always_run: false
146-
files: \.tf$
146+
files: \.(tf|tofu)$
147147
exclude: \.terraform/.*$
148148
require_serial: true
149149

@@ -155,15 +155,15 @@
155155
pass_filenames: false
156156
always_run: false
157157
require_serial: true
158-
files: \.tf$
158+
files: \.(tf|tofu)$
159159
exclude: \.terraform/.*$
160160

161161
- id: terrascan
162162
name: terrascan
163163
description: Runs terrascan on Terraform templates.
164164
language: script
165165
entry: hooks/terrascan.sh
166-
files: \.tf$
166+
files: \.(tf|tofu)$
167167
exclude: \.terraform/.*$
168168
require_serial: true
169169

@@ -174,5 +174,5 @@
174174
entry: hooks/tfupdate.sh
175175
args:
176176
- --args=terraform
177-
files: \.tf$
177+
files: \.(tf|tofu)$
178178
require_serial: true

.vscode/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@
77
"code-block-style": false
88
},
99
"markdown.validate.enabled": true,
10+
"python.analysis.extraPaths": [
11+
"./src",
12+
"./tests/pytest"
13+
],
1014
}

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
# [1.99.0](https://github.com/antonbabenko/pre-commit-terraform/compare/v1.98.1...v1.99.0) (2025-04-14)
6+
7+
8+
### Features
9+
10+
* Add support for running hooks on `.tofu` files by default ([#875](https://github.com/antonbabenko/pre-commit-terraform/issues/875)) ([fe1f62f](https://github.com/antonbabenko/pre-commit-terraform/commit/fe1f62f3aecadbc22f8ab5e1f8cb02c2821cf5c2))
11+
12+
## [1.98.1](https://github.com/antonbabenko/pre-commit-terraform/compare/v1.98.0...v1.98.1) (2025-04-06)
13+
14+
15+
### Bug Fixes
16+
17+
* **WSL:** Fix parallelism support for WSL systems with enabled systemd ([#872](https://github.com/antonbabenko/pre-commit-terraform/issues/872)) ([da2e9a8](https://github.com/antonbabenko/pre-commit-terraform/commit/da2e9a874ac61f94fe0a05e9d952ffb3c7c7639c))
18+
519
# [1.98.0](https://github.com/antonbabenko/pre-commit-terraform/compare/v1.97.4...v1.98.0) (2025-03-25)
620

721

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,10 @@ Config example:
349349
- id: terraform_tflint
350350
args:
351351
- --args=--config=${CONFIG_NAME}.${CONFIG_EXT}
352-
- --args=--module
352+
- --args=--call-module-type="all"
353353
```
354354
355-
If for config above set up `export CONFIG_NAME=.tflint; export CONFIG_EXT=hcl` before `pre-commit run`, args will be expanded to `--config=.tflint.hcl --module`.
355+
If for config above set up `export CONFIG_NAME=.tflint; export CONFIG_EXT=hcl` before `pre-commit run`, args will be expanded to `--config=.tflint.hcl --call-module-type="all"`.
356356

357357
### All hooks: Set env vars inside hook at runtime
358358

hooks/_common.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,10 @@ function common::get_cpu_num {
206206

207207
local cpu_quota cpu_period cpu_num
208208

209+
local -r wslinterop_path="/proc/sys/fs/binfmt_misc/WSLInterop"
210+
209211
if [[ -f /sys/fs/cgroup/cpu/cpu.cfs_quota_us &&
210-
! -f /proc/sys/fs/binfmt_misc/WSLInterop ]]; then # WSL have cfs_quota_us, but WSL should be checked as usual Linux host
212+
(! -f "${wslinterop_path}" && ! -f "${wslinterop_path}-late" && ! -f "/run/WSL") ]]; then # WSL has cfs_quota_us, but WSL should be checked as usual Linux host
211213
# Inside K8s pod or DinD in K8s
212214
cpu_quota=$(< /sys/fs/cgroup/cpu/cpu.cfs_quota_us)
213215
cpu_period=$(cat /sys/fs/cgroup/cpu/cpu.cfs_period_us 2> /dev/null || echo "$cpu_quota")

0 commit comments

Comments
 (0)