Rework inputs handling of update workflow for trigger 'workflow_call'#2154
Rework inputs handling of update workflow for trigger 'workflow_call'#2154OleWunschmann wants to merge 9 commits intomicrosoft:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes how the “Update AL-Go System Files” reusable workflow reads inputs when invoked via workflow_call, and adds an override mechanism in GetWorkflowMultiRunBranches so branch selection behaves the same for workflow_call as for workflow_dispatch.
Changes:
- Add
workflowEventNameinput toGetWorkflowMultiRunBranchesand treatworkflow_calllikeworkflow_dispatch. - Rework UpdateGitHubGoSystemFiles reusable workflow templates to use
inputs.*and introduce a required__callermarker input to detect workflow_call usage. - Extend Pester coverage for
workflow_calland parameter override behavior; update release notes.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| Actions/GetWorkflowMultiRunBranches/GetWorkflowMultiRunBranches.ps1 | Switches event handling to use a parameter override and adds workflow_call handling. |
| Actions/GetWorkflowMultiRunBranches/action.yaml | Exposes new workflowEventName input and passes it through to the script. |
| Actions/GetWorkflowMultiRunBranches/README.md | Documents the new input. |
| Templates/AppSource App/.github/workflows/UpdateGitHubGoSystemFiles.yaml | Updates reusable workflow input handling and passes overridden event name into branch selection. |
| Templates/Per Tenant Extension/.github/workflows/UpdateGitHubGoSystemFiles.yaml | Same workflow_call input handling changes as the AppSource template. |
| Tests/GetWorkflowMultiRunBranches.Test.ps1 | Adds workflow_call scenarios and verifies workflowEventName override behavior. |
| RELEASENOTES.md | Notes the workflow_call input-handling rework. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if('${{ env.WorkflowEventName }}' -in 'workflow_dispatch', 'workflow_call') { | ||
| Write-Host "Using inputs from ${{ env.WorkflowEventName }} event" |
There was a problem hiding this comment.
Do you need the ${{ }} expansion in this case or could you just reference the envs directly?
| if('${{ env.WorkflowEventName }}' -in 'workflow_dispatch', 'workflow_call') { | |
| Write-Host "Using inputs from ${{ env.WorkflowEventName }} event" | |
| if($env:WorkflowEventName -in 'workflow_dispatch', 'workflow_call') { | |
| Write-Host "Using inputs from $($env:WorkflowEventName) event" |
There was a problem hiding this comment.
My idea was to highlight the difference between workflow envs and step envs.
But I agree that it's clearer and more consistent to reference the envs directly.
I implemented your suggested change for the workflow in both templates.
| default: '' | ||
| workflow_call: | ||
| inputs: | ||
| __caller: |
There was a problem hiding this comment.
Could this be callingWorkflow or something like that? Or caller? Or is there a reason for the double underscore?
There was a problem hiding this comment.
I wanted to mark this input as an internal input that is only used for the call trigger.
I’m not sure why I used a double underscore instead of a single underscore.
But I can rename the input to "caller" if you prefer.
| Context 'workflow_call event' { | ||
| It 'Action sets the current branch as result when no branch patterns are specified' { | ||
| $env:GITHUB_REF_NAME = "main" | ||
|
|
There was a problem hiding this comment.
I can see we mock invoke-git in all the other tests. Is that needed here too before invoking the action?
There was a problem hiding this comment.
The tests were based on the existing tests for the workflow_dispatch event, and the first test there also lacked the mock.
I made the following changes:
- Added the mock to the first tests for workflow_dispatch and workflow_call.
- Aligned the workflow_call tests to match the workflow_dispatch tests.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Mock -CommandName invoke-git -ParameterFilter { $command -eq 'for-each-ref'} -MockWith { return @("origin/main") } | ||
|
|
There was a problem hiding this comment.
Added mocks for 'fetch' to all tests in this file.
❔What, Why & How
What
The
workflow_callinputs in the update workflow are handled incorrectly.They must be accessed as
inputs.*, notgithub.event.inputs.*.Also,
github.event_namewill always reflect the trigger of the calling workflow, not the reusable workflow itself.In my tests of the original contribution that added the trigger to the update workflow, my use case tests passed by coincidence because the parent workflow had an input named
directCommititself and all other inputs used their default values.Why
When the update workflow is invoked as a reusable workflow, it should use the values defined in its own inputs.
These should be treated the same as when the workflow is triggered by
workflow_dispatch(for example, when determining branches).How
GetWorkflowMultiRunBranches:workflowEventNamegithub.event_nameworkflow_callresuls in the same output as eventworkflow_dispatchgithub.event.inputs.*withinputs.*caller(string):WorkflowEventName:github.ref_nameor toworkflow_callwhen thecallerinput is presentworkflowEventNameof actionGetWorkflowMultiRunBranchesRelated to original discussion #1855 and PR #2031
✅ Checklist