Skip to content

Commit

Permalink
Merge pull request #45 from nix-community/43-bug-restore-prefixes-fir…
Browse files Browse the repository at this point in the history
…st-match-still-triggers-when-primary-key-matches
  • Loading branch information
deemp committed Jun 9, 2024
2 parents 433f47d + 7e7c128 commit 8351fb9
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ See [action.yml](action.yml).
| `primary-key` | <ul> <li>When a non-empty string, the action uses this key for restoring and saving a cache.</li> <li>Otherwise, the action fails.</li> </ul> | `true` | `""` |
| `restore-prefixes-first-match` | <ul> <li>When a newline-separated non-empty list of non-empty key prefixes, when there's a miss on the <code>primary-key</code>, the action searches in this list for the first prefix for which there exists a cache with a matching key and the action tries to restore that cache.</li> <li>Otherwise, this input has no effect.</li> </ul> | `false` | `""` |
| `restore-prefixes-all-matches` | <ul> <li>When a newline-separated non-empty list of non-empty key prefixes, the action tries to restore all caches whose keys match these prefixes.</li> <li>Tries caches across all refs to make use of caches created on the current, base, and default branches (see <a href="https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache">docs</a>).</li> <li>Otherwise, this input has no effect.</li> </ul> | `false` | `""` |
| `skip-restore-on-hit-primary-key` | <ul> <li>Can have an effect only when <code>restore-prefixes-first-match</code> has no effect.</li> <li>When <code>true</code>, when there's a hit on the <code>primary-key</code>, the action doesn't restore caches.</li> <li>Otherwise, this input has no effect.</li> </ul> | `false` | `false` |
| `skip-restore-on-hit-primary-key` | <ul> <li>Can have an effect only when <code>restore-prefixes-first-match</code> has no effect.</li> <li>When <code>true</code>, when there's a hit on the <code>primary-key</code>, the action doesn't restore caches.</li> <li>Otherwise, the action restores caches.</li> </ul> | `false` | `false` |
| `fail-on` | <ul> <li>Input form: <code>&lt;key type&gt;.&lt;result&gt;</code>.</li> <li><code>&lt;key type&gt;</code> options: <code>primary-key</code>, <code>first-match</code>.</li> <li><code>&lt;result&gt;</code> options: <code>miss</code>, <code>not-restored</code>.</li> <li>When the input satisfies the input form, when the event described in the input happens, the action fails.</li> <li>Example:<ul> <li>Input: <code>primary-key.not-restored</code>.</li> <li>Event: a cache could not be restored via the <code>primary-key</code>.</li></ul></li> <li>Otherwise, this input has no effect.</li> </ul> | `false` | `""` |
| `nix` | <ul> <li>Can have an effect only when the action runs on a <code>Linux</code> or a <code>macOS</code> runner.</li> <li>When <code>true</code>, the action can do Nix-specific things.</li> <li>Otherwise, the action doesn't do them.</li> </ul> | `false` | `true` |
| `save` | <ul> <li>When <code>true</code>, the action can save a cache with the <code>primary-key</code>.</li> <li>Otherwise, the action can't save a cache.</li> </ul> | `false` | `true` |
Expand Down
2 changes: 1 addition & 1 deletion action.nix
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ in
description: |
- Can have an effect only when ${q restore-prefixes-first-match} has no effect.
- When `true`, when there's a hit on the ${q primary-key}, the action doesn't restore caches.
- ${noEffectOtherwise}
- Otherwise, the action restores caches.
default: "false"
fail-on:
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ inputs:
description: |
- Can have an effect only when `restore-prefixes-first-match` has no effect.
- When `true`, when there's a hit on the `primary-key`, the action doesn't restore caches.
- Otherwise, this input has no effect.
- Otherwise, the action restores caches.
default: "false"

