This is an automated email from the ASF dual-hosted git repository.

pkarwasz pushed a commit to branch fix/revert-npm-shrinkwrap
in repository https://gitbox.apache.org/repos/asf/logging-parent.git

commit 87fa40ff67ec1d914e6d30aa6b5ca0ceeb485921
Author: Piotr P. Karwasz <[email protected]>
AuthorDate: Tue Jun 10 10:43:48 2025 +0200

    Improve Node.js caching using `package-lock.json`
    
    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.
---
 .github/dependabot.yaml                        |  6 +++-
 .github/workflows/deploy-site-reusable.yaml    | 49 +++++++++++---------------
 .gitignore                                     |  1 -
 package.json                                   |  2 +-
 pom.xml                                        |  2 +-
 src/changelog/.12.x.x/improve-nodejs-cache.xml |  9 +++++
 6 files changed, 36 insertions(+), 33 deletions(-)

diff --git a/.github/dependabot.yaml b/.github/dependabot.yaml
index e88ba5b..dcb2321 100644
--- a/.github/dependabot.yaml
+++ b/.github/dependabot.yaml
@@ -42,4 +42,8 @@ updates:
   - package-ecosystem: npm
     directory: "/"
     schedule:
-      interval: daily
+      interval: monthly
+    groups:
+      all:
+        patterns:
+          - "*"
diff --git a/.github/workflows/deploy-site-reusable.yaml 
b/.github/workflows/deploy-site-reusable.yaml
index 2464864..7f857e5 100644
--- a/.github/workflows/deploy-site-reusable.yaml
+++ b/.github/workflows/deploy-site-reusable.yaml
@@ -74,38 +74,26 @@ jobs:
             install
 
       # Node.js cache is needed for Antora
-      - name: Set up Node.js cache
-        id: nodejs-cache
-        uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684   # 4.2.3
+      - name: Restore Node.js cache
+        id: nodejs-cache-restore
+        uses: actions/cache/restore@5a3ec84eff668545956fd18022155c47e93e2684   
# 4.2.3
         with:
-          # We should be calculating the cache key using `package-lock.json` 
instead!
-          # See https://stackoverflow.com/a/48524475/1278899
-          # For that, `package-lock.json` needs to be committed into the 
repository – right now it is `.gitignore`d.
-          # Once it is there, we should ideally switch from `npm i` to `npm 
ci`.
-          # For that, we need to configure `dependabot` to update hundreds of 
dependencies listed in `package-lock.json`.
-          # That translates to a never ending rain of `dependabot` PRs.
-          # I doubt if the wasted CPU cycles worth the gain.
-          key: ${{ runner.os }}-nodejs-cache-${{ hashFiles('node', 
'node_modules') }}
-          # `actions/cache` doesn't recommend caching `node_modules`.
-          # Though none of its recipes fit our bill, since we install Node.js 
using `frontend-maven-plugin`.
-          # See 
https://github.com/actions/cache/blob/main/examples.md#node---npm
-          # We settle for this quick-n-dirty solution for the time being.
-          path: |
-            node
-            node_modules
+          # The cache is OS independent
+          enableCrossOsArchive: true
+          # The cache needs to be updated only when `logging-parent` is updated
+          key: "nodejs-cache-${{ hashFiles('package-lock.json') }}"
+          # Only the NPM modules need to be cached, since Node.js and NPM are 
retrieved from the Maven local repository
+          path: node_modules
 
       - name: Build the website
         shell: bash
-        env:
-          # Making Node.js cache hit visible for debugging purposes
-          NODEJS_CACHE_HIT: ${{ steps.nodejs-cache.outputs.cache-hit }}
         run: |
           ./mvnw \
             --show-version --batch-mode --errors --no-transfer-progress \
             site
           cd target/site
           find . -empty -type d -delete
-          find . -print0 | sort --zero-terminated | xargs -0 zip -qoX 
/tmp/site.zip
+          find . -print0 | sort --zero-terminated | xargs -0 zip -qoX 
"$RUNNER_TEMP/site.zip"
           echo "SOURCE_COMMIT_ID=$(git rev-parse HEAD)" >> $GITHUB_ENV
 
       - name: Set up Git user
@@ -115,6 +103,14 @@ jobs:
           git config user.name "ASF Logging Services RM"
           git config user.email [email protected]
 
+      # Checking out a new branch will delete the `node_modules` folder,
+      # so we need to save the cache here.
+      - name: Save Node.js cache
+        uses: actions/cache/restore@5a3ec84eff668545956fd18022155c47e93e2684   
# 4.2.3
+        with:
+          key: steps.nodejs-cache-restore.outputs.cache-primary-key
+          path: node_modules
+
       - name: Create the target branch
         shell: bash
         env:
@@ -140,19 +136,14 @@ jobs:
           TARGET_PATH: ${{ inputs.target-path }}
           ASF_YAML_CONTENT: ${{ inputs.asf-yaml-content }}
         run: |
-
           # Check if there already exists an `.asf.yaml`
           ASF_YAML_EXISTS=$([ -f .asf.yaml ] && echo "true" || echo "false")
 
           # Clean up the target path
-          if [ "." = "$TARGET_PATH" ]; then
-            git ls-files -z | xargs -0 git rm -rfq
-          else
-            git rm -rfq "$TARGET_PATH"
-          fi
+          git ls-files -z -- "$TARGET_PATH" | xargs -0 git rm -rfq
 
           # Place the generated site
-          unzip -q /tmp/site.zip -d "$TARGET_PATH"
+          unzip -q "$RUNNER_TEMP/site.zip" -d "$TARGET_PATH"
           git add "$TARGET_PATH"
 
           # Recover `.asf.yaml`, if there was one.
diff --git a/.gitignore b/.gitignore
index 712b37b..8338b2f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -29,6 +29,5 @@ target/
 # Node.js
 node
 node_modules
-package-lock.json
 # Visual Studio
 /.vs/*
diff --git a/package.json b/package.json
index 1cbc04a..ea8b37b 100644
--- a/package.json
+++ b/package.json
@@ -5,7 +5,7 @@
     "@antora/site-generator-default": "^3.2.0-alpha.4",
     "@asciidoctor/tabs": "^1.0.0-beta.6",
     "asciidoctor-kroki": "^0.18.1",
-    "fast-xml-parser": "^5.0.6",
+    "fast-xml-parser": "^5.2.3",
     "handlebars": "^4.7.8"
   }
 }
diff --git a/pom.xml b/pom.xml
index 073dc13..00b9448 100644
--- a/pom.xml
+++ b/pom.xml
@@ -244,7 +244,7 @@
 
     <!-- site-specific versions -->
     <!-- We use a separate property than `project.version` to refer to the 
most recent _published_ version of the project. -->
-    <site-project.version>11.3.0</site-project.version>
+    <site-project.version>12.1.1</site-project.version>
 
   </properties>
 
diff --git a/src/changelog/.12.x.x/improve-nodejs-cache.xml 
b/src/changelog/.12.x.x/improve-nodejs-cache.xml
new file mode 100644
index 0000000..582b7cb
--- /dev/null
+++ b/src/changelog/.12.x.x/improve-nodejs-cache.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xmlns="https://logging.apache.org/xml/ns";
+       xsi:schemaLocation="https://logging.apache.org/xml/ns 
https://logging.apache.org/xml/ns/log4j-changelog-0.xsd";
+       type="changed">
+  <issue id="366" link="https://github.com/apache/logging-parent/issues/366"/>
+  <issue id="408" link="https://github.com/apache/logging-parent/pull/408"/>
+  <description format="asciidoc">Improve Node.js caching using 
`package-lock.json`.</description>
+</entry>

Reply via email to