Skip to content

Commit 60fa3e0

Browse files
committed
Refactor
1 parent 76f6c09 commit 60fa3e0

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

.github/workflows/pr-actions.yml

+27-18
Original file line numberDiff line numberDiff line change
@@ -149,42 +149,51 @@ jobs:
149149

150150
- name: Rerun PR checks
151151
run: |
152-
# Get the PR head SHA
152+
# Get the PR head SHA and branch name
153153
PR_HEAD_SHA=$(gh pr view $PR_NUM --json headRefOid -q .headRefOid)
154-
echo "PR head SHA: $PR_HEAD_SHA"
154+
PR_BRANCH=$(gh pr view $PR_NUM --json headRefName -q .headRefName)
155+
156+
echo "PR #$PR_NUM"
157+
echo "Head SHA: $PR_HEAD_SHA"
158+
echo "Branch: $PR_BRANCH"
155159
156160
# Find workflow runs for this PR that need to be re-run
157161
echo "Finding workflow runs for PR #$PR_NUM..."
158162
159-
# Get the names of all the workflows that ran on the PR
160-
WORKFLOW_RUNS=$(gh run list --limit 30 --json name,headSha,event,databaseId,conclusion,status --jq '.[] | select(.headSha=="'$PR_HEAD_SHA'" and .event=="pull_request") | "\(.databaseId)|\(.name)|\(.conclusion)|\(.status)"')
163+
# First try to get runs for the exact SHA
164+
echo "Looking for runs with exact SHA: $PR_HEAD_SHA"
165+
WORKFLOW_RUNS=$(gh run list --limit 30 --json name,headSha,event,databaseId,conclusion,status \
166+
--jq '.[] | select(.headSha=="'$PR_HEAD_SHA'" and .event=="pull_request") | "\(.databaseId)|\(.name)|\(.conclusion)|\(.status)"')
161167
168+
# If no runs found with exact SHA, try by branch name
162169
if [ -z "$WORKFLOW_RUNS" ]; then
163-
echo "No workflow runs found for PR head SHA: $PR_HEAD_SHA"
164-
165-
# Try to find the most recent workflow runs for this PR regardless of SHA
166-
PR_BRANCH=$(gh pr view $PR_NUM --json headRefName -q .headRefName)
167-
echo "Trying with PR branch: $PR_BRANCH"
168-
169-
WORKFLOW_RUNS=$(gh run list --branch $PR_BRANCH --limit 30 --json name,databaseId,conclusion,status --jq '.[] | "\(.databaseId)|\(.name)|\(.conclusion)|\(.status)"')
170+
echo "No workflow runs found for SHA $PR_HEAD_SHA, trying branch: $PR_BRANCH"
171+
WORKFLOW_RUNS=$(gh run list --branch $PR_BRANCH --limit 30 --json name,databaseId,conclusion,status \
172+
--jq '.[] | "\(.databaseId)|\(.name)|\(.conclusion)|\(.status)"')
170173
fi
171174
175+
# Check if we found any workflows
172176
if [ -z "$WORKFLOW_RUNS" ]; then
173177
echo "No workflow runs found for this PR"
174178
exit 1
175179
fi
176180
177-
# Rerun each workflow that's completed (whether it succeeded or failed)
181+
# Print the workflows we found
182+
echo "Found the following workflow runs:"
183+
echo "$WORKFLOW_RUNS" | while IFS="|" read -r RUN_ID NAME CONCLUSION STATUS; do
184+
echo "- $NAME (ID: $RUN_ID): Status=$STATUS, Conclusion=$CONCLUSION"
185+
done
186+
187+
# Rerun each completed workflow
188+
echo ""
189+
echo "Re-running workflows:"
178190
echo "$WORKFLOW_RUNS" | while IFS="|" read -r RUN_ID NAME CONCLUSION STATUS; do
179-
echo "Workflow $NAME (ID: $RUN_ID) - Status: $STATUS, Conclusion: $CONCLUSION"
180-
181-
# Only rerun completed workflows
182191
if [ "$STATUS" = "completed" ]; then
183192
echo "Re-running workflow: $NAME (ID: $RUN_ID)"
184-
gh run rerun $RUN_ID
185-
echo "Successfully triggered rerun of workflow $NAME (ID: $RUN_ID)"
193+
RERUN_RESULT=$(gh run rerun $RUN_ID)
194+
echo "Result: $RERUN_RESULT"
186195
elif [ "$STATUS" = "in_progress" ]; then
187-
echo "Workflow $NAME (ID: $RUN_ID) is already in progress, skipping"
196+
echo "Workflow $NAME (ID: $RUN_ID) is already running, skipping"
188197
else
189198
echo "Cannot rerun workflow $NAME (ID: $RUN_ID) with status: $STATUS"
190199
fi

0 commit comments

Comments
 (0)