@@ -41,8 +41,12 @@ inputs:
4141 description : " Secondary Go version for toolchain comparison"
4242 required : true
4343 go-sum-file :
44- description : " Path to go.sum file for cache key generation"
44+ description : " Path to go.sum file for cache key generation (single module mode only; ignored when enable-multi-module is true) "
4545 required : true
46+ enable-multi-module :
47+ description : " Enable multi-module mode - uses pattern **/go.sum to hash all go.sum files for cache keys, skips root go.sum validation"
48+ required : false
49+ default : " false"
4650
4751outputs :
4852 go-version-actual :
@@ -102,6 +106,7 @@ runs:
102106 # Validate go.sum exists for cache key generation
103107 # --------------------------------------------------------------------
104108 - name : 🔍 Validate go.sum exists
109+ if : ${{ inputs.enable-multi-module != 'true' }}
105110 shell : bash
106111 run : |
107112 GO_SUM_FILE="${{ inputs.go-sum-file }}"
@@ -131,35 +136,75 @@ runs:
131136 echo "📋 Input Values:"
132137 echo " matrix-os: '${{ inputs.matrix-os }}'"
133138 echo " go-sum-file: '${{ inputs.go-sum-file }}'"
139+ echo " enable-multi-module: '${{ inputs.enable-multi-module }}'"
134140
135- # Verify go.sum file details
136- GO_SUM_FILE="${{ inputs.go-sum-file }}"
137- if [ -f "$GO_SUM_FILE" ]; then
138- echo ""
139- echo "📄 Go.sum File Analysis:"
140- echo " Path: $GO_SUM_FILE"
141- echo " Size: $(wc -c < "$GO_SUM_FILE") bytes"
142- echo " Lines: $(wc -l < "$GO_SUM_FILE") lines"
143- echo " SHA256: $(sha256sum "$GO_SUM_FILE" | cut -d' ' -f1)"
141+ if [ "${{ inputs.enable-multi-module }}" == "true" ]; then
142+ # Multi-module mode - show all go.sum files
144143 echo ""
145- echo "🔍 First 5 lines of go.sum:"
146- head -5 "$GO_SUM_FILE" | sed 's/^/ /'
144+ echo "📦 Multi-module mode enabled"
145+ echo "🔍 Found go.sum files:"
146+ find . -name "go.sum" -type f | while read file; do
147+ echo " - $file ($(wc -l < "$file") lines, $(wc -c < "$file") bytes)"
148+ done
149+
147150 echo ""
148- echo "🔍 Last 3 lines of go.sum:"
149- tail -3 "$GO_SUM_FILE" | sed 's/^/ /'
151+ echo "🔑 Expected Module Cache Key Pattern:"
152+ echo " Pattern: ${{ inputs.matrix-os }}-gomod-multi-[hash-of-all-go.sum]"
153+ echo " Actual hash: ${{ hashFiles('**/go.sum') }}"
154+ echo " Complete key: ${{ inputs.matrix-os }}-gomod-multi-${{ hashFiles('**/go.sum') }}"
150155 else
151- echo "❌ ERROR: go.sum file not found at: $GO_SUM_FILE"
156+ # Single module mode - verify go.sum file
157+ GO_SUM_FILE="${{ inputs.go-sum-file }}"
158+ if [ -f "$GO_SUM_FILE" ]; then
159+ echo ""
160+ echo "📄 Go.sum File Analysis:"
161+ echo " Path: $GO_SUM_FILE"
162+ echo " Size: $(wc -c < "$GO_SUM_FILE") bytes"
163+ echo " Lines: $(wc -l < "$GO_SUM_FILE") lines"
164+ echo " SHA256: $(sha256sum "$GO_SUM_FILE" | cut -d' ' -f1)"
165+ echo ""
166+ echo "🔍 First 5 lines of go.sum:"
167+ head -5 "$GO_SUM_FILE" | sed 's/^/ /'
168+ echo ""
169+ echo "🔍 Last 3 lines of go.sum:"
170+ tail -3 "$GO_SUM_FILE" | sed 's/^/ /'
171+ else
172+ echo "❌ ERROR: go.sum file not found at: $GO_SUM_FILE"
173+ fi
174+
175+ # Show expected cache key pattern
176+ echo ""
177+ echo "🔑 Expected Module Cache Key Pattern:"
178+ echo " Pattern: ${{ inputs.matrix-os }}-gomod-[hash-of-go.sum]"
179+ echo " Actual hash: ${{ hashFiles(inputs.go-sum-file) }}"
180+ echo " Complete key: ${{ inputs.matrix-os }}-gomod-${{ hashFiles(inputs.go-sum-file) }}"
152181 fi
153182
154- # Show expected cache key pattern
155- echo ""
156- echo "🔑 Expected Module Cache Key Pattern:"
157- echo " Pattern: ${{ inputs.matrix-os }}-gomod-[hash-of-go.sum]"
158- echo " Actual hash: ${{ hashFiles(inputs.go-sum-file) }}"
159- echo " Complete key: ${{ inputs.matrix-os }}-gomod-${{ hashFiles(inputs.go-sum-file) }}"
160183 echo ""
161184 echo "============================================================"
162185
186+ # --------------------------------------------------------------------
187+ # Compute cache keys based on multi-module mode
188+ # --------------------------------------------------------------------
189+ - name : 🔑 Compute cache keys
190+ id : cache-keys
191+ shell : bash
192+ run : |
193+ if [ "${{ inputs.enable-multi-module }}" == "true" ]; then
194+ echo "📦 Multi-module mode enabled - using hash of all go.sum files"
195+ HASH="${{ hashFiles('**/go.sum') }}"
196+ echo "module-key=${{ inputs.matrix-os }}-gomod-multi-${HASH}" >> $GITHUB_OUTPUT
197+ echo "build-key=${{ inputs.matrix-os }}-gobuild-multi-${{ inputs.go-version }}-${HASH}" >> $GITHUB_OUTPUT
198+ echo "mode=multi" >> $GITHUB_OUTPUT
199+ else
200+ echo "📁 Single module mode - using hash of ${{ inputs.go-sum-file }}"
201+ HASH="${{ hashFiles(inputs.go-sum-file) }}"
202+ echo "module-key=${{ inputs.matrix-os }}-gomod-${HASH}" >> $GITHUB_OUTPUT
203+ echo "build-key=${{ inputs.matrix-os }}-gobuild-${{ inputs.go-version }}-${HASH}" >> $GITHUB_OUTPUT
204+ echo "mode=single" >> $GITHUB_OUTPUT
205+ fi
206+ echo "🔑 Cache keys computed successfully"
207+
163208 # --------------------------------------------------------------------
164209 # Restore Go module cache (shared across versions)
165210 # --------------------------------------------------------------------
@@ -168,7 +213,7 @@ runs:
168213 uses : actions/cache/restore@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
169214 with :
170215 path : ~/go/pkg/mod
171- key : ${{ inputs.matrix-os }}-gomod-${{ hashFiles(inputs.go-sum-file) }}
216+ key : ${{ steps.cache-keys.outputs.module-key }}
172217
173218 # --------------------------------------------------------------------
174219 # DEBUG: Build cache key components
@@ -185,18 +230,27 @@ runs:
185230 echo " matrix-os: '${{ inputs.matrix-os }}'"
186231 echo " go-version: '${{ inputs.go-version }}'"
187232 echo " go-sum-file: '${{ inputs.go-sum-file }}'"
233+ echo " enable-multi-module: '${{ inputs.enable-multi-module }}'"
188234
189- # Verify go.sum file details (for build cache key)
190- GO_SUM_FILE="${{ inputs.go-sum-file }}"
191- if [ -f "$GO_SUM_FILE" ]; then
235+ if [ "${{ inputs.enable-multi-module }}" == "true" ]; then
236+ # Multi-module mode - show summary of all go.sum files
192237 echo ""
193- echo "📄 Go.sum File Analysis (for build cache):"
194- echo " Path: $GO_SUM_FILE"
195- echo " Size: $(wc -c < "$GO_SUM_FILE") bytes"
196- echo " SHA256: $(sha256sum "$GO_SUM_FILE" | cut -d' ' -f1)"
197- echo " Last Modified: $(stat -c %y "$GO_SUM_FILE" 2>/dev/null || stat -f %Sm "$GO_SUM_FILE" 2>/dev/null || echo 'Unknown')"
238+ echo "📦 Multi-module mode enabled"
239+ echo "🔍 Go.sum files count: $(find . -name "go.sum" -type f | wc -l)"
240+ echo "🔑 Cache hash: ${{ hashFiles('**/go.sum') }}"
198241 else
199- echo "❌ ERROR: go.sum file not found at: $GO_SUM_FILE"
242+ # Single module mode - verify go.sum file details
243+ GO_SUM_FILE="${{ inputs.go-sum-file }}"
244+ if [ -f "$GO_SUM_FILE" ]; then
245+ echo ""
246+ echo "📄 Go.sum File Analysis (for build cache):"
247+ echo " Path: $GO_SUM_FILE"
248+ echo " Size: $(wc -c < "$GO_SUM_FILE") bytes"
249+ echo " SHA256: $(sha256sum "$GO_SUM_FILE" | cut -d' ' -f1)"
250+ echo " Last Modified: $(stat -c %y "$GO_SUM_FILE" 2>/dev/null || stat -f %Sm "$GO_SUM_FILE" 2>/dev/null || echo 'Unknown')"
251+ else
252+ echo "❌ ERROR: go.sum file not found at: $GO_SUM_FILE"
253+ fi
200254 fi
201255
202256 # Show cache paths that will be used
@@ -210,10 +264,17 @@ runs:
210264
211265 # Show expected cache key pattern
212266 echo ""
213- echo "🔑 Expected Build Cache Key Pattern:"
214- echo " Pattern: ${{ inputs.matrix-os }}-gobuild-${{ inputs.go-version }}-[hash-of-go.sum]"
215- echo " Actual hash: ${{ hashFiles(inputs.go-sum-file) }}"
216- echo " Complete key: ${{ inputs.matrix-os }}-gobuild-${{ inputs.go-version }}-${{ hashFiles(inputs.go-sum-file) }}"
267+ if [ "${{ inputs.enable-multi-module }}" == "true" ]; then
268+ echo "🔑 Expected Build Cache Key Pattern:"
269+ echo " Pattern: ${{ inputs.matrix-os }}-gobuild-multi-${{ inputs.go-version }}-[hash-of-all-go.sum]"
270+ echo " Actual hash: ${{ hashFiles('**/go.sum') }}"
271+ echo " Complete key: ${{ inputs.matrix-os }}-gobuild-multi-${{ inputs.go-version }}-${{ hashFiles('**/go.sum') }}"
272+ else
273+ echo "🔑 Expected Build Cache Key Pattern:"
274+ echo " Pattern: ${{ inputs.matrix-os }}-gobuild-${{ inputs.go-version }}-[hash-of-go.sum]"
275+ echo " Actual hash: ${{ hashFiles(inputs.go-sum-file) }}"
276+ echo " Complete key: ${{ inputs.matrix-os }}-gobuild-${{ inputs.go-version }}-${{ hashFiles(inputs.go-sum-file) }}"
277+ fi
217278 echo ""
218279 echo "============================================================"
219280
@@ -227,7 +288,7 @@ runs:
227288 path : |
228289 ~/.cache/go-build
229290 ~/.cache/go-build/test
230- key : ${{ inputs.matrix-os }}-gobuild-${{ inputs.go-version }}-${{ hashFiles(inputs.go-sum-file) }}
291+ key : ${{ steps.cache-keys.outputs.build-key }}
231292
232293 # --------------------------------------------------------------------
233294 # DEBUG: Cache restoration summary
@@ -247,17 +308,27 @@ runs:
247308 # Show the actual keys that were used
248309 echo ""
249310 echo "🔑 Actual Cache Keys Used:"
250- MODULE_KEY="${{ inputs.matrix-os }}-gomod-${{ hashFiles(inputs.go-sum-file) }}"
251- BUILD_KEY="${{ inputs.matrix-os }}-gobuild-${{ inputs.go-version }}-${{ hashFiles(inputs.go-sum-file) }}"
252- echo " Module: $MODULE_KEY"
253- echo " Build: $BUILD_KEY"
254-
255- # Break down the keys for analysis
256- echo ""
257- echo "🔍 Key Component Analysis:"
258- echo " OS component: '${{ inputs.matrix-os }}'"
259- echo " Go version component: '${{ inputs.go-version }}'"
260- echo " Go.sum hash component: '${{ hashFiles(inputs.go-sum-file) }}'"
311+ if [ "${{ inputs.enable-multi-module }}" == "true" ]; then
312+ MODULE_KEY="${{ inputs.matrix-os }}-gomod-multi-${{ hashFiles('**/go.sum') }}"
313+ BUILD_KEY="${{ inputs.matrix-os }}-gobuild-multi-${{ inputs.go-version }}-${{ hashFiles('**/go.sum') }}"
314+ echo " Module: $MODULE_KEY"
315+ echo " Build: $BUILD_KEY"
316+ echo ""
317+ echo "🔍 Key Component Analysis (Multi-module mode):"
318+ echo " OS component: '${{ inputs.matrix-os }}'"
319+ echo " Go version component: '${{ inputs.go-version }}'"
320+ echo " Go.sum hash component (all files): '${{ hashFiles('**/go.sum') }}'"
321+ else
322+ MODULE_KEY="${{ inputs.matrix-os }}-gomod-${{ hashFiles(inputs.go-sum-file) }}"
323+ BUILD_KEY="${{ inputs.matrix-os }}-gobuild-${{ inputs.go-version }}-${{ hashFiles(inputs.go-sum-file) }}"
324+ echo " Module: $MODULE_KEY"
325+ echo " Build: $BUILD_KEY"
326+ echo ""
327+ echo "🔍 Key Component Analysis (Single module mode):"
328+ echo " OS component: '${{ inputs.matrix-os }}'"
329+ echo " Go version component: '${{ inputs.go-version }}'"
330+ echo " Go.sum hash component: '${{ hashFiles(inputs.go-sum-file) }}'"
331+ fi
261332
262333 # Cache effectiveness summary
263334 echo ""
0 commit comments