All checks were successful
Monorepo Pipeline / ⚡ Prioritize Release (push) Successful in 2s
Monorepo Pipeline / 🧪 Test (push) Successful in 6m38s
Monorepo Pipeline / 🧹 Lint (push) Successful in 7m14s
Monorepo Pipeline / 🏗️ Build (push) Successful in 10m24s
Monorepo Pipeline / 🐳 Build Directus (Base) (push) Successful in 1m39s
Monorepo Pipeline / 🐳 Build Build-Base (push) Successful in 2m7s
Monorepo Pipeline / 🐳 Build Production Runtime (push) Successful in 2m8s
Monorepo Pipeline / 🚀 Release (push) Successful in 2m18s
Monorepo Pipeline / 🐳 Build Gatekeeper (Product) (push) Successful in 6m58s
91 lines
3.0 KiB
Bash
Executable File
91 lines
3.0 KiB
Bash
Executable File
#!/bin/bash
|
||
set -e
|
||
|
||
# wait-for-upstream.sh
|
||
# Usage: ./wait-for-upstream.sh <org/repo> <version_tag> [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 <org/repo> <version_tag>"
|
||
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 by creation date.
|
||
RUN_ID=$(echo "$RUN_QUERY" | jq -r '.workflow_runs | sort_by(.created_at) | last | .id // empty')
|
||
|
||
if [[ -z "$RUN_ID" || "$RUN_ID" == "null" ]]; then
|
||
echo "ℹ️ No recent action run found for tag $TAG in $REPO."
|
||
echo "🔎 Checking if tag $TAG exists in the repository..."
|
||
|
||
TAG_EXISTS=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: token $GITEA_TOKEN" "$GITEA_API/repos/$REPO/tags/$TAG")
|
||
|
||
if [[ "$TAG_EXISTS" == "200" ]]; then
|
||
echo "✅ Tag $TAG exists. Assuming it was released successfully in the past."
|
||
exit 0
|
||
fi
|
||
|
||
echo "⚠️ Warning: Tag $TAG not found either. Upstream might be lagging or the version is invalid."
|
||
echo " Waiting 15s to see if it appears..."
|
||
sleep 15
|
||
|
||
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 // empty')
|
||
|
||
if [[ -z "$RUN_ID" || "$RUN_ID" == "null" ]]; then
|
||
# Final check for tag
|
||
TAG_EXISTS=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: token $GITEA_TOKEN" "$GITEA_API/repos/$REPO/tags/$TAG")
|
||
if [[ "$TAG_EXISTS" == "200" ]]; then
|
||
echo "✅ Tag $TAG finally detected. Proceeding."
|
||
exit 0
|
||
fi
|
||
echo "❌ Error: Could not find any action run OR tag for $TAG in $REPO."
|
||
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
|