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:
parent
323554256c
commit
aa428e375c
2 changed files with 58 additions and 1 deletions
|
@ -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(`
|
||||
|
|
|
@ -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": {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue