Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 20, 2026

Adds automation to keep PR status checks fresh by deleting stale checks and prompting PR authors to trigger new ones. This ensures status checks run on the current codebase state rather than outdated merge commits.

Implementation

  • Schedule: Cron 0 0 */3 * * (every 3 days at midnight UTC)
  • Trigger: Also supports manual workflow_dispatch
  • Files:
    • Workflow: .github/workflows/CleanUpStalePRChecks.yaml
    • Composite Action: .github/actions/CleanUpStalePRChecks/

Logic

  1. Query open PRs via gh pr list and filter to MERGEABLE state only
  2. For each mergeable PR:
    • Get checks via gh pr checks (using state field)
    • Find the "Pull Request Status Check"
    • If successful (state: SUCCESS) and completedAt > 72h:
      • Delete the stale workflow run via gh run delete
      • Add a comment to the PR with instructions to trigger a new check
  3. Display summary as workflow run summary and in logs

Why Delete Instead of Rerun?

Rerunning a workflow run would still use the old merge commit, not reflecting the current codebase state. Deleting the run puts the PR in a "waiting for status checks" state, and the next commit or close/reopen will trigger a fresh check on the current merge commit.

Key Details

  • Cross-platform compatible: Uses forward slashes in module import path
  • Date parsing uses InvariantCulture for locale safety
  • Retry logic: Uses Invoke-CommandWithRetry from EnlistmentHelperFunctions.psm1 with exponential backoff
  • Run ID validation using Int64 to handle IDs larger than 2 billion
  • Error handling: exits with error code 1 if any PRs fail to be processed
  • GitHub Actions notice when no open PRs found
  • Workflow run summary using GITHUB_STEP_SUMMARY for better visibility
  • Summary includes both successful deletions and failed PRs
  • WhatIf mode available in script for testing with accurate messaging
  • Automated PR comments provide clear instructions

Permissions Required

permissions:
  actions: write        # To delete workflow runs
  checks: read          # To read PR check status
  contents: read        # To access repository files
  pull-requests: write  # To add comments to PRs

💡 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.

Copilot AI and others added 3 commits January 20, 2026 13:51
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 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 and others added 2 commits January 20, 2026 14:25
Co-authored-by: mazhelez <43066499+mazhelez@users.noreply.github.com>
Co-authored-by: mazhelez <43066499+mazhelez@users.noreply.github.com>
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
Co-authored-by: mazhelez <43066499+mazhelez@users.noreply.github.com>
Copilot AI requested a review from mazhelez January 22, 2026 09:54
Co-authored-by: mazhelez <43066499+mazhelez@users.noreply.github.com>
Copilot AI requested a review from mazhelez January 22, 2026 10:59
Co-authored-by: mazhelez <43066499+mazhelez@users.noreply.github.com>
Copilot AI requested a review from mazhelez January 26, 2026 12:02
Co-authored-by: mazhelez <43066499+mazhelez@users.noreply.github.com>
Copilot AI changed the title Add scheduled workflow to restart stale PR status checks Add scheduled workflow to clean up stale PR status checks Jan 29, 2026
Co-authored-by: mazhelez <43066499+mazhelez@users.noreply.github.com>
@mazhelez mazhelez requested a review from aholstrup1 January 29, 2026 08:59
Updated the comment body for stale PR status checks to provide clearer instructions and reasoning for deletion.
@mazhelez mazhelez requested a review from Copilot January 29, 2026 14:47
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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: mazhelez <43066499+mazhelez@users.noreply.github.com>
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

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link

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'

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.

3 participants