mirror of
				https://github.com/actions/cache.git
				synced 2025-10-27 21:55:12 +07:00 
			
		
		
		
	Compare commits
	
		
			6 Commits
		
	
	
		
			v3.0.3
			...
			t-dedah/te
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 8546a7057e | |||
| fa608b2294 | |||
| a54eb92c7c | |||
| 1239bf6914 | |||
| 2ce8d02f04 | |||
| aad9d15d47 | 
							
								
								
									
										17
									
								
								.github/auto_assign.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										17
									
								
								.github/auto_assign.yml
									
									
									
									
										vendored
									
									
								
							| @ -1,17 +0,0 @@ | ||||
| # Set to true to add reviewers to pull requests | ||||
| addReviewers: true | ||||
|  | ||||
| # Set to true to add assignees to pull requests | ||||
| addAssignees: false | ||||
|  | ||||
| # A list of reviewers to be added to pull requests (GitHub user name) | ||||
| reviewers: | ||||
|   - phantsure | ||||
|   - aparna-ravindra | ||||
|   - tiwarishub | ||||
|   - vsvipul | ||||
|   - bishal-pdmsft | ||||
|  | ||||
| # A number of reviewers added to the pull request | ||||
| # Set 0 to add all the reviewers (default: 0) | ||||
| numberOfReviewers: 1 | ||||
							
								
								
									
										15
									
								
								.github/workflows/auto-assign-issues.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										15
									
								
								.github/workflows/auto-assign-issues.yml
									
									
									
									
										vendored
									
									
								
							| @ -1,15 +0,0 @@ | ||||
| name: Issue assignment | ||||
|  | ||||
| on: | ||||
|     issues: | ||||
|         types: [opened] | ||||
|  | ||||
| jobs: | ||||
|     auto-assign: | ||||
|         runs-on: ubuntu-latest | ||||
|         steps: | ||||
|             - name: 'Auto-assign issue' | ||||
|               uses: pozil/auto-assign-issue@v1.4.0 | ||||
|               with: | ||||
|                   assignees: phantsure,tiwarishub,aparna-ravindra,vsvipul,bishal-pdmsft | ||||
|                   numOfAssignee: 1 | ||||
							
								
								
									
										10
									
								
								.github/workflows/auto-assign.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										10
									
								
								.github/workflows/auto-assign.yml
									
									
									
									
										vendored
									
									
								
							| @ -1,10 +0,0 @@ | ||||
| name: 'Auto Assign' | ||||
| on: | ||||
|   pull_request: | ||||
|     types: [opened, ready_for_review] | ||||
|  | ||||
| jobs: | ||||
|   add-reviews: | ||||
|     runs-on: ubuntu-latest | ||||
|     steps: | ||||
|       - uses: kentaro-m/auto-assign-action@v1.2.1 | ||||
							
								
								
									
										13
									
								
								.github/workflows/check-dist.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										13
									
								
								.github/workflows/check-dist.yml
									
									
									
									
										vendored
									
									
								
							| @ -22,13 +22,16 @@ jobs: | ||||
|     runs-on: ubuntu-latest | ||||
|  | ||||
|     steps: | ||||
|       - uses: actions/checkout@v3 | ||||
|       - name: Setup Node.js 16.x | ||||
|         uses: actions/setup-node@v3 | ||||
|       - uses: actions/checkout@v2 | ||||
|  | ||||
|       - name: Set Node.js 12.x | ||||
|         uses: actions/setup-node@v1 | ||||
|         with: | ||||
|           node-version: 16.x | ||||
|           node-version: 12.x | ||||
|  | ||||
|       - name: Install dependencies | ||||
|         run: npm ci | ||||
|  | ||||
|       - name: Rebuild the dist/ directory | ||||
|         run: npm run build | ||||
|  | ||||
| @ -42,7 +45,7 @@ jobs: | ||||
|         id: diff | ||||
|  | ||||
|       # If index.js was different than expected, upload the expected version as an artifact | ||||
|       - uses: actions/upload-artifact@v3 | ||||
|       - uses: actions/upload-artifact@v2 | ||||
|         if: ${{ failure() && steps.diff.conclusion == 'failure' }} | ||||
|         with: | ||||
|           name: dist | ||||
|  | ||||
							
								
								
									
										4
									
								
								.github/workflows/close-inactive-issues.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								.github/workflows/close-inactive-issues.yml
									
									
									
									
										vendored
									
									
								
							| @ -12,10 +12,10 @@ jobs: | ||||
