#!/usr/bin/env bash set -euo pipefail max_attempts="${GENARRATIVE_CI_NPM_CI_ATTEMPTS:-3}" base_delay_seconds="${GENARRATIVE_CI_NPM_CI_RETRY_DELAY_SECONDS:-5}" if [[ ! "${max_attempts}" =~ ^[1-9][0-9]*$ ]]; then echo 'GENARRATIVE_CI_NPM_CI_ATTEMPTS must be a positive integer.' >&2 exit 2 fi if [[ ! "${base_delay_seconds}" =~ ^[0-9]+$ ]]; then echo 'GENARRATIVE_CI_NPM_CI_RETRY_DELAY_SECONDS must be a non-negative integer.' >&2 exit 2 fi for attempt in $(seq 1 "${max_attempts}"); do if npm ci "$@"; then exit 0 fi if [[ "${attempt}" -eq "${max_attempts}" ]]; then echo "npm ci failed after ${max_attempts} attempts." >&2 exit 1 fi sleep "$((attempt * base_delay_seconds))" done