Files
vscode/.github/actions/restore-node-modules/action.yml
Alexandru Dima 3980424ce8 Refactor restore-node-modules action for lookup-only functionality (#322140)
refactor: update restore-node-modules action to support lookup-only functionality

- Replaced 'extract' input with 'lookup-only' to allow cache entry checks without downloading or extracting.
- Updated action logic to conditionally extract node_modules based on the new 'lookup-only' input.
- Adjusted workflow files to utilize 'lookup-only' for cache-warming jobs on Linux, macOS, and Windows.
2026-06-19 19:38:47 +00:00

62 lines
2.4 KiB
YAML

name: Restore node_modules cache
description: Computes the node_modules cache key, restores the cache, and extracts it on a hit.
inputs:
key-prefix:
description: Prefix for the cache key. The package-lock hash is appended automatically.
required: true
key-args:
description: Arguments passed to build/azure-pipelines/common/computeNodeModulesCacheKey.ts.
required: true
lookup-only:
description: When 'true', only checks whether the cache entry exists (sets cache-hit) without downloading or extracting the archive. Use for cache-warming jobs that only need the cache-hit result.
default: 'false'
outputs:
cache-hit:
description: "'true' when the node_modules cache was restored from an exact key match."
value: ${{ steps.restore.outputs.cache-hit }}
runs:
using: composite
steps:
- name: Prepare node_modules cache key
if: runner.os != 'Windows'
shell: bash
run: mkdir -p .build && node build/azure-pipelines/common/computeNodeModulesCacheKey.ts ${{ inputs.key-args }} > .build/packagelockhash
- name: Prepare node_modules cache key
if: runner.os == 'Windows'
shell: pwsh
run: |
mkdir .build -ea 0
node build/azure-pipelines/common/computeNodeModulesCacheKey.ts ${{ inputs.key-args }} > .build/packagelockhash
- name: Restore node_modules cache
id: restore
uses: actions/cache/restore@v5
with:
path: .build/node_modules_cache
key: "${{ inputs.key-prefix }}-${{ hashFiles('.build/packagelockhash') }}"
lookup-only: ${{ inputs.lookup-only }}
- name: Export node_modules cache key
if: runner.os != 'Windows'
shell: bash
run: echo "NODE_MODULES_CACHE_KEY=${{ steps.restore.outputs.cache-primary-key }}" >> "$GITHUB_ENV"
- name: Export node_modules cache key
if: runner.os == 'Windows'
shell: pwsh
run: Add-Content -Path $env:GITHUB_ENV -Value "NODE_MODULES_CACHE_KEY=${{ steps.restore.outputs.cache-primary-key }}"
- name: Extract node_modules cache
if: runner.os != 'Windows' && inputs.lookup-only != 'true' && steps.restore.outputs.cache-hit == 'true'
shell: bash
run: ./.github/workflows/node_modules_cache/cache.sh extract
- name: Extract node_modules cache
if: runner.os == 'Windows' && inputs.lookup-only != 'true' && steps.restore.outputs.cache-hit == 'true'
shell: pwsh
run: ./.github/workflows/node_modules_cache/cache.ps1 extract