mirror of
				https://gitea.com/actions/cache.git
				synced 2025-10-29 07:47:12 +00:00 
			
		
		
		
	Compare commits
	
		
			3 Commits
		
	
	
		
			tanuj077/s
			...
			bishal-pdM
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | 619517aa29 | ||
|   | dc097e3bb9 | ||
|   | fb86cbf360 | 
							
								
								
									
										19
									
								
								examples.md
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								examples.md
									
									
									
									
									
								
							| @@ -309,14 +309,29 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba | ||||
| 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. | ||||
|  | ||||
| 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. | ||||
| After [deprecation](https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/) of save-state and set-output commands, the correct way to set output is using `${GITHUB_OUTPUT}`. For linux, we can use `${GITHUB_OUTPUT}` whereas for windows we need to use `${env:GITHUB_OUTPUT}` due to two different default shells in these two different OS ie `bash` and `pwsh` respectively. | ||||
|  | ||||
| >Note: It is not recommended to cache `node_modules`, as it can break across Node versions and won't work with `npm ci` | ||||
|  | ||||
| ### **Get npm cache directory using same shell** | ||||
| ### Bash shell | ||||
| ```yaml | ||||
| - name: Get npm cache directory | ||||
|   id: npm-cache-dir | ||||
|   run: | | ||||
|     echo "::set-output name=dir::$(npm config get cache)" | ||||
|   shell: bash | ||||
|   run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT} | ||||
| ``` | ||||
|  | ||||
| ### PWSH shell | ||||
| ```yaml | ||||
| - name: Get npm cache directory | ||||
|   id: npm-cache-dir | ||||
|   shell: pwsh | ||||
|   run: echo "dir=$(npm config get cache)" >> ${env:GITHUB_OUTPUT} | ||||
| ``` | ||||
| `Get npm cache directory` step can then be used with `actions/cache` as shown below | ||||
|  | ||||
| ```yaml | ||||
| - uses: actions/cache@v3 | ||||
|   id: npm-cache # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true' | ||||
|   with: | ||||
|   | ||||
| @@ -14,7 +14,7 @@ A cache today is immutable and cannot be updated. But some use cases require the | ||||
|           restore-keys: | | ||||
|             primes-${{ runner.os }} | ||||
|   ```           | ||||
|   Please note that this will create a new cache on every run and hence will consume the cache [quota](#cache-limits). | ||||
|   Please note that this will create a new cache on every run and hence will consume the cache [quota](./README.md#cache-limits). | ||||
|    | ||||
| ## Use cache across feature branches | ||||
| Reusing cache across feature branches is not allowed today to provide cache [isolation](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache). However if both feature branches are from the default branch, a good way to achieve this is to ensure that the default branch has a cache. This cache will then be consumable by both feature branches. | ||||
| @@ -80,4 +80,4 @@ jobs: | ||||
|         env: | ||||
|           GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||||
| ``` | ||||
| </details> | ||||
| </details> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user