|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Validate Hugo Theme Repository Configuration |
| 4 | +# Run from the theme's root directory |
| 5 | + |
| 6 | +# Color codes |
| 7 | +RED='\033[0;31m' |
| 8 | +GREEN='\033[0;32m' |
| 9 | +YELLOW='\033[1;33m' |
| 10 | +NC='\033[0m' # No Color |
| 11 | + |
| 12 | +passed_checks=0 |
| 13 | +total_checks=0 |
| 14 | + |
| 15 | +function check_required_file() { |
| 16 | + ((total_checks++)) |
| 17 | + if [[ -f "$1" ]]; then |
| 18 | + echo -e "${GREEN}✓ Found: $1${NC}" |
| 19 | + ((passed_checks++)) |
| 20 | + return 0 |
| 21 | + else |
| 22 | + echo -e "${RED}✗ Missing: $1${NC}" |
| 23 | + return 1 |
| 24 | + fi |
| 25 | +} |
| 26 | + |
| 27 | +function validate_theme_toml() { |
| 28 | + ((total_checks++)) |
| 29 | + local required_fields=("name" "license") |
| 30 | + local missing_fields=() |
| 31 | + |
| 32 | + if [[ ! -f "theme.toml" ]]; then |
| 33 | + echo -e "${RED}✗ Missing theme.toml${NC}" |
| 34 | + return 1 |
| 35 | + fi |
| 36 | + |
| 37 | + # Check required top-level fields |
| 38 | + for field in "${required_fields[@]}"; do |
| 39 | + if ! grep -q "^$field =" theme.toml; then |
| 40 | + missing_fields+=("$field") |
| 41 | + fi |
| 42 | + done |
| 43 | + |
| 44 | + # Check author information |
| 45 | + if ! grep -q "^\[author\]" theme.toml && ! grep -q "^authors = \[" theme.toml; then |
| 46 | + missing_fields+=("author(s)") |
| 47 | + fi |
| 48 | + |
| 49 | + if [[ ${#missing_fields[@]} -gt 0 ]]; then |
| 50 | + echo -e "${RED}✗ theme.toml missing: ${missing_fields[*]}${NC}" |
| 51 | + return 1 |
| 52 | + else |
| 53 | + echo -e "${GREEN}✓ theme.toml valid${NC}" |
| 54 | + ((passed_checks++)) |
| 55 | + return 0 |
| 56 | + fi |
| 57 | +} |
| 58 | +function validate_go_mod() { |
| 59 | + ((total_checks++)) |
| 60 | + if [[ ! -f "go.mod" ]]; then |
| 61 | + echo -e "${RED}✗ Missing go.mod${NC}" |
| 62 | + return 1 |
| 63 | + fi |
| 64 | + |
| 65 | + if grep -q "^module github.com/stradichenko/PKB-theme" go.mod; then |
| 66 | + echo -e "${GREEN}✓ go.mod has correct module path${NC}" |
| 67 | + ((passed_checks++)) |
| 68 | + return 0 |
| 69 | + else |
| 70 | + echo -e "${RED}✗ Invalid module path in go.mod${NC}" |
| 71 | + return 1 |
| 72 | + fi |
| 73 | +} |
| 74 | + |
| 75 | +function validate_directory_structure() { |
| 76 | + local required_dirs=("archetypes" "layouts" "static" "assets") |
| 77 | + local missing_dirs=() |
| 78 | + ((total_checks++)) |
| 79 | + |
| 80 | + for dir in "${required_dirs[@]}"; do |
| 81 | + if [[ ! -d "$dir" ]]; then |
| 82 | + missing_dirs+=("$dir") |
| 83 | + fi |
| 84 | + done |
| 85 | + |
| 86 | + if [[ ${#missing_dirs[@]} -gt 0 ]]; then |
| 87 | + echo -e "${YELLOW}⚠ Missing directories: ${missing_dirs[*]}${NC}" |
| 88 | + return 1 |
| 89 | + else |
| 90 | + echo -e "${GREEN}✓ All required directories present${NC}" |
| 91 | + ((passed_checks++)) |
| 92 | + return 0 |
| 93 | + fi |
| 94 | +} |
| 95 | + |
| 96 | +function validate_version_tags() { |
| 97 | + ((total_checks++)) |
| 98 | + local tags=$(git tag -l) |
| 99 | + local semver_tags=() |
| 100 | + |
| 101 | + while IFS= read -r tag; do |
| 102 | + if [[ $tag =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 103 | + semver_tags+=("$tag") |
| 104 | + fi |
| 105 | + done <<< "$tags" |
| 106 | + |
| 107 | + if [[ ${#semver_tags[@]} -eq 0 ]]; then |
| 108 | + echo -e "${YELLOW}⚠ No semantic version tags found (e.g., v1.0.0)${NC}" |
| 109 | + return 1 |
| 110 | + else |
| 111 | + echo -e "${GREEN}✓ Found semantic version tags: ${semver_tags[*]}${NC}" |
| 112 | + ((passed_checks++)) |
| 113 | + return 0 |
| 114 | + fi |
| 115 | +} |
| 116 | + |
| 117 | +function validate_example_site() { |
| 118 | + ((total_checks++)) |
| 119 | + if [[ ! -d "exampleSite" ]]; then |
| 120 | + echo -e "${YELLOW}⚠ Missing exampleSite directory${NC}" |
| 121 | + return 1 |
| 122 | + fi |
| 123 | + |
| 124 | + local example_checks=0 |
| 125 | + check_required_file "exampleSite/config.toml" && ((example_checks++)) |
| 126 | + [[ -d "exampleSite/content" ]] && ((example_checks++)) |
| 127 | + |
| 128 | + if [[ $example_checks -eq 2 ]]; then |
| 129 | + echo -e "${GREEN}✓ exampleSite configuration valid${NC}" |
| 130 | + ((passed_checks++)) |
| 131 | + return 0 |
| 132 | + else |
| 133 | + echo -e "${YELLOW}⚠ Incomplete exampleSite configuration${NC}" |
| 134 | + return 1 |
| 135 | + fi |
| 136 | +} |
| 137 | + |
| 138 | +function validate_readme() { |
| 139 | + ((total_checks++)) |
| 140 | + local check_passed=1 |
| 141 | + |
| 142 | + if [[ ! -f "README.md" ]]; then |
| 143 | + echo -e "${RED}✗ Missing README.md${NC}" |
| 144 | + return 1 |
| 145 | + fi |
| 146 | + |
| 147 | + grep -q "hugo mod init" README.md && \ |
| 148 | + grep -q "module.imports" README.md && \ |
| 149 | + grep -q "hugo mod get" README.md |
| 150 | + |
| 151 | + if [[ $? -eq 0 ]]; then |
| 152 | + echo -e "${GREEN}✓ README contains module installation instructions${NC}" |
| 153 | + ((passed_checks++)) |
| 154 | + return 0 |
| 155 | + else |
| 156 | + echo -e "${YELLOW}⚠ README missing module installation instructions${NC}" |
| 157 | + return 1 |
| 158 | + fi |
| 159 | +} |
| 160 | + |
| 161 | +function validate_environment() { |
| 162 | + echo -e "\n${YELLOW}=== Environment Validation ===${NC}" |
| 163 | + |
| 164 | + # Check for required commands |
| 165 | + local required_commands=("git" "hugo" "grep") |
| 166 | + for cmd in "${required_commands[@]}"; do |
| 167 | + if ! command -v $cmd &> /dev/null; then |
| 168 | + echo -e "${RED}✗ Missing required command: $cmd${NC}" |
| 169 | + exit 1 |
| 170 | + fi |
| 171 | + done |
| 172 | + |
| 173 | + # Verify we're in a git repository |
| 174 | + if ! git rev-parse --is-inside-work-tree &> /dev/null; then |
| 175 | + echo -e "${RED}✗ Not in a git repository${NC}" |
| 176 | + exit 1 |
| 177 | + fi |
| 178 | +} |
| 179 | + |
| 180 | +function main() { |
| 181 | + validate_environment |
| 182 | + |
| 183 | + echo -e "\n${YELLOW}=== Theme Configuration Validation ===${NC}" |
| 184 | + validate_theme_toml |
| 185 | + validate_go_mod |
| 186 | + validate_directory_structure |
| 187 | + validate_version_tags |
| 188 | + validate_example_site |
| 189 | + validate_readme |
| 190 | + |
| 191 | + echo -e "\n${YELLOW}=== Validation Summary ===${NC}" |
| 192 | + echo -e "Passed checks: ${GREEN}$passed_checks${NC} / $total_checks" |
| 193 | + |
| 194 | + if [[ $passed_checks -eq $total_checks ]]; then |
| 195 | + echo -e "${GREEN}✓ All critical checks passed!${NC}" |
| 196 | + else |
| 197 | + echo -e "${RED}✗ Some checks failed. Review the output above.${NC}" |
| 198 | + exit 1 |
| 199 | + fi |
| 200 | +} |
| 201 | + |
| 202 | +main |
0 commit comments