mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-08-06 17:40:58 +00:00
If not the schema validation will fail because it will be try to validate as if not calling a reusable workflow. ``` === RUN TestWorkflowCallRunsOn schema_test.go:119: Error Trace: /home/earl-warren/software/act/pkg/schema/schema_test.go:119 Error: Received unexpected error: Line: 10 Column 5: Failed to match job-factory: Line: 12 Column 5: Unknown Property uses Line: 13 Column 5: Unknown Property with Line: 15 Column 5: Unknown Property secrets Line: 10 Column 5: Failed to match workflow-job: Line: 11 Column 5: Unknown Property runs-on Test: TestWorkflowCallRunsOn ``` Reviewed-on: https://code.forgejo.org/forgejo/act/pulls/194 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>
122 lines
2.6 KiB
Go
122 lines
2.6 KiB
Go
package schema
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
func TestAdditionalFunctions(t *testing.T) {
|
|
var node yaml.Node
|
|
err := yaml.Unmarshal([]byte(`
|
|
on: push
|
|
jobs:
|
|
job-with-condition:
|
|
runs-on: self-hosted
|
|
if: success() || success('joba', 'jobb') || failure() || failure('joba', 'jobb') || always() || cancelled()
|
|
steps:
|
|
- run: exit 0
|
|
`), &node)
|
|
if !assert.NoError(t, err) {
|
|
return
|
|
}
|
|
err = (&Node{
|
|
Definition: "workflow-root-strict",
|
|
Schema: GetWorkflowSchema(),
|
|
}).UnmarshalYAML(&node)
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
func TestAdditionalFunctionsFailure(t *testing.T) {
|
|
var node yaml.Node
|
|
err := yaml.Unmarshal([]byte(`
|
|
on: push
|
|
jobs:
|
|
job-with-condition:
|
|
runs-on: self-hosted
|
|
if: success() || success('joba', 'jobb') || failure() || failure('joba', 'jobb') || always('error')
|
|
steps:
|
|
- run: exit 0
|
|
`), &node)
|
|
if !assert.NoError(t, err) {
|
|
return
|
|
}
|
|
err = (&Node{
|
|
Definition: "workflow-root-strict",
|
|
Schema: GetWorkflowSchema(),
|
|
}).UnmarshalYAML(&node)
|
|
assert.Error(t, err)
|
|
}
|
|
|
|
func TestAdditionalFunctionsSteps(t *testing.T) {
|
|
var node yaml.Node
|
|
err := yaml.Unmarshal([]byte(`
|
|
on: push
|
|
jobs:
|
|
job-with-condition:
|
|
runs-on: self-hosted
|
|
steps:
|
|
- run: exit 0
|
|
if: success() || failure() || always()
|
|
`), &node)
|
|
if !assert.NoError(t, err) {
|
|
return
|
|
}
|
|
err = (&Node{
|
|
Definition: "workflow-root-strict",
|
|
Schema: GetWorkflowSchema(),
|
|
}).UnmarshalYAML(&node)
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
func TestAdditionalFunctionsStepsExprSyntax(t *testing.T) {
|
|
var node yaml.Node
|
|
err := yaml.Unmarshal([]byte(`
|
|
on: push
|
|
jobs:
|
|
job-with-condition:
|
|
runs-on: self-hosted
|
|
steps:
|
|
- run: exit 0
|
|
if: ${{ success() || failure() || always() }}
|
|
`), &node)
|
|
if !assert.NoError(t, err) {
|
|
return
|
|
}
|
|
err = (&Node{
|
|
Definition: "workflow-root-strict",
|
|
Schema: GetWorkflowSchema(),
|
|
}).UnmarshalYAML(&node)
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
func TestWorkflowCallRunsOn(t *testing.T) {
|
|
var node yaml.Node
|
|
err := yaml.Unmarshal([]byte(`
|
|
name: Build Silo Frontend DEV
|
|
on:
|
|
push:
|
|
branches:
|
|
- dev
|
|
- dev-*
|
|
jobs:
|
|
build_frontend_dev:
|
|
name: Build Silo Frontend DEV
|
|
runs-on: ubuntu-latest
|
|
container:
|
|
image: code.forgejo.org/oci/node:22-bookworm
|
|
uses: ./.github/workflows/build.yaml
|
|
with:
|
|
STAGE: dev
|
|
secrets:
|
|
PACKAGE_WRITER_TOKEN: ${{ secrets.PACKAGE_WRITER_TOKEN }}
|
|
`), &node)
|
|
require.NoError(t, err)
|
|
n := &Node{
|
|
Definition: "workflow-root",
|
|
Schema: GetWorkflowSchema(),
|
|
}
|
|
require.NoError(t, n.UnmarshalYAML(&node))
|
|
}
|