@@ -1216,6 +1216,42 @@ jobs:
12161216 restore-keys: cache-${{ runner.os }}-
12171217` ` `
12181218
1219+ # # How Restore Keys Work (S3 cache for private repositories)
1220+
1221+ **Important**: To enable fallback to default branch caches, you **must** use the `restore-keys` property.
1222+
1223+ # ## Cache Key Resolution Order
1224+
1225+ When you provide `restore-keys`, the action searches for cache entries in this order :
1226+
1227+ 1. **Primary key** : ` ${BRANCH_NAME}/${key}`
1228+ 2. **Branch-specific restore keys** : ` ${BRANCH_NAME}/${restore-key}` (for each restore key)
1229+ 3. **Default branch fallbacks** :
1230+ - ` refs/heads/${DEFAULT_BRANCH}/${restore-key}` (for each restore key, where `DEFAULT_BRANCH` is dynamically obtained from the repository)
1231+
1232+ # ## Example
1233+
1234+ ` ` ` yaml
1235+ - uses: SonarSource/ci-github-actions/cache@v1
1236+ with:
1237+ path: ~/.npm
1238+ key: node-${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
1239+ restore-keys: |
1240+ node-${{ runner.os }}
1241+ ` ` `
1242+
1243+ For a feature branch `feature/new-ui`, this will search for :
1244+
1245+ 1. `feature/new-ui/node-linux-abc123...` (exact match)
1246+ 2. `feature/new-ui/node-linux` (branch-specific partial match)
1247+ 3. `refs/heads/main/node-linux` (default branch fallback, assuming `main` is the repository's default branch)
1248+
1249+ # ## Key Differences from Standard Cache Action
1250+
1251+ - **Fallback requires restore-keys**: Without `restore-keys`, the action only looks for branch-specific cache entries
1252+ - **Dynamic default branch detection**: The action detects your default branch using the GitHub API and uses it for fallback
1253+ - **Branch isolation**: Each branch maintains its own cache namespace, preventing cross-branch cache pollution
1254+
12191255# ## Inputs
12201256
12211257| Input | Description | Default |
0 commit comments