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

fix: an expression in with: for a reusable workflow call can use env (#931)

Resolves forgejo/runner#929

<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- bug fixes
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/931): <!--number 931 --><!--line 0 --><!--description Zml4OiBhbiBleHByZXNzaW9uIGluIHdpdGg6IGZvciBhIHJldXNhYmxlIHdvcmtmbG93IGNhbGwgY2FuIHVzZSBlbnY=-->fix: an expression in with: for a reusable workflow call can use env<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/931
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
Co-authored-by: Earl Warren <contact@earl-warren.org>
Co-committed-by: Earl Warren <contact@earl-warren.org>
This commit is contained in:
Earl Warren 2025-09-01 22:09:43 +00:00 committed by earl-warren
parent 323554256c
commit aa428e375c
No known key found for this signature in database
GPG key ID: F128CBE6AB3A7201
2 changed files with 58 additions and 1 deletions

View file

@ -1,6 +1,7 @@
package schema package schema
import ( import (
"fmt"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -29,6 +30,62 @@ jobs:
assert.NoError(t, err) 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) { func TestAdditionalFunctionsFailure(t *testing.T) {
var node yaml.Node var node yaml.Node
err := yaml.Unmarshal([]byte(` err := yaml.Unmarshal([]byte(`

View file

@ -2076,7 +2076,7 @@
"string": {} "string": {}
}, },
"scalar-needs-context": { "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"] "one-of": ["string", "boolean", "number"]
}, },
"scalar-needs-context-with-secrets": { "scalar-needs-context-with-secrets": {