From 4a28cbc0544512425977dda4ce81a9b6f0f34ad9 Mon Sep 17 00:00:00 2001 From: "P. Ottlinger" Date: Mon, 29 Jul 2024 22:07:30 +0200 Subject: [PATCH 1/4] Update README.md and use v4 of checkout action (#1437) Update examples to use latest available checkout action v4. --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d1d2aef..3da1ae0 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Cache Primes id: cache-primes @@ -122,7 +122,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Restore cached Primes id: cache-primes-restore @@ -229,7 +229,7 @@ Example: ```yaml steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/cache@v4 id: cache @@ -259,7 +259,7 @@ jobs: build-linux: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Cache Primes id: cache-primes @@ -286,7 +286,7 @@ jobs: build-windows: runs-on: windows-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Cache Primes id: cache-primes From e47d9f9ec8be3ac771b0b03c8e50f86e1c2fdea8 Mon Sep 17 00:00:00 2001 From: "Oleg A." Date: Wed, 31 Jul 2024 19:52:21 +0300 Subject: [PATCH 2/4] Explicit use bash for Windows (#1377) Co-authored-by: Josh Gross --- examples.md | 1 + 1 file changed, 1 insertion(+) diff --git a/examples.md b/examples.md index 1bcde91..2a49996 100644 --- a/examples.md +++ b/examples.md @@ -513,6 +513,7 @@ jobs: ```yaml - name: Get pip cache dir id: pip-cache + shell: bash run: | echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT From 40c3b67b2955d93d83b27ed164edd0756bc24049 Mon Sep 17 00:00:00 2001 From: r4mimu <52129983+fchimpan@users.noreply.github.com> Date: Thu, 1 Aug 2024 01:56:48 +0900 Subject: [PATCH 3/4] Fix cache-hit output when cache missed (#1404) * fix: cache-hit output * fix: Output chache hit timing * fix: Output chache hit timing --------- Co-authored-by: Josh Gross --- __tests__/restore.test.ts | 2 +- __tests__/restoreOnly.test.ts | 3 ++- dist/restore-only/index.js | 1 + dist/restore/index.js | 1 + src/restoreImpl.ts | 2 +- 5 files changed, 6 insertions(+), 3 deletions(-) diff --git a/__tests__/restore.test.ts b/__tests__/restore.test.ts index 250f7ef..9b066eb 100644 --- a/__tests__/restore.test.ts +++ b/__tests__/restore.test.ts @@ -260,7 +260,7 @@ test("Fail restore when fail on cache miss is enabled and primary + restore keys ); expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); - expect(setCacheHitOutputMock).toHaveBeenCalledTimes(0); + expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1); expect(failedMock).toHaveBeenCalledWith( `Failed to restore cache entry. Exiting as fail-on-cache-miss is set. Input key: ${key}` diff --git a/__tests__/restoreOnly.test.ts b/__tests__/restoreOnly.test.ts index 81e5bca..840307d 100644 --- a/__tests__/restoreOnly.test.ts +++ b/__tests__/restoreOnly.test.ts @@ -86,7 +86,8 @@ test("restore with no cache found", async () => { ); expect(outputMock).toHaveBeenCalledWith("cache-primary-key", key); - expect(outputMock).toHaveBeenCalledTimes(1); + expect(outputMock).toHaveBeenCalledWith("cache-hit", "false"); + expect(outputMock).toHaveBeenCalledTimes(2); expect(failedMock).toHaveBeenCalledTimes(0); expect(infoMock).toHaveBeenCalledWith( diff --git a/dist/restore-only/index.js b/dist/restore-only/index.js index 9a59ac0..d2f3631 100644 --- a/dist/restore-only/index.js +++ b/dist/restore-only/index.js @@ -59415,6 +59415,7 @@ function restoreImpl(stateProvider, earlyExit) { const lookupOnly = utils.getInputAsBool(constants_1.Inputs.LookupOnly); const cacheKey = yield cache.restoreCache(cachePaths, primaryKey, restoreKeys, { lookupOnly: lookupOnly }, enableCrossOsArchive); if (!cacheKey) { + core.setOutput(constants_1.Outputs.CacheHit, false.toString()); if (failOnCacheMiss) { throw new Error(`Failed to restore cache entry. Exiting as fail-on-cache-miss is set. Input key: ${primaryKey}`); } diff --git a/dist/restore/index.js b/dist/restore/index.js index 03a12b5..842eaa6 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -59415,6 +59415,7 @@ function restoreImpl(stateProvider, earlyExit) { const lookupOnly = utils.getInputAsBool(constants_1.Inputs.LookupOnly); const cacheKey = yield cache.restoreCache(cachePaths, primaryKey, restoreKeys, { lookupOnly: lookupOnly }, enableCrossOsArchive); if (!cacheKey) { + core.setOutput(constants_1.Outputs.CacheHit, false.toString()); if (failOnCacheMiss) { throw new Error(`Failed to restore cache entry. Exiting as fail-on-cache-miss is set. Input key: ${primaryKey}`); } diff --git a/src/restoreImpl.ts b/src/restoreImpl.ts index 74a366d..bb302ac 100644 --- a/src/restoreImpl.ts +++ b/src/restoreImpl.ts @@ -51,6 +51,7 @@ export async function restoreImpl( ); if (!cacheKey) { + core.setOutput(Outputs.CacheHit, false.toString()); if (failOnCacheMiss) { throw new Error( `Failed to restore cache entry. Exiting as fail-on-cache-miss is set. Input key: ${primaryKey}` @@ -62,7 +63,6 @@ export async function restoreImpl( ...restoreKeys ].join(", ")}` ); - return; } From 57b8e405f0f6efe89131ba09709ce4bc33291a51 Mon Sep 17 00:00:00 2001 From: Soubhik Kumar Mitra <59209034+x612skm@users.noreply.github.com> Date: Tue, 6 Aug 2024 19:56:54 +0530 Subject: [PATCH 4/4] Clarify that the `restore-keys` input is a string in the docs (#1434) * Fix Description for restore-keys at Readme As previously the restore-keys were defined as an ordered lists which is wrong as per the issue description where the actual format is a multi-line string with one key per line. * Added a space between the sentence of restore-keys description While at the PR review it's been identified there's a need for a space between the sentence ``` An ordered multiline string listing the prefix-matched keys,that are used for restoring stale cache if no cache hit occurred for key. ``` where it's written as "prefix-matched keys,that are" this commit will address the review comment and introduce a space between "prefix-matched keys, that are" and change the sentence to ``` An ordered multiline string listing the prefix-matched keys, that are used for restoring stale cache if no cache hit occurred for key. ``` * Change restore-keys description at cache/restore/action.yml and cache/action.yml --- README.md | 2 +- action.yml | 2 +- restore/action.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3da1ae0..9da9474 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ If you are using a `self-hosted` Windows runner, `GNU tar` and `zstd` are requir * `key` - An explicit key for a cache entry. See [creating a cache key](#creating-a-cache-key). * `path` - A list of files, directories, and wildcard patterns to cache and restore. See [`@actions/glob`](https://github.com/actions/toolkit/tree/main/packages/glob) for supported patterns. -* `restore-keys` - An ordered list of prefix-matched keys to use for restoring stale cache if no cache hit occurred for key. +* `restore-keys` - An ordered multiline string listing the prefix-matched keys, that are used for restoring stale cache if no cache hit occurred for key. * `enableCrossOsArchive` - An optional boolean when enabled, allows Windows runners to save or restore caches that can be restored or saved respectively on other platforms. Default: `false` * `fail-on-cache-miss` - Fail the workflow if cache entry is not found. Default: `false` * `lookup-only` - If true, only checks if cache entry exists and skips download. Does not change save cache behavior. Default: `false` diff --git a/action.yml b/action.yml index 0125281..14f247f 100644 --- a/action.yml +++ b/action.yml @@ -9,7 +9,7 @@ inputs: description: 'An explicit key for restoring and saving the cache' required: true restore-keys: - description: 'An ordered list of keys to use for restoring stale cache if no cache hit occurred for key. Note `cache-hit` returns false in this case.' + description: 'An ordered multiline string listing the prefix-matched keys, that are used for restoring stale cache if no cache hit occurred for key. Note `cache-hit` returns false in this case.' required: false upload-chunk-size: description: 'The chunk size used to split up large files during upload, in bytes' diff --git a/restore/action.yml b/restore/action.yml index 194669f..3c5e5ae 100644 --- a/restore/action.yml +++ b/restore/action.yml @@ -9,7 +9,7 @@ inputs: description: 'An explicit key for restoring the cache' required: true restore-keys: - description: 'An ordered list of keys to use for restoring stale cache if no cache hit occurred for key. Note `cache-hit` returns false in this case.' + description: 'An ordered multiline string listing the prefix-matched keys, that are used for restoring stale cache if no cache hit occurred for key. Note `cache-hit` returns false in this case.' required: false enableCrossOsArchive: description: 'An optional boolean when enabled, allows windows runners to restore caches that were saved on other platforms'