-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-packages.yml
More file actions
256 lines (255 loc) · 9.74 KB
/
install-packages.yml
File metadata and controls
256 lines (255 loc) · 9.74 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
---
description: >
Install your Node packages with automated caching and best practices applied.
Requires lock file.
parameters:
app-dir:
default: .
description: >-
Path to the directory containing your package.json file. Not needed if
package.json lives in the root.
type: string
cache-path:
default: ''
description: >
By default, this orb will utilize 'npm ci' and cache the '~/.npm'
directory. Override which path to cache with this parameter.
type: string
cache-version:
default: v1
description: >-
Change the default cache version if you need to clear the cache for any
reason.
type: string
include-branch-in-cache-key:
default: true
description: |
If true, this cache bucket will only apply to jobs within the same branch.
type: boolean
override-ci-command:
default: ''
description: >
By default, packages will be installed with "npm ci", "yarn install
--frozen-lockfile" or "yarn install --immutable".
Optionally supply a custom package installation command, with any
additional flags needed.
type: string
pkg-manager:
default: npm
description: Select the default node package manager to use. NPM v5+ Required.
enum:
- npm
- yarn
- yarn-berry
type: enum
slack-notify:
default: true
description: |
If true, it will send notifications to slack. Make sure a context `slack-secrets` exists
type: boolean
slack-mention:
default: '@devops'
description: |
A Slack group or user to mention
type: string
with-cache:
default: true
description: Cache your node packages automatically for faster install times.
type: boolean
steps:
- run:
command: |
if [ ! -f "package.json" ]; then
echo
echo "---"
echo "Unable to find your package.json file. Did you forget to set the app-dir parameter?"
echo "---"
echo
echo "Current directory: $(pwd)"
echo
echo
echo "List directory: "
echo
ls
exit 1
fi
name: Checking for package.json.
working_directory: <<parameters.app-dir>>
- when:
condition: << parameters.with-cache >>
steps:
- run:
command: |
if [ -f "package-lock.json" ]; then
echo "Found package-lock.json file, assuming lockfile"
ln package-lock.json /tmp/node-project-lockfile
elif [ -f "npm-shrinkwrap.json" ]; then
echo "Found npm-shrinkwrap.json file, assuming lockfile"
ln npm-shrinkwrap.json /tmp/node-project-lockfile
elif [ -f "yarn.lock" ]; then
echo "Found yarn.lock file, assuming lockfile"
ln yarn.lock /tmp/node-project-lockfile
fi
ln package.json /tmp/node-project-package.json
name: Determine lockfile
working_directory: <<parameters.app-dir>>
- restore_cache:
keys:
- >-
node-deps-{{ arch
}}-<<parameters.cache-version>>-<<#parameters.include-branch-in-cache-key>>{{
.Branch }}-<</parameters.include-branch-in-cache-key>>{{
checksum "/tmp/node-project-package.json" }}-{{ checksum
"/tmp/node-project-lockfile" }}
- >-
node-deps-{{ arch
}}-<<parameters.cache-version>>-<<#parameters.include-branch-in-cache-key>>{{
.Branch }}-<</parameters.include-branch-in-cache-key>>{{
checksum "/tmp/node-project-package.json" }}-
- >-
node-deps-{{ arch
}}-<<parameters.cache-version>>-<<#parameters.include-branch-in-cache-key>>{{
.Branch }}-<</parameters.include-branch-in-cache-key>>
- when:
condition:
equal:
- npm
- << parameters.pkg-manager >>
steps:
- run:
command: |
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
if [[ ! -z "<< parameters.override-ci-command >>" ]]; then
echo "Running override package installation command:"
<< parameters.override-ci-command >>
else
npm ci
fi
name: Installing NPM packages
working_directory: <<parameters.app-dir>>
- when:
condition: << parameters.with-cache >>
steps:
- when:
condition: << parameters.cache-path >>
steps:
- save_cache:
key: >-
node-deps-{{ arch
}}-<<parameters.cache-version>>-<<#parameters.include-branch-in-cache-key>>{{
.Branch
}}-<</parameters.include-branch-in-cache-key>>{{
checksum "/tmp/node-project-package.json" }}-{{
checksum "/tmp/node-project-lockfile" }}
paths:
- <<parameters.cache-path>>
- unless:
condition: << parameters.cache-path >>
steps:
- save_cache:
key: >-
node-deps-{{ arch
}}-<<parameters.cache-version>>-<<#parameters.include-branch-in-cache-key>>{{
.Branch
}}-<</parameters.include-branch-in-cache-key>>{{
checksum "/tmp/node-project-package.json" }}-{{
checksum "/tmp/node-project-lockfile" }}
paths:
- ~/.npm
- when:
condition:
equal:
- yarn
- << parameters.pkg-manager >>
steps:
- run:
command: |
if [[ ! -z "<< parameters.override-ci-command >>" ]]; then
echo "Running override package installation command:"
<< parameters.override-ci-command >>
else
yarn install --frozen-lockfile
fi
name: Installing YARN packages
working_directory: <<parameters.app-dir>>
- when:
condition: << parameters.with-cache >>
steps:
- when:
condition: << parameters.cache-path >>
steps:
- save_cache:
key: >-
node-deps-{{ arch
}}-<<parameters.cache-version>>-<<#parameters.include-branch-in-cache-key>>{{
.Branch
}}-<</parameters.include-branch-in-cache-key>>{{
checksum "/tmp/node-project-package.json" }}-{{
checksum "/tmp/node-project-lockfile" }}
paths:
- <<parameters.cache-path>>
- unless:
condition: << parameters.cache-path >>
steps:
- save_cache:
key: >-
node-deps-{{ arch
}}-<<parameters.cache-version>>-<<#parameters.include-branch-in-cache-key>>{{
.Branch
}}-<</parameters.include-branch-in-cache-key>>{{
checksum "/tmp/node-project-package.json" }}-{{
checksum "/tmp/node-project-lockfile" }}
paths:
- <<parameters.app-dir>>/node_modules
- when:
condition:
equal:
- yarn-berry
- << parameters.pkg-manager >>
steps:
- run:
command: |
if [[ ! -z "<< parameters.override-ci-command >>" ]]; then
echo "Running override package installation command:"
<< parameters.override-ci-command >>
else
yarn install --immutable
fi
name: Installing YARN packages
working_directory: <<parameters.app-dir>>
- when:
condition: << parameters.with-cache >>
steps:
- when:
condition: << parameters.cache-path >>
steps:
- save_cache:
key: >-
node-deps-{{ arch
}}-<<parameters.cache-version>>-<<#parameters.include-branch-in-cache-key>>{{
.Branch
}}-<</parameters.include-branch-in-cache-key>>{{
checksum "/tmp/node-project-package.json" }}-{{
checksum "/tmp/node-project-lockfile" }}
paths:
- <<parameters.cache-path>>
- unless:
condition: << parameters.cache-path >>
steps:
- save_cache:
key: >-
node-deps-{{ arch
}}-<<parameters.cache-version>>-<<#parameters.include-branch-in-cache-key>>{{
.Branch
}}-<</parameters.include-branch-in-cache-key>>{{
checksum "/tmp/node-project-package.json" }}-{{
checksum "/tmp/node-project-lockfile" }}
paths:
- <<parameters.app-dir>>/.yarn/cache
- when:
condition: << parameters.slack-notify >>
steps:
- slack/notify:
event: fail
mentions: << parameters.slack-mention >>
template: basic_fail_1