Skip to content

Commit fb86cbf

Browse files
authored
Updated node example (#1008)
* Updated node example * Update examples.md
1 parent a57932f commit fb86cbf

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

examples.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,14 +309,29 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba
309309
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.
310310

311311
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.
312+
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.
312313

313314
>Note: It is not recommended to cache `node_modules`, as it can break across Node versions and won't work with `npm ci`
314315

316+
### **Get npm cache directory using same shell**
317+
### Bash shell
315318
```yaml
316319
- name: Get npm cache directory
317-
id: npm-cache-dir
318-
run: |
319-
echo "::set-output name=dir::$(npm config get cache)"
320+
id: npm-cache
321+
shell: bash
322+
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
323+
```
324+
325+
### PWSH shell
326+
```yaml
327+
- name: Get npm cache directory
328+
id: npm-cache
329+
shell: pwsh
330+
run: echo "dir=$(npm config get cache)" >> ${env:GITHUB_OUTPUT}
331+
```
332+
`Get npm cache directory` step can then be used with `actions/cache` as shown below
333+
334+
```yaml
320335
- uses: actions/cache@v3
321336
id: npm-cache # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
322337
with:

0 commit comments

Comments
 (0)