Skip to content

saving cache#1834

Merged
shimat merged 2 commits intomainfrom
cache_savings
Mar 2, 2026
Merged

saving cache#1834
shimat merged 2 commits intomainfrom
cache_savings

Conversation

@shimat
Copy link
Owner

@shimat shimat commented Mar 1, 2026

Summary by CodeRabbit

  • Chores
    • Optimized CI/CD caching across Docker, Linux ARM, Ubuntu, and WebAssembly workflows.
    • Simplified cache keys by removing a redundant revision variable.
    • Scoped caches to specific build artifacts (include/lib) for Ubuntu workflows.
    • Reduced Docker cache footprint to improve efficiency and consistency of builds.

@shimat shimat self-assigned this Mar 1, 2026
@coderabbitai
Copy link

coderabbitai bot commented Mar 1, 2026

📝 Walkthrough

Walkthrough

Multiple GitHub Actions workflows were changed: OPENCV_CACHE_VERSION was removed and cache keys simplified across several workflows; ubuntu and ubuntu-slim workflows now target include and lib subdirectories for OpenCV caches; docker-test-ubuntu workflow changed the docker build-push cache-to parameter from max to min.

Changes

Cohort / File(s) Summary
OpenCV cache key removal
.github/workflows/linux-arm.yml, .github/workflows/wasm.yml
Removed OPENCV_CACHE_VERSION and dropped the -rev${{ env.OPENCV_CACHE_VERSION }} suffix from cache key construction (restore/save). Added restore-keys prefix in linux-arm restore step.
OpenCV cache path narrowing & key simplification
.github/workflows/ubuntu.yml, .github/workflows/ubuntu-slim.yml
Removed OPENCV_CACHE_VERSION; restore/save steps now target opencv_artifacts/include and opencv_artifacts/lib (instead of whole opencv_artifacts/) and use simplified cache keys without the rev component.
Docker cache strategy change
.github/workflows/docker-test-ubuntu.yml
Adjusted docker/build-push step's cache-to parameter from max to min, changing cache behavior during image builds.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title is vague and generic, using the term 'saving cache' without conveying specific details about what cache strategy changes are being made or why. Consider using a more descriptive title such as 'Remove OPENCV_CACHE_VERSION from workflows' or 'Simplify cache keys in GitHub Actions workflows' to clearly communicate the main change.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cache_savings

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
.github/workflows/linux-arm.yml (1)

56-56: Add automatic cache invalidation to the OpenCV cache key.

The cache key at lines 56 and 127 only varies by OpenCV version. Unlike other workflows in this repository (e.g., ubuntu.yml includes matrix.ubuntu, wasm.yml includes env.EM_VERSION), this workflow lacks additional differentiators. If build options or workflow logic change under the same OPENCV_VERSION, stale binaries will be restored.

Consider using:

-          key: opencv-arm-${{ env.OPENCV_VERSION }}
+          key: opencv-arm-${{ env.OPENCV_VERSION }}-${{ hashFiles('.github/workflows/linux-arm.yml') }}
+          restore-keys: |
+            opencv-arm-${{ env.OPENCV_VERSION }}-

Apply the same change to both the restore step (line 56) and save step (line 127).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/linux-arm.yml at line 56, The cache key currently uses
only "key: opencv-arm-${{ env.OPENCV_VERSION }}" which can restore stale
artifacts when build options change; update both the restore and save cache
steps that reference this key (the lines with key: opencv-arm-${{
env.OPENCV_VERSION }}) to include an additional differentiator such as a
build-options hash or a workflow/environment variable (for example append
env.BUILD_FLAGS, matrix entries, or GITHUB_SHA/GITHUB_RUN_NUMBER) so the cache
key changes whenever relevant build settings or the commit change, ensuring
automatic invalidation of stale OpenCV caches.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In @.github/workflows/linux-arm.yml:
- Line 56: The cache key currently uses only "key: opencv-arm-${{
env.OPENCV_VERSION }}" which can restore stale artifacts when build options
change; update both the restore and save cache steps that reference this key
(the lines with key: opencv-arm-${{ env.OPENCV_VERSION }}) to include an
additional differentiator such as a build-options hash or a workflow/environment
variable (for example append env.BUILD_FLAGS, matrix entries, or
GITHUB_SHA/GITHUB_RUN_NUMBER) so the cache key changes whenever relevant build
settings or the commit change, ensuring automatic invalidation of stale OpenCV
caches.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3001e35 and 8bed691.