|     steps: | ||||
|       - uses: actions/stale@v3 | ||||
|         with: | ||||
|           days-before-issue-stale: 200 | ||||
|           days-before-issue-stale: 365 | ||||
|           days-before-issue-close: 5 | ||||
|           stale-issue-label: "stale" | ||||
|           stale-issue-message: "This issue is stale because it has been open for 200 days with no activity. Leave a comment to avoid closing this issue in 5 days." | ||||
|           stale-issue-message: "This issue is stale because it has been open for 365 days with no activity. Leave a comment to avoid closing this issue in 5 days." | ||||
|           close-issue-message: "This issue was closed because it has been inactive for 5 days since being marked as stale." | ||||
|           days-before-pr-stale: -1 | ||||
|           days-before-pr-close: -1 | ||||
|  | ||||
							
								
								
									
										4
									
								
								.github/workflows/codeql.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								.github/workflows/codeql.yml
									
									
									
									
										vendored
									
									
								
							| @ -14,7 +14,7 @@ jobs: | ||||
|  | ||||
|     steps: | ||||
|     - name: Checkout repository | ||||
|       uses: actions/checkout@v3 | ||||
|       uses: actions/checkout@v2 | ||||
|       with: | ||||
|         # We must fetch at least the immediate parents so that if this is | ||||
|         # a pull request then we can checkout the head. | ||||
| @ -24,7 +24,7 @@ jobs: | ||||
|     # the head of the pull request instead of the merge commit. | ||||
|     - run: git checkout HEAD^2 | ||||
|       if: ${{ github.event_name == 'pull_request' }} | ||||
|  | ||||
|        | ||||
|     # Initializes the CodeQL tools for scanning. | ||||
|     - name: Initialize CodeQL | ||||
|       uses: github/codeql-action/init@v1 | ||||
|  | ||||
							
								
								
									
										2
									
								
								.github/workflows/licensed.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.github/workflows/licensed.yml
									
									
									
									
										vendored
									
									
								
							| @ -13,7 +13,7 @@ jobs: | ||||
|     runs-on: ubuntu-latest | ||||
|     name: Check licenses | ||||
|     steps: | ||||
|       - uses: actions/checkout@v3 | ||||
|       - uses: actions/checkout@v2 | ||||
|       - run: npm ci | ||||
|       - name: Install licensed | ||||
|         run: | | ||||
|  | ||||
							
								
								
									
										16
									
								
								.github/workflows/workflow.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										16
									
								
								.github/workflows/workflow.yml
									
									
									
									
										vendored
									
									
								
							| @ -24,11 +24,11 @@ jobs: | ||||
|     runs-on: ${{ matrix.os }} | ||||
|     steps: | ||||
|     - name: Checkout | ||||
|       uses: actions/checkout@v3 | ||||
|     - name: Setup Node.js 16.x | ||||
|       uses: actions/setup-node@v3 | ||||
|       uses: actions/checkout@v2 | ||||
|     - name: Setup Node.js | ||||
|       uses: actions/setup-node@v1 | ||||
|       with: | ||||
|         node-version: 16.x | ||||
|         node-version: '12.x' | ||||
|     - name: Determine npm cache directory | ||||
|       id: npm-cache | ||||
|       run: | | ||||
| @ -57,7 +57,7 @@ jobs: | ||||
|     runs-on: ${{ matrix.os }} | ||||
|     steps: | ||||
|     - name: Checkout | ||||
|       uses: actions/checkout@v3 | ||||
|       uses: actions/checkout@v2 | ||||
|     - name: Generate files in working directory | ||||
|       shell: bash | ||||
|       run: __tests__/create-cache-files.sh ${{ runner.os }} test-cache | ||||
| @ -80,7 +80,7 @@ jobs: | ||||
|     runs-on: ${{ matrix.os }} | ||||
|     steps: | ||||
|     - name: Checkout | ||||
|       uses: actions/checkout@v3 | ||||
|       uses: actions/checkout@v2 | ||||
|     - name: Restore cache | ||||
|       uses: ./ | ||||
|       with: | ||||
| @ -110,7 +110,7 @@ jobs: | ||||
|       https_proxy: http://squid-proxy:3128 | ||||
|     steps: | ||||
|     - name: Checkout | ||||
|       uses: actions/checkout@v3 | ||||
|       uses: actions/checkout@v2 | ||||
|     - name: Generate files | ||||
|       run: __tests__/create-cache-files.sh proxy test-cache | ||||
|     - name: Save cache | ||||
| @ -133,7 +133,7 @@ jobs: | ||||
|       https_proxy: http://squid-proxy:3128 | ||||
|     steps: | ||||
|     - name: Checkout | ||||
|       uses: actions/checkout@v3 | ||||
|       uses: actions/checkout@v2 | ||||
|     - name: Restore cache | ||||
|       uses: ./ | ||||
|       with: | ||||
|  | ||||
							
								
								
									
										2
									
								
								.licenses/npm/@actions/cache.dep.yml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										2
									
								
								.licenses/npm/@actions/cache.dep.yml
									
									
									
										generated
									
									
									
								
							| @ -1,6 +1,6 @@ | ||||
| --- | ||||
| name: "@actions/cache" | ||||
| version: 2.0.5 | ||||
| version: 1.0.10 | ||||
| type: npm | ||||
| summary:  | ||||
| homepage:  | ||||
|  | ||||
							
								
								
									
										2
									
								
								.licenses/npm/@actions/core.dep.yml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										2
									
								
								.licenses/npm/@actions/core.dep.yml
									
									
									
										generated
									
									
									
								
							| @ -1,6 +1,6 @@ | ||||
