Skip to content

Rework inputs handling of update workflow for trigger 'workflow_call'#2154

Open
OleWunschmann wants to merge 9 commits intomicrosoft:mainfrom
OleWunschmann:fix-reusable-update-workflow
Open

Rework inputs handling of update workflow for trigger 'workflow_call'#2154
OleWunschmann wants to merge 9 commits intomicrosoft:mainfrom
OleWunschmann:fix-reusable-update-workflow

Conversation

@OleWunschmann
Copy link
Contributor

@OleWunschmann OleWunschmann commented Mar 4, 2026

❔What, Why & How

What

The workflow_call inputs in the update workflow are handled incorrectly.
They must be accessed as inputs.*, not github.event.inputs.*.
Also, github.event_name will 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 directCommit itself 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

  • Modified the action GetWorkflowMultiRunBranches:
    • Added a new optional input workflowEventName
      • Default: github.event_name
      • Purpose: override the event name used to determine which branches to include
      • Event workflow_call resuls in the same output as event workflow_dispatch
  • Modified the update workflow:
    • Replaced all uses of github.event.inputs.* with inputs.*
    • Added a new required workflow_call input caller (string):
      • Marks that the update workflow was called from another workflow
    • Added a new environment variable WorkflowEventName:
      • Set to github.ref_name or to workflow_call when the caller input is present
      • Passed to input workflowEventName of action GetWorkflowMultiRunBranches
      • Used to determine the commit options

Related to original discussion #1855 and PR #2031

✅ Checklist

  • Add tests (E2E, unit tests)
  • Update RELEASENOTES.md

@OleWunschmann OleWunschmann marked this pull request as ready for review March 4, 2026 21:55
@OleWunschmann OleWunschmann requested a review from a team as a code owner March 4, 2026 21:55
Copilot AI review requested due to automatic review settings March 4, 2026 21:55
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 workflowEventName input to GetWorkflowMultiRunBranches and treat workflow_call like workflow_dispatch.
  • Rework UpdateGitHubGoSystemFiles reusable workflow templates to use inputs.* and introduce a required __caller marker input to detect workflow_call usage.
  • Extend Pester coverage for workflow_call and 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.

@mazhelez mazhelez self-requested a review March 17, 2026 13:38
Comment on lines +146 to +147
if('${{ env.WorkflowEventName }}' -in 'workflow_dispatch', 'workflow_call') {
Write-Host "Using inputs from ${{ env.WorkflowEventName }} event"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you need the ${{ }} expansion in this case or could you just reference the envs directly?

Suggested change
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"

Copy link
Contributor Author

@OleWunschmann OleWunschmann Mar 17, 2026

Choose a reason for hiding this comment

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

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:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could this be callingWorkflow or something like that? Or caller? Or is there a reason for the double underscore?

Copy link
Contributor Author

@OleWunschmann OleWunschmann Mar 17, 2026

Choose a reason for hiding this comment

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

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"

Copy link
Collaborator

Choose a reason for hiding this comment

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

I can see we mock invoke-git in all the other tests. Is that needed here too before invoking the action?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +42 to +43
Mock -CommandName invoke-git -ParameterFilter { $command -eq 'for-each-ref'} -MockWith { return @("origin/main") }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added mocks for 'fetch' to all tests in this file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants