Skip to content

Commit

Permalink
better caching (#4923)
Browse files Browse the repository at this point in the history
### Intent
I previously implemented caching but had to partially [roll it
back](https://github.com/posit-dev/positron/pull/4771/files) because I
mistakenly tied the nested directories to the root lock files for
`extensions` and `build`. My goal now is to correct this setup and
restore caching for the nested directories.

### Approach
I separated the `extensions` and "extensions nested" directories into
distinct caches. For the nested caches, I’m using a hash generated from
**all** the existing yarn.lock files in the nested directories. This
ensures that if a single extension changes, the cache is updated
accordingly. I applied the same approach to the `remote` directory and
its nested extensions. For example:
```bash
    - name: Cache nested extensions
      id: cache-nested-extensions
      uses: actions/cache@v4
      with:
        path: ./extensions/**/node_modules
        key: cache-nested-extensions-v2-${{ runner.os }}-${{ hashFiles('extensions/**/yarn.lock') }}
```
In this example, the cache key is built using the content of all
`yarn.lock` files under `extensions/**/yarn.lock`. If there are separate
`yarn.lock` files in the root extensions directory and in its
subdirectories, each will be hashed independently, making the root and
nested caches distinct from one another.

### QA Notes
* I [temporarily modified a nested lock
file](1ff4252)
and confirmed the caching behaved as expected.
<img width="910" alt="Screenshot 2024-10-07 at 1 21 25 PM"
src="https://github.com/user-attachments/assets/cebd80ad-007d-49a0-9f0a-946a9d5c4d6c">
  • Loading branch information
midleman authored Oct 7, 2024
1 parent 41a835a commit 5442db7
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions .github/actions/cache-multi-paths/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,44 @@ description: "Restores/Saves cache for node_modules, build, extensions, and remo
runs:
using: "composite"
steps:
- name: Cache node_modules
id: cache-node-modules
- name: Cache root
id: cache-root
uses: actions/cache@v4
with:
path: ./node_modules
key: root-node-modules-v7-${{ runner.os }}-${{ hashFiles('yarn.lock') }}
key: cache-root-v2-${{ runner.os }}-${{ hashFiles('./yarn.lock') }}

- name: Cache build
id: cache-build
uses: actions/cache@v4
with:
path: ./build/node_modules
key: build-node-modules-v7-${{ runner.os }}-${{ hashFiles('build/yarn.lock') }}
key: cache-build-v2-${{ runner.os }}-${{ hashFiles('build/yarn.lock') }}

- name: Cache extensions
id: cache-extensions
uses: actions/cache@v4
with:
path: ./extensions/node_modules
key: extensions-v7-${{ runner.os }}-${{ hashFiles('extensions/yarn.lock') }}
key: cache-extensions-v2-${{ runner.os }}-${{ hashFiles('extensions/yarn.lock') }}

- name: Cache nested extensions
id: cache-nested-extensions
uses: actions/cache@v4
with:
path: ./extensions/**/node_modules
key: cache-nested-extensions-v2-${{ runner.os }}-${{ hashFiles('extensions/**/yarn.lock') }}

- name: Cache remote
id: cache-remote
uses: actions/cache@v4
with:
path: ./remote/node_modules
key: remote-node-modules-v7-${{ runner.os }}-${{ hashFiles('remote/yarn.lock') }}
key: cache-remote-v2-${{ runner.os }}-${{ hashFiles('remote/yarn.lock') }}

- name: Cache nested remote
id: cache-nested-remote
uses: actions/cache@v4
with:
path: ./remote/**/node_modules
key: cache-nested-remote-v2-${{ runner.os }}-${{ hashFiles('remote/**/yarn.lock') }}

0 comments on commit 5442db7

Please sign in to comment.