Skip to content

Commit deea8ec

Browse files
fix: prevent unintended input replacement in reusable workflows with workflow_dispatch when using workflow_call (#2502)
* Remove redundant check See: #2464 (comment) * Add condition to prevent replacing inputs in reusable workflows with workflow_dispatch inputs Closes: #2464 * fmt * Revert "Remove redundant check" This reverts commit 6345596. * add test * Update runner_test.go * update label --------- Co-authored-by: ChristopherHX <christopher.homberger@web.de>
1 parent bd8dda1 commit deea8ec

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed

pkg/runner/expression.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ func getEvaluatorInputs(ctx context.Context, rc *RunContext, step step, ghc *mod
497497
}
498498
}
499499

500-
if ghc.EventName == "workflow_dispatch" {
500+
if rc.caller == nil && ghc.EventName == "workflow_dispatch" {
501501
config := rc.Run.Workflow.WorkflowDispatchConfig()
502502
if config != nil && config.Inputs != nil {
503503
for k, v := range config.Inputs {

pkg/runner/runner_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ func TestRunEvent(t *testing.T) {
305305
{workdir, "workflow_dispatch_no_inputs_mapping", "workflow_dispatch", "", platforms, secrets},
306306
{workdir, "workflow_dispatch-scalar", "workflow_dispatch", "", platforms, secrets},
307307
{workdir, "workflow_dispatch-scalar-composite-action", "workflow_dispatch", "", platforms, secrets},
308+
{workdir, "uses-workflow-defaults", "workflow_dispatch", "", platforms, secrets},
308309
{workdir, "job-needs-context-contains-result", "push", "", platforms, secrets},
309310
{"../model/testdata", "strategy", "push", "", platforms, secrets}, // TODO: move all testdata into pkg so we can validate it with planner and runner
310311
{"../model/testdata", "container-volumes", "push", "", platforms, secrets},
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: reuse
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
my-val:
7+
type: string
8+
required: true
9+
default: "default_value_reuse_workflow_dispatch_call"
10+
dispatch-val:
11+
type: string
12+
default: "I am a dispatch var for checking if I am being used in workflow_call"
13+
14+
workflow_call:
15+
inputs:
16+
my-val:
17+
type: string
18+
required: true
19+
default: "default_value_reuse_workflow_call"
20+
21+
jobs:
22+
reusable_workflow_job:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v4
26+
- name: Run a one-line script
27+
run: echo "✅ 🚀 ✅ hello this is from workflow reuse. Value - " ${{ inputs.my-val }} ${{ github.event_name }} ${{ inputs.dispatch-val }}
28+
- name: Assert
29+
run: |
30+
exit ${{ ( inputs.my-val == 'default_value_reuse_workflow_call' || inputs.my-val == 'passed value from main' ) && !inputs.dispatch-val && '0' || '1' }}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
workflow_dispatch:
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- name: Run a one-line script
17+
run: echo "✅ 🚀 ✅ hello this is from workflow main" ${{ github.event_name }}
18+
call-reuse-w-val:
19+
uses: ./.github/workflows/local-reusable-and-dispatch.yml
20+
with:
21+
my-val: "passed value from main"

0 commit comments

Comments
 (0)