-
Notifications
You must be signed in to change notification settings - Fork 328
181 lines (148 loc) · 5.85 KB
/
validate.yml
File metadata and controls
181 lines (148 loc) · 5.85 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
name: Validate Blueprints Structure and Meta
on:
pull_request:
branches:
- canary
push:
branches:
- canary
jobs:
validate:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Validate blueprint folders and files
run: |
echo "🔍 Validating blueprints folder structure..."
ERROR=0
# Loop through each blueprint folder
for dir in blueprints/*; do
if [ -d "$dir" ]; then
TEMPLATE_NAME=$(basename "$dir")
COMPOSE_FILE="$dir/docker-compose.yml"
TEMPLATE_FILE="$dir/template.toml"
if [ ! -f "$COMPOSE_FILE" ]; then
echo "❌ Missing docker-compose.yml in $TEMPLATE_NAME"
ERROR=1
fi
if [ ! -f "$TEMPLATE_FILE" ]; then
echo "❌ Missing template.toml in $TEMPLATE_NAME"
ERROR=1
fi
fi
done
if [ $ERROR -eq 1 ]; then
echo "❌ Blueprint folder validation failed."
exit 1
else
echo "✅ Blueprint folders validated successfully."
fi
- name: Validate meta.json structure and required fields
run: |
echo "🔍 Validating meta.json structure and required fields..."
# First check if meta.json exists and is valid JSON
if [ ! -f "meta.json" ]; then
echo "❌ meta.json file not found"
exit 1
fi
if ! jq empty meta.json 2>/dev/null; then
echo "❌ meta.json is not a valid JSON file"
exit 1
fi
ERROR=0
ERRORS_FOUND=""
# Debug: Show total number of entries
TOTAL_ENTRIES=$(jq '. | length' meta.json)
echo "📊 Total entries in meta.json: $TOTAL_ENTRIES"
# Get all entries at once and process them
TOTAL_INDEX=$(($TOTAL_ENTRIES - 1))
for i in $(seq 0 $TOTAL_INDEX); do
entry=$(jq -c ".[$i]" meta.json)
INDEX=$((i + 1))
echo "-------------------------------------------"
echo "🔍 Checking entry #$INDEX..."
# Get the ID for better error reporting
ID=$(echo "$entry" | jq -r '.id // "UNKNOWN"')
echo "📝 Processing entry with ID: $ID"
# Validate required top-level fields
for field in "id" "name" "version" "description" "logo" "links" "tags"; do
if [ "$(echo "$entry" | jq "has(\"$field\")")" != "true" ]; then
ERROR_MSG="❌ Entry #$INDEX (ID: $ID) is missing required field: $field"
echo "$ERROR_MSG"
ERRORS_FOUND="${ERRORS_FOUND}${ERROR_MSG}\n"
ERROR=1
fi
done
# Validate links object required fields
if [ "$(echo "$entry" | jq 'has("links")')" == "true" ]; then
for link_field in "github" "website" "docs"; do
if [ "$(echo "$entry" | jq ".links | has(\"$link_field\")")" != "true" ]; then
ERROR_MSG="❌ Entry #$INDEX (ID: $ID): links object is missing required field: $link_field"
echo "$ERROR_MSG"
ERRORS_FOUND="${ERRORS_FOUND}${ERROR_MSG}\n"
ERROR=1
fi
done
fi
# Validate tags array is not empty
if [ "$(echo "$entry" | jq '.tags | length')" -eq 0 ]; then
ERROR_MSG="❌ Entry #$INDEX (ID: $ID): tags array cannot be empty"
echo "$ERROR_MSG"
ERRORS_FOUND="${ERRORS_FOUND}${ERROR_MSG}\n"
ERROR=1
fi
done
echo "-------------------------------------------"
if [ $ERROR -eq 1 ]; then
echo "❌ meta.json structure validation failed."
echo -e "Summary of all errors found:${ERRORS_FOUND}"
exit 1
else
echo "✅ meta.json structure validated successfully."
fi
- name: Validate meta.json matches blueprint folders and logo files
run: |
echo "🔍 Validating meta.json against blueprint folders and logos..."
ERROR=0
# Read all blueprint folder names into an array
FOLDERS=($(ls -1 blueprints))
# Extract ids and logos from meta.json
IDS_AND_LOGOS=$(jq -c '.[] | {id, logo}' meta.json)
# Validate each id in meta.json exists as a folder
for item in $IDS_AND_LOGOS; do
ID=$(echo "$item" | jq -r '.id')
LOGO=$(echo "$item" | jq -r '.logo')
# Check if folder exists
if [ ! -d "blueprints/$ID" ]; then
echo "❌ meta.json id \"$ID\" does not have a matching folder in blueprints/"
ERROR=1
continue
fi
# Check if logo file exists inside its folder
if [ ! -f "blueprints/$ID/$LOGO" ]; then
echo "❌ Logo \"$LOGO\" defined for \"$ID\" does not exist in blueprints/$ID/"
ERROR=1
fi
done
# Validate each folder has a matching id in meta.json
META_IDS=$(jq -r '.[].id' meta.json)
for FOLDER in "${FOLDERS[@]}"; do
FOUND=0
for ID in $META_IDS; do
if [ "$FOLDER" == "$ID" ]; then
FOUND=1
break
fi
done
if [ "$FOUND" -eq 0 ]; then
echo "❌ Folder \"$FOLDER\" has no matching id in meta.json"
ERROR=1
fi
done
if [ $ERROR -eq 1 ]; then
echo "❌ meta.json validation failed."
exit 1
else
echo "✅ meta.json validated successfully."
fi