-
Notifications
You must be signed in to change notification settings - Fork 184
Rework inputs handling of update workflow for trigger 'workflow_call' #2154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
87c98a7
8697647
6adad8f
cd8bda8
8c94b4b
2f7b0e2
8fb13fd
fb02443
d214f4c
3abb861
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,9 @@ Describe "GetWorkflowMultiRunBranches Action" { | |
| $env:Settings = "" | ||
| $env:GITHUB_REF_NAME = "main" | ||
|
|
||
| Mock -CommandName invoke-git -ParameterFilter { $command -eq 'fetch' } -MockWith { } | ||
| Mock -CommandName invoke-git -ParameterFilter { $command -eq 'for-each-ref'} -MockWith { return @("origin/main") } | ||
|
|
||
|
Comment on lines
+43
to
+44
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added mocks for 'fetch' to all tests in this file. |
||
| # Call the action script | ||
| . (Join-Path $scriptRoot "$actionName.ps1") | ||
|
|
||
|
|
@@ -52,6 +55,7 @@ Describe "GetWorkflowMultiRunBranches Action" { | |
| $env:Settings = "" | ||
| $env:GITHUB_REF_NAME = "main" | ||
|
|
||
| Mock -CommandName invoke-git -ParameterFilter { $command -eq 'fetch' } -MockWith { } | ||
| 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 | ||
|
|
@@ -67,6 +71,7 @@ Describe "GetWorkflowMultiRunBranches Action" { | |
| $env:Settings = "" | ||
| $env:GITHUB_REF_NAME = "main" | ||
|
|
||
| Mock -CommandName invoke-git -ParameterFilter { $command -eq 'fetch' } -MockWith { } | ||
| 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 | ||
|
|
@@ -82,6 +87,7 @@ Describe "GetWorkflowMultiRunBranches Action" { | |
| $env:Settings = "" | ||
| $env:GITHUB_REF_NAME = "main" | ||
|
|
||
| Mock -CommandName invoke-git -ParameterFilter { $command -eq 'fetch' } -MockWith { } | ||
| 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 | ||
|
|
@@ -101,6 +107,7 @@ Describe "GetWorkflowMultiRunBranches Action" { | |
| $env:Settings = "{ 'workflowSchedule': { 'includeBranches': [] } }" | ||
| $env:GITHUB_REF_NAME = "default-branch" | ||
|
|
||
| Mock -CommandName invoke-git -ParameterFilter { $command -eq 'fetch' } -MockWith { } | ||
| Mock -CommandName invoke-git -ParameterFilter { $command -eq 'for-each-ref'} -MockWith { return @("origin/test-branch", "origin/main", "origin/default-branch", "origin") } | ||
|
|
||
| # Call the action script | ||
|
|
@@ -116,6 +123,7 @@ Describe "GetWorkflowMultiRunBranches Action" { | |
| $env:Settings = "{ 'workflowSchedule': { 'includeBranches': ['test-branch'] } }" | ||
| $env:GITHUB_REF_NAME = "main" | ||
|
|
||
| Mock -CommandName invoke-git -ParameterFilter { $command -eq 'fetch' } -MockWith { } | ||
| 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 | ||
|
|
@@ -131,6 +139,7 @@ Describe "GetWorkflowMultiRunBranches Action" { | |
| $env:Settings = "{ 'workflowSchedule': { 'includeBranches': ['*branch*'] } }" | ||
| $env:GITHUB_REF_NAME = "main" | ||
|
|
||
| Mock -CommandName invoke-git -ParameterFilter { $command -eq 'fetch' } -MockWith { } | ||
| 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 | ||
|
|
@@ -141,4 +150,89 @@ 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_EVENT_NAME = "workflow_call" | ||
| $env:Settings = "" | ||
| $env:GITHUB_REF_NAME = "main" | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
|
||
| Mock -CommandName invoke-git -ParameterFilter { $command -eq 'fetch' } -MockWith { } | ||
| Mock -CommandName invoke-git -ParameterFilter { $command -eq 'for-each-ref'} -MockWith { return @("origin/main") } | ||
|
|
||
| # Call the action script | ||
| . (Join-Path $scriptRoot "$actionName.ps1") | ||
|
|
||
| $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_EVENT_NAME = "workflow_call" | ||
| $env:Settings = "" | ||
| $env:GITHUB_REF_NAME = "main" | ||
|
|
||
| Mock -CommandName invoke-git -ParameterFilter { $command -eq 'fetch' } -MockWith { } | ||
| 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 | ||
| . (Join-Path $scriptRoot "$actionName.ps1") -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_EVENT_NAME = "workflow_call" | ||
| $env:Settings = "" | ||
| $env:GITHUB_REF_NAME = "main" | ||
|
|
||
| Mock -CommandName invoke-git -ParameterFilter { $command -eq 'fetch' } -MockWith { } | ||
| 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 | ||
| . (Join-Path $scriptRoot "$actionName.ps1") -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_EVENT_NAME = "workflow_call" | ||
| $env:Settings = "" | ||
| $env:GITHUB_REF_NAME = "main" | ||
|
|
||
| Mock -CommandName invoke-git -ParameterFilter { $command -eq 'fetch' } -MockWith { } | ||
| 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") -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 'fetch' } -MockWith { } | ||
| 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`"]}" | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.