mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-08-16 18:01:34 +00:00
the actions schema validation must not fail when using an expression such as: ```yaml runs: using: composite steps: - name: Build the container image for each architecture env: BUILDKIT_HOST: ${{ vars.BUILDKIT_HOST }} run: buildkit-build.sh ``` --- Without the fix, the test fails with: ``` go test -run=TestActionSchema -v ./act/schema === RUN TestActionSchema schema_test.go:153: Error Trace: /home/earl-warren/software/runner/act/schema/schema_test.go:153 Error: Received unexpected error: Line: 14 Column 3: Failed to match container-runs: Line: 15 Column 3: Unknown Property steps Line: 14 Column 3: Failed to match node-runs: Line: 15 Column 3: Unknown Property steps Line: 14 Column 3: Failed to match plugin-runs: Line: 14 Column 3: Unknown Property using Line: 15 Column 3: Unknown Property steps Line: 14 Column 3: Failed to match composite-runs: Line: 16 Column 7: Failed to match run-step: Line: 19 Column 18: Unknown Variable Access vars Line: 16 Column 7: Failed to match uses-step: Line: 16 Column 7: Unknown Property run Line: 19 Column 18: Unknown Variable Access vars Test: TestActionSchema --- FAIL: TestActionSchema (0.00s) FAIL FAIL code.forgejo.org/forgejo/runner/act/schema 0.003s FAIL ``` --- <!--start release-notes-assistant--> <!--URL:https://code.forgejo.org/forgejo/runner--> - bug fixes - [PR](https://code.forgejo.org/forgejo/runner/pulls/761): <!--number 761 --><!--line 0 --><!--description Zml4OiB0aGUgdmFycyBjb250ZXh0IGlzIGFsbG93ZWQgaW4gYW4gYWN0aW9uIHN0ZXAgZW52-->fix: the vars context is allowed in an action step env<!--description--> <!--end release-notes-assistant--> Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/761 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>
155 lines
3.3 KiB
Go
155 lines
3.3 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()
|
|
- uses: https://${{ secrets.PAT }}@example.com/action/here@v1
|
|
`), &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: ./.forgejo/workflows/${{ vars.PATHNAME }}
|
|
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))
|
|
}
|
|
|
|
func TestActionSchema(t *testing.T) {
|
|
var node yaml.Node
|
|
err := yaml.Unmarshal([]byte(`
|
|
name: 'action name'
|
|
author: 'action authors'
|
|
description: |
|
|
action description
|
|
inputs:
|
|
url:
|
|
description: 'url description'
|
|
default: '${{ env.GITHUB_SERVER_URL }}'
|
|
repo:
|
|
description: 'repo description'
|
|
default: '${{ github.repository }}'
|
|
runs:
|
|
using: "composite"
|
|
steps:
|
|
- run: |
|
|
echo "${{ github.action_path }}"
|
|
env:
|
|
MYVAR: ${{ vars.VARIABLE }}
|
|
`), &node)
|
|
if !assert.NoError(t, err) {
|
|
return
|
|
}
|
|
err = (&Node{
|
|
Definition: "action-root",
|
|
Schema: GetActionSchema(),
|
|
}).UnmarshalYAML(&node)
|
|
assert.NoError(t, err)
|
|
}
|