@@ -21,78 +21,132 @@ command -v flutter >/dev/null 2>&1 || { echo >&2 "Error: 'flutter' command not f
21
21
# calls for each one.
22
22
23
23
FAILURE_LOG=$( mktemp)
24
- trap ' rm -f "$FAILURE_LOG"' EXIT
24
+ LOG_DIR=$( mktemp -d)
25
+ trap ' rm -f "$FAILURE_LOG"; rm -rf "$LOG_DIR"' EXIT
25
26
26
- readonly PROJECT_TOTAL_STEPS=3
27
+ readonly PROJECT_TOTAL_STEPS=4
27
28
28
29
run_project_step () {
29
30
local project_dir=" $1 "
30
31
local description=" $2 "
31
32
local step_num=" $3 "
32
33
shift 3
33
- local cmd_str=$( printf ' %q ' " $@ " ) ; cmd_str=${cmd_str% }
34
-
35
- echo " [$step_num /$PROJECT_TOTAL_STEPS ] $description ..."
36
- echo " To rerun this command:"
37
- echo " cd \" $project_dir \" && $cmd_str "
38
- if ! " $@ " ; then
39
- echo " '$cmd_str ' failed in \" $project_dir \" " >> " $FAILURE_LOG "
34
+ local cmd_to_run=($@ )
35
+ local cmd_str_to_run=$( printf ' %q ' " ${cmd_to_run[@]} " ) ; cmd_str_to_run=${cmd_str_to_run% }
36
+
37
+ # Create a version of the command for display, removing the reporter flag.
38
+ local cmd_for_display=()
39
+ for arg in " ${cmd_to_run[@]} " ; do
40
+ if [[ " $arg " != " --reporter=failures-only" ]]; then
41
+ cmd_for_display+=(" $arg " )
42
+ fi
43
+ done
44
+ local cmd_str_for_display=$( printf ' %q ' " ${cmd_for_display[@]} " ) ; cmd_str_for_display=${cmd_str_for_display% }
45
+
46
+ echo " "
47
+ echo " ### [$step_num /$PROJECT_TOTAL_STEPS ] $description "
48
+ echo " > To rerun this command:"
49
+ echo " >
50
+ > (cd \" $project_dir \" && $cmd_str_for_display )
51
+ > "
52
+ if ! " ${cmd_to_run[@]} " ; then
53
+ echo " '(cd \" $project_dir \" && $cmd_str_to_run )' failed" >> " $FAILURE_LOG "
40
54
fi
41
55
}
42
56
57
+ process_project () {
58
+ local project_dir=" $1 "
59
+ (
60
+ echo " ## Processing project in: \` $project_dir \` "
61
+ echo " ---"
62
+
63
+ # Navigate into the project's directory.
64
+ cd " $project_dir " || exit 1
65
+
66
+ run_project_step " $project_dir " " Applying fixes with 'dart fix --apply'" 1 dart fix --apply
67
+ run_project_step " $project_dir " " Formatting with 'dart format .'" 2 dart format .
68
+ if [ -d " test" ]; then
69
+ run_project_step " $project_dir " " Running tests with 'flutter test'" 3 flutter test --reporter=failures-only
70
+ else
71
+ echo " "
72
+ echo " ### [3/$PROJECT_TOTAL_STEPS ] Skipping tests, no 'test' directory found."
73
+ fi
74
+ run_project_step " $project_dir " " Analyzing code with 'flutter analyze'" 4 flutter analyze
75
+
76
+ echo " "
77
+ echo " ---"
78
+ echo " Finished processing \` $project_dir \` ."
79
+ echo " "
80
+ )
81
+ }
43
82
44
83
# --- 0. Run commands at the root project level ---
45
- echo " Running root-level commands... "
46
- echo " -------------------------------------------------- "
84
+ echo " ## Running root-level commands"
85
+ echo " ---"
47
86
# Check if the copyright tool exists before running
48
87
if [ -f " tool/fix_copyright/bin/fix_copyright.dart" ]; then
49
- echo " Running copyright fix. To rerun:"
50
- echo " dart run tool/fix_copyright/bin/fix_copyright.dart --force"
88
+ echo " ### Running copyright fix"
89
+ echo " > To rerun this command:"
90
+ echo " >
91
+ > dart run tool/fix_copyright/bin/fix_copyright.dart --force
92
+ > "
51
93
# Log failures without stopping the script.
52
- dart run tool/fix_copyright/bin/fix_copyright.dart --force || echo " 'dart run tool/fix_copyright/bin/fix_copyright.dart --force' failed " >> " $FAILURE_LOG "
94
+ dart run tool/fix_copyright/bin/fix_copyright.dart --force > /dev/null 2>&1 || true
53
95
else
54
- echo " Warning: Copyright tool not found. Skipping."
96
+
97
+ echo " ### Skipping copyright fix: tool not found."
55
98
fi
56
- # Log failures without stopping the script.
57
- echo " Running dart format. To rerun:"
58
- echo " dart format ."
59
- dart format . || echo " 'dart format .' failed" >> " $FAILURE_LOG "
99
+ echo " ---"
60
100
echo " Root-level commands complete."
61
101
echo " "
62
102
63
103
# --- 1. Find all Flutter projects ---
64
104
# We find all `pubspec.yaml` files and process each one.
65
105
# The `find ... -print0 | while ...` construct safely handles file paths with spaces.
66
106
echo " Searching for Flutter projects..."
67
- echo " =================================================="
68
- find . -name " build" -type d -prune -o -name " .dart_tool" -type d -prune -o -path " ./melos_tool" -prune -o -name " pubspec.yaml" -exec grep -q ' sdk: flutter' {} \; -print0 | while IFS= read -r -d ' ' pubspec_path; do
69
- (
70
- # Get the directory containing the pubspec.yaml file.
71
- project_dir=$( dirname " $pubspec_path " )
72
-
73
- echo " Processing project in: $project_dir "
74
- echo " --------------------------------------------------"
75
107
76
- # Navigate into the project's directory.
77
- cd " $project_dir " || exit 1
78
-
79
- run_project_step " $project_dir " " Applying fixes with 'dart fix --apply'" 1 dart fix --apply
80
- echo " "
81
- run_project_step " $project_dir " " Running tests with 'flutter test'" 2 flutter test
82
- echo " "
83
- run_project_step " $project_dir " " Analyzing code with 'flutter analyze'" 3 flutter analyze
84
-
85
- echo " Finished processing $project_dir ."
86
- echo " "
87
- )
108
+ # Collect all project directories first to process them in a stable order.
109
+ project_dirs=()
110
+ while IFS= read -r -d ' ' pubspec_path; do
111
+ project_dirs+=(" $( dirname " $pubspec_path " ) " )
112
+ done < <( find . -name " build" -type d -prune -o -name " .dart_tool" -type d -prune -o -path " ./melos_tool" -prune -o -path " ./packages/spikes" -prune -o -name " pubspec.yaml" -exec grep -q ' sdk: flutter' {} \; -print0)
113
+
114
+ # Run processing in parallel for each project.
115
+ pids=()
116
+ log_files=()
117
+ for i in " ${! project_dirs[@]} " ; do
118
+ project_dir=" ${project_dirs[$i]} "
119
+ log_file=" $LOG_DIR /project_$i .log"
120
+ log_files+=(" $log_file " )
121
+
122
+ # Run the processing in the background, redirecting output to the log file.
123
+ process_project " $project_dir " > " $log_file " 2>&1 &
124
+ pids+=($! )
88
125
done
89
126
127
+ # Wait for all background jobs to complete.
128
+ echo " ## Running tests and analysis for ${# project_dirs[@]} projects in parallel"
129
+ for project_dir in " ${project_dirs[@]} " ; do
130
+ echo " - \` $project_dir \` "
131
+ done
132
+ echo " "
133
+ wait " ${pids[@]} "
134
+ echo " ## All projects have been processed."
90
135
echo " =================================================="
91
- echo " All projects have been processed."
92
- echo " =================================================="
136
+ echo " "
137
+
138
+ # Print the logs from each project in the original order.
139
+ for log_file in " ${log_files[@]} " ; do
140
+ cat " $log_file "
141
+ done
93
142
94
143
if [ -s " $FAILURE_LOG " ]; then
95
- echo " Tooling errors occurred:" >&2
144
+ echo " "
145
+ echo " ## Tooling errors occurred:" >&2
146
+ echo '
147
+ ```' >&2
96
148
cat " $FAILURE_LOG " >&2
149
+ echo '
150
+ ```' >&2
97
151
exit 1
98
- fi
152
+ fi
0 commit comments