Skip to content

🪲 [Fix]: Pipeline bulk deletion of workflow runs no longer silently drops items#573

Open
Marius Storhaug (MariusStorhaug) wants to merge 1 commit intomainfrom
fix/workflow-run-pipeline-deletion
Open

🪲 [Fix]: Pipeline bulk deletion of workflow runs no longer silently drops items#573
Marius Storhaug (MariusStorhaug) wants to merge 1 commit intomainfrom
fix/workflow-run-pipeline-deletion

Conversation

@MariusStorhaug
Copy link
Copy Markdown
Member

Piping workflow runs from Get-GitHubWorkflowRun through Where-Object into Remove-GitHubWorkflowRun now correctly processes all matching items. Previously, only a subset of runs were deleted and the rest were silently skipped.

Fixed: All pipeline items now processed during bulk deletion

Bulk deletion via pipeline now works end-to-end:

Get-GitHubWorkflowRun -Owner PSModule -Repository GitHub |
    Where-Object { $_.Status -ne 'in_progress' } |
    Remove-GitHubWorkflowRun

Previously, this pattern could silently skip most workflow runs. Now all matching runs are deleted, and any individual failures are reported as non-terminating errors without interrupting the remaining deletions.

Fixed: Deletion failures no longer kill the pipeline

If a single workflow run cannot be deleted (e.g., due to a conflict or permission issue), the error is now reported with the run ID and the pipeline continues processing remaining items. Previously, a terminating error from the GitHub API would stop the entire pipeline, leaving subsequent runs undeleted with no indication of what happened.

Technical Details

  • GitHubWorkflowRun constructor: All property assignments used $_ (the automatic pipeline variable from the calling ForEach-Object scope) instead of the $Object constructor parameter. This relied on undocumented PowerShell behavior where $_ leaks from ForEach-Object into class constructors. Replaced all $_ references with $Object for correctness and reliability across PowerShell versions.
  • Remove-GitHubWorkflowRun: Wrapped the Invoke-GitHubAPI call in try/catch to convert terminating API errors into non-terminating errors (Write-Error). The error message includes the run ID, owner, and repository for diagnostics. Moved Write-Verbose inside the try block so it only emits on successful deletion.
  • Created Audit Remove-* functions for pipeline-safe error handling #572 to audit all other Remove-*/Set-*/Add-* functions for the same pipeline-killing error handling pattern.

Copy link
Copy Markdown
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

Fixes bulk deletion of workflow runs via pipeline by ensuring workflow run objects are constructed reliably and deletion errors don’t terminate the pipeline.

Changes:

  • Updated Remove-GitHubWorkflowRun to wrap the delete API call in try/catch and emit a non-terminating error per failed run.
  • Fixed GitHubWorkflowRun constructor to use the $Object parameter consistently instead of relying on leaked $_.

Reviewed changes

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

File Description
src/functions/public/Workflows/Runs/Remove-GitHubWorkflowRun.ps1 Makes pipeline deletions resilient by catching API failures and continuing with remaining items.
src/classes/public/Workflows/GitHubWorkflowRun.ps1 Removes reliance on $_ leakage in the constructor by switching all assignments to $Object.*.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Remove-GitHubWorkflowRun does not delete all piped workflow runs

2 participants