forked from longtao.wu/droboticflow
28 lines
710 B
Bash
Executable File
28 lines
710 B
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
attempts="${NPM_AUDIT_ATTEMPTS:-3}"
|
|
delay_seconds="${NPM_AUDIT_RETRY_DELAY_SECONDS:-5}"
|
|
|
|
if ! [[ "$attempts" =~ ^[0-9]+$ ]] || (( attempts < 1 )); then
|
|
echo "ERROR: NPM_AUDIT_ATTEMPTS must be a positive integer." >&2
|
|
exit 1
|
|
fi
|
|
|
|
if ! [[ "$delay_seconds" =~ ^[0-9]+$ ]]; then
|
|
echo "ERROR: NPM_AUDIT_RETRY_DELAY_SECONDS must be a non-negative integer." >&2
|
|
exit 1
|
|
fi
|
|
|
|
for ((attempt = 1; attempt <= attempts; attempt += 1)); do
|
|
if npm audit "$@"; then
|
|
exit 0
|
|
fi
|
|
status=$?
|
|
if (( attempt == attempts )); then
|
|
exit "$status"
|
|
fi
|
|
echo "npm audit failed on attempt $attempt/$attempts; retrying in ${delay_seconds}s..." >&2
|
|
sleep "$delay_seconds"
|
|
done
|