Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use cache for npm #263

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/actions/cache-npm/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# https://docs.github.com/en/actions/creating-actions/creating-a-composite-action
name: Cache NPM
description: Composite action (cache NPM)

runs:
using: composite
steps:
# https://github.com/actions/cache/blob/master/examples.md#node---npm
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter
- name: Get NPM cache directory
run: echo "NPM_CACHE_DIRECTORY=$(npm config get cache)" >> ${{ github.env }} # use "github.env" instead of "github.output"; if use "github.output", "Warning: Input required and not supplied: path" is displayed on post-process
shell: pwsh # use PowerShell; Bash doesn't work on Windows because the value of "github.env" is like "D:\a\_temp\_runner_file_commands\set_env_XXX".

- name: Get Node.js version
run: echo "NODEJS_VERSION=$(node -v)" >> ${{ github.env }}
shell: pwsh

- name: Cache NPM modules
uses: actions/cache@v3
with:
path: ${{ env.NPM_CACHE_DIRECTORY }}
key: npm-${{ runner.os }}-${{ runner.arch }}-${{ env.NODEJS_VERSION }}-${{ hashFiles('package-lock.json') }}
restore-keys: |
npm-${{ runner.os }}-${{ runner.arch }}-${{ env.NODEJS_VERSION }}-
npm-${{ runner.os }}-${{ runner.arch }}
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.nodejs }}
- name: Cache NPM
uses: ./.github/actions/cache-npm
- name: Install dependencies
run: npm ci
- name: Build
Expand Down
Loading