Skip to content

Commit 4ab1753

Browse files
committed
ci: test script
ci: test script ci: test script ci: test script ci: test script ci: test script ci: test script ci: test script
1 parent 06f05a4 commit 4ab1753

File tree

4 files changed

+117
-60
lines changed

4 files changed

+117
-60
lines changed

.github/workflows/build.yml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,38 @@
11
name: build
2+
23
on:
34
push:
45
branches: [ main, feature/* ]
56
pull_request:
67
branches: [ main ]
78
merge_group:
89

9-
1010
jobs:
1111
pre-commit:
1212
runs-on: ubuntu-latest
13+
1314
steps:
14-
- uses: actions/checkout@v4
15+
- name: Checkout repository
16+
uses: actions/checkout@v4
1517

16-
- uses: meshcloud/setup-collie@main
18+
- name: Set up meshcloud collie CLI
19+
uses: meshcloud/setup-collie@main
1720

18-
- uses: nixbuild/nix-quick-install-action@v26
21+
- name: Install Nix
22+
uses: nixbuild/nix-quick-install-action@v26
1923
with:
2024
nix_on_tmpfs: true
2125

22-
- uses: rrbutani/use-nix-shell-action@v1
26+
- name: Enter nix dev shell
27+
uses: rrbutani/use-nix-shell-action@v1
2328
with:
24-
devShell: .#github_actions # use a special github actions shell
29+
devShell: .#github_actions
2530

26-
- name: ensure all pre-commit hooks pass
31+
- name: Run pre-commit checks
2732
run: pre-commit run --all-files --show-diff-on-failure
2833

29-
- name: Run validation script
30-
run: ci/validate_modules.sh
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

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ yarn-error.log*
2727
crash.log
2828

2929
# Exclude all .tfvars files, which are likely to contain sentitive data, such as
30-
# password, private keys, and other secrets. These should not be part of version
31-
# control as they are data points which are potentially sensitive and subject
30+
# password, private keys, and other secrets. These should not be part of version
31+
# control as they are data points which are potentially sensitive and subject
3232
# to change depending on the environment.
3333
#
3434
*.tfvars

ci/validate_modules.sh

Lines changed: 96 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
#!/bin/bash
22

3-
# CLI output colors
3+
# Colors for output
44
RED='\033[0;31m'
55
YELLOW='\033[1;33m'
6-
NC='\033[0m' # No Color
6+
NC='\033[0m'
77

88
errors=()
99
warnings=()
1010

11-
# Check if Terraform is installed
12-
if ! command -v terraform >/dev/null 2>&1; then
13-
echo -e "${RED}Error:${NC} Terraform is not installed or not in PATH"
14-
exit 1
15-
fi
16-
1711
check_readme_format() {
1812
local readme_path="$1"
1913

@@ -22,30 +16,60 @@ check_readme_format() {
2216
return 1
2317
fi
2418

25-
# Check for valid YAML front matter
26-
if ! awk '/^---/{f=1; next} /^---$/{if(f){exit 0}} END{exit 1}' "$readme_path"; then
27-
errors+=("README.md at $readme_path does not have a valid YAML front matter block (start and end with '---')")
19+
# 1. Check that the first line is exactly ---
20+
local first_line
21+
first_line=$(head -n 1 "$readme_path")
22+
if [[ "$first_line" != "---" ]]; then
23+
errors+=("Missing starting '---' in README.md at $readme_path")
2824
return 1
2925
fi
3026

31-
# Extract YAML block
32-
local yaml_header
33-
yaml_header=$(awk '/^---/{f=1; next} /^---$/{f=0} f' "$readme_path")
34-
35-
# Check for required fields
36-
if ! grep -q "name:" <<< "$yaml_header"; then
37-
errors+=("Missing 'name' in YAML header of README.md at $readme_path")
27+
# 2. Find end of YAML block
28+
local end_line
29+
end_line=$(awk 'NR>1 && /^---$/ { print NR; exit }' "$readme_path")
30+
if [[ -z "$end_line" ]]; then
31+
errors+=("Missing closing '---' in README.md at $readme_path")
32+
return 1
3833
fi
39-
if ! grep -q "supportedPlatforms:" <<< "$yaml_header"; then
40-
errors+=("Missing 'supportedPlatforms' in YAML header of README.md at $readme_path")
34+
35+
# 3. Extract YAML block
36+
local yaml
37+
yaml=$(head -n "$((end_line - 1))" "$readme_path" | tail -n +2)
38+
39+
# 4. Check for required fields and that they are not empty
40+
41+
# name
42+
if ! grep -q "^name:" <<< "$yaml"; then
43+
errors+=("Missing 'name:' field in YAML header of README.md at $readme_path")
44+
elif [[ -z $(grep "^name:" <<< "$yaml" | cut -d':' -f2 | xargs) ]]; then
45+
errors+=("Field 'name:' is empty in README.md at $readme_path")
4146
fi
42-
if ! grep -q "description:" <<< "$yaml_header"; then
43-
errors+=("Missing 'description' in YAML header of README.md at $readme_path")
47+
48+
# supportedPlatforms
49+
if ! grep -q "^supportedPlatforms:" <<< "$yaml"; then
50+
errors+=("Missing 'supportedPlatforms:' field in YAML header of README.md at $readme_path")
51+
else
52+
local platforms_count
53+
platforms_count=$(awk '/^supportedPlatforms:/ {found=1; next} /^ *[^- ]/ {found=0} found && /^ *-/{count++} END{print count+0}' <<< "$yaml")
54+
if [[ "$platforms_count" -eq 0 ]]; then
55+
errors+=("Field 'supportedPlatforms:' is empty in README.md at $readme_path")
56+
fi
4457
fi
4558

46-
return 0
59+
# description
60+
if ! grep -q "^description:" <<< "$yaml"; then
61+
errors+=("Missing 'description:' field in YAML header of README.md at $readme_path")
62+
else
63+
local desc_start desc_content
64+
desc_start=$(awk '/^description:/ {print NR; exit}' <<< "$yaml")
65+
desc_content=$(echo "$yaml" | tail -n +"$((desc_start + 1))" | awk 'NF {print; exit}')
66+
if [[ -z "$desc_content" ]]; then
67+
errors+=("Field 'description:' is empty in README.md at $readme_path")
68+
fi
69+
fi
4770
}
4871

72+
4973
check_png_naming() {
5074
local png_path="$1"
5175
local png_name
@@ -59,33 +83,44 @@ check_png_naming() {
5983
check_terraform_files() {
6084
local buildingblock_path="$1"
6185

62-
# Check if any .tf files exist
63-
if ! find "$buildingblock_path" -maxdepth 1 -name '*.tf' | grep -q .; then
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
6488
errors+=("No Terraform (.tf) files found in $buildingblock_path")
6589
return 1
6690
fi
6791

68-
# Optional: Check for recommended files
69-
local required_tf_files=("main.tf" "variables.tf" "outputs.tf" "provider.tf" "versions.tf")
70-
for tf_file in "${required_tf_files[@]}"; do
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
7195
if [[ ! -f "$buildingblock_path/$tf_file" ]]; then
7296
warnings+=("Recommended file '$tf_file' is missing in $buildingblock_path")
7397
fi
7498
done
7599

76-
# Validate Terraform configuration
100+
# Run terraform init + validate with visible output
77101
pushd "$buildingblock_path" > /dev/null || return 1
102+
rm -rf .terraform/ > /dev/null 2>&1
78103

79-
if ! terraform init -backend=false -input=false > /dev/null 2>&1; then
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}"
80107
errors+=("Terraform init failed in $buildingblock_path")
81-
elif ! terraform validate > /dev/null 2>&1; then
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}"
82117
errors+=("Terraform validate failed in $buildingblock_path")
83118
fi
84119

85-
popd > /dev/null || return 1
120+
popd > /dev/null
86121
}
87122

88-
# Ensure the script is run from repo root
123+
# Ensure script is run from repo root
89124
cd "$(dirname "$0")/.." || exit 1
90125
modules_path="modules"
91126

@@ -96,42 +131,55 @@ fi
96131

97132
modules_glob="$modules_path/*/*/buildingblock"
98133

99-
# Check all README.md files
100-
find $modules_glob -name 'README.md' -print0 | while IFS= read -r -d '' readme_file; do
134+
# Check README.md files only directly inside each buildingblock
135+
for readme_file in $(find $modules_glob -maxdepth 1 -name 'README.md'); do
101136
check_readme_format "$readme_file"
102137
done
103138

104-
# Check all PNG files
105-
find $modules_glob -name '*.png' -print0 | while IFS= read -r -d '' png_file; do
139+
# Check PNG files only directly inside each buildingblock
140+
for png_file in $(find $modules_glob -maxdepth 1 -name '*.png'); do
106141
check_png_naming "$png_file"
107142
done
108143

109-
# Check all Terraform buildingblock directories
110-
find $modules_glob -type d -name 'buildingblock' -print0 | while IFS= read -r -d '' buildingblock_dir; do
144+
Check each buildingblock directory
145+
for buildingblock_dir in $(find $modules_glob -type d -name 'buildingblock'); do
111146
check_terraform_files "$buildingblock_dir"
112147
done
113148

114-
# Print results
149+
# Output summary
115150
echo ""
116151
echo "Number of errors: ${#errors[@]}"
117152
echo "Number of warnings: ${#warnings[@]}"
118153
echo ""
119154

120155
if [[ ${#errors[@]} -gt 0 ]]; then
121-
echo -e "${RED}Errors found:${NC}"
122-
for error in "${errors[@]}"; do
123-
echo -e "- $error"
156+
echo -e "${RED}Errors:${NC}"
157+
for e in "${errors[@]}"; do
158+
echo "- $e"
124159
done
125-
echo ""
126160
exit 1
127161
elif [[ ${#warnings[@]} -gt 0 ]]; then
128-
echo -e "${YELLOW}Warnings found:${NC}"
129-
for warning in "${warnings[@]}"; do
130-
echo -e "- $warning"
162+
echo -e "${YELLOW}Warnings:${NC}"
163+
for w in "${warnings[@]}"; do
164+
echo "- $w"
131165
done
132-
echo ""
133166
exit 0
134167
else
135168
echo "✅ All checks passed successfully."
136169
exit 0
137170
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

modules/aws/s3_bucket/buildingblock/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
name: AWS S3 Bucket
33
supportedPlatforms:
44
- aws
5-
description: Provides an AWS S3 bucket for object storage with access controls, lifecycle policies, and encryption.
5+
description: |
6+
Provides an AWS S3 bucket for object storage with access controls, lifecycle policies, and encryption.
67
---
78

89
# AWS S3 Bucket

0 commit comments

Comments
 (0)