From aa428e375c46d6e17c68d750263c7fb4c2624b18 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Mon, 1 Sep 2025 22:09:43 +0000 Subject: [PATCH] fix: an expression in with: for a reusable workflow call can use env (#931) Resolves forgejo/runner#929 - bug fixes - [PR](https://code.forgejo.org/forgejo/runner/pulls/931): fix: an expression in with: for a reusable workflow call can use env Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/931 Reviewed-by: Michael Kriese Co-authored-by: Earl Warren Co-committed-by: Earl Warren --- act/schema/schema_test.go | 57 +++++++++++++++++++++++++++++++++ act/schema/workflow_schema.json | 2 +- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/act/schema/schema_test.go b/act/schema/schema_test.go index fe2598f2..45109b1d 100644 --- a/act/schema/schema_test.go +++ b/act/schema/schema_test.go @@ -1,6 +1,7 @@ package schema import ( + "fmt" "testing" "github.com/stretchr/testify/assert" @@ -29,6 +30,62 @@ jobs: assert.NoError(t, err) } +func TestReusableWorkflow(t *testing.T) { + t.Run("KnownContexts", func(t *testing.T) { + var node yaml.Node + err := yaml.Unmarshal([]byte(` +on: push + +jobs: + job: + uses: ./.forgejo/workflow/test.yaml + with: + input1: | + ${{ forge.KEY }} + ${{ github.KEY }} + ${{ inputs.KEY }} + ${{ vars.KEY }} + ${{ env.KEY }} + ${{ needs.KEY }} + ${{ strategy.KEY }} + ${{ matrix.KEY }} +`), &node) + if !assert.NoError(t, err) { + return + } + err = (&Node{ + Definition: "workflow-root", + Schema: GetWorkflowSchema(), + }).UnmarshalYAML(&node) + assert.NoError(t, err) + }) + + t.Run("UnknownContext", func(t *testing.T) { + for _, context := range []string{"secrets", "job", "steps", "runner"} { + t.Run(context, func(t *testing.T) { + var node yaml.Node + err := yaml.Unmarshal([]byte(fmt.Sprintf(` +on: push + +jobs: + job: + uses: ./.forgejo/workflow/test.yaml + with: + input1: ${{ %[1]s.KEY }} +`, context)), &node) + if !assert.NoError(t, err) { + return + } + err = (&Node{ + Definition: "workflow-root", + Schema: GetWorkflowSchema(), + }).UnmarshalYAML(&node) + assert.ErrorContains(t, err, "Unknown Variable Access "+context) + }) + } + }) +} + func TestAdditionalFunctionsFailure(t *testing.T) { var node yaml.Node err := yaml.Unmarshal([]byte(` diff --git a/act/schema/workflow_schema.json b/act/schema/workflow_schema.json index 9c88f5b5..826269a8 100644 --- a/act/schema/workflow_schema.json +++ b/act/schema/workflow_schema.json @@ -2076,7 +2076,7 @@ "string": {} }, "scalar-needs-context": { - "context": ["forge", "github", "inputs", "vars", "needs", "strategy", "matrix"], + "context": ["forge", "github", "inputs", "vars", "env", "needs", "strategy", "matrix"], "one-of": ["string", "boolean", "number"] }, "scalar-needs-context-with-secrets": {