Skip to content

Commit 44123b8

Browse files
committed
fix: install npm in CI based on node version
Fixes #353
1 parent d67bd69 commit 44123b8

File tree

11 files changed

+2077
-153
lines changed

11 files changed

+2077
-153
lines changed

.github/workflows/audit.yml

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,54 @@ jobs:
2525
git config --global user.name "npm CLI robot"
2626
- name: Setup Node
2727
uses: actions/setup-node@v3
28+
id: node
2829
with:
2930
node-version: 18.x
30-
- name: Install npm@latest
31+
check-latest: contains('18.x', '.x')
32+
33+
# node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows
34+
- name: Update Windows npm
35+
if: |
36+
matrix.platform.os == 'windows-latest' && (
37+
startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.')
38+
)
39+
run: |
40+
curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz
41+
tar xf npm-7.5.4.tgz
42+
cd package
43+
node lib/npm.js install --no-fund --no-audit -g ..\npm-7.5.4.tgz
44+
cd ..
45+
rmdir /s /q package
46+
47+
# Start on Node 10 because we dont test on anything lower
48+
- name: Install npm@7 on Node 10
49+
shell: bash
50+
if: startsWith(steps.node.outputs.node-version, 'v10.')
51+
id: npm-7
52+
run: |
53+
npm i --prefer-online --no-fund --no-audit -g npm@7
54+
echo "updated=true" >> "$GITHUB_OUTPUT"
55+
56+
- name: Install npm@8 on Node 12
57+
shell: bash
58+
if: startsWith(steps.node.outputs.node-version, 'v12.')
59+
id: npm-8
60+
run: |
61+
npm i --prefer-online --no-fund --no-audit -g npm@8
62+
echo "updated=true" >> "$GITHUB_OUTPUT"
63+
64+
- name: Install npm@9 on Node 14/16/18.0
65+
shell: bash
66+
if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.')
67+
id: npm-9
68+
run: |
69+
npm i --prefer-online --no-fund --no-audit -g npm@9
70+
echo "updated=true" >> "$GITHUB_OUTPUT"
71+
72+
- name: Install npm@latest on Node
73+
if: ${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }}
3174
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
75+
3276
- name: npm Version
3377
run: npm -v
3478
- name: Install Dependencies

.github/workflows/ci-release.yml

Lines changed: 82 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,54 @@ jobs:
8080
git config --global user.name "npm CLI robot"
8181
- name: Setup Node
8282
uses: actions/setup-node@v3
83+
id: node
8384
with:
8485
node-version: 18.x
85-
- name: Install npm@latest
86+
check-latest: contains('18.x', '.x')
87+
88+
# node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows
89+
- name: Update Windows npm
90+
if: |
91+
matrix.platform.os == 'windows-latest' && (
92+
startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.')
93+
)
94+
run: |
95+
curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz
96+
tar xf npm-7.5.4.tgz
97+
cd package
98+
node lib/npm.js install --no-fund --no-audit -g ..\npm-7.5.4.tgz
99+
cd ..
100+
rmdir /s /q package
101+
102+
# Start on Node 10 because we dont test on anything lower
103+
- name: Install npm@7 on Node 10
104+
shell: bash
105+
if: startsWith(steps.node.outputs.node-version, 'v10.')
106+
id: npm-7
107+
run: |
108+
npm i --prefer-online --no-fund --no-audit -g npm@7
109+
echo "updated=true" >> "$GITHUB_OUTPUT"
110+
111+
- name: Install npm@8 on Node 12
112+
shell: bash
113+
if: startsWith(steps.node.outputs.node-version, 'v12.')
114+
id: npm-8
115+
run: |
116+
npm i --prefer-online --no-fund --no-audit -g npm@8
117+
echo "updated=true" >> "$GITHUB_OUTPUT"
118+
119+
- name: Install npm@9 on Node 14/16/18.0
120+
shell: bash
121+
if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.')
122+
id: npm-9
123+
run: |
124+
npm i --prefer-online --no-fund --no-audit -g npm@9
125+
echo "updated=true" >> "$GITHUB_OUTPUT"
126+
127+
- name: Install npm@latest on Node
128+
if: ${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }}
86129
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
130+
87131
- name: npm Version
88132
run: npm -v
89133
- name: Install Dependencies
@@ -181,24 +225,54 @@ jobs:
181225
git config --global user.name "npm CLI robot"
182226
- name: Setup Node
183227
uses: actions/setup-node@v3
228+
id: node
184229
with:
185230
node-version: ${{ matrix.node-version }}
231+
check-latest: contains(matrix.node-version, '.x')
232+
233+
# node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows
186234
- name: Update Windows npm
187-
# node 12 and 14 ship with npm@6, which is known to fail when updating itself in windows
188-
if: matrix.platform.os == 'windows-latest' && (startsWith(matrix.node-version, '12.') || startsWith(matrix.node-version, '14.'))
235+
if: |
236+
matrix.platform.os == 'windows-latest' && (
237+
startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.')
238+
)
189239
run: |
190240
curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz
191241
tar xf npm-7.5.4.tgz
192242
cd package
193243
node lib/npm.js install --no-fund --no-audit -g ..\npm-7.5.4.tgz
194244
cd ..
195245
rmdir /s /q package
196-
- name: Install npm@7
197-
if: startsWith(matrix.node-version, '10.')
198-
run: npm i --prefer-online --no-fund --no-audit -g npm@7
199-
- name: Install npm@latest
200-
if: ${{ !startsWith(matrix.node-version, '10.') }}
246+
247+
# Start on Node 10 because we dont test on anything lower
248+
- name: Install npm@7 on Node 10
249+
shell: bash
250+
if: startsWith(steps.node.outputs.node-version, 'v10.')
251+
id: npm-7
252+
run: |
253+
npm i --prefer-online --no-fund --no-audit -g npm@7
254+
echo "updated=true" >> "$GITHUB_OUTPUT"
255+
256+
- name: Install npm@8 on Node 12
257+
shell: bash
258+
if: startsWith(steps.node.outputs.node-version, 'v12.')
259+
id: npm-8
260+
run: |
261+
npm i --prefer-online --no-fund --no-audit -g npm@8
262+
echo "updated=true" >> "$GITHUB_OUTPUT"
263+
264+
- name: Install npm@9 on Node 14/16/18.0
265+
shell: bash
266+
if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.')
267+
id: npm-9
268+
run: |
269+
npm i --prefer-online --no-fund --no-audit -g npm@9
270+
echo "updated=true" >> "$GITHUB_OUTPUT"
271+
272+
- name: Install npm@latest on Node
273+
if: ${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }}
201274
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
275+
202276
- name: npm Version
203277
run: npm -v
204278
- name: Install Dependencies

.github/workflows/ci-test-workspace.yml

Lines changed: 82 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,54 @@ jobs:
3333
git config --global user.name "npm CLI robot"
3434
- name: Setup Node
3535
uses: actions/setup-node@v3
36+
id: node
3637
with:
3738
node-version: 18.x
38-
- name: Install npm@latest
39+
check-latest: contains('18.x', '.x')
40+
41+
# node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows
42+
- name: Update Windows npm
43+
if: |
44+
matrix.platform.os == 'windows-latest' && (
45+
startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.')
46+
)
47+
run: |
48+
curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz
49+
tar xf npm-7.5.4.tgz
50+
cd package
51+
node lib/npm.js install --no-fund --no-audit -g ..\npm-7.5.4.tgz
52+
cd ..
53+
rmdir /s /q package
54+
55+
# Start on Node 10 because we dont test on anything lower
56+
- name: Install npm@7 on Node 10
57+
shell: bash
58+
if: startsWith(steps.node.outputs.node-version, 'v10.')
59+
id: npm-7
60+
run: |
61+
npm i --prefer-online --no-fund --no-audit -g npm@7
62+
echo "updated=true" >> "$GITHUB_OUTPUT"
63+
64+
- name: Install npm@8 on Node 12
65+
shell: bash
66+
if: startsWith(steps.node.outputs.node-version, 'v12.')
67+
id: npm-8
68+
run: |
69+
npm i --prefer-online --no-fund --no-audit -g npm@8
70+
echo "updated=true" >> "$GITHUB_OUTPUT"
71+
72+
- name: Install npm@9 on Node 14/16/18.0
73+
shell: bash
74+
if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.')
75+
id: npm-9
76+
run: |
77+
npm i --prefer-online --no-fund --no-audit -g npm@9
78+
echo "updated=true" >> "$GITHUB_OUTPUT"
79+
80+
- name: Install npm@latest on Node
81+
if: ${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }}
3982
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
83+
4084
- name: npm Version
4185
run: npm -v
4286
- name: Install Dependencies
@@ -82,24 +126,54 @@ jobs:
82126
git config --global user.name "npm CLI robot"
83127
- name: Setup Node
84128
uses: actions/setup-node@v3
129+
id: node
85130
with:
86131
node-version: ${{ matrix.node-version }}
132+
check-latest: contains(matrix.node-version, '.x')
133+
134+
# node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows
87135
- name: Update Windows npm
88-
# node 12 and 14 ship with npm@6, which is known to fail when updating itself in windows
89-
if: matrix.platform.os == 'windows-latest' && (startsWith(matrix.node-version, '12.') || startsWith(matrix.node-version, '14.'))
136+
if: |
137+
matrix.platform.os == 'windows-latest' && (
138+
startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.')
139+
)
90140
run: |
91141
curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz
92142
tar xf npm-7.5.4.tgz
93143
cd package
94144
node lib/npm.js install --no-fund --no-audit -g ..\npm-7.5.4.tgz
95145
cd ..
96146
rmdir /s /q package
97-
- name: Install npm@7
98-
if: startsWith(matrix.node-version, '10.')
99-
run: npm i --prefer-online --no-fund --no-audit -g npm@7
100-
- name: Install npm@latest
101-
if: ${{ !startsWith(matrix.node-version, '10.') }}
147+
148+
# Start on Node 10 because we dont test on anything lower
149+
- name: Install npm@7 on Node 10
150+
shell: bash
151+
if: startsWith(steps.node.outputs.node-version, 'v10.')
152+
id: npm-7
153+
run: |
154+
npm i --prefer-online --no-fund --no-audit -g npm@7
155+
echo "updated=true" >> "$GITHUB_OUTPUT"
156+
157+
- name: Install npm@8 on Node 12
158+
shell: bash
159+
if: startsWith(steps.node.outputs.node-version, 'v12.')
160+
id: npm-8
161+
run: |
162+
npm i --prefer-online --no-fund --no-audit -g npm@8
163+
echo "updated=true" >> "$GITHUB_OUTPUT"
164+
165+
- name: Install npm@9 on Node 14/16/18.0
166+
shell: bash
167+
if: startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.')
168+
id: npm-9
169+
run: |
170+
npm i --prefer-online --no-fund --no-audit -g npm@9
171+
echo "updated=true" >> "$GITHUB_OUTPUT"
172+
173+
- name: Install npm@latest on Node
174+
if: ${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }}
102175
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
176+
103177
- name: npm Version
104178
run: npm -v
105179
- name: Install Dependencies

0 commit comments

Comments
 (0)