Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,41 @@ jobs:
run: |
# Find the PR that was merged with this push using the commits/pulls API
COMMIT_SHA="${{ github.sha }}"
PR_DATA=$(gh api "repos/${{ github.repository }}/commits/$COMMIT_SHA/pulls" \
--jq '.[0] // empty' 2>/dev/null || echo "")

# Retry up to 3 times with increasing delay to handle indexing lag
# after squash-merge commits.
GH_ERR_FILE="$RUNNER_TEMP/gh_api_err_$$"
for attempt in 1 2 3; do
API_ERR=""
PR_DATA=$(gh api "repos/${{ github.repository }}/commits/$COMMIT_SHA/pulls" \
--jq '.[0] // empty' 2>"$GH_ERR_FILE") || API_ERR=$(cat "$GH_ERR_FILE")
if [ -n "$API_ERR" ]; then
echo "::warning::Attempt $attempt: commits/pulls API error: $API_ERR"
fi
if [ -n "$PR_DATA" ]; then
Comment thread
nilsandrey marked this conversation as resolved.
echo "Found PR via commits/pulls API (attempt $attempt)."
break
fi
echo "Attempt $attempt: commits/pulls API returned no results, retrying in $((attempt * 5))s..."
if [ "$attempt" -lt 3 ]; then
sleep $((attempt * 5))
fi
done

# Fallback: extract PR number from squash-merge commit message "(#N)"
if [ -z "$PR_DATA" ]; then
echo "Commits/pulls API returned no results. Trying commit-message fallback..."
PR_NUMBER=$(git log -1 --format=%s "$COMMIT_SHA" | grep -oE '\(#[0-9]+\)' | tail -1 | tr -d '(#)')
if [ -n "$PR_NUMBER" ]; then
echo "Found PR #$PR_NUMBER from commit message."
API_ERR=""
PR_DATA=$(gh api "repos/${{ github.repository }}/pulls/$PR_NUMBER" 2>"$GH_ERR_FILE") || API_ERR=$(cat "$GH_ERR_FILE")
if [ -n "$API_ERR" ]; then
echo "::error::Failed to fetch PR #$PR_NUMBER: $API_ERR"
exit 1
fi
fi
Comment thread
nilsandrey marked this conversation as resolved.
fi

if [ -z "$PR_DATA" ]; then
echo "No merged PR found for this commit. Skipping release."
Expand Down