-
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 <43066499+mazhelez@users.noreply.github.com>
Co-authored-by: mazhelez <43066499+mazhelez@users.noreply.github.com>
Co-authored-by: mazhelez <43066499+mazhelez@users.noreply.github.com>
Co-authored-by: mazhelez <43066499+mazhelez@users.noreply.github.com>
Co-authored-by: mazhelez <43066499+mazhelez@users.noreply.github.com>
Co-authored-by: mazhelez <43066499+mazhelez@users.noreply.github.com>
Co-authored-by: mazhelez <43066499+mazhelez@users.noreply.github.com>
Co-authored-by: mazhelez <43066499+mazhelez@users.noreply.github.com>
Co-authored-by: mazhelez <43066499+mazhelez@users.noreply.github.com>
|
@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 <43066499+mazhelez@users.noreply.github.com>
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.
Co-authored-by: mazhelez <43066499+mazhelez@users.noreply.github.com>
|
Could not find a linked ADO work item. Please link one by using the pattern 'AB#' followed by the relevant work item number. You may use the 'Fixes' keyword to automatically resolve the work item when the pull request is merged. E.g. 'Fixes AB#1234' |
| } | ||
| else { | ||
| Invoke-CommandWithRetry -ScriptBlock { | ||
| gh run rerun $runId -R $env:GITHUB_REPOSITORY | Out-Null |
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.
A rerun doesn't force an update of the merge commit AFAIK 🤔 So, the rerun would still be running on the old commit. It's also an expensive solution to keep rerunning builds on PRs that are kind of stale.
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.
If rerun wouldn't work, how about:
- updating the PR branch (gh pr update-branch). Major con: disruptive.
- deleting the workflow run altogether (gh run delete). Major con: PR is in a limbo state. A push to the PR branch or close/reopen is needed to trigger the PR build again.
I am leaning towards the second option + a comment with instructions on how to proceed to unblock the PR. What do you think?
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✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.