| --- | ||||
| name: "@actions/core" | ||||
| version: 1.7.0 | ||||
| version: 1.6.0 | ||||
| type: npm | ||||
| summary: Actions core lib | ||||
| homepage: https://github.com/actions/toolkit/tree/main/packages/core | ||||
|  | ||||
							
								
								
									
										6
									
								
								.licenses/npm/@opentelemetry/api.dep.yml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										6
									
								
								.licenses/npm/@opentelemetry/api.dep.yml
									
									
									
										generated
									
									
									
								
							| @ -1,9 +1,9 @@ | ||||
| --- | ||||
| name: "@opentelemetry/api" | ||||
| version: 1.0.4 | ||||
| version: 1.1.0 | ||||
| type: npm | ||||
| summary: Public API for OpenTelemetry | ||||
| homepage: https://github.com/open-telemetry/opentelemetry-js-api#readme | ||||
| summary:  | ||||
| homepage:  | ||||
| license: apache-2.0 | ||||
| licenses: | ||||
| - sources: LICENSE | ||||
|  | ||||
							
								
								
									
										6
									
								
								.licenses/npm/@types/node.dep.yml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										6
									
								
								.licenses/npm/@types/node.dep.yml
									
									
									
										generated
									
									
									
								
							| @ -1,9 +1,9 @@ | ||||
