Skip to content

Commit cc7d552

Browse files
committed
Actions prettyfier
1 parent 60fa3e0 commit cc7d552

File tree

1 file changed

+61
-23
lines changed

1 file changed

+61
-23
lines changed

.github/workflows/pr-actions.yml

+61-23
Original file line numberDiff line numberDiff line change
@@ -152,40 +152,76 @@ jobs:
152152
# Get the PR head SHA and branch name
153153
PR_HEAD_SHA=$(gh pr view $PR_NUM --json headRefOid -q .headRefOid)
154154
PR_BRANCH=$(gh pr view $PR_NUM --json headRefName -q .headRefName)
155-
155+
PR_REPO=$(gh pr view $PR_NUM --json headRepositoryName -q .headRepositoryName)
156+
PR_OWNER=$(gh pr view $PR_NUM --json headRepositoryOwner -q .headRepositoryOwner.login)
157+
156158
echo "PR #$PR_NUM"
157159
echo "Head SHA: $PR_HEAD_SHA"
158160
echo "Branch: $PR_BRANCH"
159-
160-
# Find workflow runs for this PR that need to be re-run
161-
echo "Finding workflow runs for PR #$PR_NUM..."
162-
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)"')
167-
168-
# If no runs found with exact SHA, try by branch name
169-
if [ -z "$WORKFLOW_RUNS" ]; then
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)"')
161+
echo "Repo: $PR_OWNER/$PR_REPO"
162+
163+
# Method 1: Try to trigger workflows by making an empty commit on the PR branch
164+
# This will only work if we have write access to the PR's branch
165+
if gh pr checkout $PR_NUM; then
166+
echo "Checked out PR #$PR_NUM branch: $PR_BRANCH"
167+
168+
# Try to push an empty commit to trigger the checks
169+
git config --local user.email "$USER_EMAIL"
170+
git config --local user.name "$USER_NAME"
171+
172+
if git commit --allow-empty -m "Trigger PR checks via /nudge command"; then
173+
echo "Created empty commit to trigger checks"
174+
git push
175+
echo "Pushed commit, checks should now be triggered on the PR"
176+
exit 0
177+
else
178+
echo "Failed to create empty commit, trying alternative method"
179+
fi
180+
else
181+
echo "Could not checkout PR branch, likely due to permissions. Trying alternative method."
173182
fi
174-
175-
# Check if we found any workflows
183+
184+
# Method 2: Find workflow files and try to manually dispatch them if possible
185+
echo "Finding workflow runs for PR #$PR_NUM..."
186+
187+
# Try to trigger workflow_dispatch events for workflows that support it
188+
echo "Attempting to trigger workflow_dispatch events..."
189+
190+
# List all workflows in the repo
191+
WORKFLOWS=$(gh workflow list --all --json id,name,state --jq '.[] | "\(.id)|\(.name)|\(.state)"')
192+
193+
echo "Available workflows:"
194+
echo "$WORKFLOWS" | while IFS="|" read -r WF_ID WF_NAME WF_STATE; do
195+
echo "- $WF_NAME (ID: $WF_ID): State=$WF_STATE"
196+
197+
if [ "$WF_STATE" = "active" ]; then
198+
# Try to dispatch this workflow with the PR branch as ref
199+
echo "Attempting to dispatch workflow: $WF_NAME (ID: $WF_ID) for branch: $PR_BRANCH"
200+
if gh workflow run $WF_ID --ref $PR_BRANCH; then
201+
echo "Successfully dispatched workflow: $WF_NAME"
202+
else
203+
echo "Could not dispatch workflow: $WF_NAME - It may not support workflow_dispatch event"
204+
fi
205+
fi
206+
done
207+
208+
# Method 3: As a fallback, just rerun existing workflow runs as we did before
209+
echo "Falling back to rerunning existing workflow runs..."
210+
211+
WORKFLOW_RUNS=$(gh run list --limit 30 --branch $PR_BRANCH --json name,databaseId,conclusion,status \
212+
--jq '.[] | "\(.databaseId)|\(.name)|\(.conclusion)|\(.status)"')
213+
176214
if [ -z "$WORKFLOW_RUNS" ]; then
177-
echo "No workflow runs found for this PR"
215+
echo "No workflow runs found for this PR branch: $PR_BRANCH"
216+
echo "Unable to rerun checks for PR #$PR_NUM"
178217
exit 1
179218
fi
180-
181-
# Print the workflows we found
219+
182220
echo "Found the following workflow runs:"
183221
echo "$WORKFLOW_RUNS" | while IFS="|" read -r RUN_ID NAME CONCLUSION STATUS; do
184222
echo "- $NAME (ID: $RUN_ID): Status=$STATUS, Conclusion=$CONCLUSION"
185223
done
186-
187-
# Rerun each completed workflow
188-
echo ""
224+
189225
echo "Re-running workflows:"
190226
echo "$WORKFLOW_RUNS" | while IFS="|" read -r RUN_ID NAME CONCLUSION STATUS; do
191227
if [ "$STATUS" = "completed" ]; then
@@ -201,6 +237,8 @@ jobs:
201237
env:
202238
GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}
203239
PR_NUM: ${{ github.event.issue.number }}
240+
USER_EMAIL: 107717825+opentelemetrybot@users.noreply.github.com
241+
USER_NAME: opentelemetrybot
204242

205243
- name: Report success
206244
if: ${{ !failure() && !cancelled() }}

0 commit comments

Comments
 (0)