fail-on:
Expand Down
4 changes: 2 additions & 2 deletions dist/restore-only/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94537,7 +94537,7 @@ function restoreImpl(stateProvider, earlyExit) {
}
let hitFirstMatch = false;
if (inputs.restorePrefixesFirstMatch.length > 0 &&
!(lookedUpPrimaryKey && inputs.skipRestoreOnHitPrimaryKey)) {
!(lookedUpPrimaryKey || inputs.skipRestoreOnHitPrimaryKey)) {
utils.info(`
Searching for a cache using the "${constants_1.Inputs.RestorePrefixesFirstMatch}":
${JSON.stringify(inputs.restorePrefixesFirstMatch)}
Expand Down Expand Up @@ -94569,7 +94569,7 @@ function restoreImpl(stateProvider, earlyExit) {
}
}
}
if (!(lookedUpPrimaryKey && inputs.skipRestoreOnHitPrimaryKey)) {
if (!(lookedUpPrimaryKey || inputs.skipRestoreOnHitPrimaryKey)) {
restoredKeys.push(...(yield restore.restoreAllMatches()));
}
restoredKey !== null && restoredKey !== void 0 ? restoredKey : (restoredKey = "");
Expand Down
4 changes: 2 additions & 2 deletions dist/restore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94537,7 +94537,7 @@ function restoreImpl(stateProvider, earlyExit) {
}
let hitFirstMatch = false;
if (inputs.restorePrefixesFirstMatch.length > 0 &&
!(lookedUpPrimaryKey && inputs.skipRestoreOnHitPrimaryKey)) {
!(lookedUpPrimaryKey || inputs.skipRestoreOnHitPrimaryKey)) {
utils.info(`
Searching for a cache using the "${constants_1.Inputs.RestorePrefixesFirstMatch}":
${JSON.stringify(inputs.restorePrefixesFirstMatch)}
Expand Down Expand Up @@ -94569,7 +94569,7 @@ function restoreImpl(stateProvider, earlyExit) {
}
}
}
if (!(lookedUpPrimaryKey && inputs.skipRestoreOnHitPrimaryKey)) {
if (!(lookedUpPrimaryKey || inputs.skipRestoreOnHitPrimaryKey)) {
restoredKeys.push(...(yield restore.restoreAllMatches()));
}
restoredKey !== null && restoredKey !== void 0 ? restoredKey : (restoredKey = "");
Expand Down
2 changes: 1 addition & 1 deletion restore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The restore action restores a cache. It works similarly to the `cache` action ex
| `primary-key` | <ul> <li>When a non-empty string, the action uses this key for restoring a cache.</li> <li>Otherwise, the action fails.</li> </ul> | `true` | `""` |
| `restore-prefixes-first-match` | <ul> <li>When a newline-separated non-empty list of non-empty key prefixes, when there's a miss on the <code>primary-key</code>, the action searches in this list for the first prefix for which there exists a cache with a matching key and the action tries to restore that cache.</li> <li>Otherwise, this input has no effect.</li> </ul> | `false` | `""` |
| `restore-prefixes-all-matches` | <ul> <li>When a newline-separated non-empty list of non-empty key prefixes, the action tries to restore all caches whose keys match these prefixes.</li> <li>Tries caches across all refs to make use of caches created on the current, base, and default branches (see <a href="https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache">docs</a>).</li> <li>Otherwise, this input has no effect.</li> </ul> | `false` | `""` |
| `skip-restore-on-hit-primary-key` | <ul> <li>Can have an effect only when <code>restore-prefixes-first-match</code> has no effect.</li> <li>When <code>true</code>, when there's a hit on the <code>primary-key</code>, the action doesn't restore caches.</li> <li>Otherwise, this input has no effect.</li> </ul> | `false` | `false` |
| `skip-restore-on-hit-primary-key` | <ul> <li>Can have an effect only when <code>restore-prefixes-first-match</code> has no effect.</li> <li>When <code>true</code>, when there's a hit on the <code>primary-key</code>, the action doesn't restore caches.</li> <li>Otherwise, the action restores caches.</li> </ul> | `false` | `false` |
| `fail-on` | <ul> <li>Input form: <code>&lt;key type&gt;.&lt;result&gt;</code>.</li> <li><code>&lt;key type&gt;</code> options: <code>primary-key</code>, <code>first-match</code>.</li> <li><code>&lt;result&gt;</code> options: <code>miss</code>, <code>not-restored</code>.</li> <li>When the input satisfies the input form, when the event described in the input happens, the action fails.</li> <li>Example:<ul> <li>Input: <code>primary-key.not-restored</code>.</li> <li>Event: a cache could not be restored via the <code>primary-key</code>.</li></ul></li> <li>Otherwise, this input has no effect.</li> </ul> | `false` | `""` |
| `nix` | <ul> <li>Can have an effect only when the action runs on a <code>Linux</code> or a <code>macOS</code> runner.</li> <li>When <code>true</code>, the action can do Nix-specific things.</li> <li>Otherwise, the action doesn't do them.</li> </ul> | `false` | `true` |
| `save` | <ul> <li>When <code>true</code>, the action can save a cache with the <code>primary-key</code>.</li> <li>Otherwise, the action can't save a cache.</li> </ul> | `false` | `true` |
Expand Down
2 changes: 1 addition & 1 deletion restore/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ inputs:
description: |
- Can have an effect only when `restore-prefixes-first-match` has no effect.
- When `true`, when there's a hit on the `primary-key`, the action doesn't restore caches.
- Otherwise, this input has no effect.
- Otherwise, the action restores caches.
default: "false"

fail-on:
Expand Down
4 changes: 2 additions & 2 deletions src/restoreImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export async function restoreImpl(

if (
inputs.restorePrefixesFirstMatch.length > 0 &&
!(lookedUpPrimaryKey && inputs.skipRestoreOnHitPrimaryKey)
!(lookedUpPrimaryKey || inputs.skipRestoreOnHitPrimaryKey)
) {
utils.info(
`
Expand Down Expand Up @@ -136,7 +136,7 @@ export async function restoreImpl(
}
}

if (!(lookedUpPrimaryKey && inputs.skipRestoreOnHitPrimaryKey)) {
if (!(lookedUpPrimaryKey || inputs.skipRestoreOnHitPrimaryKey)) {
restoredKeys.push(...(await restore.restoreAllMatches()));
}

Expand Down

0 comments on commit 8351fb9

Please sign in to comment.