| --- | ||||
| name: "@types/node" | ||||
| version: 16.11.33 | ||||
| version: 16.11.26 | ||||
| type: npm | ||||
| summary: TypeScript definitions for Node.js | ||||
| homepage: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node | ||||
| summary:  | ||||
| homepage:  | ||||
| license: mit | ||||
| licenses: | ||||
| - sources: LICENSE | ||||
|  | ||||
							
								
								
									
										82
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										82
									
								
								README.md
									
									
									
									
									
								
							| @ -10,12 +10,28 @@ See ["Caching dependencies to speed up workflows"](https://help.github.com/githu | ||||
|  | ||||
| ## What's New | ||||
| ### v3 | ||||
| * Added support for caching from GHES 3.5. | ||||
| * 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. | ||||
|  | ||||
| Refer [here](https://github.com/actions/cache/blob/v2/README.md) for previous versions | ||||
| ### v2 | ||||
| * Increased the cache size limit to 10 GB. | ||||
| * Added support for multiple paths, [glob patterns](https://github.com/actions/toolkit/tree/main/packages/glob), and single file caches. | ||||
|  | ||||
| ```yaml | ||||
| - name: Cache multiple paths | ||||
|   uses: actions/cache@v3 | ||||
|   with: | ||||
|     path: | | ||||
|       ~/cache | ||||
|       !~/cache/exclude | ||||
|     key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} | ||||
| ``` | ||||
|  | ||||
| * Increased performance and improved cache sizes using `zstd` compression for Linux and macOS runners | ||||
| * Allowed caching for all events with a ref. See [events that trigger workflow](https://help.github.com/en/actions/reference/events-that-trigger-workflows) for info on which events do not have a `GITHUB_REF` | ||||
| * Released the [`@actions/cache`](https://github.com/actions/toolkit/tree/main/packages/cache) npm package to allow other actions to utilize caching | ||||
| * Added a best-effort cleanup step to delete the archive after extraction to reduce storage space | ||||
|  | ||||
| Refer [here](https://github.com/actions/cache/blob/v1/README.md) for previous versions | ||||
|  | ||||
| ## Usage | ||||
|  | ||||
| @ -53,7 +69,7 @@ jobs: | ||||
|     runs-on: ubuntu-latest | ||||
|  | ||||
|     steps: | ||||
|     - uses: actions/checkout@v3 | ||||
|     - uses: actions/checkout@v2 | ||||
|  | ||||
|     - name: Cache Primes | ||||
|       id: cache-primes | ||||
| @ -144,7 +160,7 @@ Using the `cache-hit` output, subsequent steps (such as install or build) can be | ||||
| Example: | ||||
| ```yaml | ||||
| steps: | ||||
|   - uses: actions/checkout@v3 | ||||
|   - uses: actions/checkout@v2 | ||||
|  | ||||
|   - uses: actions/cache@v3 | ||||
|     id: cache | ||||
| @ -159,57 +175,17 @@ steps: | ||||
|  | ||||
| > Note: The `id` defined in `actions/cache` must match the `id` in the `if` statement (i.e. `steps.[ID].outputs.cache-hit`) | ||||
|  | ||||
| ## Known limitation | ||||
|  | ||||
| ## Cache Version | ||||
| Cache version is unique for a combination of compression tool used for compression of cache (Gzip, Zstd, etc based on runner OS) and the path of directories being cached. If two caches have different versions, they are identified as unique cache entries. This also means that a cache created on `windows-latest` runner can't be restored on `ubuntu-latest` as cache `Version`s are different.  | ||||
| - `action/cache` is currently not supported on GitHub Enterprise Server. <https://github.com/github/roadmap/issues/273> is tracking this. | ||||
|  | ||||
| Example: Below example will create 3 unique caches with same keys. Ubuntu and windows runners will use different compression technique and hence create two different caches. And `build-linux` will create two different caches as the `paths` are different. | ||||
| Since GitHub Enterprise Server uses self-hosted runners, dependencies are typically cached on the runner by whatever dependency management tool is being used (npm, maven, etc.).  This eliminates the need for explicit caching in some scenarios. | ||||
|  | ||||
| ```yaml | ||||
| jobs: | ||||
|   build-linux: | ||||
|     runs-on: ubuntu-latest | ||||
|     steps: | ||||
|     - uses: actions/checkout@v3 | ||||
| ## Changelog schedule and history  | ||||
|  | ||||
|     - 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 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 | ||||
|         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 -d prime-numbers | ||||
| ``` | ||||
| | Status  | Version  | Date  | Highlights  | | ||||
| |:---|:---|:---|:---| | ||||
| | Published  | v3.0.0  | Mar 21st, 2022 | -  Updated minimum runner version support from node 12 -> node 16 <br>  | | ||||
|  | ||||
| ## Contributing | ||||
| We would love for you to contribute to `actions/cache`, pull requests are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) for more information. | ||||
|  | ||||
							
								
								
									
										14
									
								
								RELEASES.md
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								RELEASES.md
									
									
									
									
									
								
							| @ -1,14 +0,0 @@ | ||||
| # Releases | ||||
|  | ||||
| ### 3.0.0 | ||||
| - Updated minimum runner version support from node 12 -> node 16 | ||||
|  | ||||
| ### 3.0.1 | ||||
| - Added support for caching from GHES 3.5. | ||||
| - Fixed download issue for files > 2GB during restore. | ||||
|  | ||||
| ### 3.0.2 | ||||
| - 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)) | ||||
| @ -1,4 +1,3 @@ | ||||
| import * as cache from "@actions/cache"; | ||||
| import * as core from "@actions/core"; | ||||
|  | ||||
| import { Events, Outputs, RefKey, State } from "../src/constants"; | ||||
| @ -6,7 +5,6 @@ import * as actionUtils from "../src/utils/actionUtils"; | ||||
| import * as testUtils from "../src/utils/testUtils"; | ||||
|  | ||||
| jest.mock("@actions/core"); | ||||
| jest.mock("@actions/cache"); | ||||
|  | ||||
| beforeAll(() => { | ||||
|     jest.spyOn(core, "getInput").mockImplementation((name, options) => { | ||||
| @ -22,7 +20,7 @@ afterEach(() => { | ||||
| test("isGhes returns true if server url is not github.com", () => { | ||||
|     try { | ||||
|         process.env["GITHUB_SERVER_URL"] = "http://example.com"; | ||||
|         expect(actionUtils.isGhes()).toBe(true); | ||||
|         expect(actionUtils.isGhes()).toBe(false); | ||||
|     } finally { | ||||
|         process.env["GITHUB_SERVER_URL"] = undefined; | ||||
|     } | ||||
| @ -234,41 +232,3 @@ test("getInputAsInt throws if required and value missing", () => { | ||||
|         actionUtils.getInputAsInt("undefined", { required: true }) | ||||
|     ).toThrowError(); | ||||
| }); | ||||
|  | ||||
| test("isCacheFeatureAvailable for ac enabled", () => { | ||||
|     jest.spyOn(cache, "isFeatureAvailable").mockImplementation(() => true); | ||||
|  | ||||
|     expect(actionUtils.isCacheFeatureAvailable()).toBe(true); | ||||
| }); | ||||
|  | ||||
| test("isCacheFeatureAvailable for ac disabled on GHES", () => { | ||||
|     jest.spyOn(cache, "isFeatureAvailable").mockImplementation(() => false); | ||||
|  | ||||
|     const message = | ||||
|         "Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not."; | ||||
|     const infoMock = jest.spyOn(core, "info"); | ||||
|  | ||||
|     try { | ||||
|         process.env["GITHUB_SERVER_URL"] = "http://example.com"; | ||||
|         expect(actionUtils.isCacheFeatureAvailable()).toBe(false); | ||||
|         expect(infoMock).toHaveBeenCalledWith(`[warning]${message}`); | ||||
|     } finally { | ||||
|         delete process.env["GITHUB_SERVER_URL"]; | ||||
|     } | ||||
| }); | ||||
|  | ||||
| test("isCacheFeatureAvailable for ac disabled on dotcom", () => { | ||||
|     jest.spyOn(cache, "isFeatureAvailable").mockImplementation(() => false); | ||||
|  | ||||
|     const message = | ||||
|         "An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions."; | ||||
|     const infoMock = jest.spyOn(core, "info"); | ||||
|  | ||||
|     try { | ||||
|         process.env["GITHUB_SERVER_URL"] = "http://github.com"; | ||||
|         expect(actionUtils.isCacheFeatureAvailable()).toBe(false); | ||||
|         expect(infoMock).toHaveBeenCalledWith(`[warning]${message}`); | ||||
|     } finally { | ||||
|         delete process.env["GITHUB_SERVER_URL"]; | ||||
|     } | ||||
| }); | ||||
|  | ||||
| @ -34,9 +34,6 @@ beforeEach(() => { | ||||
|     process.env[RefKey] = "refs/heads/feature-branch"; | ||||
|  | ||||
|     jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false); | ||||
|     jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation( | ||||
|         () => true | ||||
|     ); | ||||
| }); | ||||
|  | ||||
| afterEach(() => { | ||||
| @ -58,12 +55,10 @@ test("restore with invalid event outputs warning", async () => { | ||||
|     expect(failedMock).toHaveBeenCalledTimes(0); | ||||
| }); | ||||
|  | ||||
| test("restore without AC available should no-op", async () => { | ||||
|     jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false); | ||||
|     jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation( | ||||
|         () => false | ||||
|     ); | ||||
| test("restore on GHES should no-op", async () => { | ||||
|     jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true); | ||||
|  | ||||
|     const logWarningMock = jest.spyOn(actionUtils, "logWarning"); | ||||
|     const restoreCacheMock = jest.spyOn(cache, "restoreCache"); | ||||
|     const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput"); | ||||
|  | ||||
| @ -72,54 +67,9 @@ test("restore without AC available should no-op", async () => { | ||||
|     expect(restoreCacheMock).toHaveBeenCalledTimes(0); | ||||
|     expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1); | ||||
|     expect(setCacheHitOutputMock).toHaveBeenCalledWith(false); | ||||
| }); | ||||
|  | ||||
| test("restore on GHES without AC available should no-op", async () => { | ||||
|     jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true); | ||||
|     jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation( | ||||
|         () => false | ||||
|     expect(logWarningMock).toHaveBeenCalledWith( | ||||
|         "Cache action is not supported on GHES. See https://github.com/actions/cache/issues/505 for more details" | ||||
|     ); | ||||
|  | ||||
|     const restoreCacheMock = jest.spyOn(cache, "restoreCache"); | ||||
|     const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput"); | ||||
|  | ||||
|     await run(); | ||||
|  | ||||
|     expect(restoreCacheMock).toHaveBeenCalledTimes(0); | ||||
|     expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1); | ||||
|     expect(setCacheHitOutputMock).toHaveBeenCalledWith(false); | ||||
| }); | ||||
|  | ||||
| test("restore on GHES with AC available ", async () => { | ||||
|     jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true); | ||||
|     const path = "node_modules"; | ||||
|     const key = "node-test"; | ||||
|     testUtils.setInputs({ | ||||
|         path: path, | ||||
|         key | ||||
|     }); | ||||
|  | ||||
|     const infoMock = jest.spyOn(core, "info"); | ||||
|     const failedMock = jest.spyOn(core, "setFailed"); | ||||
|     const stateMock = jest.spyOn(core, "saveState"); | ||||
|     const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput"); | ||||
|     const restoreCacheMock = jest | ||||
|         .spyOn(cache, "restoreCache") | ||||
|         .mockImplementationOnce(() => { | ||||
|             return Promise.resolve(key); | ||||
|         }); | ||||
|  | ||||
|     await run(); | ||||
|  | ||||
|     expect(restoreCacheMock).toHaveBeenCalledTimes(1); | ||||
|     expect(restoreCacheMock).toHaveBeenCalledWith([path], key, []); | ||||
|  | ||||
|     expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); | ||||
|     expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1); | ||||
|     expect(setCacheHitOutputMock).toHaveBeenCalledWith(true); | ||||
|  | ||||
|     expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`); | ||||
|     expect(failedMock).toHaveBeenCalledTimes(0); | ||||
| }); | ||||
|  | ||||
| test("restore with no path should fail", async () => { | ||||
|  | ||||
| @ -54,9 +54,6 @@ beforeEach(() => { | ||||
|     process.env[RefKey] = "refs/heads/feature-branch"; | ||||
|  | ||||
|     jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false); | ||||
|     jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation( | ||||
|         () => true | ||||
|     ); | ||||
| }); | ||||
|  | ||||
| afterEach(() => { | ||||
| @ -104,67 +101,18 @@ test("save with no primary key in state outputs warning", async () => { | ||||
|     expect(failedMock).toHaveBeenCalledTimes(0); | ||||
| }); | ||||
|  | ||||
| test("save without AC available should no-op", async () => { | ||||
|     jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation( | ||||
|         () => false | ||||
|     ); | ||||
| test("save on GHES should no-op", async () => { | ||||
|     jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true); | ||||
|  | ||||
|     const logWarningMock = jest.spyOn(actionUtils, "logWarning"); | ||||
|     const saveCacheMock = jest.spyOn(cache, "saveCache"); | ||||
|  | ||||
|     await run(); | ||||
|  | ||||
|     expect(saveCacheMock).toHaveBeenCalledTimes(0); | ||||
| }); | ||||
|  | ||||
| test("save on ghes without AC available should no-op", async () => { | ||||
|     jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true); | ||||
|     jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation( | ||||
|         () => false | ||||
|     expect(logWarningMock).toHaveBeenCalledWith( | ||||
|         "Cache action is not supported on GHES. See https://github.com/actions/cache/issues/505 for more details" | ||||
|     ); | ||||
|  | ||||
|     const saveCacheMock = jest.spyOn(cache, "saveCache"); | ||||
|  | ||||
|     await run(); | ||||
|  | ||||
|     expect(saveCacheMock).toHaveBeenCalledTimes(0); | ||||
| }); | ||||
|  | ||||
| test("save on GHES with AC available", async () => { | ||||
|     jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true); | ||||
|     const failedMock = jest.spyOn(core, "setFailed"); | ||||
|  | ||||
|     const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43"; | ||||
|     const savedCacheKey = "Linux-node-"; | ||||
|  | ||||
|     jest.spyOn(core, "getState") | ||||
|         // Cache Entry State | ||||
|         .mockImplementationOnce(() => { | ||||
|             return savedCacheKey; | ||||
|         }) | ||||
|         // Cache Key State | ||||
|         .mockImplementationOnce(() => { | ||||
|             return primaryKey; | ||||
|         }); | ||||
|  | ||||
|     const inputPath = "node_modules"; | ||||
|     testUtils.setInput(Inputs.Path, inputPath); | ||||
|     testUtils.setInput(Inputs.UploadChunkSize, "4000000"); | ||||
|  | ||||
|     const cacheId = 4; | ||||
|     const saveCacheMock = jest | ||||
|         .spyOn(cache, "saveCache") | ||||
|         .mockImplementationOnce(() => { | ||||
|             return Promise.resolve(cacheId); | ||||
|         }); | ||||
|  | ||||
|     await run(); | ||||
|  | ||||
|     expect(saveCacheMock).toHaveBeenCalledTimes(1); | ||||
|     expect(saveCacheMock).toHaveBeenCalledWith([inputPath], primaryKey, { | ||||
|         uploadChunkSize: 4000000 | ||||
|     }); | ||||
|  | ||||
|     expect(failedMock).toHaveBeenCalledTimes(0); | ||||
| }); | ||||
|  | ||||
| test("save with exact match returns early", async () => { | ||||
|  | ||||
							
								
								
									
										1159
									
								
								dist/restore/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1159
									
								
								dist/restore/index.js
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										1163
									
								
								dist/save/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1163
									
								
								dist/save/index.js
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										40
									
								
								examples.md
									
									
									
									
									
								
							
							
						
						
									
										40
									
								
								examples.md
									
									
									
									
									
								
							| @ -18,6 +18,9 @@ | ||||
| - [Java - Gradle](#java---gradle) | ||||
| - [Java - Maven](#java---maven) | ||||
| - [Node - npm](#node---npm) | ||||
|   - [macOS and Ubuntu](#macos-and-ubuntu) | ||||
|   - [Windows](#windows-3) | ||||
|   - [Using multiple systems and `npm config`](#using-multiple-systems-and-npm-config) | ||||
| - [Node - Lerna](#node---lerna) | ||||
| - [Node - Yarn](#node---yarn) | ||||
| - [Node - Yarn 2](#node---yarn-2) | ||||
| @ -87,7 +90,7 @@ steps: | ||||
| - uses: actions/cache@v3 | ||||
|   with: | ||||
|     path: ~/.dub | ||||
|     key: ${{ runner.os }}-dub-${{ hashFiles('**/dub.selections.json') }} | ||||
|     key: ${{ runner.os }}-dub-${{ hashFiles('**/dub.json') }} | ||||
|     restore-keys: | | ||||
|       ${{ runner.os }}-dub- | ||||
| ``` | ||||
| @ -98,7 +101,7 @@ steps: | ||||
| - uses: actions/cache@v3 | ||||
|   with: | ||||
|     path: ~\AppData\Local\dub | ||||
|     key: ${{ runner.os }}-dub-${{ hashFiles('**/dub.selections.json') }} | ||||
|     key: ${{ runner.os }}-dub-${{ hashFiles('**/dub.json') }} | ||||
|     restore-keys: | | ||||
|       ${{ runner.os }}-dub- | ||||
| ``` | ||||
| @ -134,10 +137,11 @@ steps: | ||||
|   with: | ||||
|     path: | | ||||
|       ~\.deno | ||||
|       ~\AppData\Local\deno | ||||
|       %LocalAppData%\deno | ||||
|     key: ${{ runner.os }}-deno-${{ hashFiles('**/deps.ts') }} | ||||
| ``` | ||||
|  | ||||
|  | ||||
| ## Elixir - Mix | ||||
|  | ||||
| ```yaml | ||||
| @ -256,12 +260,40 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba | ||||
|  | ||||
| ## Node - npm | ||||
|  | ||||
| For npm, cache files are stored in `~/.npm` on Posix, or `~\AppData\npm-cache` on Windows, but it's possible to use `npm config get cache` to find the path on any platform. See [the npm docs](https://docs.npmjs.com/cli/cache#cache) for more details. | ||||
| For npm, cache files are stored in `~/.npm` on Posix, or `%AppData%/npm-cache` on Windows. See https://docs.npmjs.com/cli/cache#cache | ||||
|  | ||||
| If using `npm config` to retrieve the cache directory, ensure you run [actions/setup-node](https://github.com/actions/setup-node) first to ensure your `npm` version is correct. | ||||
|  | ||||
| >Note: It is not recommended to cache `node_modules`, as it can break across Node versions and won't work with `npm ci` | ||||
|  | ||||
| ### macOS and Ubuntu | ||||
|  | ||||
| ```yaml | ||||
| - uses: actions/cache@v3 | ||||
|   with: | ||||
|     path: ~/.npm | ||||
|     key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | ||||
|     restore-keys: | | ||||
|       ${{ runner.os }}-node- | ||||
| ``` | ||||
|  | ||||
| ### Windows | ||||
|  | ||||
| ```yaml | ||||
| - name: Get npm cache directory | ||||
|   id: npm-cache | ||||
|   run: | | ||||
|     echo "::set-output name=dir::$(npm config get cache)" | ||||
| - uses: actions/cache@v3 | ||||
|   with: | ||||
|     path: ${{ steps.npm-cache.outputs.dir }} | ||||
|     key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | ||||
|     restore-keys: | | ||||
|       ${{ runner.os }}-node- | ||||
| ``` | ||||
|  | ||||
| ### Using multiple systems and `npm config` | ||||
|  | ||||
| ```yaml | ||||
| - name: Get npm cache directory | ||||
|   id: npm-cache-dir | ||||
|  | ||||
							
								
								
									
										13397
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										13397
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										30
									
								
								package.json
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								package.json
									
									
									
									
									
								
							| @ -1,6 +1,6 @@ | ||||
| { | ||||
|   "name": "cache", | ||||
|   "version": "3.0.3", | ||||
|   "version": "3.0.0", | ||||
|   "private": true, | ||||
|   "description": "Cache dependencies and build outputs", | ||||
|   "main": "dist/restore/index.js", | ||||
| @ -23,29 +23,29 @@ | ||||
|   "author": "GitHub", | ||||
|   "license": "MIT", | ||||
|   "dependencies": { | ||||
|     "@actions/cache": "^2.0.5", | ||||
|     "@actions/core": "^1.7.0", | ||||
|     "@actions/cache": "file:actions-cache-2.6.0.tgz", | ||||
|     "@actions/core": "^1.2.6", | ||||
|     "@actions/exec": "^1.1.1", | ||||
|     "@actions/io": "^1.1.2" | ||||
|   }, | ||||
|   "devDependencies": { | ||||
|     "@types/jest": "^27.5.0", | ||||
|     "@types/jest": "^27.4.1", | ||||
|     "@types/nock": "^11.1.0", | ||||
|     "@types/node": "^16.11.33", | ||||
|     "@typescript-eslint/eslint-plugin": "^5.22.0", | ||||
|     "@typescript-eslint/parser": "^5.22.0", | ||||
|     "@types/node": "^16.11.26", | ||||
|     "@typescript-eslint/eslint-plugin": "^5.15.0", | ||||
|     "@typescript-eslint/parser": "^5.15.0", | ||||
|     "@zeit/ncc": "^0.20.5", | ||||
|     "eslint": "^8.14.0", | ||||
|     "eslint": "^8.11.0", | ||||
|     "eslint-config-prettier": "^8.5.0", | ||||
|     "eslint-plugin-import": "^2.26.0", | ||||
|     "eslint-plugin-jest": "^26.1.5", | ||||
|     "eslint-plugin-import": "^2.25.4", | ||||
|     "eslint-plugin-jest": "^26.1.2", | ||||
|     "eslint-plugin-prettier": "^4.0.0", | ||||
|     "eslint-plugin-simple-import-sort": "^7.0.0", | ||||
|     "jest": "^28.0.3", | ||||
|     "jest": "^27.5.1", | ||||
|     "jest-circus": "^27.5.1", | ||||
|     "nock": "^13.2.4", | ||||
|     "prettier": "^2.6.2", | ||||
|     "ts-jest": "^28.0.2", | ||||
|     "typescript": "^4.6.4" | ||||
|     "nock": "^11.7.0", | ||||
|     "prettier": "^2.6.0", | ||||
|     "ts-jest": "^27.1.3", | ||||
|     "typescript": "^3.9.9" | ||||
|   } | ||||
| } | ||||
|  | ||||
| @ -6,7 +6,10 @@ import * as utils from "./utils/actionUtils"; | ||||
|  | ||||
| async function run(): Promise<void> { | ||||
|     try { | ||||
|         if (!utils.isCacheFeatureAvailable()) { | ||||
|         if (utils.isGhes()) { | ||||
|             utils.logWarning( | ||||
|                 "Cache action is not supported on GHES. See https://github.com/actions/cache/issues/505 for more details" | ||||
|             ); | ||||
|             utils.setCacheHitOutput(false); | ||||
|             return; | ||||
|         } | ||||
| @ -52,17 +55,16 @@ async function run(): Promise<void> { | ||||
|             utils.setCacheHitOutput(isExactKeyMatch); | ||||
|  | ||||
|             core.info(`Cache restored from key: ${cacheKey}`); | ||||
|         } catch (error: unknown) { | ||||
|             const typedError = error as Error; | ||||
|             if (typedError.name === cache.ValidationError.name) { | ||||
|         } catch (error) { | ||||
|             if (error.name === cache.ValidationError.name) { | ||||
|                 throw error; | ||||
|             } else { | ||||
|                 utils.logWarning(typedError.message); | ||||
|                 utils.logWarning(error.message); | ||||
|                 utils.setCacheHitOutput(false); | ||||
|             } | ||||
|         } | ||||
|     } catch (error: unknown) { | ||||
|         core.setFailed((error as Error).message); | ||||
|     } catch (error) { | ||||
|         core.setFailed(error.message); | ||||
|     } | ||||
| } | ||||
|  | ||||
|  | ||||
							
								
								
									
										20
									
								
								src/save.ts
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								src/save.ts
									
									
									
									
									
								
							| @ -11,7 +11,10 @@ process.on("uncaughtException", e => utils.logWarning(e.message)); | ||||
|  | ||||
| async function run(): Promise<void> { | ||||
|     try { | ||||
|         if (!utils.isCacheFeatureAvailable()) { | ||||
|         if (utils.isGhes()) { | ||||
|             utils.logWarning( | ||||
|                 "Cache action is not supported on GHES. See https://github.com/actions/cache/issues/505 for more details" | ||||
|             ); | ||||
|             return; | ||||
|         } | ||||
|  | ||||
| @ -49,18 +52,17 @@ async function run(): Promise<void> { | ||||
|                 uploadChunkSize: utils.getInputAsInt(Inputs.UploadChunkSize) | ||||
|             }); | ||||
|             core.info(`Cache saved with key: ${primaryKey}`); | ||||
|         } catch (error: unknown) { | ||||
|             const typedError = error as Error; | ||||
|             if (typedError.name === cache.ValidationError.name) { | ||||
|         } catch (error) { | ||||
|             if (error.name === cache.ValidationError.name) { | ||||
|                 throw error; | ||||
|             } else if (typedError.name === cache.ReserveCacheError.name) { | ||||
|                 core.info(typedError.message); | ||||
|             } else if (error.name === cache.ReserveCacheError.name) { | ||||
|                 core.info(error.message); | ||||
|             } else { | ||||
|                 utils.logWarning(typedError.message); | ||||
|                 utils.logWarning(error.message); | ||||
|             } | ||||
|         } | ||||
|     } catch (error: unknown) { | ||||
|         utils.logWarning((error as Error).message); | ||||
|     } catch (error) { | ||||
|         utils.logWarning(error.message); | ||||
|     } | ||||
| } | ||||
|  | ||||
|  | ||||
| @ -1,13 +1,9 @@ | ||||
| import * as cache from "@actions/cache"; | ||||
| import * as core from "@actions/core"; | ||||
|  | ||||
| import { Outputs, RefKey, State } from "../constants"; | ||||
|  | ||||
| export function isGhes(): boolean { | ||||
|     const ghUrl = new URL( | ||||
|         process.env["GITHUB_SERVER_URL"] || "https://github.com" | ||||
|     ); | ||||
|     return ghUrl.hostname.toUpperCase() !== "GITHUB.COM"; | ||||
|     return false; | ||||
| } | ||||
|  | ||||
| export function isExactKeyMatch(key: string, cacheKey?: string): boolean { | ||||
| @ -75,20 +71,3 @@ export function getInputAsInt( | ||||
|     } | ||||
|     return value; | ||||
| } | ||||
|  | ||||
| export function isCacheFeatureAvailable(): boolean { | ||||
|     if (!cache.isFeatureAvailable()) { | ||||
|         if (isGhes()) { | ||||
|             logWarning( | ||||
|                 "Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not." | ||||
|             ); | ||||
|         } else { | ||||
|             logWarning( | ||||
|                 "An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions." | ||||
|             ); | ||||
|         } | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     return true; | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	