fix: make release PR creation robust against race conditions

Two fixes:
- Use BASE_BRANCH (with fallback) instead of DEFAULT_BRANCH for the
  PR base field, preventing empty base causing 404
- Replace fixed sleep with branch readiness poll (up to 10 attempts)
  and add retry loop for PR creation (up to 5 attempts), fixing
  intermittent 404 when Gitea hasn't indexed the branch yet

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-23 16:51:47 +01:00
parent 068c6ef686
commit 581ccba72e
+44 -20
View File
@@ -189,27 +189,51 @@ jobs:
fi fi
echo "Creating new PR..." echo "Creating new PR..."
echo "Waiting for branch to be ready..." echo "Waiting for next-release branch to be ready..."
sleep 3 for i in $(seq 1 10); do
BRANCH_STATUS=$(curl -s --retry 3 --retry-delay 2 --retry-connrefused \
-w "%{http_code}" -o /dev/null \
-H "Authorization: token ${TOKEN}" \
"${API_URL}/branches/next-release")
if [ "${BRANCH_STATUS}" = "200" ]; then
echo "Branch ready after ${i} attempt(s)"
break
fi
if [ "${i}" = "10" ]; then
echo "Branch next-release not found after 10 attempts, giving up"
exit 1
fi
echo "Branch not ready yet (attempt ${i}/10), waiting..."
sleep 3
done
RESPONSE=$(curl -s --retry 3 --retry-delay 3 --retry-all-errors --retry-connrefused \ PR_DATA=$(jq -n \
-w "\n%{http_code}" -X POST \ --arg title "${TITLE}" \
-H "Authorization: token ${TOKEN}" \ --arg body "${DESCRIPTION}" \
-H "Content-Type: application/json" \ --arg head "next-release" \
--data "$(jq -n \ --arg base "${BASE_BRANCH}" \
--arg title "${TITLE}" \ '{title: $title, body: $body, head: $head, base: $base}')
--arg body "${DESCRIPTION}" \
--arg head "next-release" \ for i in $(seq 1 5); do
--arg base "${DEFAULT_BRANCH}" \ RESPONSE=$(curl -s --retry 3 --retry-delay 2 --retry-connrefused \
'{title: $title, body: $body, head: $head, base: $base}')" \ -w "\n%{http_code}" -X POST \
"${API_URL}/pulls") -H "Authorization: token ${TOKEN}" \
HTTP_CODE=$(echo "${RESPONSE}" | tail -1) -H "Content-Type: application/json" \
BODY=$(echo "${RESPONSE}" | sed '$d') --data "${PR_DATA}" \
if [ "${HTTP_CODE}" -ge 400 ]; then "${API_URL}/pulls")
echo "Error creating PR (HTTP ${HTTP_CODE}): ${BODY}" HTTP_CODE=$(echo "${RESPONSE}" | tail -1)
exit 1 BODY=$(echo "${RESPONSE}" | sed '$d')
fi if [ "${HTTP_CODE}" -lt 400 ]; then
echo "PR created successfully" echo "PR created successfully"
break
fi
if [ "${i}" = "5" ]; then
echo "Error creating PR after 5 attempts (HTTP ${HTTP_CODE}): ${BODY}"
exit 1
fi
echo "PR creation attempt ${i}/5 failed (HTTP ${HTTP_CODE}), retrying..."
sleep 3
done
create-release: create-release:
name: Create Release name: Create Release