@@ -192,6 +192,7 @@ runs:
192192 if : ${{ inputs.enable-multi-module == 'true' }}
193193 shell : bash
194194 run : |
195+ set -euo pipefail
195196 echo "🔧 Multi-module mode - detecting workspace configuration"
196197
197198 # Check if go.work exists (workspace mode)
@@ -205,12 +206,31 @@ runs:
205206
206207 # Find and tidy each module in the workspace
207208 echo "🔍 Finding all modules in workspace..."
208- go list -f '{{.Dir}}' -m | while read -r module_dir; do
209- if [ -f "$module_dir/go.mod" ]; then
210- echo "🔧 Tidying module: $module_dir"
211- (cd "$module_dir" && go mod tidy)
209+ module_paths=$(go work edit -json | jq -r '(.Use // [])[].DiskPath')
210+ if [ -z "$module_paths" ]; then
211+ echo "⚠️ Warning: No modules found in workspace"
212+ fi
213+
214+ tidy_failed=0
215+ while read -r module_dir; do
216+ # Skip empty lines
217+ [ -n "$module_dir" ] || continue
218+
219+ if [ ! -f "$module_dir/go.mod" ]; then
220+ echo "❌ Module directory $module_dir is missing go.mod file"
221+ exit 1
212222 fi
213- done
223+ echo "🔧 Tidying module: $module_dir"
224+ if ! (cd "$module_dir" && go mod tidy); then
225+ echo "❌ Failed to tidy module: $module_dir"
226+ tidy_failed=1
227+ fi
228+ done <<< "$module_paths"
229+
230+ if [ "$tidy_failed" -ne 0 ]; then
231+ echo "❌ One or more modules failed to tidy"
232+ exit 1
233+ fi
214234
215235 echo "✅ All workspace modules synced and tidied successfully"
216236 else
0 commit comments