Skip to content

Commit e6f8ac3

Browse files
authored
Improve Node.js caching using package-lock.json (#409)
This PR updates the caching strategy for Node.js dependencies to base the cache key on the contents of `package-lock.json`, rather than the `node` or `node_modules` directories. ### Problem Currently, caching is ineffective because: * The cache key relies on `node` and `node_modules` directories. * These directories are not checked into the repository and therefore don’t exist when the cache is computed. ### Solution Update the cache key to use the contents of `package-lock.json`, which is a reliable representation of the dependency tree: * If `package-lock.json` **is not committed**, the cache behavior remains unchanged. * If it **is committed**, caching will function as expected, restoring and saving dependencies based on lockfile changes. ### Additional Changes * Commit `package-lock.json` in the `logging-parent` repository to evaluate the effectiveness of this approach. * Reverts the use of `npm-shrinkwrap.json` introduced in #367.
1 parent 3b4379f commit e6f8ac3

File tree

5 files changed

+98
-334
lines changed

5 files changed

+98
-334
lines changed

.github/workflows/deploy-site-reusable.yaml

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ on:
4545
description: GPG secret key for signing commits
4646
required: true
4747

48-
env:
49-
logging-parent-version: "12.2.0"
50-
5148
jobs:
5249

5350
deploy:
@@ -77,13 +74,14 @@ jobs:
7774
install
7875
7976
# Node.js cache is needed for Antora
80-
- name: Set up Node.js cache
81-
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # 4.2.3
77+
- name: Restore Node.js cache
78+
id: nodejs-cache-restore
79+
uses: actions/cache/restore@5a3ec84eff668545956fd18022155c47e93e2684 # 4.2.3
8280
with:
8381
# The cache is OS independent
8482
enableCrossOsArchive: true
8583
# The cache needs to be updated only when `logging-parent` is updated
86-
key: "nodejs-cache-${{ env.logging-parent-version }}"
84+
key: "nodejs-cache-${{ hashFiles('package-lock.json') }}"
8785
# Only the NPM modules need to be cached, since Node.js and NPM are retrieved from the Maven local repository
8886
path: node_modules
8987

@@ -105,11 +103,13 @@ jobs:
105103
git config user.name "ASF Logging Services RM"
106104
git config user.email private@logging.apache.org
107105
108-
# Checking out a new branch will delete the `node_modules` folder
109-
- name: Save Node.js modules
110-
shell: bash
111-
run: |
112-
zip -q0X "$RUNNER_TEMP"/node_modules.zip node_modules
106+
# Checking out a new branch will delete the `node_modules` folder,
107+
# so we need to save the cache here.
108+
- name: Save Node.js cache
109+
uses: actions/cache/save@5a3ec84eff668545956fd18022155c47e93e2684 # 4.2.3
110+
with:
111+
key: steps.nodejs-cache-restore.outputs.cache-primary-key
112+
path: node_modules
113113

114114
- name: Create the target branch
115115
shell: bash
@@ -181,8 +181,3 @@ jobs:
181181
git push -f origin
182182
183183
fi
184-
185-
- name: Restore Node.js modules
186-
shell: bash
187-
run: |
188-
unzip -q "$RUNNER_TEMP"/node_modules.zip

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,5 @@ target/
2929
# Node.js
3030
node
3131
node_modules
32-
package-lock.json
3332
# Visual Studio
3433
/.vs/*

0 commit comments

Comments
 (0)