Skip to content

Commit

Permalink
Cache node_modules/ in between CircleCI jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
danielrozenberg committed Feb 9, 2024
1 parent c401c63 commit c853043
Showing 1 changed file with 57 additions and 38 deletions.
95 changes: 57 additions & 38 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ commands:
checkout_repo:
parameters:
save-git-cache:
description: 'True when this step should save the .git directory to the cache'
type: boolean
default: false
steps:
- restore_cache:
name: 'Restore Git Cache'
Expand All @@ -93,12 +93,37 @@ commands:
key: git-cache-{{ arch }}-v2-{{ .Branch }}-{{ .Revision }}
paths:
- .git
setup_node_environment:
setup_vm:
parameters:
initializing-job:
description: 'True when this is an initializing job, which would perform several caching and workspace setup steps'
type: boolean
default: false
node-version:
type: string
default: '18' # TODO(wg-infra): restore this to 'lts' once #39510 is fixed.
steps:
- unless:
condition: << parameters.initializing-job >>
steps:
- checkout_repo:
save-git-cache: false
- attach_workspace:
at: /tmp
- run:
name: 'Configure Temporary Workspace'
command: |
mv /tmp/workspace /tmp/restored-workspace
mkdir -p /tmp/workspace
- run:
name: 'Maybe Gracefully Halt'
command: /tmp/restored-workspace/maybe_gracefully_halt.sh
- run:
name: 'Configure Development Environment'
command: |
./.circleci/fetch_merge_commit.sh
./.circleci/restore_build_output.sh
cat ./build-system/test-configs/hosts | sudo tee -a /etc/hosts
- restore_cache:
name: 'Restore nvm Cache'
keys:
Expand All @@ -107,41 +132,31 @@ commands:
name: 'Create .nvmrc file'
command: echo << parameters.node-version >> > .nvmrc
- node/install
- run:
name: 'Create nvm Cache Checksum File'
command: node -v > ~/.node-version
- save_cache:
name: 'Save nvm Cache'
key: nvm-cache-{{ arch }}-v2-<< parameters.node-version >>-{{ checksum "~/.node-version" }}
paths:
- ~/.nvm/.cache
- node/install-packages:
with-cache: false
setup_vm:
parameters:
save-git-cache:
type: boolean
default: false
steps:
- attach_workspace:
at: /tmp
- run:
name: 'Configure Temporary Workspace'
command: |
mv /tmp/workspace /tmp/restored-workspace
mkdir -p /tmp/workspace
- run:
name: 'Maybe Gracefully Halt'
command: /tmp/restored-workspace/maybe_gracefully_halt.sh
- checkout_repo:
save-git-cache: << parameters.save-git-cache >>
- run:
name: 'Configure Development Environment'
command: |
./.circleci/fetch_merge_commit.sh
./.circleci/restore_build_output.sh
cat ./build-system/test-configs/hosts | sudo tee -a /etc/hosts
- setup_node_environment
- when:
condition: << parameters.initializing-job >>
steps:
- run:
name: 'Create nvm Cache Checksum File'
command: node -v > ~/.node-version
- save_cache:
name: 'Save nvm Cache'
key: nvm-cache-{{ arch }}-v2-<< parameters.node-version >>-{{ checksum "~/.node-version" }}
paths:
- ~/.nvm/.cache
- restore_cache:
name: 'Restore node_modules/ Cache'
keys:
- node-modules-cache-{{ arch }}-v0aaad-{{ checksum "package-lock.json" }}
- when:
condition: << parameters.initializing-job >>
steps:
- run:
name: 'Install npm packages'
command: if [[ ! -d node_modules/ ]]; then npm ci; fi
- save_cache:
name: 'Save node_modules/ Cache'
key: node-modules-cache-{{ arch }}-v0aaad-{{ checksum "package-lock.json" }}
paths: node_modules/
teardown_vm:
steps:
- persist_to_workspace:
Expand Down Expand Up @@ -198,7 +213,7 @@ commands:
jobs:
initialize_repository:
executor:
name: base-docker-small
name: node-docker-medium
steps:
- checkout_repo:
save-git-cache: true
Expand All @@ -211,13 +226,17 @@ jobs:
- run:
name: 'Initialize Workspace'
command: cp .circleci/maybe_gracefully_halt.sh /tmp/workspace
- setup_vm:
initializing-job: true
- teardown_vm
initialize_mac_os:
executor:
name: macos-medium
steps:
- checkout_repo:
save-git-cache: true
- setup_vm:
initializing-job: true
checks:
executor:
name: node-docker-medium
Expand Down

0 comments on commit c853043

Please sign in to comment.