Hello, I've tried to follow the Yarn example, but am running into issues restoring the cache between jobs.
Here's some example code:
jobs:
install:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up node 12
uses: actions/setup-node@v1
with:
node-version: 12.x
- name: Get Yarn Cache Directory
id: yarn-cache
run: |
echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v1
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
run: yarn install
build:
needs: install
runs-on: ubuntu-latest
steps:
- name: Use cache
uses: actions/cache@v1
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Bundle library
run: yarn rollup
This is the output of the echo command from the install job:
shell: /bin/bash -e {0}
This is the output when attempting to restore/use the cache in the build job:
##[error]The template is not valid. hashFiles('/home/runner/work/my-library/my-library/**/yarn.lock') failed. Directory '/home/runner/work/my-library/my-library' is empty
It seems like setting up the cache is fine, but I'm not sure if the steps to restore the cache is correct in the build job.
Run actions/cache@v1
with:
path: /home/runner/.cache/yarn/v6
key: Linux-yarn-41015f9cc5726fbdc66b81d2c0629ca1c83e0330cc716214b95e6e86fce51a56
restore-keys: Linux-yarn-
Cache Size: ~154 MB (161229517 B)
/bin/tar -xz -f /home/runner/work/_temp/5ba7fc03-08f9-4747-9696-d1baa8806b49/cache.tgz -C /home/runner/.cache/yarn/v6
Cache restored from key: Linux-yarn-41015f9cc5726fbdc66b81d2c0629ca1c83e0330cc716214b95e6e86fce51a56
I feel like I'm missing something fairly simple, but can't pinpoint it exactly. Any help would be grateful.
try this:
- name: Use cached Node modules
uses: actions/cache@v1
with:
path: node_modules
key: nodeModules-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
nodeModules-
and make sure that runs-on is the same as what your yarn.lock was made on like macos-latest.
@webjay That worked, thank you for your help!
Most helpful comment
try this: