-
Notifications
You must be signed in to change notification settings - Fork 82
/
install-packages.yml
185 lines (175 loc) · 9.45 KB
/
install-packages.yml
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
description: >
Install your Node packages with automated caching and best practices applied.
Requires lock file.
parameters:
pkg-manager:
type: enum
enum: ["npm", "yarn", "yarn-berry"]
default: "npm"
description: Select the default node package manager to use. NPM v5+ Required.
with-cache:
type: boolean
default: true
description: Cache your node packages automatically for faster install times.
check-cache:
type: enum
default: "never"
enum: ["never", "always", "detect"]
description: |
Yarn berry only for Zero install support -
Use 'always' to always --check-cache argument to yarn install.
Use 'detect' to enable caching of yarn.lock and to only add when required.
app-dir:
type: string
default: "."
description: Path to the directory containing your package.json file. Not needed if package.json lives in the root.
override-ci-command:
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
default: ""
cache-path:
description: |
By default, this orb will utilize 'npm ci' and cache the '~/.npm' directory. Override which path to cache with this parameter.
type: string
default: ""
cache-only-lockfile:
type: boolean
default: true
description: |
If true, package.json will be ignored in the cache key. Useful for projects where package.json changes do not always invalidate dependencies.
Note: package.json will still be the final fallback key incase a project is not configured with a lock file.
cache-version:
type: string
default: "v1"
description: Change the default cache version if you need to clear the cache for any reason.
include-branch-in-cache-key:
type: boolean
default: true
description: >
If true, this cache bucket will only apply to jobs within the same branch.
steps:
- run:
name: Checking for package.json
working_directory: <<parameters.app-dir>>
command: <<include(scripts/packages/find-package.sh)>>
- when:
condition: << parameters.with-cache >>
steps:
- run:
working_directory: <<parameters.app-dir>>
name: Determine lockfile
command: <<include(scripts/packages/determine-lockfile.sh)>>
- restore_cache: # Include branch and package.json checksum if defined. Prioritize lock-file as it is a more definitive version of dependency cache.
keys:
- node-deps-{{ arch }}-<<parameters.cache-version>>-<<#parameters.include-branch-in-cache-key>>{{ .Branch }}-<</parameters.include-branch-in-cache-key>><<^parameters.cache-only-lockfile>>{{ checksum "/tmp/node-project-package.json" }}-<</parameters.cache-only-lockfile>>{{ 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: # Install packages based on NPM
condition:
equal: [npm, << parameters.pkg-manager >>]
steps:
- run:
name: Installing NPM packages
working_directory: <<parameters.app-dir>>
environment:
PARAM_CACHE_PATH: << parameters.cache-path >>
PARAM_OVERRIDE_COMMAND: << parameters.override-ci-command >>
command: <<include(scripts/packages/npm-install.sh)>>
- when: # cache enabled, save cache
condition: << parameters.with-cache >>
steps:
- when: # custom cache path selected
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: # npm ci cache path
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: # Install packages based on YARN
condition:
equal: [yarn, << parameters.pkg-manager >>]
steps:
- run:
name: Installing YARN packages
working_directory: <<parameters.app-dir>>
environment:
YARN_CACHE_FOLDER: << parameters.cache-path >>
PARAM_OVERRIDE_COMMAND: << parameters.override-ci-command >>
command: <<include(scripts/packages/yarn-v1-install.sh)>>
- when: # cache enabled, save cache
condition: << parameters.with-cache >>
steps:
- when: # custom cache path selected
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: # use node modules
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: # yarn v1 cache is slow, so it is faster to use node
- <<parameters.app-dir>>/node_modules
- when: # Install packages based on YARN
condition:
equal: [yarn-berry, << parameters.pkg-manager >>]
steps:
- when: # check-cache is set to detect, so cache yarn lock
condition:
equal: [detect, << parameters.check-cache >>]
steps:
- restore_cache:
keys:
- yarn-berry-{{ arch }}-<<parameters.cache-version>>-<<#parameters.include-branch-in-cache-key>>{{ .Branch }}-<</parameters.include-branch-in-cache-key>>{{ checksum "/tmp/yarn-zero-lockfile" }}
- yarn-berry-{{ arch }}-<<parameters.cache-version>>-<<#parameters.include-branch-in-cache-key>>{{ .Branch }}-<</parameters.include-branch-in-cache-key>>
- run:
name: Installing YARN packages
working_directory: <<parameters.app-dir>>
environment:
PARAM_CACHE_PATH: << parameters.cache-path >>
PARAM_OVERRIDE_COMMAND: << parameters.override-ci-command >>
PARAM_CHECK_CACHE: << parameters.check-cache >>
command: <<include(scripts/packages/yarn-berry-install.sh)>>
- when: # check-cache is set to detect, so cache yarn lock
condition:
equal: [detect, << parameters.check-cache >>]
steps:
- save_cache:
key: yarn-berry-{{ arch }}-<<parameters.cache-version>>-<<#parameters.include-branch-in-cache-key>>{{ .Branch }}-<</parameters.include-branch-in-cache-key>>{{ checksum "/tmp/yarn-zero-lockfile" }}
paths:
- <<parameters.cache-path>>
- when: # cache enabled, save cache
condition: << parameters.with-cache >>
steps:
- when: # custom cache path selected
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: # use node modules
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.with-cache >>
steps:
- run:
name: "Remove temporary links"
command: rm -f /tmp/node-project-lockfile /tmp/node-project-package.json /tmp/yarn-zero-lockfile