-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yaml
More file actions
58 lines (50 loc) · 2.04 KB
/
Copy pathaction.yaml
File metadata and controls
58 lines (50 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
name: "Setup Node.js Environment"
description: "Checkout, setup Node.js, and restore cache, install NPM, install dependencies, and save cache."
runs:
using: "composite"
steps:
- name: 🤘 Checkout
uses: actions/checkout@v4
- name: ⚙️ Setup Node.js environment
id: setup-node
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
- name: 📦 Install npm
shell: bash
run: |
# Safely extract the packageManager field (if it exists).
PACKAGE_MANAGER="$(node -p "require('./package.json').packageManager" 2>/dev/null || '')"
if [[ "$PACKAGE_MANAGER" =~ ^npm@ ]]; then
# Extract the npm version from something like "npm@11.0.0"
NPM_VERSION="$(echo "$PACKAGE_MANAGER" | cut -d '@' -f2)"
echo "Detected npm version from package.json: npm@$NPM_VERSION"
npm install -g "npm@$NPM_VERSION"
else
echo "No valid npm packageManager specified, installing latest npm..."
npm install -g npm@latest
fi
- name: Display node/npm versions
shell: bash
run: node --version && npm --version
- name: 🔄 Retrieve npm version
id: get-npm-version
shell: bash
run: echo "npm_version=$(npm --version)" >> $GITHUB_ENV
- name: 🔄 Restore node_modules cache
id: node_modules-cache
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ runner.os }}-node-${{ steps.setup-node.outputs.node-version }}-npm-${{ env.npm_version }}-${{ hashFiles('package-lock.json') }}
- name: ⬇️ install
shell: "bash"
run: |
npm ci --ignore-scripts --include=dev
- name: 🔄 Save node_modules cache
if: steps.node_modules-cache.outputs.cache-hit != 'true'
continue-on-error: true
uses: actions/cache/save@v4
with:
key: node_modules-${{ runner.os }}-node-${{ steps.setup-node.outputs.node-version }}-npm-${{ env.npm_version }}-${{ hashFiles('package-lock.json') }}
path: node_modules