Describe the issue
The CleanUpStalePRChecks composite action (.github/actions/CleanUpStalePRChecks/action.ps1) fails whenever a repository has exactly one open pull request.
The script runs:
$prs = gh pr list --state open --json number,title,url,mergeable --limit 1000 | ConvertFrom-Json
...
Write-Host "Found $($prs.Count) open pull requests"
When gh pr list returns a single result, ConvertFrom-Json returns a single PSCustomObject instead of an array. A PSCustomObject has no Count property. Because the script runs under Set-StrictMode -Version 2.0, accessing $prs.Count in this case throws a terminating error instead of silently returning $null or 1:
action.ps1: /home/runner/work/_temp/<guid>.ps1:2
Line |
2 | /home/runner/work/BCApps/BCApps/./.github/actions/CleanUpStalePRChecks …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| The property 'Count' cannot be found on this object. Verify that the
| property exists.
Error: Process completed with exit code 1.
This causes the scheduled workflow run to fail every day for as long as the repository has exactly one open PR, and generates a daily failure notification email to the repository owner.
Expected behavior
The action should correctly handle the case where gh pr list returns a single pull request (as well as zero or multiple), count it as 1 open PR, and continue processing normally without throwing a StrictMode error.
Steps to reproduce
- In a repository where this action is installed, ensure there is exactly one open pull request.
- Trigger the
Clean Up Stale PR Status Checks workflow (scheduled run, or manually via workflow_dispatch).
- Observe that the job fails in the "Clean Up Stale PR Checks" step with the error
The property 'Count' cannot be found on this object.
Additional context
Root cause: ConvertFrom-Json in PowerShell does not return an array when the JSON input contains a single object, so .Count is undefined on the resulting PSCustomObject. Under Set-StrictMode -Version 2.0, this is a hard error rather than a silent $null.
Suggested fix — wrap the result in @(...) to force it into an array regardless of element count:
$prs = @(gh pr list --state open --json number,title,url,mergeable --limit 1000 | ConvertFrom-Json)
Observed on: fork pamura1977/BCApps, workflow file .github/workflows/CleanUpStalePRChecks.yaml, action .github/actions/CleanUpStalePRChecks/action.ps1 (owned per CODEOWNERS by @microsoft/d365-bc-engineering-systems).
Example failed run: pamura1977/BCApps Actions run #7 (job "Clean Up Stale PR Status Checks"), failed in 29s with 1 annotation.
Log: https://github.com/pamura1977/BCApps/actions/runs/30600290979/job/91061250206#logs
Describe the issue
The
CleanUpStalePRCheckscomposite action (.github/actions/CleanUpStalePRChecks/action.ps1) fails whenever a repository has exactly one open pull request.The script runs:
When
gh pr listreturns a single result,ConvertFrom-Jsonreturns a singlePSCustomObjectinstead of an array. APSCustomObjecthas noCountproperty. Because the script runs underSet-StrictMode -Version 2.0, accessing$prs.Countin this case throws a terminating error instead of silently returning$nullor1:This causes the scheduled workflow run to fail every day for as long as the repository has exactly one open PR, and generates a daily failure notification email to the repository owner.
Expected behavior
The action should correctly handle the case where
gh pr listreturns a single pull request (as well as zero or multiple), count it as 1 open PR, and continue processing normally without throwing aStrictModeerror.Steps to reproduce
Clean Up Stale PR Status Checksworkflow (scheduled run, or manually viaworkflow_dispatch).The property 'Count' cannot be found on this object.Additional context
Root cause:
ConvertFrom-Jsonin PowerShell does not return an array when the JSON input contains a single object, so.Countis undefined on the resultingPSCustomObject. UnderSet-StrictMode -Version 2.0, this is a hard error rather than a silent$null.Suggested fix — wrap the result in
@(...)to force it into an array regardless of element count:Observed on: fork
pamura1977/BCApps, workflow file.github/workflows/CleanUpStalePRChecks.yaml, action.github/actions/CleanUpStalePRChecks/action.ps1(owned per CODEOWNERS by@microsoft/d365-bc-engineering-systems).Example failed run:
pamura1977/BCAppsActions run #7 (job "Clean Up Stale PR Status Checks"), failed in 29s with 1 annotation.Log: https://github.com/pamura1977/BCApps/actions/runs/30600290979/job/91061250206#logs