@@ -473,9 +473,62 @@ function Get-WorkflowReference {
473473 [string ] $DefaultBranch
474474 )
475475
476- foreach ($workflowPath in @ (' .github/workflows/workflow.yml' , ' .github/workflows/workflow.yaml' )) {
476+ $encodedRef = [uri ]::EscapeDataString($DefaultBranch )
477+ $workflowFolderPath = ' .github/workflows'
478+ $workflowFolderUri = " https://api.github.com/repos/$Owner /$Name /contents/$workflowFolderPath ?ref=$encodedRef "
479+ Write-Host " Discovering workflow files under [$workflowFolderPath ] for [$Owner /$Name ] on [$DefaultBranch ]"
480+ $workflowEntries = Invoke-GitHubApi - Uri $workflowFolderUri
481+ if ($null -eq $workflowEntries ) {
482+ Write-Host " Workflow folder not found: [$workflowFolderPath ]"
483+ return ' N/A'
484+ }
485+
486+ $workflowFiles = @ (
487+ $workflowEntries |
488+ Where-Object {
489+ (Get-PropertyValue - InputObject $_ - Names @ (' type' ) - Default ' ' ) -eq ' file' -and
490+ [string ](Get-PropertyValue - InputObject $_ - Names @ (' name' ) - Default ' ' ) -match ' \.ya?ml$'
491+ } |
492+ Sort-Object { [string ](Get-PropertyValue - InputObject $_ - Names @ (' name' ) - Default ' ' ) }
493+ )
494+
495+ if ($workflowFiles.Count -eq 0 ) {
496+ Write-Host ' No workflow .yml/.yaml files found'
497+ return ' N/A'
498+ }
499+
500+ if ($workflowFiles.Count -eq 1 ) {
501+ Write-Host " Single workflow file found: [$ ( [string ](Get-PropertyValue - InputObject $workflowFiles [0 ] - Names @ (' name' ) - Default ' unknown' )) ]"
502+ } else {
503+ Write-Host " Multiple workflow files found: $ ( $workflowFiles.Count ) "
504+ $workflowFiles | ForEach-Object {
505+ $workflowName = [string ](Get-PropertyValue - InputObject $_ - Names @ (' name' ) - Default ' unknown' )
506+ Write-Host " - $workflowName "
507+ }
508+ }
509+
510+ $candidateWorkflowFiles = $workflowFiles
511+ if ($workflowFiles.Count -gt 1 ) {
512+ $preferredFiles = @ (
513+ $workflowFiles | Where-Object {
514+ [string ](Get-PropertyValue - InputObject $_ - Names @ (' name' ) - Default ' ' ) -match ' (?i)^process-psmodule\.ya?ml$'
515+ }
516+ )
517+ if ($preferredFiles.Count -eq 1 ) {
518+ $preferredFileName = [string ](Get-PropertyValue - InputObject $preferredFiles [0 ] - Names @ (' name' ) - Default ' unknown' )
519+ Write-Host " Multiple workflows detected; preferring canonical workflow file [$preferredFileName ]"
520+ $candidateWorkflowFiles = $preferredFiles
521+ }
522+ }
523+
524+ $resolvedRefs = @ ()
525+ foreach ($workflowFile in $candidateWorkflowFiles ) {
526+ $workflowPath = [string ](Get-PropertyValue - InputObject $workflowFile - Names @ (' path' ) - Default ' ' )
527+ if ([string ]::IsNullOrWhiteSpace($workflowPath )) {
528+ continue
529+ }
530+
477531 Write-Host " Checking workflow path [$workflowPath ] for [$Owner /$Name ] on [$DefaultBranch ]"
478- $encodedRef = [uri ]::EscapeDataString($DefaultBranch )
479532 $uri = " https://api.github.com/repos/$Owner /$Name /contents/${workflowPath} ?ref=$encodedRef "
480533 $response = Invoke-GitHubApi - Uri $uri
481534 if ($null -eq $response ) {
@@ -503,10 +556,21 @@ function Get-WorkflowReference {
503556
504557 $match = [regex ]::Match($decoded , $processReferencePattern )
505558 if ($match.Success ) {
506- Write-Host " Resolved Process-PSModule ref [$ ( $match.Groups [' ref' ].Value) ] from [$workflowPath ]"
507- return $match.Groups [' ref' ].Value
559+ $resolvedRef = $match.Groups [' ref' ].Value
560+ Write-Host " Resolved Process-PSModule ref [$resolvedRef ] from [$workflowPath ]"
561+ $resolvedRefs += $resolvedRef
562+ } else {
563+ Write-Host " Unable to parse Process-PSModule ref in [$workflowPath ]"
508564 }
509- Write-Host " Unable to parse Process-PSModule ref in [$workflowPath ]"
565+ }
566+
567+ $uniqueResolvedRefs = @ ($resolvedRefs | Select-Object - Unique)
568+ if ($uniqueResolvedRefs.Count -eq 1 ) {
569+ return [string ]$uniqueResolvedRefs [0 ]
570+ }
571+ if ($uniqueResolvedRefs.Count -gt 1 ) {
572+ Write-Host " Multiple Process-PSModule refs resolved for [$Owner /$Name ]: $ ( $uniqueResolvedRefs -join ' , ' ) "
573+ return ' N/A'
510574 }
511575
512576 Write-Host " No Process-PSModule workflow reference found for [$Owner /$Name ]"
0 commit comments