Skip to content

Commit ac52865

Browse files
committed
ci: adding everything to pre-commit
1 parent 4ab1753 commit ac52865

File tree

4 files changed

+46
-65
lines changed

4 files changed

+46
-65
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,3 @@ jobs:
3030

3131
- name: Run pre-commit checks
3232
run: pre-commit run --all-files --show-diff-on-failure
33-
34-
- name: Run validation script and write summary
35-
run: |
36-
export GITHUB_STEP_SUMMARY="$GITHUB_STEP_SUMMARY"
37-
chmod +x ci/validate_modules.sh
38-
ci/validate_modules.sh

.pre-commit-config.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
repos:
2+
- repo: local
3+
hooks:
4+
- id: check-terraform-structure
5+
name: Check Terraform module structure
6+
entry: bash ci/check_tf_structure.sh
7+
language: system
8+
pass_filenames: false
9+
- repo: local
10+
hooks:
11+
- id: validate-buildingblock
12+
name: Validate README and PNG in buildingblocks
13+
entry: bash ci/validate_modules.sh
14+
language: system
15+
pass_filenames: false
16+
217
- repo: https://github.com/antonbabenko/pre-commit-terraform
318
rev: v1.81.0
419
hooks:
@@ -7,8 +22,10 @@ repos:
722
- --args=--config=.terraform-docs.yml
823
- id: terraform_fmt
924
- id: terragrunt_fmt
25+
- id: terraform_validate
1026
- repo: https://github.com/pre-commit/pre-commit-hooks
1127
rev: v4.4.0 # Use the ref you want to point at
1228
hooks:
1329
- id: trailing-whitespace
1430
exclude: "^compliance/"
31+

ci/check_tf_structure.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
warnings=()
6+
recommended_tf_files=("main.tf" "variables.tf" "outputs.tf" "provider.tf" "versions.tf")
7+
8+
# Nur Verzeichnisse prüfen, in denen mindestens eine .tf-Datei liegt
9+
for buildingblock_path in $(find . -type f -name "*.tf" -exec dirname {} \; | sort -u); do
10+
for tf_file in "${recommended_tf_files[@]}"; do
11+
if [[ ! -f "$buildingblock_path/$tf_file" ]]; then
12+
warnings+=("⚠️ '$tf_file' fehlt in $buildingblock_path")
13+
fi
14+
done
15+
done
16+
17+
# Ausgabe & Exit-Code
18+
if [ "${#warnings[@]}" -gt 0 ]; then
19+
for warn in "${warnings[@]}"; do
20+
echo "$warn"
21+
done
22+
exit 1
23+
else
24+
echo "✅ Alle empfohlenen Terraform-Dateien sind vorhanden."
25+
fi

ci/validate_modules.sh

Lines changed: 4 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -80,46 +80,6 @@ check_png_naming() {
8080
fi
8181
}
8282

83-
check_terraform_files() {
84-
local buildingblock_path="$1"
85-
86-
# Check for at least one .tf file (excluding .terraform subfolder)
87-
if ! find "$buildingblock_path" -maxdepth 1 -type f -name '*.tf' | grep -q .; then
88-
errors+=("No Terraform (.tf) files found in $buildingblock_path")
89-
return 1
90-
fi
91-
92-
# Optional recommended file check
93-
local recommended_tf_files=("main.tf" "variables.tf" "outputs.tf", "provider.tf" "versions.tf")
94-
for tf_file in "${recommended_tf_files[@]}"; do
95-
if [[ ! -f "$buildingblock_path/$tf_file" ]]; then
96-
warnings+=("Recommended file '$tf_file' is missing in $buildingblock_path")
97-
fi
98-
done
99-
100-
# Run terraform init + validate with visible output
101-
pushd "$buildingblock_path" > /dev/null || return 1
102-
rm -rf .terraform/ > /dev/null 2>&1
103-
104-
echo "🔄 Running terraform init in $buildingblock_path"
105-
if ! terraform init -backend=false -input=false; then
106-
echo -e "${RED}Terraform init failed in $buildingblock_path${NC}"
107-
errors+=("Terraform init failed in $buildingblock_path")
108-
popd > /dev/null
109-
return 1
110-
fi
111-
112-
echo "🔄 Running terraform validate in $buildingblock_path"
113-
if terraform validate; then
114-
echo -e "${buildingblock_path} validated successfully"
115-
else
116-
echo -e "${RED}Terraform validate failed in $buildingblock_path${NC}"
117-
errors+=("Terraform validate failed in $buildingblock_path")
118-
fi
119-
120-
popd > /dev/null
121-
}
122-
12383
# Ensure script is run from repo root
12484
cd "$(dirname "$0")/.." || exit 1
12585
modules_path="modules"
@@ -141,10 +101,10 @@ for png_file in $(find $modules_glob -maxdepth 1 -name '*.png'); do
141101
check_png_naming "$png_file"
142102
done
143103

144-
Check each buildingblock directory
145-
for buildingblock_dir in $(find $modules_glob -type d -name 'buildingblock'); do
146-
check_terraform_files "$buildingblock_dir"
147-
done
104+
# Check each buildingblock directory
105+
# for buildingblock_dir in $(find $modules_glob -type d -name 'buildingblock'); do
106+
# check_terraform_files "$buildingblock_dir"
107+
# done
148108

149109
# Output summary
150110
echo ""
@@ -168,18 +128,3 @@ else
168128
echo "✅ All checks passed successfully."
169129
exit 0
170130
fi
171-
172-
if [[ -n "$GITHUB_STEP_SUMMARY" ]]; then
173-
{
174-
echo "## 🧪 Module Validation Summary"
175-
echo ""
176-
echo "**Errors:** ${#errors[@]}"
177-
for e in "${errors[@]}"; do echo "- ❌ $e"; done
178-
echo ""
179-
echo "**Warnings:** ${#warnings[@]}"
180-
for w in "${warnings[@]}"; do echo "- ⚠️ $w"; done
181-
if [[ ${#errors[@]} -eq 0 && ${#warnings[@]} -eq 0 ]]; then
182-
echo "- ✅ All checks passed successfully."
183-
fi
184-
}
185-
fi

0 commit comments

Comments
 (0)