From 63d2acfab519fdf9712bfefb72ce95cee9e1523b Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Wed, 11 Feb 2026 22:41:47 +0100 Subject: [PATCH] feat(infra): add wait-for-upstream script for smart dependencies --- packages/infra/scripts/wait-for-upstream.sh | 75 +++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100755 packages/infra/scripts/wait-for-upstream.sh diff --git a/packages/infra/scripts/wait-for-upstream.sh b/packages/infra/scripts/wait-for-upstream.sh new file mode 100755 index 0000000..6643078 --- /dev/null +++ b/packages/infra/scripts/wait-for-upstream.sh @@ -0,0 +1,75 @@ +#!/bin/bash +set -e + +# wait-for-upstream.sh +# Usage: ./wait-for-upstream.sh [poll_interval_sec] + +REPO=$1 +TAG=$2 +INTERVAL=${3:-30} +MAX_RETRIES=40 # ~20 minutes default + +if [[ -z "$REPO" || -z "$TAG" ]]; then + echo "❌ Error: REPO and TAG are required." + echo "Usage: $0 " + exit 1 +fi + +if [[ -z "$GITEA_TOKEN" ]]; then + echo "❌ Error: GITEA_TOKEN is not set." + exit 1 +fi + +GITEA_API="https://git.infra.mintel.me/api/v1" + +echo "🔎 Searching for upstream release $TAG in $REPO..." + +# 1. Find the run for the specific tag +# We look for runs on the specific ref (refs/tags/vX.Y.Z) +RUN_QUERY=$(curl -s -H "Authorization: token $GITEA_TOKEN" "$GITEA_API/repos/$REPO/actions/runs?ref=refs/tags/$TAG") + +# Gitea returns a list of runs. We take the latest one. +RUN_ID=$(echo "$RUN_QUERY" | jq -r '.workflow_runs[0].id') + +if [[ "$RUN_ID" == "null" ]]; then + echo "⚠️ Warning: No active run found for tag $TAG in $REPO yet. Upstream might be lagging." + echo " If this is a new tag, it might take a few seconds to appear." + # Optional: Wait a bit and try once more before failing + sleep 10 + RUN_QUERY=$(curl -s -H "Authorization: token $GITEA_TOKEN" "$GITEA_API/repos/$REPO/actions/runs?ref=refs/tags/$TAG") + RUN_ID=$(echo "$RUN_QUERY" | jq -r '.workflow_runs[0].id') + + if [[ "$RUN_ID" == "null" ]]; then + echo "❌ Error: Could not find any action run for $TAG. Proceeding blindly or failing?" + # For safety, we fail if we explicitly requested a version that isn't building + exit 1 + fi +fi + +echo "⏳ Waiting for upstream run $RUN_ID status..." + +RETRY_COUNT=0 +while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do + STATUS_QUERY=$(curl -s -H "Authorization: token $GITEA_TOKEN" "$GITEA_API/repos/$REPO/actions/runs/$RUN_ID") + STATUS=$(echo "$STATUS_QUERY" | jq -r '.status') + CONCLUSION=$(echo "$STATUS_QUERY" | jq -r '.conclusion') + + echo " - Current Status: $STATUS (Conclusion: $CONCLUSION)" + + if [[ "$STATUS" == "success" || "$CONCLUSION" == "success" ]]; then + echo "✅ Upstream release $TAG is READY." + exit 0 + fi + + if [[ "$STATUS" == "failure" || "$CONCLUSION" == "failure" || "$CONCLUSION" == "cancelled" ]]; then + echo "❌ Error: Upstream release $TAG FAILED or was CANCELLED." + exit 1 + fi + + echo " - Still working... waiting $INTERVAL seconds (Attempt $((RETRY_COUNT+1))/$MAX_RETRIES)" + sleep $INTERVAL + RETRY_COUNT=$((RETRY_COUNT+1)) +done + +echo "❌ Error: Timeout waiting for upstream release $TAG." +exit 1