@@ -175,7 +175,7 @@ jobs:
175175 # Restore (and later save) a compact cache for the go-coverage binary
176176 # Skip cache when using local development version
177177 # ————————————————————————————————————————————————————————————————
178- - name : 💾 Restore go-coverage binary cache
178+ - name : 💾 Restore go-coverage binary cache (production)
179179 id : go-coverage-cache
180180 if : env.GO_COVERAGE_USE_LOCAL != 'true'
181181 uses : actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
@@ -184,7 +184,20 @@ jobs:
184184 ~/.cache/go-coverage-bin
185185 key : ${{ inputs.primary-runner }}-go-coverage-${{ env.GO_COVERAGE_VERSION }}
186186
187- - name : 🛠️ Make cached go-coverage usable
187+ # Restore cache for local development builds (branch and commit specific)
188+ # ————————————————————————————————————————————————————————————————
189+ - name : 💾 Restore go-coverage binary cache (local)
190+ id : go-coverage-local-cache
191+ if : env.GO_COVERAGE_USE_LOCAL == 'true'
192+ uses : actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
193+ with :
194+ path : |
195+ ~/.cache/go-coverage-local
196+ key : ${{ inputs.primary-runner }}-local-go-coverage-${{ inputs.branch-name }}-${{ inputs.commit-sha }}
197+ restore-keys : |
198+ ${{ inputs.primary-runner }}-local-go-coverage-${{ inputs.branch-name }}-
199+
200+ - name : 🛠️ Make cached go-coverage usable (production)
188201 if : env.GO_COVERAGE_USE_LOCAL != 'true'
189202 run : |
190203 set -euo pipefail
@@ -199,6 +212,28 @@ jobs:
199212 # Make sure the binary location is on PATH for *all* subsequent steps.
200213 echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH"
201214
215+ - name : 🛠️ Make cached go-coverage usable (local)
216+ if : env.GO_COVERAGE_USE_LOCAL == 'true'
217+ run : |
218+ set -euo pipefail
219+ BIN_DIR="$HOME/.cache/go-coverage-local"
220+ GO_COVERAGE_BIN="$BIN_DIR/go-coverage"
221+ COMMIT_MARKER="$BIN_DIR/commit-sha"
222+ # If we restored a cache, verify it's from the correct commit
223+ if [[ -f "$GO_COVERAGE_BIN" && -f "$COMMIT_MARKER" ]]; then
224+ CACHED_COMMIT=$(cat "$COMMIT_MARKER")
225+ if [[ "$CACHED_COMMIT" == "${{ inputs.commit-sha }}" ]]; then
226+ echo "✅ Using cached local go-coverage binary (commit: ${CACHED_COMMIT:0:8})"
227+ mkdir -p "$(go env GOPATH)/bin"
228+ cp "$GO_COVERAGE_BIN" "$(go env GOPATH)/bin/"
229+ else
230+ echo "⚠️ Cached binary is from different commit (cached: ${CACHED_COMMIT:0:8}, current: ${{ inputs.commit-sha }}), will rebuild"
231+ rm -f "$GO_COVERAGE_BIN" "$COMMIT_MARKER"
232+ fi
233+ fi
234+ # Make sure the binary location is on PATH for *all* subsequent steps.
235+ echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH"
236+
202237 - name : 🎯 Set go-coverage binary path
203238 run : |
204239 # Set the binary path for both cache hit and cache miss scenarios
@@ -213,28 +248,40 @@ jobs:
213248 run : |
214249 # Check if we should use local development version
215250 if [[ "${{ env.GO_COVERAGE_USE_LOCAL }}" == "true" ]]; then
216- echo "📦 Using local development version of go-coverage"
217- echo " Building from source at: $GITHUB_WORKSPACE/cmd/go-coverage"
251+ # Check if we already have a current binary from cache restoration
252+ if [[ -f "$(go env GOPATH)/bin/go-coverage" ]]; then
253+ echo "✅ Local go-coverage binary already available from cache"
254+ echo "GO_COVERAGE_BINARY=$(go env GOPATH)/bin/go-coverage" >> $GITHUB_ENV
255+ "$(go env GOPATH)/bin/go-coverage" --version || echo "Version info not available for cached build"
256+ else
257+ echo "📦 Building local development version of go-coverage"
258+ echo " Building from source at: $GITHUB_WORKSPACE/cmd/go-coverage"
259+ echo " Branch: ${{ inputs.branch-name }}"
260+ echo " Commit: ${{ inputs.commit-sha }}"
218261
219- # Build from local source
220- cd "$GITHUB_WORKSPACE"
221- go build -v -o /tmp/go-coverage ./cmd/go-coverage
222- chmod +x /tmp/go-coverage
262+ # Build from local source
263+ cd "$GITHUB_WORKSPACE"
264+ go build -v -o /tmp/go-coverage ./cmd/go-coverage
265+ chmod +x /tmp/go-coverage
223266
224- # Copy the freshly built binary to cache directory
225- mkdir -p ~/.cache/go-coverage-bin
226- cp /tmp/go-coverage ~/.cache/go-coverage-bin /
267+ # Copy the freshly built binary to local cache directory
268+ mkdir -p ~/.cache/go-coverage-local
269+ cp /tmp/go-coverage ~/.cache/go-coverage-local /
227270
228- # Also copy to GOPATH/bin for immediate use
229- mkdir -p "$(go env GOPATH)/bin"
230- cp /tmp/go-coverage "$(go env GOPATH)/bin/go-coverage"
271+ # Store commit SHA marker for cache validation
272+ echo "${{ inputs.commit-sha }}" > ~/.cache/go-coverage-local/commit-sha
231273
232- # Store the binary path
233- echo "GO_COVERAGE_BINARY=$(go env GOPATH)/bin/go-coverage" >> $GITHUB_ENV
274+ # Also copy to GOPATH/bin for immediate use
275+ mkdir -p "$(go env GOPATH)/bin"
276+ cp /tmp/go-coverage "$(go env GOPATH)/bin/go-coverage"
234277
235- # Show version info
236- echo "✅ Local go-coverage built and stored in cache"
237- "$(go env GOPATH)/bin/go-coverage" --version || echo "Version info not available for local build"
278+ # Store the binary path
279+ echo "GO_COVERAGE_BINARY=$(go env GOPATH)/bin/go-coverage" >> $GITHUB_ENV
280+
281+ # Show version info
282+ echo "✅ Local go-coverage built and cached (commit: ${{ inputs.commit-sha }})"
283+ "$(go env GOPATH)/bin/go-coverage" --version || echo "Version info not available for local build"
284+ fi
238285 else
239286 # Use production version
240287 VERSION="${{ env.GO_COVERAGE_VERSION }}"
0 commit comments