From 87c98a75f55e350ff7ca128f24a70cec4dc048f2 Mon Sep 17 00:00:00 2001 From: Ole Wunschmann <44057549+OleWunschmann@users.noreply.github.com> Date: Wed, 4 Mar 2026 19:26:11 +0100 Subject: [PATCH 1/2] Fix call trigger inputs of update workflow (#2) --- .../GetWorkflowMultiRunBranches.ps1 | 8 ++- Actions/GetWorkflowMultiRunBranches/README.md | 1 + .../GetWorkflowMultiRunBranches/action.yaml | 7 +- .../workflows/UpdateGitHubGoSystemFiles.yaml | 18 +++-- .../workflows/UpdateGitHubGoSystemFiles.yaml | 18 +++-- Tests/GetWorkflowMultiRunBranches.Test.ps1 | 70 +++++++++++++++++++ 6 files changed, 106 insertions(+), 16 deletions(-) diff --git a/Actions/GetWorkflowMultiRunBranches/GetWorkflowMultiRunBranches.ps1 b/Actions/GetWorkflowMultiRunBranches/GetWorkflowMultiRunBranches.ps1 index 822daede31..1da9a963ca 100644 --- a/Actions/GetWorkflowMultiRunBranches/GetWorkflowMultiRunBranches.ps1 +++ b/Actions/GetWorkflowMultiRunBranches/GetWorkflowMultiRunBranches.ps1 @@ -1,4 +1,6 @@ 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 ) @@ -6,7 +8,7 @@ $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 @@ -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() }) } } diff --git a/Actions/GetWorkflowMultiRunBranches/README.md b/Actions/GetWorkflowMultiRunBranches/README.md index a253210c15..3ed5a4f32d 100644 --- a/Actions/GetWorkflowMultiRunBranches/README.md +++ b/Actions/GetWorkflowMultiRunBranches/README.md @@ -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 diff --git a/Actions/GetWorkflowMultiRunBranches/action.yaml b/Actions/GetWorkflowMultiRunBranches/action.yaml index 75593060f6..3cee775851 100644 --- a/Actions/GetWorkflowMultiRunBranches/action.yaml +++ b/Actions/GetWorkflowMultiRunBranches/action.yaml @@ -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 @@ -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 diff --git a/Templates/AppSource App/.github/workflows/UpdateGitHubGoSystemFiles.yaml b/Templates/AppSource App/.github/workflows/UpdateGitHubGoSystemFiles.yaml index 204fa8810e..f0fbeb0a02 100644 --- a/Templates/AppSource App/.github/workflows/UpdateGitHubGoSystemFiles.yaml +++ b/Templates/AppSource App/.github/workflows/UpdateGitHubGoSystemFiles.yaml @@ -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 @@ -50,6 +54,7 @@ defaults: shell: powershell env: + WorkflowEventName: ${{ inputs.__caller && 'workflow_call' || github.event_name }} ALGoOrgSettings: ${{ vars.ALGoOrgSettings }} ALGoRepoSettings: ${{ vars.ALGoRepoSettings }} @@ -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) { @@ -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 } diff --git a/Templates/Per Tenant Extension/.github/workflows/UpdateGitHubGoSystemFiles.yaml b/Templates/Per Tenant Extension/.github/workflows/UpdateGitHubGoSystemFiles.yaml index 204fa8810e..f0fbeb0a02 100644 --- a/Templates/Per Tenant Extension/.github/workflows/UpdateGitHubGoSystemFiles.yaml +++ b/Templates/Per Tenant Extension/.github/workflows/UpdateGitHubGoSystemFiles.yaml @@ -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 @@ -50,6 +54,7 @@ defaults: shell: powershell env: + WorkflowEventName: ${{ inputs.__caller && 'workflow_call' || github.event_name }} ALGoOrgSettings: ${{ vars.ALGoOrgSettings }} ALGoRepoSettings: ${{ vars.ALGoRepoSettings }} @@ -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) { @@ -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 } diff --git a/Tests/GetWorkflowMultiRunBranches.Test.ps1 b/Tests/GetWorkflowMultiRunBranches.Test.ps1 index 0059df4d0d..87dde926e1 100644 --- a/Tests/GetWorkflowMultiRunBranches.Test.ps1 +++ b/Tests/GetWorkflowMultiRunBranches.Test.ps1 @@ -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`"]}" + } + } } From 8697647e0105e141759dc21dc7f12db43dd5497b Mon Sep 17 00:00:00 2001 From: Ole Wunschmann Date: Wed, 4 Mar 2026 19:30:19 +0100 Subject: [PATCH 2/2] Update releasenotes --- RELEASENOTES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 8b69114709..2f2c3b4b1e 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -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