-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: How to properly cache node-gyp builds? #785
Comments
Hello @arminrosu. I think for that case is better to use actions/cache because the setup-node saves only global cache. Through |
@dmitry-shibanov thanks, that's how I did it. I asked the question here because this repo is concerned with node, whereas actions/cache is a generic action. Was hoping the team behind the actions was sharing knowledge maybe. |
It's quite disappointing and surprising to find that https://github.com/marketplace/actions/yarn-install-cache was deprecated in favour of this ( So what's the recommended best practice for GitHub actions which caches everything which might need to be cached? https://yarnpkg.com/features/caching#github-actions says:
My best guess is that currently a combination of |
I found yarnpkg/berry#5924 which says that caching |
Also there seems to be no way to configure this action to cache |
I went down the rabbit hole of caching The best I ever did was to pre-build a Docker image with a fairly recent
Then I created a Github action I could reuse in jobs in name: "fast monorepo yarn install"
description: |
Our base CI image contains prebaked npm + yarn + node_modules caches inside
an artifacts directory.
This shared action will:
- Set up all the caches from the artifacts directory
- Run `yarn install --immutable` to resolve any drift
This action _will_ get slower over time as we add more packages to yarn, so
rebuilding the base CI image every so often to resolve package drift is
advised.
runs:
using: composite
steps:
- name: Find the NPM global cache directory
id: npm-config
shell: bash
run: |
echo "NPM_GLOBAL_CACHE_FOLDER=$(npm config get cache)" >> $GITHUB_OUTPUT
- name: Move yarn install state into place
shell: bash
run: |
mv /build-artifacts/yarn-install-state.gz .yarn/install-state.gz
- name: Unpack npm global cache
shell: bash
run: |
mkdir -p "${{ steps.npm-config.outputs.NPM_GLOBAL_CACHE_FOLDER }}"
tar xf /build-artifacts/npm_global_cache.tar.zst -C "${{ steps.npm-config.outputs.NPM_GLOBAL_CACHE_FOLDER }}"
- name: Unpack recursive node_modules cache directly into the monorepo
shell: bash
run: |
tar xf /build-artifacts/node_modules_archive.tar.zst -C .
- name: Run yarn install
shell: bash
run: |
yarn install --immutable --inline-builds
env:
# Use local cache folder to keep downloaded archives
YARN_ENABLE_GLOBAL_CACHE: "false"
# Reduce node_modules size
YARN_NM_MODE: "hardlinks-local"
# Ensure we're using the local monologue cache
YARN_CACHE_FOLDER: ".yarn/cache" and referenced it in jobs like: - name: yarn install
uses: ./.github/actions/fast-yarn-install |
Hello,
Description:
I'm struggling to figure out how to properly cache node-gyp builds. This adds +30s to my
yarn install
, by rebuilding them every timeyarn install
runs.After manually caching and restoring the build paths, it still triggers a new gyp build every
yarn install
. The paths I cached:My previous question in the node-gyp repo lead me here. The suggestion was to look into node-gyp-build.
Any advice would be appreciated.
Justification:
Save myself time and the planet by not wasting electricity.
Are you willing to submit a PR?
Of course.
The text was updated successfully, but these errors were encountered: