From 009fe4e01c738128004be8e891a703b198264c6c Mon Sep 17 00:00:00 2001 From: Leandro Ostera Date: Tue, 29 Dec 2020 13:33:30 +0100 Subject: [PATCH 01/14] Add sample cache for Erlang with Rebar3 --- examples.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/examples.md b/examples.md index 15da4e3..c748065 100644 --- a/examples.md +++ b/examples.md @@ -4,6 +4,7 @@ - [C# - NuGet](#c---nuget) - [D - DUB](#d---dub) - [Elixir - Mix](#elixir---mix) + - [Erlang - Rebar3](#erlang--rebar3) - [Go - Modules](#go---modules) - [Haskell - Cabal](#haskell---cabal) - [Java - Gradle](#java---gradle) @@ -104,6 +105,18 @@ steps: ${{ runner.os }}-mix- ``` +## Erlang - Rebar3 +```yaml +- uses: actions/cache@v2 + with: + path: | + ~/.cache/rebar3 + _build + key: ${{ runner.os }}-erlang-${{ env.OTP_VERSION }}-${{ hashFiles('**/*rebar.lock') }} + restore-keys: | + ${{ runner.os }}-erlang-${{ env.OTP_VERSION }}- +``` + ## Go - Modules ```yaml From 2086306d9c0f866eb68c70488ab86c2917e3e819 Mon Sep 17 00:00:00 2001 From: Jason Axelson Date: Sat, 6 Feb 2021 13:36:42 -1000 Subject: [PATCH 02/14] Make it more obvious that the cache call does double duty --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 8c0a808..7c5bf2d 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,8 @@ jobs: run: /primes.sh -d prime-numbers ``` +Note: The call to cache both restores the cache and sets up a hook to restore the cache at the end of the workflow so you need to add the cache step near the beginning of your workflow. + ## Implementation Examples Every programming language and framework has its own way of caching. From 3767bf0386fab655782439a25c2326ace47f41c6 Mon Sep 17 00:00:00 2001 From: Albert Still Date: Fri, 26 Mar 2021 10:36:55 +1100 Subject: [PATCH 03/14] Improve restore-key documentation --- README.md | 3 ++- action.yml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 07f12e8..d22bd4f 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,8 @@ Create a workflow `.yml` file in your repositories `.github/workflows` directory * `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. * `key` - An explicit key for restoring and saving the cache -* `restore-keys` - An ordered list of keys to use for restoring the cache if no cache hit occurred for key +* `restore-keys` - 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. ### Outputs diff --git a/action.yml b/action.yml index 323a4bd..bc17d36 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 the cache if no cache hit occurred for key' + 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.' required: false upload-chunk-size: description: 'The chunk size used to split up large files during upload, in bytes' From 7ed7f22ed87596cd0d1c13baca967dc49bd9dc6f Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Mon, 6 Jun 2022 09:40:27 +0000 Subject: [PATCH 04/14] Updated actions/cache to v2.0.6 --- dist/restore/index.js | 2 ++ dist/save/index.js | 2 ++ package-lock.json | 14 +++++++------- package.json | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/dist/restore/index.js b/dist/restore/index.js index 06e8122..9351a66 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -37317,6 +37317,8 @@ function createTar(archiveFolder, sourceDirectories, compressionMethod) { ...getCompressionProgram(), '-cf', cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), + '--exclude', + cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), '-P', '-C', workingDirectory.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), diff --git a/dist/save/index.js b/dist/save/index.js index ef4d318..983cb5d 100644 --- a/dist/save/index.js +++ b/dist/save/index.js @@ -37317,6 +37317,8 @@ function createTar(archiveFolder, sourceDirectories, compressionMethod) { ...getCompressionProgram(), '-cf', cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), + '--exclude', + cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), '-P', '-C', workingDirectory.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), diff --git a/package-lock.json b/package-lock.json index 878008b..7368e95 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "3.0.3", "license": "MIT", "dependencies": { - "@actions/cache": "^2.0.5", + "@actions/cache": "^2.0.6", "@actions/core": "^1.7.0", "@actions/exec": "^1.1.1", "@actions/io": "^1.1.2" @@ -36,9 +36,9 @@ } }, "node_modules/@actions/cache": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/@actions/cache/-/cache-2.0.5.tgz", - "integrity": "sha512-aG06dsgcVtiuHLJsIfwrDtvzNNJQ+Iqk8DQt1IeI6gG7ezmLaSdZkHEwA/DNrm5TtOahLcgGEo2SXqbFElVMQg==", + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/@actions/cache/-/cache-2.0.6.tgz", + "integrity": "sha512-Z39ZrWaTRRPaV/AOQdY7hve+Iy/HloH5prpz+k+0lZgGQs/3SeO0UYSIakVuXOk2pdMZnl0Nv0PoK1rmh9YfGQ==", "dependencies": { "@actions/core": "^1.2.6", "@actions/exec": "^1.0.1", @@ -9533,9 +9533,9 @@ }, "dependencies": { "@actions/cache": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/@actions/cache/-/cache-2.0.5.tgz", - "integrity": "sha512-aG06dsgcVtiuHLJsIfwrDtvzNNJQ+Iqk8DQt1IeI6gG7ezmLaSdZkHEwA/DNrm5TtOahLcgGEo2SXqbFElVMQg==", + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/@actions/cache/-/cache-2.0.6.tgz", + "integrity": "sha512-Z39ZrWaTRRPaV/AOQdY7hve+Iy/HloH5prpz+k+0lZgGQs/3SeO0UYSIakVuXOk2pdMZnl0Nv0PoK1rmh9YfGQ==", "requires": { "@actions/core": "^1.2.6", "@actions/exec": "^1.0.1", diff --git a/package.json b/package.json index 30cdd88..64fb57c 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "author": "GitHub", "license": "MIT", "dependencies": { - "@actions/cache": "^2.0.5", + "@actions/cache": "^2.0.6", "@actions/core": "^1.7.0", "@actions/exec": "^1.1.1", "@actions/io": "^1.1.2" From c296e6a08c6a639ec6e35fbfdcde61c3f6107885 Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Mon, 6 Jun 2022 09:55:39 +0000 Subject: [PATCH 05/14] Updated @actions/cache version in license file --- .licenses/npm/@actions/cache.dep.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.licenses/npm/@actions/cache.dep.yml b/.licenses/npm/@actions/cache.dep.yml index f3f6ad9..e2af04c 100644 --- a/.licenses/npm/@actions/cache.dep.yml +++ b/.licenses/npm/@actions/cache.dep.yml @@ -1,6 +1,6 @@ --- name: "@actions/cache" -version: 2.0.5 +version: 2.0.6 type: npm summary: homepage: From dd58d1315fbfa379835d53b0bc75d1a3420fcaf0 Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Mon, 6 Jun 2022 12:31:18 +0000 Subject: [PATCH 06/14] Added release info and upgraded version --- RELEASES.md | 5 ++++- package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index 59bb4a6..87e9980 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -11,4 +11,7 @@ - Added support for dynamic cache size cap on GHES. ### 3.0.3 -- Fixed avoiding empty cache save when no files are available for caching. ([issue](https://github.com/actions/cache/issues/624)) \ No newline at end of file +- Fixed avoiding empty cache save when no files are available for caching. ([issue](https://github.com/actions/cache/issues/624)) + +### 3.0.4 +- Fixed tar creation error while trying to create tar with path has `~/` home folder on ubuntu-latest. ([issue](https://github.com/actions/cache/issues/689)) \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 7368e95..fec209b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "cache", - "version": "3.0.3", + "version": "3.0.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "cache", - "version": "3.0.3", + "version": "3.0.4", "license": "MIT", "dependencies": { "@actions/cache": "^2.0.6", diff --git a/package.json b/package.json index 64fb57c..5d418b2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cache", - "version": "3.0.3", + "version": "3.0.4", "private": true, "description": "Cache dependencies and build outputs", "main": "dist/restore/index.js", From 8c5bd0c82db6e9fd53fc132c68d5f7649d568271 Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Tue, 7 Jun 2022 07:11:42 +0000 Subject: [PATCH 07/14] Updated README file with release info --- README.md | 1 + RELEASES.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fd4ba82..a59430b 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ See ["Caching dependencies to speed up workflows"](https://help.github.com/githu * Fixed download issue for files > 2GB during restore. * Updated the minimum runner version support from node 12 -> node 16. * Fixed avoiding empty cache save when no files are available for caching. +* Fixed tar creation error while trying to create tar with path has `~/` home folder on `ubuntu-latest`. Refer [here](https://github.com/actions/cache/blob/v2/README.md) for previous versions diff --git a/RELEASES.md b/RELEASES.md index 87e9980..3c02fcb 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -14,4 +14,4 @@ - Fixed avoiding empty cache save when no files are available for caching. ([issue](https://github.com/actions/cache/issues/624)) ### 3.0.4 -- Fixed tar creation error while trying to create tar with path has `~/` home folder on ubuntu-latest. ([issue](https://github.com/actions/cache/issues/689)) \ No newline at end of file +- Fixed tar creation error while trying to create tar with path has `~/` home folder on `ubuntu-latest`. ([issue](https://github.com/actions/cache/issues/689)) \ No newline at end of file From d0a54b996cb35d7beba3674d28753ff7ccf2430c Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Tue, 7 Jun 2022 07:14:00 +0000 Subject: [PATCH 08/14] Fixed typo --- README.md | 2 +- RELEASES.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a59430b..803b624 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ See ["Caching dependencies to speed up workflows"](https://help.github.com/githu * Fixed download issue for files > 2GB during restore. * Updated the minimum runner version support from node 12 -> node 16. * Fixed avoiding empty cache save when no files are available for caching. -* Fixed tar creation error while trying to create tar with path has `~/` home folder on `ubuntu-latest`. +* Fixed tar creation error while trying to create tar with path as `~/` home folder on `ubuntu-latest`. Refer [here](https://github.com/actions/cache/blob/v2/README.md) for previous versions diff --git a/RELEASES.md b/RELEASES.md index 3c02fcb..a7a3a6c 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -14,4 +14,4 @@ - Fixed avoiding empty cache save when no files are available for caching. ([issue](https://github.com/actions/cache/issues/624)) ### 3.0.4 -- Fixed tar creation error while trying to create tar with path has `~/` home folder on `ubuntu-latest`. ([issue](https://github.com/actions/cache/issues/689)) \ No newline at end of file +- Fixed tar creation error while trying to create tar with path as `~/` home folder on `ubuntu-latest`. ([issue](https://github.com/actions/cache/issues/689)) \ No newline at end of file From 02be3a9c7373760f0eb5389179e2a043e8e0df84 Mon Sep 17 00:00:00 2001 From: Luis Obis <35803280+lobis@users.noreply.github.com> Date: Wed, 8 Jun 2022 21:43:57 +0200 Subject: [PATCH 09/14] fixed bad yaml in README example --- README.md | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index fa491a6..0a3215f 100644 --- a/README.md +++ b/README.md @@ -172,33 +172,33 @@ jobs: build-linux: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v3 - - name: Cache Primes - id: cache-primes - uses: actions/cache@v3 - with: - path: prime-numbers - key: primes + - name: Cache Primes + id: cache-primes + uses: actions/cache@v3 + with: + path: prime-numbers + key: primes - - name: Generate Prime Numbers - if: steps.cache-primes.outputs.cache-hit != 'true' - run: ./generate-primes.sh -d prime-numbers - - - name: Cache Numbers - id: cache-numbers - uses: actions/cache@v3 - with: - path: numbers - key: primes + - name: Generate Prime Numbers + if: steps.cache-primes.outputs.cache-hit != 'true' + run: ./generate-primes.sh -d prime-numbers - - name: Generate Numbers - if: steps.cache-numbers.outputs.cache-hit != 'true' - run: ./generate-primes.sh -d numbers - - build-windows: - runs-on: windows-latest - steps: + - name: Cache Numbers + id: cache-numbers + uses: actions/cache@v3 + with: + path: numbers + key: primes + + - name: Generate Numbers + if: steps.cache-numbers.outputs.cache-hit != 'true' + run: ./generate-primes.sh -d numbers + + build-windows: + runs-on: windows-latest + steps: - uses: actions/checkout@v3 - name: Cache Primes From d25c51bbfd594e35fe9630893979b06e853530a0 Mon Sep 17 00:00:00 2001 From: Mike Pilgrem Date: Sun, 12 Jun 2022 16:45:20 +0100 Subject: [PATCH 10/14] Adapt existing Haskell Stack example for Windows The default `STACK_ROOT` is `~/.stack` only on Unix-like operating systems. On Windows, the default is `%APPDATA%/stack` (usually `%HOME%\AppData\Roaming\stack`). On Unix-like OSs, Stack stores GHC and other tools in a `programs` directory in the `STACK_ROOT`. On Windows, Stack stores those tools and MSYS2 in `%LOCALAPPDATA%\Programs\stack` (usually `%HOME%\AppData\Local\Programs\stack`). --- examples.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/examples.md b/examples.md index 47c2b22..d9c4499 100644 --- a/examples.md +++ b/examples.md @@ -223,6 +223,8 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba ## Haskell - Stack +### Linux or macOS + ```yaml - uses: actions/cache@v3 name: Cache ~/.stack @@ -240,6 +242,27 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba ${{ runner.os }}-stack-work- ``` +### Windows + +```yaml +- uses: actions/cache@v3 + name: Cache %APPDATA%\stack %LOCALAPPDATA%\Programs\stack + with: + path: | + ~\AppData\Roaming\stack + ~\AppData\Local\Programs\stack + key: ${{ runner.os }}-stack-global-${{ hashFiles('stack.yaml') }}-${{ hashFiles('package.yaml') }} + restore-keys: | + ${{ runner.os }}-stack-global- +- uses: actions/cache@v3 + name: Cache .stack-work + with: + path: .stack-work + key: ${{ runner.os }}-stack-work-${{ hashFiles('stack.yaml') }}-${{ hashFiles('package.yaml') }}-${{ hashFiles('**/*.hs') }} + restore-keys: | + ${{ runner.os }}-stack-work- +``` + ## Java - Gradle >Note: Ensure no Gradle daemons are running anymore when your workflow completes. Creating the cache package might fail due to locks being held by Gradle. Refer to the [Gradle Daemon documentation](https://docs.gradle.org/current/userguide/gradle_daemon.html) on how to disable or stop the Gradle Daemons. From a0efc56c52d97277af82db9d7773d0effa61807d Mon Sep 17 00:00:00 2001 From: Vipul Date: Tue, 21 Jun 2022 22:38:08 +0530 Subject: [PATCH 11/14] Use pull_request_target instead of pull_request Fixes autoassign reviewer for PRs from forked repos. --- .github/workflows/auto-assign.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto-assign.yml b/.github/workflows/auto-assign.yml index 4dcc612..d7161b1 100644 --- a/.github/workflows/auto-assign.yml +++ b/.github/workflows/auto-assign.yml @@ -1,6 +1,6 @@ name: 'Auto Assign' on: - pull_request: + pull_request_target: types: [opened, ready_for_review] jobs: From 5cc84c012398469b34beb3321a27a56652b45c64 Mon Sep 17 00:00:00 2001 From: Vipul Date: Sun, 26 Jun 2022 05:26:49 +0000 Subject: [PATCH 12/14] Add kotewar and remove phantsure from auto-assignees lists --- .github/auto_assign.yml | 2 +- .github/workflows/auto-assign-issues.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/auto_assign.yml b/.github/auto_assign.yml index 0cbc269..4b62284 100644 --- a/.github/auto_assign.yml +++ b/.github/auto_assign.yml @@ -6,7 +6,7 @@ addAssignees: false # A list of reviewers to be added to pull requests (GitHub user name) reviewers: - - phantsure + - kotewar - aparna-ravindra - tiwarishub - vsvipul diff --git a/.github/workflows/auto-assign-issues.yml b/.github/workflows/auto-assign-issues.yml index 23ddc28..fe7fa42 100644 --- a/.github/workflows/auto-assign-issues.yml +++ b/.github/workflows/auto-assign-issues.yml @@ -11,5 +11,5 @@ jobs: - name: 'Auto-assign issue' uses: pozil/auto-assign-issue@v1.4.0 with: - assignees: phantsure,tiwarishub,aparna-ravindra,vsvipul,bishal-pdmsft + assignees: kotewar,tiwarishub,aparna-ravindra,vsvipul,bishal-pdmsft numOfAssignee: 1 From 8829e97be1115f1ebd06bfe5d45b80a4cbf8edf4 Mon Sep 17 00:00:00 2001 From: Vipul Date: Mon, 27 Jun 2022 10:48:52 +0530 Subject: [PATCH 13/14] Update README.md Co-authored-by: Lucas Costi --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7c5bf2d..cc9889f 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ jobs: run: /primes.sh -d prime-numbers ``` -Note: The call to cache both restores the cache and sets up a hook to restore the cache at the end of the workflow so you need to add the cache step near the beginning of your workflow. +> Note: You must use the `cache` action in your workflow before you need to use the files that might be restored from the cache. If the provided `key` doesn't match an existing cache, a new cache is automatically created if the job completes successfully. ## Implementation Examples From 354a2ae15e3e38c9c450c9bacb8f2fe7c684cacb Mon Sep 17 00:00:00 2001 From: Shubham Tiwari <64764738+tiwarishub@users.noreply.github.com> Date: Thu, 7 Jul 2022 21:56:17 +0530 Subject: [PATCH 14/14] Consuming 3.0 actions/cache (#834) * Consuming 3.0 actions/cache * formatting and error * updated package version * resolve package * dist * review comment * dist * dist --- .licenses/npm/@actions/cache.dep.yml | 2 +- __tests__/restore.test.ts | 34 ----------- __tests__/save.test.ts | 5 +- dist/restore/index.js | 84 ++++++++++++++++------------ dist/save/index.js | 68 ++++++++++++---------- package-lock.json | 14 ++--- package.json | 2 +- src/restore.ts | 49 +++++++--------- src/save.ts | 18 ++---- 9 files changed, 124 insertions(+), 152 deletions(-) diff --git a/.licenses/npm/@actions/cache.dep.yml b/.licenses/npm/@actions/cache.dep.yml index e2af04c..cb0614a 100644 --- a/.licenses/npm/@actions/cache.dep.yml +++ b/.licenses/npm/@actions/cache.dep.yml @@ -1,6 +1,6 @@ --- name: "@actions/cache" -version: 2.0.6 +version: 3.0.0 type: npm summary: homepage: diff --git a/__tests__/restore.test.ts b/__tests__/restore.test.ts index b4dbba9..e9a505b 100644 --- a/__tests__/restore.test.ts +++ b/__tests__/restore.test.ts @@ -227,40 +227,6 @@ test("restore with no cache found", async () => { ); }); -test("restore with server error should fail", async () => { - const path = "node_modules"; - const key = "node-test"; - testUtils.setInputs({ - path: path, - key - }); - - const logWarningMock = jest.spyOn(actionUtils, "logWarning"); - const failedMock = jest.spyOn(core, "setFailed"); - const stateMock = jest.spyOn(core, "saveState"); - const restoreCacheMock = jest - .spyOn(cache, "restoreCache") - .mockImplementationOnce(() => { - throw new Error("HTTP Error Occurred"); - }); - const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput"); - - await run(); - - expect(restoreCacheMock).toHaveBeenCalledTimes(1); - expect(restoreCacheMock).toHaveBeenCalledWith([path], key, []); - - expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); - - expect(logWarningMock).toHaveBeenCalledTimes(1); - expect(logWarningMock).toHaveBeenCalledWith("HTTP Error Occurred"); - - expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1); - expect(setCacheHitOutputMock).toHaveBeenCalledWith(false); - - expect(failedMock).toHaveBeenCalledTimes(0); -}); - test("restore with restore keys and no cache found", async () => { const path = "node_modules"; const key = "node-test"; diff --git a/__tests__/save.test.ts b/__tests__/save.test.ts index 7598e0c..4a3ae39 100644 --- a/__tests__/save.test.ts +++ b/__tests__/save.test.ts @@ -267,7 +267,6 @@ test("save with large cache outputs warning", async () => { }); test("save with reserve cache failure outputs warning", async () => { - const infoMock = jest.spyOn(core, "info"); const logWarningMock = jest.spyOn(actionUtils, "logWarning"); const failedMock = jest.spyOn(core, "setFailed"); @@ -306,10 +305,10 @@ test("save with reserve cache failure outputs warning", async () => { expect.anything() ); - expect(infoMock).toHaveBeenCalledWith( + expect(logWarningMock).toHaveBeenCalledWith( `Unable to reserve cache with key ${primaryKey}, another job may be creating this cache.` ); - expect(logWarningMock).toHaveBeenCalledTimes(0); + expect(logWarningMock).toHaveBeenCalledTimes(1); expect(failedMock).toHaveBeenCalledTimes(0); }); diff --git a/dist/restore/index.js b/dist/restore/index.js index 9351a66..cc1c684 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -46850,17 +46850,18 @@ function restoreCache(paths, primaryKey, restoreKeys, options) { checkKey(key); } const compressionMethod = yield utils.getCompressionMethod(); - // path are needed to compute version - const cacheEntry = yield cacheHttpClient.getCacheEntry(keys, paths, { - compressionMethod - }); - if (!(cacheEntry === null || cacheEntry === void 0 ? void 0 : cacheEntry.archiveLocation)) { - // Cache not found - return undefined; - } - const archivePath = path.join(yield utils.createTempDirectory(), utils.getCacheFileName(compressionMethod)); - core.debug(`Archive Path: ${archivePath}`); + let archivePath = ''; try { + // path are needed to compute version + const cacheEntry = yield cacheHttpClient.getCacheEntry(keys, paths, { + compressionMethod + }); + if (!(cacheEntry === null || cacheEntry === void 0 ? void 0 : cacheEntry.archiveLocation)) { + // Cache not found + return undefined; + } + archivePath = path.join(yield utils.createTempDirectory(), utils.getCacheFileName(compressionMethod)); + core.debug(`Archive Path: ${archivePath}`); // Download the cache from the cache entry yield cacheHttpClient.downloadCache(cacheEntry.archiveLocation, archivePath, options); if (core.isDebug()) { @@ -46870,6 +46871,17 @@ function restoreCache(paths, primaryKey, restoreKeys, options) { core.info(`Cache Size: ~${Math.round(archiveFileSize / (1024 * 1024))} MB (${archiveFileSize} B)`); yield tar_1.extractTar(archivePath, compressionMethod); core.info('Cache restored successfully'); + return cacheEntry.cacheKey; + } + catch (error) { + const typedError = error; + if (typedError.name === ValidationError.name) { + throw error; + } + else { + // Supress all non-validation cache related errors because caching should be optional + core.warning(`Failed to restore: ${error.message}`); + } } finally { // Try to delete the archive to save space @@ -46880,7 +46892,7 @@ function restoreCache(paths, primaryKey, restoreKeys, options) { core.debug(`Failed to delete archive: ${error}`); } } - return cacheEntry.cacheKey; + return undefined; }); } exports.restoreCache = restoreCache; @@ -46898,7 +46910,7 @@ function saveCache(paths, key, options) { checkPaths(paths); checkKey(key); const compressionMethod = yield utils.getCompressionMethod(); - let cacheId = null; + let cacheId = -1; const cachePaths = yield utils.resolvePaths(paths); core.debug('Cache Paths:'); core.debug(`${JSON.stringify(cachePaths)}`); @@ -46937,6 +46949,18 @@ function saveCache(paths, key, options) { core.debug(`Saving Cache (ID: ${cacheId})`); yield cacheHttpClient.saveCache(cacheId, archivePath, options); } + catch (error) { + const typedError = error; + if (typedError.name === ValidationError.name) { + throw error; + } + else if (typedError.name === ReserveCacheError.name) { + core.info(`Failed to save: ${typedError.message}`); + } + else { + core.warning(`Failed to save: ${typedError.message}`); + } + } finally { // Try to delete the archive to save space try { @@ -48996,31 +49020,19 @@ function run() { const cachePaths = utils.getInputAsArray(constants_1.Inputs.Path, { required: true }); - try { - const cacheKey = yield cache.restoreCache(cachePaths, primaryKey, restoreKeys); - if (!cacheKey) { - core.info(`Cache not found for input keys: ${[ - primaryKey, - ...restoreKeys - ].join(", ")}`); - return; - } - // Store the matched cache key - utils.setCacheState(cacheKey); - const isExactKeyMatch = utils.isExactKeyMatch(primaryKey, cacheKey); - utils.setCacheHitOutput(isExactKeyMatch); - core.info(`Cache restored from key: ${cacheKey}`); - } - catch (error) { - const typedError = error; - if (typedError.name === cache.ValidationError.name) { - throw error; - } - else { - utils.logWarning(typedError.message); - utils.setCacheHitOutput(false); - } + const cacheKey = yield cache.restoreCache(cachePaths, primaryKey, restoreKeys); + if (!cacheKey) { + core.info(`Cache not found for input keys: ${[ + primaryKey, + ...restoreKeys + ].join(", ")}`); + return; } + // Store the matched cache key + utils.setCacheState(cacheKey); + const isExactKeyMatch = utils.isExactKeyMatch(primaryKey, cacheKey); + utils.setCacheHitOutput(isExactKeyMatch); + core.info(`Cache restored from key: ${cacheKey}`); } catch (error) { core.setFailed(error.message); diff --git a/dist/save/index.js b/dist/save/index.js index 983cb5d..b0f3e41 100644 --- a/dist/save/index.js +++ b/dist/save/index.js @@ -46792,24 +46792,12 @@ function run() { const cachePaths = utils.getInputAsArray(constants_1.Inputs.Path, { required: true }); - try { - yield cache.saveCache(cachePaths, primaryKey, { - uploadChunkSize: utils.getInputAsInt(constants_1.Inputs.UploadChunkSize) - }); + const cacheId = yield cache.saveCache(cachePaths, primaryKey, { + uploadChunkSize: utils.getInputAsInt(constants_1.Inputs.UploadChunkSize) + }); + if (cacheId != -1) { core.info(`Cache saved with key: ${primaryKey}`); } - catch (error) { - const typedError = error; - if (typedError.name === cache.ValidationError.name) { - throw error; - } - else if (typedError.name === cache.ReserveCacheError.name) { - core.info(typedError.message); - } - else { - utils.logWarning(typedError.message); - } - } } catch (error) { utils.logWarning(error.message); @@ -46948,17 +46936,18 @@ function restoreCache(paths, primaryKey, restoreKeys, options) { checkKey(key); } const compressionMethod = yield utils.getCompressionMethod(); - // path are needed to compute version - const cacheEntry = yield cacheHttpClient.getCacheEntry(keys, paths, { - compressionMethod - }); - if (!(cacheEntry === null || cacheEntry === void 0 ? void 0 : cacheEntry.archiveLocation)) { - // Cache not found - return undefined; - } - const archivePath = path.join(yield utils.createTempDirectory(), utils.getCacheFileName(compressionMethod)); - core.debug(`Archive Path: ${archivePath}`); + let archivePath = ''; try { + // path are needed to compute version + const cacheEntry = yield cacheHttpClient.getCacheEntry(keys, paths, { + compressionMethod + }); + if (!(cacheEntry === null || cacheEntry === void 0 ? void 0 : cacheEntry.archiveLocation)) { + // Cache not found + return undefined; + } + archivePath = path.join(yield utils.createTempDirectory(), utils.getCacheFileName(compressionMethod)); + core.debug(`Archive Path: ${archivePath}`); // Download the cache from the cache entry yield cacheHttpClient.downloadCache(cacheEntry.archiveLocation, archivePath, options); if (core.isDebug()) { @@ -46968,6 +46957,17 @@ function restoreCache(paths, primaryKey, restoreKeys, options) { core.info(`Cache Size: ~${Math.round(archiveFileSize / (1024 * 1024))} MB (${archiveFileSize} B)`); yield tar_1.extractTar(archivePath, compressionMethod); core.info('Cache restored successfully'); + return cacheEntry.cacheKey; + } + catch (error) { + const typedError = error; + if (typedError.name === ValidationError.name) { + throw error; + } + else { + // Supress all non-validation cache related errors because caching should be optional + core.warning(`Failed to restore: ${error.message}`); + } } finally { // Try to delete the archive to save space @@ -46978,7 +46978,7 @@ function restoreCache(paths, primaryKey, restoreKeys, options) { core.debug(`Failed to delete archive: ${error}`); } } - return cacheEntry.cacheKey; + return undefined; }); } exports.restoreCache = restoreCache; @@ -46996,7 +46996,7 @@ function saveCache(paths, key, options) { checkPaths(paths); checkKey(key); const compressionMethod = yield utils.getCompressionMethod(); - let cacheId = null; + let cacheId = -1; const cachePaths = yield utils.resolvePaths(paths); core.debug('Cache Paths:'); core.debug(`${JSON.stringify(cachePaths)}`); @@ -47035,6 +47035,18 @@ function saveCache(paths, key, options) { core.debug(`Saving Cache (ID: ${cacheId})`); yield cacheHttpClient.saveCache(cacheId, archivePath, options); } + catch (error) { + const typedError = error; + if (typedError.name === ValidationError.name) { + throw error; + } + else if (typedError.name === ReserveCacheError.name) { + core.info(`Failed to save: ${typedError.message}`); + } + else { + core.warning(`Failed to save: ${typedError.message}`); + } + } finally { // Try to delete the archive to save space try { diff --git a/package-lock.json b/package-lock.json index fec209b..5f16fd2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "3.0.4", "license": "MIT", "dependencies": { - "@actions/cache": "^2.0.6", + "@actions/cache": "^3.0.0", "@actions/core": "^1.7.0", "@actions/exec": "^1.1.1", "@actions/io": "^1.1.2" @@ -36,9 +36,9 @@ } }, "node_modules/@actions/cache": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/@actions/cache/-/cache-2.0.6.tgz", - "integrity": "sha512-Z39ZrWaTRRPaV/AOQdY7hve+Iy/HloH5prpz+k+0lZgGQs/3SeO0UYSIakVuXOk2pdMZnl0Nv0PoK1rmh9YfGQ==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@actions/cache/-/cache-3.0.0.tgz", + "integrity": "sha512-GL9CT1Fnu+pqs8TTB621q8Xa8Cilw2n9MwvbgMedetH7L1q2n6jY61gzbwGbKgtVbp3gVJ12aNMi4osSGXx3KQ==", "dependencies": { "@actions/core": "^1.2.6", "@actions/exec": "^1.0.1", @@ -9533,9 +9533,9 @@ }, "dependencies": { "@actions/cache": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/@actions/cache/-/cache-2.0.6.tgz", - "integrity": "sha512-Z39ZrWaTRRPaV/AOQdY7hve+Iy/HloH5prpz+k+0lZgGQs/3SeO0UYSIakVuXOk2pdMZnl0Nv0PoK1rmh9YfGQ==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@actions/cache/-/cache-3.0.0.tgz", + "integrity": "sha512-GL9CT1Fnu+pqs8TTB621q8Xa8Cilw2n9MwvbgMedetH7L1q2n6jY61gzbwGbKgtVbp3gVJ12aNMi4osSGXx3KQ==", "requires": { "@actions/core": "^1.2.6", "@actions/exec": "^1.0.1", diff --git a/package.json b/package.json index 5d418b2..7c8bfaa 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "author": "GitHub", "license": "MIT", "dependencies": { - "@actions/cache": "^2.0.6", + "@actions/cache": "^3.0.0", "@actions/core": "^1.7.0", "@actions/exec": "^1.1.1", "@actions/io": "^1.1.2" diff --git a/src/restore.ts b/src/restore.ts index 648e4cb..5bc17fa 100644 --- a/src/restore.ts +++ b/src/restore.ts @@ -29,38 +29,29 @@ async function run(): Promise { required: true }); - try { - const cacheKey = await cache.restoreCache( - cachePaths, - primaryKey, - restoreKeys + const cacheKey = await cache.restoreCache( + cachePaths, + primaryKey, + restoreKeys + ); + + if (!cacheKey) { + core.info( + `Cache not found for input keys: ${[ + primaryKey, + ...restoreKeys + ].join(", ")}` ); - if (!cacheKey) { - core.info( - `Cache not found for input keys: ${[ - primaryKey, - ...restoreKeys - ].join(", ")}` - ); - return; - } - // Store the matched cache key - utils.setCacheState(cacheKey); - - const isExactKeyMatch = utils.isExactKeyMatch(primaryKey, cacheKey); - utils.setCacheHitOutput(isExactKeyMatch); - - core.info(`Cache restored from key: ${cacheKey}`); - } catch (error: unknown) { - const typedError = error as Error; - if (typedError.name === cache.ValidationError.name) { - throw error; - } else { - utils.logWarning(typedError.message); - utils.setCacheHitOutput(false); - } + return; } + + // Store the matched cache key + utils.setCacheState(cacheKey); + + const isExactKeyMatch = utils.isExactKeyMatch(primaryKey, cacheKey); + utils.setCacheHitOutput(isExactKeyMatch); + core.info(`Cache restored from key: ${cacheKey}`); } catch (error: unknown) { core.setFailed((error as Error).message); } diff --git a/src/save.ts b/src/save.ts index 7b333fb..a0a21bf 100644 --- a/src/save.ts +++ b/src/save.ts @@ -44,20 +44,12 @@ async function run(): Promise { required: true }); - try { - await cache.saveCache(cachePaths, primaryKey, { - uploadChunkSize: utils.getInputAsInt(Inputs.UploadChunkSize) - }); + const cacheId = await cache.saveCache(cachePaths, primaryKey, { + uploadChunkSize: utils.getInputAsInt(Inputs.UploadChunkSize) + }); + + if (cacheId != -1) { core.info(`Cache saved with key: ${primaryKey}`); - } catch (error: unknown) { - const typedError = error as Error; - if (typedError.name === cache.ValidationError.name) { - throw error; - } else if (typedError.name === cache.ReserveCacheError.name) { - core.info(typedError.message); - } else { - utils.logWarning(typedError.message); - } } } catch (error: unknown) { utils.logWarning((error as Error).message);