Skip to content

Commit 9568d28

Browse files
committed
feat(update-checker): check for #ddev-generated comment
1 parent bd2d894 commit 9568d28

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

.github/scripts/update-checker.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,62 @@ check_license() {
316316
fi
317317
}
318318

319+
# Check that files listed in install.yaml project_files/global_files contain exactly one #ddev-generated
320+
check_ddev_generated() {
321+
local install_yaml="install.yaml"
322+
323+
local line entry count in_section section dir_file
324+
local list_item_re='^[[:space:]]*-[[:space:]]+(.*)'
325+
326+
for section in project_files global_files; do
327+
in_section=false
328+
while IFS= read -r line; do
329+
# Detect section header
330+
if [[ "$line" == "${section}:" ]]; then
331+
in_section=true
332+
continue
333+
fi
334+
335+
[[ "$in_section" != "true" ]] && continue
336+
337+
# A top-level YAML key (starts with a letter) ends the section
338+
[[ "$line" =~ ^[a-zA-Z] ]] && break
339+
340+
# Match non-commented list entries with any indentation: "- <value>"
341+
[[ "$line" =~ $list_item_re ]] || continue
342+
entry="${BASH_REMATCH[1]}"
343+
344+
[[ -z "$entry" ]] && continue
345+
346+
# Skip entries with environment variable interpolation (can't resolve at check time)
347+
[[ "$entry" =~ \$\{ ]] && continue
348+
349+
# For directories, check all files inside recursively
350+
if [[ -d "$entry" ]]; then
351+
while IFS= read -r -d '' dir_file; do
352+
count=$(grep -c "#ddev-generated" "$dir_file" 2>/dev/null) || count=0
353+
if [[ "$count" -eq 0 ]]; then
354+
actions+=("$dir_file (in directory $entry listed in install.yaml $section) does not contain '#ddev-generated'")
355+
elif [[ "$count" -gt 1 ]]; then
356+
actions+=("$dir_file (in directory $entry listed in install.yaml $section) should contain exactly one '#ddev-generated', found $count occurrences")
357+
fi
358+
done < <(find "$entry" -type f -print0 2>/dev/null)
359+
continue
360+
fi
361+
362+
[[ ! -f "$entry" ]] && continue
363+
364+
count=$(grep -c "#ddev-generated" "$entry" 2>/dev/null) || count=0
365+
366+
if [[ "$count" -eq 0 ]]; then
367+
actions+=("$entry is listed in install.yaml ($section) but does not contain '#ddev-generated'")
368+
elif [[ "$count" -gt 1 ]]; then
369+
actions+=("$entry is listed in install.yaml ($section) should contain exactly one '#ddev-generated', found $count occurrences")
370+
fi
371+
done < "$install_yaml"
372+
done
373+
}
374+
319375
# Check .gitattributes
320376
check_gitattributes() {
321377
local gitattributes=".gitattributes"
@@ -415,6 +471,9 @@ run_checks() {
415471
# Check install.yaml for conditions
416472
check_install_yaml
417473

474+
# Check #ddev-generated in files listed in install.yaml
475+
check_ddev_generated
476+
418477
# Check docker-compose.*.yaml for conditions
419478
check_docker_compose_yaml
420479

0 commit comments

Comments
 (0)