From 02247b852aab7bc47027bbfbabe66cc36c81b78f Mon Sep 17 00:00:00 2001 From: Mathieu Fenniak Date: Fri, 10 Oct 2025 21:55:08 +0000 Subject: [PATCH] fix: allow mapping into env variable INPUT_N from ${{ inputs.n }} (#1080) When using a reusable workflow such as: ```yaml name: "use-inputs-impl" on: workflow_call: inputs: image: description: "Image to be used in job" type: string required: false default: "docker.io/alpine:3.22" condition: description: "Only run a job if this is true" type: string required: false default: false jobs: works: runs-on: docker container: image: alpine:3.22 env: INPUT_IMAGE: ${{ inputs.image }} INPUT_CONDITION: ${{ inputs.condition }} steps: - run: echo "Hello world from Alpine" - run: cat /etc/alpine-release - run: echo "INPUT_IMAGE=$INPUT_IMAGE" - run: echo "INPUT_CONDITION=$INPUT_CONDITION" ``` The runner will currently output un-evaluated expressions: ``` INPUT_IMAGE=${{ inputs.image }} INPUT_CONDITION=${{ inputs.condition }} ``` Internally, the workflow is using `INPUT_...` environment variables to transfer data into local reusable workflows, and the order of evaluation in `getEvaluatorInputs` was preferring to use the un-evaluated value, over the evaluated value. - bug fixes - [PR](https://code.forgejo.org/forgejo/runner/pulls/1080): fix: allow mapping into env variable INPUT_N from ${{ inputs.n }} Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1080 Reviewed-by: earl-warren Co-authored-by: Mathieu Fenniak Co-committed-by: Mathieu Fenniak --- act/runner/expression.go | 4 ++-- act/runner/runner_test.go | 1 + .../workflows/local-reusable-env-input.yml | 21 +++++++++++++++++++ .../testdata/uses-workflow-env-input/push.yml | 8 +++++++ 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 act/runner/testdata/.github/workflows/local-reusable-env-input.yml create mode 100644 act/runner/testdata/uses-workflow-env-input/push.yml diff --git a/act/runner/expression.go b/act/runner/expression.go index e17af233..152a2f8e 100644 --- a/act/runner/expression.go +++ b/act/runner/expression.go @@ -479,8 +479,6 @@ func rewriteSubExpression(ctx context.Context, in string, forceFormat bool) (str func getEvaluatorInputs(ctx context.Context, rc *RunContext, step step, ghc *model.GithubContext) map[string]any { inputs := map[string]any{} - setupWorkflowInputs(ctx, &inputs, rc) - var env map[string]string if step != nil { env = *step.getEnv() @@ -494,6 +492,8 @@ func getEvaluatorInputs(ctx context.Context, rc *RunContext, step step, ghc *mod } } + setupWorkflowInputs(ctx, &inputs, rc) + if rc.caller == nil && ghc.EventName == "workflow_dispatch" { config := rc.Run.Workflow.WorkflowDispatchConfig() if config != nil && config.Inputs != nil { diff --git a/act/runner/runner_test.go b/act/runner/runner_test.go index 0d29eca8..f8b3918c 100644 --- a/act/runner/runner_test.go +++ b/act/runner/runner_test.go @@ -263,6 +263,7 @@ func TestRunner_RunEvent(t *testing.T) { {workdir, "uses-workflow", "pull_request", "", platforms, map[string]string{"secret": "keep_it_private"}}, {workdir, "uses-docker-url", "push", "", platforms, secrets}, {workdir, "act-composite-env-test", "push", "", platforms, secrets}, + {workdir, "uses-workflow-env-input", "push", "", platforms, secrets}, // Eval {workdir, "evalmatrix", "push", "", platforms, secrets}, diff --git a/act/runner/testdata/.github/workflows/local-reusable-env-input.yml b/act/runner/testdata/.github/workflows/local-reusable-env-input.yml new file mode 100644 index 00000000..eb1d9092 --- /dev/null +++ b/act/runner/testdata/.github/workflows/local-reusable-env-input.yml @@ -0,0 +1,21 @@ +name: "use-inputs-impl" + +on: + workflow_call: + inputs: + greet_target: + type: string + required: false + default: "Some Default Value" + +jobs: + works: + runs-on: ubuntu-latest + env: + MY_INPUT_TEST: ${{ inputs.greet_target }} + INPUT_TEST: ${{ inputs.greet_target }} + INPUT_GREET_TARGET: ${{ inputs.greet_target }} + steps: + - run: '[ "$MY_INPUT_TEST" = "Mona the Octocat" ] || exit 1' + - run: '[ "$INPUT_TEST" = "Mona the Octocat" ] || exit 1' + - run: '[ "$INPUT_GREET_TARGET" = "Mona the Octocat" ] || exit 1' diff --git a/act/runner/testdata/uses-workflow-env-input/push.yml b/act/runner/testdata/uses-workflow-env-input/push.yml new file mode 100644 index 00000000..d702c4bb --- /dev/null +++ b/act/runner/testdata/uses-workflow-env-input/push.yml @@ -0,0 +1,8 @@ +name: local-action-env-input +on: push +jobs: + test: + runs-on: docker + uses: ./testdata/.github/workflows/local-reusable-env-input.yml + with: + greet_target: 'Mona the Octocat'