@@ -160,9 +160,10 @@ runs:
160160 fi
161161
162162 # --------------------------------------------------------------------
163- # Ensure go.sum exists and download modules
163+ # Ensure go.sum exists (single-module mode only)
164164 # --------------------------------------------------------------------
165- - name : 📋 Ensure go.sum exists
165+ - name : 📋 Ensure go.sum exists (single-module)
166+ if : ${{ inputs.enable-multi-module != 'true' }}
166167 shell : bash
167168 run : |
168169 GO_SUM_FILE="${{ inputs.go-sum-file }}"
@@ -171,11 +172,7 @@ runs:
171172 echo "🔍 Checking for go.sum file at: $GO_SUM_FILE"
172173 if [ ! -f "$GO_SUM_FILE" ]; then
173174 echo "⚠️ Go.sum not found at $GO_SUM_FILE, running 'magex tidy' to generate it."
174- if [ "$ENABLE_MULTI_MODULE_TESTING" == "true" ]; then
175- echo "🔧 Multi-module mode - running magex tidy from repository root"
176- echo "📦 magex will discover all Go modules"
177- magex tidy
178- elif [ -n "$GO_MODULE_DIR" ]; then
175+ if [ -n "$GO_MODULE_DIR" ]; then
179176 echo "🔧 Running magex tidy from directory: $GO_MODULE_DIR"
180177 (cd "$GO_MODULE_DIR" && magex tidy)
181178 else
@@ -187,6 +184,43 @@ runs:
187184 echo "✅ Go.sum already exists at $GO_SUM_FILE"
188185 fi
189186
187+ # --------------------------------------------------------------------
188+ # Ensure all modules are tidy (multi-module mode only)
189+ # Handles both go.work workspaces and single-module repos with multi-module testing enabled
190+ # --------------------------------------------------------------------
191+ - name : 📋 Ensure modules are tidy (multi-module)
192+ if : ${{ inputs.enable-multi-module == 'true' }}
193+ shell : bash
194+ run : |
195+ echo "🔧 Multi-module mode - detecting workspace configuration"
196+
197+ # Check if go.work exists (workspace mode)
198+ if [ -f "go.work" ]; then
199+ echo "📦 go.work workspace detected - syncing and tidying all modules"
200+ echo "ℹ️ No root go.sum validation required (go.work manages workspace modules)"
201+
202+ # Sync the workspace
203+ echo "🔄 Running 'go work sync' to synchronize workspace modules..."
204+ go work sync
205+
206+ # Find and tidy each module in the workspace
207+ 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)
212+ fi
213+ done
214+
215+ echo "✅ All workspace modules synced and tidied successfully"
216+ else
217+ # No go.work - single module with multi-module testing enabled
218+ echo "📁 No go.work file - running single module tidy from repository root"
219+ echo "ℹ️ Multi-module testing mode without workspace (legacy behavior)"
220+ magex tidy
221+ echo "✅ Module tidied successfully"
222+ fi
223+
190224 # ────────────────────────────────────────────────────────────────────────────
191225 # Ensure cache directories exist
192226 # ────────────────────────────────────────────────────────────────────────────
0 commit comments