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
34 changes: 31 additions & 3 deletions .github/workflows/nodejs-publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,38 @@ jobs:
id: label
env:
GH_TOKEN: ${{ github.token }}
REPOSITORY: ${{ github.repository }}
COMMIT_SHA: ${{ github.sha }}
run: |
RESULT=$(gh api repos/${{ github.repository }}/commits/${{ github.sha }}/pulls \
--jq 'any(.[].labels[].name; . == "hra-release")' 2>/dev/null || echo "false")
echo "result=$RESULT" >> "$GITHUB_OUTPUT"
set -euo pipefail

# The commits/{sha}/pulls endpoint is eventually consistent: right
# after a merge it can return an empty array for tens of seconds
# before the commit gets associated with its PR. We retry ONLY while
# the array is empty (the actual race). Once a PR is associated we
# trust its labels and stop, so non-release merges never wait.
attempts=5
delay=30
result="false"

for i in $(seq 1 "$attempts"); do
pulls=$(gh api "repos/${REPOSITORY}/commits/${COMMIT_SHA}/pulls" 2>/dev/null || echo "[]")
count=$(echo "$pulls" | jq 'length')

if [ "$count" -gt 0 ]; then
result=$(echo "$pulls" | jq -r 'any(.[].labels[].name; . == "hra-release")')
echo "Found $count associated PR(s) on attempt $i/$attempts; is-release=$result"
break
fi

echo "No PR associated with ${COMMIT_SHA} yet (attempt $i/$attempts)"
if [ "$i" -lt "$attempts" ]; then
echo "Retrying in ${delay}s to let the GitHub API catch up..."
sleep "$delay"
fi
done

echo "result=$result" >> "$GITHUB_OUTPUT"

publish:
needs: check
Expand Down