-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate.sh
More file actions
executable file
·126 lines (113 loc) · 3.12 KB
/
Copy pathvalidate.sh
File metadata and controls
executable file
·126 lines (113 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
# validate.sh — validate charm structure and syntax
set -euo pipefail
ERRORS=0
WARNINGS=0
info() { echo " ✓ $*"; }
warn() { echo " ⚠ $*"; WARNINGS=$((WARNINGS + 1)); }
fail() { echo " ✗ $*"; ERRORS=$((ERRORS + 1)); }
echo "=== Hermes Charm Validation ==="
echo
# ---- Required files ----
echo "Checking required files..."
for f in charmcraft.yaml metadata.yaml config.yaml actions.yaml README.md LICENSE; do
if [ -f "$f" ]; then
info "$f exists"
else
fail "$f missing"
fi
done
# ---- Hooks ----
echo
echo "Checking hooks..."
REQUIRED_HOOKS="install config-changed start stop remove update-status upgrade-charm"
for hook in $REQUIRED_HOOKS; do
if [ -f "hooks/$hook" ]; then
if [ -x "hooks/$hook" ]; then
info "hooks/$hook (executable)"
else
fail "hooks/$hook not executable"
fi
# Syntax check
if bash -n "hooks/$hook" 2>/dev/null; then
info "hooks/$hook syntax OK"
else
fail "hooks/$hook has syntax errors"
fi
else
fail "hooks/$hook missing"
fi
done
# common.sh
if [ -f "hooks/common.sh" ]; then
if bash -n "hooks/common.sh" 2>/dev/null; then
info "hooks/common.sh syntax OK"
else
fail "hooks/common.sh has syntax errors"
fi
else
fail "hooks/common.sh missing"
fi
# ---- Actions ----
echo
echo "Checking actions..."
if [ -d "actions" ]; then
for action in actions/*; do
[ -f "$action" ] || continue
name=$(basename "$action")
if [ -x "$action" ]; then
info "actions/$name (executable)"
else
fail "actions/$name not executable"
fi
if bash -n "$action" 2>/dev/null; then
info "actions/$name syntax OK"
else
fail "actions/$name has syntax errors"
fi
done
else
warn "actions/ directory missing"
fi
# ---- YAML validation (basic) ----
echo
echo "Checking YAML structure..."
if command -v python3 &>/dev/null; then
for yaml_file in charmcraft.yaml metadata.yaml config.yaml actions.yaml; do
if [ -f "$yaml_file" ]; then
if python3 -c "import yaml; yaml.safe_load(open('$yaml_file'))" 2>/dev/null; then
info "$yaml_file valid YAML"
else
fail "$yaml_file invalid YAML"
fi
fi
done
else
warn "python3 not available — skipping YAML validation"
fi
# ---- metadata.yaml checks ----
echo
echo "Checking metadata.yaml content..."
if command -v python3 &>/dev/null && [ -f "metadata.yaml" ]; then
NAME=$(python3 -c "import yaml; print(yaml.safe_load(open('metadata.yaml')).get('name',''))" 2>/dev/null)
if [ "$NAME" = "hermes" ]; then
info "charm name is 'hermes'"
else
fail "charm name should be 'hermes', got '$NAME'"
fi
fi
# ---- Summary ----
echo
echo "=== Summary ==="
echo " Errors: $ERRORS"
echo " Warnings: $WARNINGS"
if [ $ERRORS -gt 0 ]; then
echo
echo "FAILED — fix errors before packing"
exit 1
fi
if [ $WARNINGS -gt 0 ]; then
echo "PASSED with warnings"
else
echo "ALL CHECKS PASSED ✓"
fi