Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
param(
[Parameter(Mandatory = $false, HelpMessage = "The GitHub event name that triggered the workflow.")]
[string] $workflowEventName = $env:GITHUB_EVENT_NAME,
[Parameter(Mandatory = $false, HelpMessage = "Comma-separated value of branch name patterns to include if they exist. If not specified, only the current branch is returned. Wildcards are supported.")]
[string] $includeBranches
)

$gitHubHelperPath = Join-Path $PSScriptRoot '../Github-Helper.psm1' -Resolve
Import-Module $gitHubHelperPath -DisableNameChecking

switch ($env:GITHUB_EVENT_NAME) {
switch ($workflowEventName) {
'schedule' {
Write-Host "Event is schedule: getting branches from settings"
$settings = ConvertFrom-Json $env:Settings
Expand All @@ -20,8 +22,8 @@ switch ($env:GITHUB_EVENT_NAME) {
$branchPatterns = @()
}
}
'workflow_dispatch' {
Write-Host "Event is workflow_dispatch: getting branches from input"
{ $_ -in 'workflow_dispatch', 'workflow_call' } {
Write-Host "Event is $($_): getting branches from input"
$branchPatterns = @($includeBranches.Split(',') | ForEach-Object { $_.Trim() })
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the workflow_dispatch/workflow_call branch, $includeBranches.Split(',') will throw when -includeBranches isn’t provided (null) and will produce a single empty pattern when the action passes the default empty string. In both cases the later if (-not $branchPatterns) { ... } fallback won’t reliably select the current branch, so the action can fail or return an empty branch list even though the docs/tests expect it to default to GITHUB_REF_NAME. Treat null/whitespace includeBranches as “no patterns” (and/or filter out empty patterns after split) before populating $branchPatterns.

Suggested change
$branchPatterns = @($includeBranches.Split(',') | ForEach-Object { $_.Trim() })
if (-not [string]::IsNullOrWhiteSpace($includeBranches)) {
$branchPatterns = @(
$includeBranches.Split(',') |
ForEach-Object { $_.Trim() } |
Where-Object { -not [string]::IsNullOrWhiteSpace($_) }
)
}
else {
$branchPatterns = @()
}

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not part of this change.

It’s been working so far because the action always invokes this script with at least an empty string.
The check if (-not $branchPatterns) { ... } therefore behaves as expected and returns $true when the array only contains a single empty-string element.

@mazhelez @aholstrup1 Do you want me to add the suggested null-check in this PR, just to be safe?

}
}
Expand Down
1 change: 1 addition & 0 deletions Actions/GetWorkflowMultiRunBranches/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ If the workflow is run on a schedule, the branches are determined based on the `
| Name | Required | Description | Default value |
| :-- | :-: | :-- | :-- |
| shell | false | The shell (powershell or pwsh) in which the PowerShell script in this action should run | powershell |
| workflowEventName | false | The GitHub event name that triggered the workflow. *(override for reusable workflows)* | github.event_name |
| includeBranches | false | Comma-separated value of branch name patterns to include if they exist. If not specified, only the current branch is returned. Wildcards are supported. |''|

## OUTPUT
Expand Down
7 changes: 6 additions & 1 deletion Actions/GetWorkflowMultiRunBranches/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ inputs:
description: Shell in which you want to run the action (powershell or pwsh)
required: false
default: powershell
workflowEventName:
description: The GitHub event name that triggered the workflow.
required: false
default: ${{ github.event_name }}
includeBranches:
description: Comma-separated value of branch name patterns to include if they exist. If not specified, only the current branch is returned. Wildcards are supported.
required: false
Expand All @@ -20,10 +24,11 @@ runs:
shell: ${{ inputs.shell }}
id: GetWorkflowMultiRunBranches
env:
_workflowEventName: ${{ inputs.workflowEventName }}
_includeBranches: ${{ inputs.includeBranches }}
run: |
${{ github.action_path }}/../Invoke-AlGoAction.ps1 -ActionName "GetWorkflowMultiRunBranches" -Action {
${{ github.action_path }}/GetWorkflowMultiRunBranches.ps1 -includeBranches $env:_includeBranches
${{ github.action_path }}/GetWorkflowMultiRunBranches.ps1 -workflowEventName $env:_workflowEventName -includeBranches $env:_includeBranches
}
branding:
icon: terminal
Expand Down
1 change: 1 addition & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The `DownloadProjectDependencies` action now downloads app files from URLs speci

- Attempt to start docker service in case it is not running
- NextMajor (v28) fails when downloading dependencies from NuGet-feed
- Rework input handling of workflow 'Update AL-Go System Files' for trigger 'workflow_call'

## v8.3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ on:
default: ''
workflow_call:
inputs:
__caller:
description: Name of the calling workflow (use github.workflow as value when calling)
type: string
required: true
templateUrl:
description: Template Repository URL (current is {TEMPLATEURL})
type: string
Expand Down Expand Up @@ -50,6 +54,7 @@ defaults:
shell: powershell

env:
WorkflowEventName: ${{ inputs.__caller && 'workflow_call' || github.event_name }}
ALGoOrgSettings: ${{ vars.ALGoOrgSettings }}
ALGoRepoSettings: ${{ vars.ALGoRepoSettings }}

Expand All @@ -76,12 +81,13 @@ jobs:
uses: microsoft/AL-Go-Actions/GetWorkflowMultiRunBranches@main
with:
shell: powershell
includeBranches: ${{ github.event.inputs.includeBranches }}
workflowEventName: ${{ env.WorkflowEventName }}
includeBranches: ${{ inputs.includeBranches }}

- name: Determine Template URL
id: DetermineTemplateUrl
env:
TemplateUrlAsInput: '${{ github.event.inputs.templateUrl }}'
TemplateUrlAsInput: '${{ inputs.templateUrl }}'
run: |
$templateUrl = $env:templateUrl # Available from ReadSettings step
if ($ENV:TemplateUrlAsInput) {
Expand Down Expand Up @@ -133,12 +139,12 @@ jobs:

- name: Calculate Commit Options
env:
directCommit: '${{ github.event.inputs.directCommit }}'
downloadLatest: '${{ github.event.inputs.downloadLatest }}'
directCommit: '${{ inputs.directCommit }}'
downloadLatest: '${{ inputs.downloadLatest }}'
run: |
$errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0
if('${{ github.event_name }}' -in 'workflow_dispatch', 'workflow_call') {
Write-Host "Using inputs from ${{ github.event_name }} event"
if('${{ env.WorkflowEventName }}' -in 'workflow_dispatch', 'workflow_call') {
Write-Host "Using inputs from ${{ env.WorkflowEventName }} event"
$directCommit = $env:directCommit
$downloadLatest = $env:downloadLatest
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ on:
default: ''
workflow_call:
inputs:
__caller:
description: Name of the calling workflow (use github.workflow as value when calling)
type: string
required: true
templateUrl:
description: Template Repository URL (current is {TEMPLATEURL})
type: string
Expand Down Expand Up @@ -50,6 +54,7 @@ defaults:
shell: powershell

env:
WorkflowEventName: ${{ inputs.__caller && 'workflow_call' || github.event_name }}
ALGoOrgSettings: ${{ vars.ALGoOrgSettings }}
ALGoRepoSettings: ${{ vars.ALGoRepoSettings }}

Expand All @@ -76,12 +81,13 @@ jobs:
uses: microsoft/AL-Go-Actions/GetWorkflowMultiRunBranches@main
with:
shell: powershell
includeBranches: ${{ github.event.inputs.includeBranches }}
workflowEventName: ${{ env.WorkflowEventName }}
includeBranches: ${{ inputs.includeBranches }}

- name: Determine Template URL
id: DetermineTemplateUrl
env:
TemplateUrlAsInput: '${{ github.event.inputs.templateUrl }}'
TemplateUrlAsInput: '${{ inputs.templateUrl }}'
run: |
$templateUrl = $env:templateUrl # Available from ReadSettings step
if ($ENV:TemplateUrlAsInput) {
Expand Down Expand Up @@ -133,12 +139,12 @@ jobs:

- name: Calculate Commit Options
env:
directCommit: '${{ github.event.inputs.directCommit }}'
downloadLatest: '${{ github.event.inputs.downloadLatest }}'
directCommit: '${{ inputs.directCommit }}'
downloadLatest: '${{ inputs.downloadLatest }}'
run: |
$errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0
if('${{ github.event_name }}' -in 'workflow_dispatch', 'workflow_call') {
Write-Host "Using inputs from ${{ github.event_name }} event"
if('${{ env.WorkflowEventName }}' -in 'workflow_dispatch', 'workflow_call') {
Write-Host "Using inputs from ${{ env.WorkflowEventName }} event"
$directCommit = $env:directCommit
$downloadLatest = $env:downloadLatest
}
Expand Down
70 changes: 70 additions & 0 deletions Tests/GetWorkflowMultiRunBranches.Test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,74 @@ Describe "GetWorkflowMultiRunBranches Action" {
$outputValue | Should -Be "{`"branches`":[`"test-branch`",`"some-other-branch`"]}"
}
}

Context 'workflow_call event' {
It 'Action sets the current branch as result when no branch patterns are specified' {
$env:GITHUB_REF_NAME = "main"

# Call the action script with workflowEventName parameter
. (Join-Path $scriptRoot "$actionName.ps1") -workflowEventName "workflow_call"

$outputName, $outputValue = (Get-Content $env:GITHUB_OUTPUT) -split '='
$outputName | Should -Be "Result"
$outputValue | Should -Be "{`"branches`":[`"main`"]}"
}

It 'Action sets the input branch as result when a branch pattern is specified' {
$env:GITHUB_REF_NAME = "main"

Mock -CommandName invoke-git -ParameterFilter { $command -eq 'for-each-ref'} -MockWith { return @("origin/test-branch", "origin/main", "origin/some-other-branch", "origin") }

# Call the action script with workflowEventName and includeBranches parameters
. (Join-Path $scriptRoot "$actionName.ps1") -workflowEventName "workflow_call" -includeBranches "test-branch"

$outputName, $outputValue = (Get-Content $env:GITHUB_OUTPUT) -split '='
$outputName | Should -Be "Result"
$outputValue | Should -Be "{`"branches`":[`"test-branch`"]}"
}

It 'Action sets the input branch as result when a branch pattern with wild card is specified' {
$env:GITHUB_REF_NAME = "main"

Mock -CommandName invoke-git -ParameterFilter { $command -eq 'for-each-ref'} -MockWith { return @("origin/test-branch", "origin/main", "origin/some-other-branch", "origin") }

# Call the action script with workflowEventName and wildcard pattern
. (Join-Path $scriptRoot "$actionName.ps1") -workflowEventName "workflow_call" -includeBranches "*branch*"

$outputName, $outputValue = (Get-Content $env:GITHUB_OUTPUT) -split '='
$outputName | Should -Be "Result"
$outputValue | Should -Be "{`"branches`":[`"test-branch`",`"some-other-branch`"]}"
}

It 'Action filters out HEAD symbolic reference when using wildcard' {
$env:GITHUB_REF_NAME = "main"

Mock -CommandName invoke-git -ParameterFilter { $command -eq 'for-each-ref'} -MockWith { return @("origin/HEAD", "origin/main", "origin/develop", "origin/feature-1") }

# Call the action script with wildcard to get all branches
. (Join-Path $scriptRoot "$actionName.ps1") -workflowEventName "workflow_call" -includeBranches "*"

$outputName, $outputValue = (Get-Content $env:GITHUB_OUTPUT) -split '='
$outputName | Should -Be "Result"
# Verify that HEAD is not included in the result
$outputValue | Should -Not -Match "HEAD"
$outputValue | Should -Be "{`"branches`":[`"main`",`"develop`",`"feature-1`"]}"
}
}

Context 'Parameter override tests' {
It 'workflowEventName parameter overrides GITHUB_EVENT_NAME environment variable' {
$env:GITHUB_EVENT_NAME = "schedule"
$env:Settings = "{ 'workflowSchedule': { 'includeBranches': ['schedule-branch'] } }"
$env:GITHUB_REF_NAME = "main"

Mock -CommandName invoke-git -ParameterFilter { $command -eq 'for-each-ref'} -MockWith { return @("origin/call-branch", "origin/schedule-branch", "origin/main") }

# Parameter should override environment variable
. (Join-Path $scriptRoot "$actionName.ps1") -workflowEventName "workflow_call" -includeBranches "call-branch"

$outputName, $outputValue = (Get-Content $env:GITHUB_OUTPUT) -split '='
$outputValue | Should -Be "{`"branches`":[`"call-branch`"]}"
}
}
}
Loading