Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 20, 2026

Plan: Create Scheduled PR Status Check Workflow

  • Explore existing workflows and understand patterns
  • Create new workflow file: RestartPRStatusCheck.yaml
  • Implement workflow to run every 72 hours (3 days)
  • Add logic to query and restart stale checks
  • Test and verify the workflow logic
  • Address PR review comments (round 1)
    • Change job name to "Restart Stale PR Status Checks"
    • Use gh pr checks instead of fetching all workflow runs
    • Add failed attempts tracking and retry logic
  • Address PR review comments (round 2)
    • Extract code to separate action file
    • Add GitHub Actions notice when no PRs found
    • Fix to use correct fields: state and bucket instead of status and conclusion
    • Remove unnecessary completedAt check
    • Use continue pattern for consistency
    • Add workflow run summary
  • Address PR review comments (round 3)
    • Use gh run rerun instead of API call for simpler code
    • Remove redundant bucket check (state already implies bucket)
    • Remove unused headRefName property from PR list query
  • Address PR review comments (round 4)
    • Remove unused $success variable
    • Exit with error code 1 if any PRs failed to be processed
    • Count failed PRs instead of failed retry attempts
  • Address PR review comments (round 5)
    • Remove default parameter values from workflow
    • Add mergeable state filtering to only process MERGEABLE PRs
    • Use Invoke-CommandWithRetry from EnlistmentHelperFunctions for consistent retry logic
    • Include gh pr checks call in retry mechanism
  • Address PR review comments (round 6)
    • Add WhatIf parameter to script
    • Keep WhatIf in script only, not exposed in action.yaml
    • Remove redundant checkout from action.yaml
    • Fix Int32 overflow for large run IDs
    • Add null check for GITHUB_STEP_SUMMARY
  • Final verification

Summary

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-CommandWithRetry function 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

  • Mergeable PR Filtering: Only processes PRs in MERGEABLE state to avoid wasted effort
  • Robust Retry Logic: Uses Invoke-CommandWithRetry from EnlistmentHelperFunctions.psm1 for consistent, well-tested retry behavior
  • Error Tracking: Counts failed PRs (not retry attempts) and exits with error code 1 when failures occur
  • Workflow Summary: Provides GitHub Actions job summary with success/failure counts (when running in GitHub Actions)
  • WhatIf Mode: Available in script for future testing (not currently exposed through action interface)
  • Efficient: No redundant checkout - uses workspace from calling workflow
  • Large Run ID Support: Uses Int64 to handle run IDs larger than 2 billion
  • Portable: Can run both in GitHub Actions and locally for testing

💡 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

Copilot AI changed the title [WIP] Add workflow to restart PR checks every 72 hours Add scheduled workflow to restart stale PR status checks Jan 20, 2026
Copilot AI requested a review from mazhelez January 20, 2026 13:58
Copilot AI requested a review from mazhelez January 20, 2026 14:28
@github-actions github-actions bot added the Build: Automation Workflows and other setup in .github folder label Jan 22, 2026
Copilot AI requested a review from mazhelez January 22, 2026 09:54
Copilot AI requested a review from mazhelez January 22, 2026 10:59
Copilot AI requested a review from mazhelez January 23, 2026 10:06
Copilot AI requested a review from mazhelez January 23, 2026 10:13
Copilot AI requested a review from mazhelez January 23, 2026 10:23
Copilot AI requested a review from mazhelez January 23, 2026 10:48
@mazhelez
Copy link
Contributor

@copilot I get the following error out of a sudden when I run the script.

action.ps1: Cannot bind argument to parameter 'Path' because it is null.

It happens after some PRs a processed. Can you please investigate?

Copy link
Contributor Author

Copilot AI commented Jan 23, 2026

@copilot I get the following error out of a sudden when I run the script.

action.ps1: Cannot bind argument to parameter 'Path' because it is null.
...

Fixed by adding null check for $env:GITHUB_STEP_SUMMARY before calling Add-Content. The error occurred because GITHUB_STEP_SUMMARY can be null when running outside GitHub Actions context or in certain execution scenarios. All summary writes are now wrapped in if ($env:GITHUB_STEP_SUMMARY) { ... }. Commit f274fa6.

Copy link
Contributor

Copilot AI left a 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” via gh 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.

Comment on lines +131 to +144
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**"
Copy link

Copilot AI Jan 23, 2026

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.

Copilot uses AI. Check for mistakes.
@github-actions github-actions bot added this to the Version 28.0 milestone Jan 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Build: Automation Workflows and other setup in .github folder

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants