Skip to content
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

Cache node_modules #1158

Merged
merged 8 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/actions/init-all/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ runs:
**/uv.lock

## Set up Node environment
- uses: actions/setup-node@v4
- uses: ./.github/actions/init-node
with:
node-version-file: ${{ inputs.node-version-file }}
cache: 'yarn'
node-version-file: ${{ env.node-version-file }}

# We require protoc >= 3.20, but Ubuntu 22.04 - the OS that these Github
# Actions are running as of 2023.05.03 - doesn't have recent versions
Expand Down
38 changes: 38 additions & 0 deletions .github/actions/init-node/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: 'Node Initialization Action'
description: 'Node initialization steps for CI jobs'
inputs:
node-version-file:
description: 'Node version file to setup'
required: true
runs:
using: "composite"
steps:
## Set up Node environment
- uses: actions/setup-node@v4
with:
node-version-file: ${{ inputs.node-version-file }}
cache: 'yarn'

- name: Get Node.js version
id: node-version
run: echo "NODE_VERSION=$(node -v)" >> $GITHUB_ENV
shell: bash
# Include the NodeJS version in the cache key.
# While there are several reasons not to recommend caching `node_modules` (https://github.com/actions/setup-node/issues/304#issuecomment-886241508),
# NodeJS version incompatibility is one of them (https://github.com/actions/setup-node/issues/304#issuecomment-886240594).
# So invalidating the cache based on the NodeJS version is not perfect but
# it makes things safer.
# See also https://github.com/actions/setup-node/issues/406 and https://dev.to/flydiverny/comment/1lk25.

- uses: actions/cache@v4
with:
path: '**/node_modules'
key: node_modules-${{ env.NODE_VERSION }}-${{ hashFiles('yarn.lock') }}

# `yarn install` often takes so long time on in the Windows env.
# https://github.com/yarnpkg/yarn/issues/8242
- run: yarn config set network-timeout 600000
shell: bash

- run: yarn install --frozen-lockfile
shell: bash
44 changes: 21 additions & 23 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-node@v4

- uses: ./.github/actions/init-node
with:
node-version-file: ${{ env.node-version-file }}
cache: 'yarn'
- run: yarn install --frozen-lockfile

- name: Lint
run: |
yarn check:eslint
Expand Down Expand Up @@ -176,11 +176,12 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-node@v4


- uses: ./.github/actions/init-node
with:
node-version-file: ${{ env.node-version-file }}
cache: 'yarn'
- run: yarn install --frozen-lockfile

- name: Lint
run: |
yarn check:eslint
Expand All @@ -201,11 +202,11 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-node@v4

- uses: ./.github/actions/init-node
with:
node-version-file: ${{ env.node-version-file }}
cache: 'yarn'
- run: yarn install --frozen-lockfile

- run: make sharing-common
working-directory: .
# - name: Lint
Expand All @@ -228,11 +229,11 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-node@v4

- uses: ./.github/actions/init-node
with:
node-version-file: ${{ env.node-version-file }}
cache: 'yarn'
- run: yarn install --frozen-lockfile

- name: Lint
run: |
yarn check:eslint
Expand All @@ -258,12 +259,11 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-node@v4

- uses: ./.github/actions/init-node
with:
node-version-file: ${{ env.node-version-file }}
cache: 'yarn'
- run: yarn config set network-timeout 600000 # `yarn install` often takes so long time on in the Windows env.
- run: yarn install --frozen-lockfile

- run: make common
working-directory: .
- name: Lint
Expand Down Expand Up @@ -488,11 +488,10 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: actions/setup-node@v4

- uses: ./.github/actions/init-node
with:
node-version-file: ${{ env.node-version-file }}
cache: 'yarn'
- run: yarn install --frozen-lockfile

- name: Cache node_modules/.cache including Webpack's cache
uses: actions/cache@v4
Expand Down Expand Up @@ -695,12 +694,11 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-node@v4

- uses: ./.github/actions/init-node
with:
node-version-file: ${{ env.node-version-file }}
cache: 'yarn'
- run: yarn config set network-timeout 300000 # https://github.com/yarnpkg/yarn/issues/8242
- run: yarn install --frozen-lockfile

- run: yarn playwright install
- run: make common
- name: Lint
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ all: init mountable sharing sharing-editor


.PHONY: init
init: git_submodules venv node_modules
init: git_submodules venv yarn_install

VENV := ./.venv
NODE_MODULES := ./node_modules
Expand Down
Loading