From f9c43e5ab436b95f43493a5904a377864ec73442 Mon Sep 17 00:00:00 2001 From: Florian Rival Date: Sat, 22 Mar 2025 16:23:44 +0100 Subject: [PATCH] Add CircleCI cache for node_modules --- .circleci/checksum-package-lock-json.sh | 24 ++++++++++++++++++++++++ .circleci/config.yml | 24 +++++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100755 .circleci/checksum-package-lock-json.sh diff --git a/.circleci/checksum-package-lock-json.sh b/.circleci/checksum-package-lock-json.sh new file mode 100755 index 000000000..35e64545f --- /dev/null +++ b/.circleci/checksum-package-lock-json.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# Generate a checksum file for the package-lock.json files of all APIs. + +RESULT_FILE=$1 + +if [ -f $RESULT_FILE ]; then + rm $RESULT_FILE +fi +touch $RESULT_FILE + +checksum_file() { + echo `openssl md5 $1 | awk '{print $2}'` +} + +# List package locks to use as cache keys. +FILES='package-lock.json GDevelop/newIDE/app/package-lock.json' + +# Loop through files and append filename and MD5 to result file. +for FILE in ${FILES}; do + echo $FILE `checksum_file $FILE` >> $RESULT_FILE +done + +# Now sort the file so that it is stable. +sort $RESULT_FILE -o $RESULT_FILE \ No newline at end of file diff --git a/.circleci/config.yml b/.circleci/config.yml index 42853134e..1284a92f2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,15 +3,37 @@ version: 2.1 orbs: aws-cli: circleci/aws-cli@2.0.2 +commands: + restore_node_modules: + steps: + - run: + name: Generate cache key + command: ./.circleci/checksum-package-lock-json.sh package-lock-json-checksums + - restore_cache: + keys: + - v1-dependencies-{{ checksum "package-lock-json-checksums" }} + # fallback to using the latest cache if no exact match is found + - v1-dependencies- + cache_node_modules: + steps: + - save_cache: + paths: + - ~/.npm + - node_modules + - GDevelop/newIDE/app/node_modules + key: v1-dependencies-{{ checksum "package-lock-json-checksums" }} + jobs: install: docker: - image: cimg/node:20.13.1 steps: - checkout - - run: npm install - run: git clone git@github.com:4ian/GDevelop.git --depth 1 + - restore_node_modules + - run: npm install - run: cd GDevelop/newIDE/app && npm install + - cache_node_modules - persist_to_workspace: root: . paths: