Skip to content

Commit 3fc0314

Browse files
committed
Address promotion copy retry review feedback
1 parent 60aefcc commit 3fc0314

1 file changed

Lines changed: 25 additions & 6 deletions

File tree

.github/workflows/cpflow-promote-staging-to-production.yml

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -348,25 +348,44 @@ jobs:
348348
run: |
349349
set -euo pipefail
350350
351-
CPLN_TOKEN="${CPLN_TOKEN_STAGING}" cpln image get "${STAGING_IMAGE}" --org "${CPLN_ORG_STAGING}" -o json >/dev/null
351+
if ! [[ "${COPY_IMAGE_RETRIES}" =~ ^[0-9]+$ ]]; then
352+
echo "::error::COPY_IMAGE_RETRIES must be a non-negative integer."
353+
exit 1
354+
fi
355+
356+
if ! [[ "${COPY_IMAGE_RETRY_INTERVAL}" =~ ^[0-9]+$ ]]; then
357+
echo "::error::COPY_IMAGE_RETRY_INTERVAL must be a non-negative integer."
358+
exit 1
359+
fi
360+
361+
copy_image_retries=$((10#${COPY_IMAGE_RETRIES}))
362+
copy_image_attempts=$((copy_image_retries + 1))
363+
copy_image_retry_interval=$((10#${COPY_IMAGE_RETRY_INTERVAL}))
364+
365+
if ! CPLN_TOKEN="${CPLN_TOKEN_STAGING}" cpln image get "${STAGING_IMAGE}" --org "${CPLN_ORG_STAGING}" -o json >/dev/null; then
366+
echo "::error::Staging image '${STAGING_IMAGE}' was not found in org '${CPLN_ORG_STAGING}'; aborting promotion."
367+
exit 1
368+
fi
352369
353370
copy_status=1
354-
for attempt in $(seq 1 "${COPY_IMAGE_RETRIES}"); do
371+
for attempt in $(seq 1 "${copy_image_attempts}"); do
355372
if cpflow copy-image-from-upstream -a "${PRODUCTION_APP_NAME}" --org "${CPLN_ORG_PRODUCTION}" --image "${STAGING_IMAGE}"; then
356373
copy_status=0
357374
break
358375
else
359376
copy_status=$?
360377
fi
361378
362-
if [[ "${attempt}" -lt "${COPY_IMAGE_RETRIES}" ]]; then
363-
echo "::warning::Image copy attempt ${attempt}/${COPY_IMAGE_RETRIES} failed with exit ${copy_status}; retrying in ${COPY_IMAGE_RETRY_INTERVAL}s."
364-
sleep "${COPY_IMAGE_RETRY_INTERVAL}"
379+
if [[ "${attempt}" -lt "${copy_image_attempts}" ]]; then
380+
echo "::warning::Image copy attempt ${attempt}/${copy_image_attempts} failed with exit ${copy_status}; retrying in ${copy_image_retry_interval}s."
381+
sleep "${copy_image_retry_interval}"
382+
else
383+
echo "::warning::Image copy attempt ${attempt}/${copy_image_attempts} failed with exit ${copy_status}; no attempts remain."
365384
fi
366385
done
367386
368387
if [[ "${copy_status}" -ne 0 ]]; then
369-
echo "::error::Could not copy staging image '${STAGING_IMAGE}' from '${CPLN_ORG_STAGING}' to '${CPLN_ORG_PRODUCTION}' after ${COPY_IMAGE_RETRIES} attempt(s)."
388+
echo "::error::Could not copy staging image '${STAGING_IMAGE}' from '${CPLN_ORG_STAGING}' to '${CPLN_ORG_PRODUCTION}' after ${copy_image_attempts} attempt(s)."
370389
exit "${copy_status}"
371390
fi
372391

0 commit comments

Comments
 (0)