-
Notifications
You must be signed in to change notification settings - Fork 318
Add scheduled workflow to restart stale PR status checks #6224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: mazhelez <[email protected]>
Co-authored-by: mazhelez <[email protected]>
Co-authored-by: mazhelez <[email protected]>
Co-authored-by: mazhelez <[email protected]>
Co-authored-by: mazhelez <[email protected]>
Co-authored-by: mazhelez <[email protected]>
Co-authored-by: mazhelez <[email protected]>
Co-authored-by: mazhelez <[email protected]>
Co-authored-by: mazhelez <[email protected]>
Co-authored-by: mazhelez <[email protected]>
Co-authored-by: mazhelez <[email protected]>
|
@copilot I get the following error out of a sudden when I run the script.
It happens after some PRs a processed. Can you please investigate? |
Co-authored-by: mazhelez <[email protected]>
Fixed by adding null check for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces a scheduled GitHub Actions workflow and supporting composite action to automatically detect and restart stale “Pull Request Status Check” runs on mergeable PRs, with retry logic and summarized reporting. It leverages the existing EnlistmentHelperFunctions module for consistent retry behavior and integrates cleanly with the repository’s existing PR validation workflow.
Changes:
- Add a scheduled workflow (
RestartPRStatusCheck.yaml) that runs every three days (and via manual dispatch) to invoke a local composite action for restarting stale PR status checks. - Add a composite action definition (
RestartStalePRChecks/action.yaml) that wires inputs, environment, and execution of a PowerShell script. - Implement a PowerShell script (
RestartStalePRChecks/action.ps1) that lists open PRs, filters to MERGEABLE ones, inspects the “Pull Request Status Check” viagh pr checks, and conditionally reruns the workflow with robust retry logic, WhatIf support, and a GitHub Actions step summary.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
.github/workflows/RestartPRStatusCheck.yaml |
Defines the scheduled and manually-triggerable workflow that calls the new composite action to restart stale PR status checks. |
.github/actions/RestartStalePRChecks/action.yaml |
Declares the composite action interface (inputs, env) and runs the underlying PowerShell script with appropriate GitHub context. |
.github/actions/RestartStalePRChecks/action.ps1 |
Contains the core logic to query mergeable PRs, identify stale successful “Pull Request Status Check” runs, rerun them with Invoke-CommandWithRetry, and emit a textual and step summary, exiting non‑zero on failures. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Write-Host " ✓ Successfully restarted: $restarted workflow run(s)" | ||
| Write-Host " ✗ Failed attempts: $failed" | ||
|
|
||
| # Add GitHub Actions job summary | ||
| if ($env:GITHUB_STEP_SUMMARY) { | ||
| $summaryTitle = if ($WhatIf) { "## PR Status Check Restart Summary (WhatIf Mode)" } else { "## PR Status Check Restart Summary" } | ||
| Add-Content -Path $env:GITHUB_STEP_SUMMARY -Value $summaryTitle | ||
| Add-Content -Path $env:GITHUB_STEP_SUMMARY -Value "" | ||
| if ($WhatIf) { | ||
| Add-Content -Path $env:GITHUB_STEP_SUMMARY -Value "- ℹ️ Running in **WhatIf mode** - no workflows were actually rerun" | ||
| Add-Content -Path $env:GITHUB_STEP_SUMMARY -Value "" | ||
| } | ||
| Add-Content -Path $env:GITHUB_STEP_SUMMARY -Value "- ✓ Successfully restarted: **$restarted** workflow run(s)" | ||
| Add-Content -Path $env:GITHUB_STEP_SUMMARY -Value "- ✗ Failed attempts: **$failed**" |
Copilot
AI
Jan 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The $failed counter is tracking failed PRs (incremented once per PR failure), but the summary and job summary label it as "Failed attempts", which is misleading. Consider updating the text (both here and in the GITHUB_STEP_SUMMARY section) to clarify that this is the count of PRs that could not be processed, not retry attempts.
Plan: Create Scheduled PR Status Check Workflow
RestartPRStatusCheck.yamlgh pr checksinstead of fetching all workflow runsstateandbucketinstead ofstatusandconclusioncompletedAtcheckcontinuepattern for consistencygh run reruninstead of API call for simpler codeheadRefNameproperty from PR list query$successvariableInvoke-CommandWithRetryfrom EnlistmentHelperFunctions for consistent retry logicgh pr checkscall in retry mechanismSummary
Adds a scheduled workflow that runs every 72 hours to automatically restart stale PR status checks. The workflow only processes PRs in MERGEABLE state and uses the repository's standard
Invoke-CommandWithRetryfunction for robust error handling. Both fetching checks and triggering reruns use retry mechanisms with exponential backoff to handle transient failures. The workflow exits with an error if any PRs fail to be processed, ensuring issues are visible.Key Features
Invoke-CommandWithRetryfrom EnlistmentHelperFunctions.psm1 for consistent, well-tested retry behavior💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
AB#619349