From f4f9a4f89fd9ef3274151bcd6517572266aec4bd Mon Sep 17 00:00:00 2001
From: Kristian Klausen <kristian@klausen.dk>
Date: Tue, 16 Mar 2021 00:28:55 +0100
Subject: [PATCH] arch_boxes_sync: Handle delay between release and artifacts
 being ready gracefully

The releases are released/tagged and then built, so there is a delay
between releasing a release and the artifcats being ready, we should
handle that gracefully.
---
 roles/arch_boxes_sync/files/arch-boxes-sync.sh | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/roles/arch_boxes_sync/files/arch-boxes-sync.sh b/roles/arch_boxes_sync/files/arch-boxes-sync.sh
index 5c80e3373..2304424ee 100755
--- a/roles/arch_boxes_sync/files/arch-boxes-sync.sh
+++ b/roles/arch_boxes_sync/files/arch-boxes-sync.sh
@@ -19,7 +19,13 @@ readonly TMPDIR="$(mktemp --directory --tmpdir="/var/tmp")"
 trap "rm -rf \"${TMPDIR}\"" EXIT
 cd "${TMPDIR}"
 
-curl --silent --show-error --fail --output "output.zip" "https://gitlab.archlinux.org/api/v4/projects/${PROJECT_ID}/jobs/artifacts/${LATEST_RELEASE_TAG}/download?job=${JOB_NAME}"
+readonly HTTP_CODE="$(curl --silent --show-error --fail --output "output.zip" --write-out "%{http_code}" "https://gitlab.archlinux.org/api/v4/projects/${PROJECT_ID}/jobs/artifacts/${LATEST_RELEASE_TAG}/download?job=${JOB_NAME}")"
+# The releases are released/tagged and then built, so the artifacts aren't necessarily ready (yet).
+if (( HTTP_CODE == 404 )); then
+  echo "Skipping release: ${LATEST_RELEASE_TAG}, artifacts not ready (404)"
+  exit
+fi
+
 mkdir "${LATEST_RELEASE_TAG}"
 unzip output.zip
 # People should download the vagrant images from Vagrant Cloud
-- 
GitLab