File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ name : Pull request checks
2+
3+ on :
4+ pull_request :
5+
6+ permissions :
7+ contents : read
8+ pull-requests : write
9+
10+ jobs :
11+ lint :
12+ runs-on : ubuntu-latest
13+ steps :
14+ - uses : actions/checkout@v6
15+ - uses : actions/setup-python@v6
16+ with :
17+ python-version : ' 3.x'
18+ - uses : pre-commit/action@v3.0.1
Original file line number Diff line number Diff line change 11# Local .terraform directories
22** /.terraform /*
33
4+ # Terrform lock files
5+ .terraform.lock.hcl
6+
47# .tfstate files
58* .tfstate
69* .tfstate. *
Original file line number Diff line number Diff line change 1+ repos :
2+ - repo : local
3+ hooks :
4+ - id : check-tf-variable-order
5+ name : Check OpenTofu variable ordering
6+ language : system
7+ entry : bash scripts/check-tf-variable-order.sh
8+ files : \.tf$
Original file line number Diff line number Diff line change @@ -66,6 +66,28 @@ tofu init -upgrade
6666
6767## Contributing
6868
69+ This repository uses [ pre-commit] ( https://pre-commit.com ) to enforce code
70+ style checks before each commit. Install it once after cloning:
71+
72+ ** 1. Install pre-commit**
73+
74+ ``` sh
75+ brew install pre-commit
76+ ```
77+
78+ ** 2. Install the git hook**
79+
80+ ``` sh
81+ pre-commit install
82+ ```
83+
84+ This symlinks the hook into ` .git/hooks/pre-commit ` . The checks will now run
85+ automatically on every ` git commit ` . To run them manually against all files:
86+
87+ ``` sh
88+ pre-commit run --all-files
89+ ```
90+
6991Follow the [ contributing guidelines] [ contributing ] to contribute to this
7092repository.
7193
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+ # Check that variable blocks in OpenTofu/Terraform files are in alphabetical order.
3+
4+ set -euo pipefail
5+
6+ failed=0
7+
8+ for file in " $@ " ; do
9+ vars=$( grep -E ' ^variable "' " $file " | sed ' s/^variable "\([^"]*\)".*/\1/' || true)
10+
11+ [ -z " $vars " ] && continue
12+
13+ sorted=$( echo " $vars " | sort)
14+
15+ if [ " $vars " != " $sorted " ]; then
16+ echo " ERROR: Variables in $file are not in alphabetical order."
17+ echo " Current: $( echo " $vars " | tr ' \n' ' ' ) "
18+ echo " Expected: $( echo " $sorted " | tr ' \n' ' ' ) "
19+ failed=1
20+ fi
21+ done
22+
23+ exit $failed
You can’t perform that action at this time.
0 commit comments