1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-09-15 18:57:01 +00:00

fix: prevent unintended input replacement in reusable workflows with workflow_dispatch when using workflow_call (#2502)

* Remove redundant check

See: https://github.com/nektos/act/issues/2464#issuecomment-2430903650

* Add condition to prevent replacing inputs in reusable workflows with workflow_dispatch inputs

Closes: https://github.com/nektos/act/issues/2464

* fmt

* Revert "Remove redundant check"

This reverts commit 63455960ec714eea7631a586bcd59bed449739fc.

* add test

* Update runner_test.go

* update label

---------

Co-authored-by: ChristopherHX <christopher.homberger@web.de>
(cherry picked from commit f4f4265e977a760e0637a65b1554af2cada034cc)
This commit is contained in:
S. M. Mahmudul Haque (Yamin) 2024-12-29 15:52:06 +01:00 committed by Earl Warren
parent 3ef94e3b41
commit f1a8f17827
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
4 changed files with 53 additions and 1 deletions

View file

@ -487,7 +487,7 @@ func getEvaluatorInputs(ctx context.Context, rc *RunContext, step step, ghc *mod
} }
} }
if ghc.EventName == "workflow_dispatch" { if rc.caller == nil && ghc.EventName == "workflow_dispatch" {
config := rc.Run.Workflow.WorkflowDispatchConfig() config := rc.Run.Workflow.WorkflowDispatchConfig()
if config != nil && config.Inputs != nil { if config != nil && config.Inputs != nil {
for k, v := range config.Inputs { for k, v := range config.Inputs {

View file

@ -311,6 +311,7 @@ func TestRunner_RunEvent(t *testing.T) {
{workdir, "workflow_dispatch_no_inputs_mapping", "workflow_dispatch", "", platforms, secrets}, {workdir, "workflow_dispatch_no_inputs_mapping", "workflow_dispatch", "", platforms, secrets},
{workdir, "workflow_dispatch-scalar", "workflow_dispatch", "", platforms, secrets}, {workdir, "workflow_dispatch-scalar", "workflow_dispatch", "", platforms, secrets},
{workdir, "workflow_dispatch-scalar-composite-action", "workflow_dispatch", "", platforms, secrets}, {workdir, "workflow_dispatch-scalar-composite-action", "workflow_dispatch", "", platforms, secrets},
{workdir, "uses-workflow-defaults", "workflow_dispatch", "", platforms, secrets},
{workdir, "job-needs-context-contains-result", "push", "", platforms, secrets}, {workdir, "job-needs-context-contains-result", "push", "", platforms, secrets},
{"../model/testdata", "strategy", "push", "", platforms, secrets}, // TODO: move all testdata into pkg so we can validate it with planner and runner {"../model/testdata", "strategy", "push", "", platforms, secrets}, // TODO: move all testdata into pkg so we can validate it with planner and runner
{workdir, "path-handling", "push", "", platforms, secrets}, {workdir, "path-handling", "push", "", platforms, secrets},

View file

@ -0,0 +1,30 @@
name: reuse
on:
workflow_dispatch:
inputs:
my-val:
type: string
required: true
default: "default_value_reuse_workflow_dispatch_call"
dispatch-val:
type: string
default: "I am a dispatch var for checking if I am being used in workflow_call"
workflow_call:
inputs:
my-val:
type: string
required: true
default: "default_value_reuse_workflow_call"
jobs:
reusable_workflow_job:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run a one-line script
run: echo "✅ 🚀 ✅ hello this is from workflow reuse. Value - " ${{ inputs.my-val }} ${{ github.event_name }} ${{ inputs.dispatch-val }}
- name: Assert
run: |
exit ${{ ( inputs.my-val == 'default_value_reuse_workflow_call' || inputs.my-val == 'passed value from main' ) && !inputs.dispatch-val && '0' || '1' }}

View file

@ -0,0 +1,21 @@
name: CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run a one-line script
run: echo "✅ 🚀 ✅ hello this is from workflow main" ${{ github.event_name }}
call-reuse-w-val:
uses: ./.github/workflows/local-reusable-and-dispatch.yml
with:
my-val: "passed value from main"