2020#
2121# [1]: https://help.github.com/en/articles/about-github-actions
2222
23- # shellcheck disable=SC2181
23+ # shellcheck disable=SC2181,SC2129
2424
2525# Ensure that the exit status of pipelines is non-zero in the event that at least one of the commands in a pipeline fails:
2626set -o pipefail
@@ -115,78 +115,92 @@ print_success() {
115115
116116# Performs local installation initialization tasks.
117117install_init () {
118- echo ' Creating installation directory...' >&2
118+ echo " Creating installation directory: ${install_dir} ..." >> " ${log_file} " 2>&1
119119 mkdir -p " ${install_dir} " || return 1
120120
121- echo ' Navigating to installation directory...' >&2
121+ echo ' Navigating to installation directory...' >> " ${log_file} " 2>&1
122122 cd " ${install_dir} " || return 1
123123
124- echo ' Creating package.json...' >&2
124+ echo ' Creating package.json...' >> " ${log_file} " 2>&1
125125 echo ' {"name":"test-install","version":"0.0.0","private":true}' > " ${install_dir} /package.json"
126+ echo ' package.json:' >> " ${log_file} " 2>&1
127+ cat " ${install_dir} /package.json" >> " ${log_file} " 2>&1
126128
127129 return 0
128130}
129131
130132# Tests that a local installation works as expected.
131133install_test () {
132- echo ' Testing installation...' >&2
134+ echo ' Testing installation...' >> " ${log_file} " 2>&1
133135
134- echo ' Creating test script (require global namespace)...' >&2
136+ echo ' Creating test script (require global namespace)...' >> " ${log_file} " 2>&1
135137 echo ' var stdlib = require( "@stdlib/stdlib" ); console.log( stdlib.math.base.special.sin( 3.14 ) );' > " ${install_dir} /script.js"
138+ echo ' script:' >> " ${log_file} " 2>&1
139+ cat " ${install_dir} /script.js" >> " ${log_file} " 2>&1
136140
137- echo ' Running test script...' >&2
138- node " ${install_dir} /script.js"
141+ echo ' Running test script...' >> " ${log_file} " 2>&1
142+ node " ${install_dir} /script.js" >> " ${log_file} " 2>&1
139143 if [[ " $? " -ne 0 ]]; then
140- echo " Encountered an error when running test script." >&2
144+ echo " Encountered an error when running test script." >> " ${log_file} " 2>&1
141145 return 1
142146 fi
143- echo ' Successfully ran test script.' >&2
147+ echo ' ' >> " ${log_file} " 2>&1
148+ echo ' Successfully ran test script.' >> " ${log_file} " 2>&1
144149
145- echo ' Creating test script (require individual package)...' >&2
150+ echo ' Creating test script (require individual package)...' >> " ${log_file} " 2>&1
146151 echo ' var sin = require( "@stdlib/math/base/special/sin" ); console.log( sin( 3.14 ) );' > " ${install_dir} /script.js"
152+ echo ' script:' >> " ${log_file} " 2>&1
153+ cat " ${install_dir} /script.js" >> " ${log_file} " 2>&1
147154
148- echo ' Running test script...' >&2
149- node " ${install_dir} /script.js"
155+ echo ' Running test script...' >> " ${log_file} " 2>&1
156+ node " ${install_dir} /script.js" >> " ${log_file} " 2>&1
150157 if [[ " $? " -ne 0 ]]; then
151- echo " Encountered an error when running test script." >&2
158+ echo " Encountered an error when running test script." >> " ${log_file} " 2>&1
152159 return 1
153160 fi
154- echo ' Successfully ran test script.' >&2
161+ echo ' ' >> " ${log_file} " 2>&1
162+ echo ' Successfully ran test script.' >> " ${log_file} " 2>&1
155163
156164 # Test `import` syntax on more recent Node.js versions which support ES modules without having to set flags to enable experimental support...
157165 if [[ " ${node_major_version} " -gt 13 ]]; then
158- echo ' Creating test script (import global namespace)...' >&2
166+ echo ' Creating test script (import global namespace)...' >> " ${log_file} " 2>&1
159167 echo ' import stdlib from "@stdlib/stdlib"; console.log( stdlib.math.base.special.sin( 3.14 ) );' > " ${install_dir} /script.mjs"
168+ echo ' script:' >> " ${log_file} " 2>&1
169+ cat " ${install_dir} /script.mjs" >> " ${log_file} " 2>&1
160170
161- echo ' Running test script...' >&2
162- node " ${install_dir} /script.mjs"
171+ echo ' Running test script...' >> " ${log_file} " 2>&1
172+ node " ${install_dir} /script.mjs" >> " ${log_file} " 2>&1
163173 if [[ " $? " -ne 0 ]]; then
164- echo " Encountered an error when running test script." >&2
174+ echo " Encountered an error when running test script." >> " ${log_file} " 2>&1
165175 return 1
166176 fi
167- echo ' Successfully ran test script.' >&2
177+ echo ' ' >> " ${log_file} " 2>&1
178+ echo ' Successfully ran test script.' >> " ${log_file} " 2>&1
168179
169180 # FIMXE: uncomment once we've figured out our package.json `exports` strategy...
170- # echo 'Creating test script (import individual package)...' >&2
181+ # echo 'Creating test script (import individual package)...' >> "${log_file}" 2>&1
171182 # echo 'import sin from "@stdlib/math/base/special/sin"; console.log( sin( 3.14 ) );' > "${install_dir}/script.mjs"
183+ # echo 'script:' >> "${log_file}" 2>&1
184+ # cat "${install_dir}/script.mjs" >> "${log_file}" 2>&1
172185
173- # echo 'Running test script...' >&2
174- # node "${install_dir}/script.mjs"
186+ # echo 'Running test script...' >> "${log_file}" 2>&1
187+ # node "${install_dir}/script.mjs" >> "${log_file}" 2>&1
175188 # if [[ "$?" -ne 0 ]]; then
176- # echo "Encountered an error when running test script." >&2
189+ # echo "Encountered an error when running test script." >> "${log_file}" 2>&1
177190 # return 1
178191 # fi
179- # echo 'Successfully ran test script.' >&2
192+ # echo '' >> "${log_file}" 2>&1
193+ # echo 'Successfully ran test script.' >> "${log_file}" 2>&1
180194 fi
181195 return 0
182196}
183197
184198# Performs local installation cleanup tasks.
185199install_clean () {
186- echo ' Returning to original directory...' >&2
200+ echo " Returning to original directory: ${working_dir} ..." >> " ${log_file} " 2>&1
187201 cd " ${working_dir} " || return 1
188202
189- echo ' Removing installation directory...' >&2
203+ echo " Removing installation directory: ${install_dir} ..." >> " ${log_file} " 2>&1
190204 rm -rf " ${install_dir} " || return 1
191205
192206 return 0
@@ -196,22 +210,25 @@ install_clean() {
196210npm_install () {
197211 install_init
198212 if [[ " $? " -ne 0 ]]; then
199- echo " Encountered an error when performing pre-install initialization tasks." >&2
213+ echo " Encountered an error when performing pre-install initialization tasks." >> " ${log_file} " 2>&1
200214 return 1
201215 fi
202- npm install " ${pkg_name} @${pkg_version} "
216+ echo " Installing ${pkg_name} @${pkg_version} ..." >> " ${log_file} " 2>&1
217+ npm install " ${pkg_name} @${pkg_version} " >> " ${log_file} " 2>&1
203218 if [[ " $? " -ne 0 ]]; then
204- echo " Encountered an error when installing ${pkg_name} @${pkg_version} via npm." >&2
219+ echo " Encountered an error when installing ${pkg_name} @${pkg_version} via npm." >> " ${log_file} " 2>&1
205220 return 1
206221 fi
222+ echo " Successfully installed ${pkg_name} @${pkg_version} ." >> " ${log_file} " 2>&1
223+
207224 install_test
208225 if [[ " $? " -ne 0 ]]; then
209- echo " Encountered an error when testing installation." >&2
226+ echo " Encountered an error when testing installation." >> " ${log_file} " 2>&1
210227 return 1
211228 fi
212229 install_clean
213230 if [[ " $? " -ne 0 ]]; then
214- echo " Encountered an error when performing post-install cleanup tasks." >&2
231+ echo " Encountered an error when performing post-install cleanup tasks." >> " ${log_file} " 2>&1
215232 return 1
216233 fi
217234 return 0
@@ -221,79 +238,96 @@ npm_install() {
221238npm_install_from_github () {
222239 install_init
223240 if [[ " $? " -ne 0 ]]; then
224- echo " Encountered an error when performing pre-install initialization tasks." >&2
241+ echo " Encountered an error when performing pre-install initialization tasks." >> " ${log_file} " 2>&1
225242 return 1
226243 fi
227- npm install " ${pkg_github_url} #${pkg_github_tag} "
244+ echo " Installing ${pkg_github_url} #${pkg_github_tag} ..." >> " ${log_file} " 2>&1
245+ npm install " ${pkg_github_url} #${pkg_github_tag} " >> " ${log_file} " 2>&1
228246 if [[ " $? " -ne 0 ]]; then
229- echo " Encountered an error when installing ${pkg_github_url} #${pkg_github_tag} via npm." >&2
247+ echo " Encountered an error when installing ${pkg_github_url} #${pkg_github_tag} via npm." >> " ${log_file} " 2>&1
230248 return 1
231249 fi
250+ echo " Successfully installed ${pkg_github_url} #${pkg_github_tag} ." >> " ${log_file} " 2>&1
251+
232252 install_test
233253 if [[ " $? " -ne 0 ]]; then
234- echo " Encountered an error when testing installation." >&2
254+ echo " Encountered an error when testing installation." >> " ${log_file} " 2>&1
235255 return 1
236256 fi
237257 install_clean
238258 if [[ " $? " -ne 0 ]]; then
239- echo " Encountered an error when performing post-install cleanup tasks." >&2
259+ echo " Encountered an error when performing post-install cleanup tasks." >> " ${log_file} " 2>&1
240260 return 1
241261 fi
242262 return 0
243263}
244264
245265# Installs a package globally via `npm`.
246266npm_install_global () {
247- npm install -g " ${pkg_name} @${pkg_version} "
267+ echo " Installing ${pkg_name} @${pkg_version} as a global package..." >> " ${log_file} " 2>&1
268+ npm install -g " ${pkg_name} @${pkg_version} " >> " ${log_file} " 2>&1
248269 if [[ " $? " -ne 0 ]]; then
249- echo " Encountered an error when installing ${pkg_name} @${pkg_version} as a global package via npm." >&2
270+ echo " Encountered an error when installing ${pkg_name} @${pkg_version} as a global package via npm." >> " ${log_file} " 2>&1
250271 return 1
251272 fi
252- stdlib --help
273+ echo " Successfully installed ${pkg_name} @${pkg_version} ." >> " ${log_file} " 2>&1
274+
275+ echo ' Testing global installation...' >> " ${log_file} " 2>&1
276+ stdlib --help >> " ${log_file} " 2>&1
253277 if [[ " $? " -ne 0 ]]; then
254- echo " Encountered an error when testing installation." >&2
278+ echo " Encountered an error when testing installation." >> " ${log_file} " 2>&1
255279 return 1
256280 fi
257- npm uninstall -g " ${pkg_name} "
281+ echo ' Successfully tested global installation...' >> " ${log_file} " 2>&1
282+
283+ echo ' Removing global installation...' >> " ${log_file} " 2>&1
284+ npm uninstall -g " ${pkg_name} " >> " ${log_file} " 2>&1
258285 if [[ " $? " -ne 0 ]]; then
259- echo " Encountered an error when performing post-install cleanup tasks." >&2
286+ echo " Encountered an error when performing post-install cleanup tasks." >> " ${log_file} " 2>&1
260287 return 1
261288 fi
289+ echo ' Successfully removed global installation...' >> " ${log_file} " 2>&1
262290 return 0
263291}
264292
265293# Installs a package globally via `npm` from GitHub.
266294npm_install_global_github () {
267- npm install " ${pkg_github_url} #${pkg_github_tag} "
295+ echo " Installing ${pkg_github_url} #${pkg_github_tag} as a global package..." >> " ${log_file} " 2>&1
296+ npm install " ${pkg_github_url} #${pkg_github_tag} " >> " ${log_file} " 2>&1
268297 if [[ " $? " -ne 0 ]]; then
269- echo " Encountered an error when installing ${pkg_github_url} #${pkg_github_tag} as a global package via npm." >&2
298+ echo " Encountered an error when installing ${pkg_github_url} #${pkg_github_tag} as a global package via npm." >> " ${log_file} " 2>&1
270299 return 1
271300 fi
272- stdlib --help
301+ echo " Successfully installed ${pkg_github_url} #${pkg_github_tag} ." >> " ${log_file} " 2>&1
302+
303+ echo ' Testing global installation...' >> " ${log_file} " 2>&1
304+ stdlib --help >> " ${log_file} " 2>&1
273305 if [[ " $? " -ne 0 ]]; then
274- echo " Encountered an error when testing installation." >&2
306+ echo " Encountered an error when testing installation." >> " ${log_file} " 2>&1
275307 return 1
276308 fi
277- npm uninstall -g " ${pkg_name} "
309+ echo ' Successfully tested global installation...' >> " ${log_file} " 2>&1
310+
311+ echo ' Removing global installation...' >> " ${log_file} " 2>&1
312+ npm uninstall -g " ${pkg_name} " >> " ${log_file} " 2>&1
278313 if [[ " $? " -ne 0 ]]; then
279- echo " Encountered an error when performing post-install cleanup tasks." >&2
314+ echo " Encountered an error when performing post-install cleanup tasks." >> " ${log_file} " 2>&1
280315 return 1
281316 fi
317+ echo ' Successfully removed global installation...' >> " ${log_file} " 2>&1
282318 return 0
283319}
284320
285321# Tests whether the project successfully installs via `npm`.
286- #
287- # $1 - log file
288322test_npm_install () {
289323 echo ' Testing npm install...' >&2
290- npm_install >> " $1 " 2>&1
324+ npm_install
291325 if [[ " $? " -ne 0 ]]; then
292326 echo ' Installation failed.' >&2
293327 echo ' Retry 1 of 1...' >&2
294328 sleep 15s
295329 echo ' Testing npm install...' >&2
296- npm_install >> " $1 " 2>&1
330+ npm_install
297331 if [[ " $? " -ne 0 ]]; then
298332 echo ' Installation failed.' >&2
299333 return 1
@@ -302,13 +336,13 @@ test_npm_install() {
302336 echo ' Successfully installed.' >&2
303337
304338 echo ' Testing npm install (via GitHub)...' >&2
305- npm_install_from_github >> " $1 " 2>&1
339+ npm_install_from_github
306340 if [[ " $? " -ne 0 ]]; then
307341 echo ' Installation (via GitHub) failed.' >&2
308342 echo ' Retry 1 of 1...' >&2
309343 sleep 15s
310344 echo ' Testing npm install (via GitHub)...' >&2
311- npm_install_from_github >> " $1 " 2>&1
345+ npm_install_from_github
312346 if [[ " $? " -ne 0 ]]; then
313347 echo ' Installation (via GitHub) failed.' >&2
314348 return 1
@@ -317,13 +351,13 @@ test_npm_install() {
317351 echo ' Successfully installed (via GitHub).' >&2
318352
319353 echo ' Testing npm install (global)...' >&2
320- npm_install_global >> " $1 " 2>&1
354+ npm_install_global
321355 if [[ " $? " -ne 0 ]]; then
322356 echo ' Installation (global) failed.' >&2
323357 echo ' Retry 1 of 1...' >&2
324358 sleep 15s
325359 echo ' Testing npm install (global)...' >&2
326- npm_install_global >> " $1 " 2>&1
360+ npm_install_global
327361 if [[ " $? " -ne 0 ]]; then
328362 echo ' Installation (global) failed.' >&2
329363 return 1
@@ -332,13 +366,13 @@ test_npm_install() {
332366 echo ' Successfully installed (global).' >&2
333367
334368 echo ' Testing npm install (global via GitHub)...' >&2
335- npm_install_global_github >> " $1 " 2>&1
369+ npm_install_global_github
336370 if [[ " $? " -ne 0 ]]; then
337371 echo ' Installation (global via GitHub) failed.' >&2
338372 echo ' Retry 1 of 1...' >&2
339373 sleep 15s
340374 echo ' Testing npm install (global via GitHub)...' >&2
341- npm_install_global_github >> " $1 " 2>&1
375+ npm_install_global_github
342376 if [[ " $? " -ne 0 ]]; then
343377 echo ' Installation (global via GitHub) failed.' >&2
344378 return 1
@@ -357,7 +391,7 @@ main() {
357391
358392 # Note: please keep the list of package managers in alphabetical order...
359393 if [[ " ${pm} " = " npm" ]]; then
360- test_npm_install " ${log_file} "
394+ test_npm_install
361395 if [[ " $? " -ne 0 ]]; then
362396 on_error 1
363397 fi
0 commit comments