📒 Files selected for processing (5)
  • .github/workflows/docker-test-ubuntu.yml
  • .github/workflows/linux-arm.yml
  • .github/workflows/ubuntu-slim.yml
  • .github/workflows/ubuntu.yml
  • .github/workflows/wasm.yml

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.github/workflows/linux-arm.yml:
- Around line 56-58: The cache restore/save keys are mismatched: align the
restore key prefix and saved key format so restore can hit the saved cache by
making the restore key use the same full pattern as the save key (opencv-arm-${{
env.OPENCV_VERSION }}-${{ hashFiles(...) }} and keep restore-keys prefix
opencv-arm-${{ env.OPENCV_VERSION }}-); also change the hashFiles argument to
point at the checked-out repo path used by checkout (use
opencvsharp/.github/workflows/linux-arm.yml instead of
.github/workflows/linux-arm.yml) so the calculated hash matches the saved key;
update both occurrences (the restore key block and the save cache key) to use
the identical pattern.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8bed691 and ac8f633.

📒 Files selected for processing (1)
  • .github/workflows/linux-arm.yml

Comment on lines +56 to +58
key: opencv-arm-${{ env.OPENCV_VERSION }}-${{ hashFiles('.github/workflows/linux-arm.yml') }}
restore-keys: |
opencv-arm-${{ env.OPENCV_VERSION }}-
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Align restore/save cache keys; current keys won’t produce cache hits.

Line 56/58 and Line 129 use incompatible key formats (...-<hash>/...- vs ...<version>), so the saved cache key won’t be restored. Also, because checkout uses path: opencvsharp (Line 22), hashFiles('.github/workflows/linux-arm.yml') is likely hashing the wrong path.

Suggested fix
       - name: Restore OpenCV cache
         id: opencv-cache
         uses: actions/cache/restore@v5
         with:
           path: ${{ github.workspace }}/opencv_artifacts/
-          key: opencv-arm-${{ env.OPENCV_VERSION }}-${{ hashFiles('.github/workflows/linux-arm.yml') }}
+          key: opencv-arm-${{ env.OPENCV_VERSION }}-${{ hashFiles('opencvsharp/.github/workflows/linux-arm.yml') }}
           restore-keys: |
             opencv-arm-${{ env.OPENCV_VERSION }}-
@@
       - name: Save OpenCV cache
         if: steps.opencv-cache.outputs.cache-hit != 'true' && github.event_name == 'push' && github.ref == 'refs/heads/main'
         uses: actions/cache/save@v5
         with:
           path: ${{ github.workspace }}/opencv_artifacts/
-          key: opencv-arm-${{ env.OPENCV_VERSION }}
+          key: opencv-arm-${{ env.OPENCV_VERSION }}-${{ hashFiles('opencvsharp/.github/workflows/linux-arm.yml') }}
#!/bin/bash
set -euo pipefail

file=".github/workflows/linux-arm.yml"
echo "Inspecting cache key lines..."
awk 'NR>=50 && NR<=132 {print NR ":" $0}' "$file"

echo
echo "Expected after fix:"
echo "- Restore key == Save key"
echo "- restore-keys prefix remains: opencv-arm-\${{ env.OPENCV_VERSION }}-"
echo "- hashFiles path points to: opencvsharp/.github/workflows/linux-arm.yml"

Also applies to: 129-129

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/linux-arm.yml around lines 56 - 58, The cache restore/save
keys are mismatched: align the restore key prefix and saved key format so
restore can hit the saved cache by making the restore key use the same full
pattern as the save key (opencv-arm-${{ env.OPENCV_VERSION }}-${{ hashFiles(...)
}} and keep restore-keys prefix opencv-arm-${{ env.OPENCV_VERSION }}-); also
change the hashFiles argument to point at the checked-out repo path used by
checkout (use opencvsharp/.github/workflows/linux-arm.yml instead of
.github/workflows/linux-arm.yml) so the calculated hash matches the saved key;
update both occurrences (the restore key block and the save cache key) to use
the identical pattern.

@shimat shimat merged commit 4b35e9d into main Mar 2, 2026
9 of 10 checks passed
@shimat shimat deleted the cache_savings branch March 2, 2026 00:02
@coderabbitai coderabbitai bot mentioned this pull request Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant