Skip to content

Commit

Permalink
Fix node modules cache
Browse files Browse the repository at this point in the history
  • Loading branch information
jolelievre committed Sep 14, 2023
1 parent ab1b77d commit ed3281a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
13 changes: 5 additions & 8 deletions .github/workflows/actions/install-node-modules/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ inputs:
package_locks:
description: JS packages.lock list
required: true
node_modules:
description: Node modules folders list
required: true

runs:
using: "composite"
Expand All @@ -19,17 +22,13 @@ runs:
buildCommandJson='['
# Install plus build when the cache is not found
installCommandJson='['
# Build list of node_modules folders
nodeModules=''
IFS=$' \t\n'
commaSeparator=''
spaceSeparator=''
while read -r package_lock; do
if test -f "$package_lock"; then
js_folder=$(echo $package_lock | sed s_/package-lock\.json__)
package_json=$(echo $package_lock | sed s_package-lock\.json_package\.json_)
nodeModules+="$spaceSeparator$js_folder/node_modules"
# Only build when the action is in the package.json
if grep -q '"build":' "$package_json"; then
buildCommandJson+="$commaSeparator\"(pushd $js_folder; npm run build; popd)\""
Expand All @@ -38,7 +37,6 @@ runs:
installCommandJson+="$commaSeparator\"(pushd $js_folder; npm ci; popd)\""
fi
commaSeparator=', '
spaceSeparator=' '
fi
done <<< "${{ inputs.package_locks }}"
Expand All @@ -47,15 +45,14 @@ runs:
echo "build-command=$buildCommandJson" >> $GITHUB_OUTPUT
echo "install-command=$installCommandJson" >> $GITHUB_OUTPUT
echo "node-modules=$nodeModules" >> $GITHUB_OUTPUT
shell: bash

# Try and restore cache if it exists, then build assets only (no npm ci needed)
- name: Restore dependencies
- name: Save dependencies
id: save-dependencies
uses: actions/cache@v3
with:
path: ${{ steps.action-parameters.outputs.node-modules }}
path: ${{ inputs.node_modules }}
key: node-modules-${{ inputs.node_version }}-${{ hashFiles(inputs.package_locks) }}
- name: Build assets only (dependencies came from cache)
if: steps.save-dependencies.outputs.cache-hit == 'true'
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/actions/run-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ runs:
node_version: ${{ inputs.node_version }}
package_locks: |
${{ inputs.ps_dir }}/tests/UI/package-lock.json
node_modules: |
${{ inputs.ps_dir }}/tests/UI/node_modules
# Always rebuild, it seems required although the cache should speed that up
- run: npm ci
working-directory: ${{ inputs.ps_dir }}/tests/UI
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/build-shop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ jobs:
${{ env.PS_DIR }}/admin-dev/themes/default/package-lock.json
${{ env.PS_DIR }}/themes/classic/_dev/package-lock.json
${{ env.PS_DIR }}/themes/package-lock.json
node_modules: |
${{ env.PS_DIR }}/admin-dev/themes/new-theme/node_modules
${{ env.PS_DIR }}/admin-dev/themes/default/node_modules
${{ env.PS_DIR }}/themes/classic/_dev/node_modules
${{ env.PS_DIR }}/themes/node_modules
# Create shop with Docker build assets, and initialize database and shop content
- name: Build and run shop with docker
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/test-sanity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ jobs:
${{ env.PS_DIR }}/admin-dev/themes/default/package-lock.json
${{ env.PS_DIR }}/themes/classic/_dev/package-lock.json
${{ env.PS_DIR }}/themes/package-lock.json
node_modules: |
${{ env.PS_DIR }}/admin-dev/themes/new-theme/node_modules
${{ env.PS_DIR }}/admin-dev/themes/default/node_modules
${{ env.PS_DIR }}/themes/classic/_dev/node_modules
${{ env.PS_DIR }}/themes/node_modules
# Create shop with Docker build assets, and initialize database and shop content
- name: Build and run shop with docker
Expand Down

0 comments on commit ed3281a

Please sign in to comment.