From b1e4f5a87a492df9d8e9c91e471c8b0a7fa27721 Mon Sep 17 00:00:00 2001 From: Jonathan Lelievre Date: Thu, 14 Sep 2023 02:16:01 +0200 Subject: [PATCH] Fix node cache saving --- .../actions/install-node-modules/action.yml | 31 +++++++------------ .../workflows/actions/run-tests/action.yml | 2 ++ .github/workflows/build-shop.yml | 5 +++ .github/workflows/test-sanity.yml | 5 +++ 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/.github/workflows/actions/install-node-modules/action.yml b/.github/workflows/actions/install-node-modules/action.yml index 7df7e89a..6d01bedc 100644 --- a/.github/workflows/actions/install-node-modules/action.yml +++ b/.github/workflows/actions/install-node-modules/action.yml @@ -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" @@ -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)\"" @@ -38,7 +37,6 @@ runs: installCommandJson+="$commaSeparator\"(pushd $js_folder; npm ci; popd)\"" fi commaSeparator=', ' - spaceSeparator=' ' fi done <<< "${{ inputs.package_locks }}" @@ -47,36 +45,29 @@ 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 - id: restore-dependencies - uses: actions/cache/restore@v3 + - 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.restore-dependencies.outputs.cache-hit == 'true' + if: steps.save-dependencies.outputs.cache-hit == 'true' run: ${{ join(fromJson(steps.action-parameters.outputs.build-command), ' & ') }} shell: bash - # If the cache was not restored we install npm, node_modules dependencies and then build the assets, the we save the cache + # If the cache was not restored we install npm, node_modules dependencies and then build the assets, then we save the cache - name: Setup Node ${{ inputs.node_version }} - if: steps.restore-dependencies.outputs.cache-hit != 'true' + if: steps.save-dependencies.outputs.cache-hit != 'true' uses: actions/setup-node@v3 with: node-version: ${{ inputs.node_version }} cache: 'npm' cache-dependency-path: ${{ inputs.package_locks }} - name: Install dependencies and build assets - if: steps.restore-dependencies.outputs.cache-hit != 'true' + if: steps.save-dependencies.outputs.cache-hit != 'true' run: ${{ join(fromJson(steps.action-parameters.outputs.install-command), ' & ') }} shell: bash - - name: Cache dependencies - if: steps.restore-dependencies.outputs.cache-hit == 'true' - uses: actions/cache/restore@v3 - with: - path: ${{ steps.action-parameters.outputs.node-modules }} - key: node-modules-${{ inputs.node_version }}-${{ hashFiles(inputs.package_locks) }} diff --git a/.github/workflows/actions/run-tests/action.yml b/.github/workflows/actions/run-tests/action.yml index 72f1471d..e5d9b300 100644 --- a/.github/workflows/actions/run-tests/action.yml +++ b/.github/workflows/actions/run-tests/action.yml @@ -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 diff --git a/.github/workflows/build-shop.yml b/.github/workflows/build-shop.yml index bcc50ae8..717f25d5 100644 --- a/.github/workflows/build-shop.yml +++ b/.github/workflows/build-shop.yml @@ -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 diff --git a/.github/workflows/test-sanity.yml b/.github/workflows/test-sanity.yml index 0a7b9461..935e69ce 100644 --- a/.github/workflows/test-sanity.yml +++ b/.github/workflows/test-sanity.yml @@ -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