Skip to content

Commit 6ecfb3b

Browse files
authored
feat(update-checker): add workspace mode (#104)
1 parent bc19c7c commit 6ecfb3b

1 file changed

Lines changed: 75 additions & 9 deletions

File tree

.github/scripts/update-checker.sh

Lines changed: 75 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@
1313
# - Proper shebangs in command files
1414
# - Command files are executable
1515
#
16-
# Usage (run from the add-on root directory):
17-
# curl -fsSL https://ddev.com/s/addon-update-checker.sh | bash
16+
# Usage:
17+
# curl -fsSL https://ddev.com/s/addon-update-checker.sh | bash # run in current directory
18+
# curl -fsSL https://ddev.com/s/addon-update-checker.sh | bash -s /path # run in specific directory
19+
#
20+
# If the target directory contains install.yaml, checks run there. Otherwise, immediate
21+
# subdirectories that contain install.yaml are each checked (workspace mode).
1822
#
1923
# Note: This script is removed from add-ons created from this template.
2024
# Add-on developers should always use the remote version via curl.
@@ -27,6 +31,17 @@ set -o nounset
2731

2832
UPSTREAM=https://github.com/ddev/ddev-addon-template/blob/main
2933

34+
# Color support - disabled when NO_COLOR is set or stdout is not a terminal
35+
if [[ -z "${NO_COLOR:-}" && -t 1 ]]; then
36+
COLOR_GREEN='\033[0;32m'
37+
COLOR_RED='\033[0;31m'
38+
COLOR_RESET='\033[0m'
39+
else
40+
COLOR_GREEN=''
41+
COLOR_RED=''
42+
COLOR_RESET=''
43+
fi
44+
3045
# List to store info messages
3146
info_messages=()
3247

@@ -363,12 +378,24 @@ check_editorconfig() {
363378
fi
364379
}
365380

366-
# Main function
367-
main() {
368-
if [[ ! -f "install.yaml" ]]; then
369-
echo "ERROR: run this script from the add-on root directory, install.yaml is missing" >&2
370-
exit 1
381+
# Run checks in a single directory, printing header and colored exit code
382+
run_in_dir() {
383+
local dir=$1
384+
local exit_code=0
385+
printf "${COLOR_GREEN}Running add-on update checker in: %s${COLOR_RESET}\n" "$dir"
386+
(cd "$dir" && run_checks) || exit_code=$?
387+
if [[ $exit_code -eq 0 ]]; then
388+
printf "${COLOR_GREEN}Exit code: %d${COLOR_RESET}\n" "$exit_code"
389+
else
390+
printf "${COLOR_RED}Exit code: %d${COLOR_RESET}\n" "$exit_code"
371391
fi
392+
return "$exit_code"
393+
}
394+
395+
# Run checks in the current directory (which must contain install.yaml)
396+
run_checks() {
397+
info_messages=()
398+
actions=()
372399

373400
# Check unnecessary files
374401
check_remove_file "docker-compose.addon-template.yaml"
@@ -435,11 +462,50 @@ main() {
435462
for action in "${actions[@]}"; do
436463
echo "- $action" >&2
437464
done
438-
exit 1
465+
return 1
439466
else
440467
echo "All checks passed, no actions needed."
441468
fi
442469
}
443470

471+
# Main entry point - accepts an optional directory argument (defaults to current directory).
472+
# If the directory contains install.yaml, checks run there. Otherwise, immediate subdirectories
473+
# that contain install.yaml are each checked (workspace mode).
474+
main() {
475+
local root_dir="${1:-.}"
476+
root_dir="$(cd "$root_dir" && pwd)"
477+
478+
if [[ -f "$root_dir/install.yaml" ]]; then
479+
run_in_dir "$root_dir"
480+
return
481+
fi
482+
483+
# Workspace mode: scan immediate subdirectories for install.yaml
484+
local dirs
485+
dirs=()
486+
local entry
487+
for entry in "$root_dir"/*/; do
488+
if [[ -d "$entry" && -f "${entry}install.yaml" ]]; then
489+
dirs+=("$entry")
490+
fi
491+
done
492+
493+
if [[ ${#dirs[@]} -eq 0 ]]; then
494+
printf "${COLOR_RED}ERROR: No install.yaml found in %s or its immediate subdirectories${COLOR_RESET}\n" "$root_dir" >&2
495+
exit 1
496+
fi
497+
498+
local had_error=false
499+
local dir
500+
for dir in "${dirs[@]}"; do
501+
echo ""
502+
run_in_dir "$dir" || had_error=true
503+
done
504+
505+
if [[ "$had_error" == "true" ]]; then
506+
exit 1
507+
fi
508+
}
509+
444510
# Run the main function
445-
main
511+
main "${1:-}"

0 commit comments

Comments
 (0)