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

fix: allow expressions in action descriptions and incomplete action inputs (#770)

They are commonly used for documentation purposes and never evaluated.

<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- bug fixes
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/770): <!--number 770 --><!--line 0 --><!--description Zml4OiBhbGxvdyBleHByZXNzaW9ucyBpbiBhY3Rpb24gZGVzY3JpcHRpb25zIGFuZCBpbmNvbXBsZXRlIGFjdGlvbiBpbnB1dHM=-->fix: allow expressions in action descriptions and incomplete action inputs<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/770
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-07-31 04:35:19 +00:00 committed by earl-warren
parent 9e02dd8c7e
commit 29cc7e1a71
No known key found for this signature in database
GPG key ID: F128CBE6AB3A7201
4 changed files with 60 additions and 16 deletions

View file

@ -53,8 +53,8 @@ jobs:
- name: unit test - name: unit test
run: | run: |
go test -short -v ./act/container go test -short ./act/container
go test -v ./act/artifactcache/... ./act/workflowpattern/... ./act/filecollector/... ./act/common/... ./act/jobparser ./act/model ./act/exprparser ./act/schema go test ./act/artifactcache/... ./act/workflowpattern/... ./act/filecollector/... ./act/common/... ./act/jobparser ./act/model ./act/exprparser ./act/schema
integration: integration:
runs-on: lxc-bookworm runs-on: lxc-bookworm
@ -74,5 +74,5 @@ jobs:
- name: integration test - name: integration test
run: | run: |
go test -v ./act/container go test ./act/container
go test -v ./act/runner/... go test ./act/runner/...

View file

@ -15,12 +15,18 @@
} }
}, },
"inputs": { "inputs": {
"one-of": ["null", "inputs-mapping"]
},
"inputs-mapping": {
"mapping": { "mapping": {
"loose-key-type": "non-empty-string", "loose-key-type": "non-empty-string",
"loose-value-type": "input" "loose-value-type": "input"
} }
}, },
"input": { "input": {
"one-of": ["null", "input-mapping"]
},
"input-mapping": {
"mapping": { "mapping": {
"properties": { "properties": {
"default": "input-default-context" "default": "input-default-context"
@ -190,6 +196,7 @@
"steps", "steps",
"job", "job",
"runner", "runner",
"vars",
"env", "env",
"hashFiles(1,255)" "hashFiles(1,255)"
], ],
@ -205,6 +212,7 @@
"steps", "steps",
"job", "job",
"runner", "runner",
"vars",
"env", "env",
"hashFiles(1,255)" "hashFiles(1,255)"
], ],
@ -239,6 +247,7 @@
"steps", "steps",
"job", "job",
"runner", "runner",
"vars",
"env", "env",
"always(0,0)", "always(0,0)",
"failure(0,0)", "failure(0,0)",
@ -258,6 +267,7 @@
"steps", "steps",
"job", "job",
"runner", "runner",
"vars",
"env", "env",
"hashFiles(1,255)" "hashFiles(1,255)"
], ],

View file

@ -125,9 +125,10 @@ func (s *Node) checkSingleExpression(exprNode actionlint.ExprNode) error {
case actionlint.TokenKindInt: case actionlint.TokenKindInt:
case actionlint.TokenKindFloat: case actionlint.TokenKindFloat:
case actionlint.TokenKindString: case actionlint.TokenKindString:
case actionlint.TokenKindIdent:
return nil return nil
default: default:
return fmt.Errorf("expressions are not allowed here") return fmt.Errorf("expressions are not allowed in %v", exprNode.Token().Kind)
} }
} }

View file

@ -123,12 +123,17 @@ jobs:
} }
func TestActionSchema(t *testing.T) { func TestActionSchema(t *testing.T) {
var node yaml.Node for _, testCase := range []struct {
err := yaml.Unmarshal([]byte(` name string
action string
}{
{
name: "Expressions",
action: `
name: 'action name' name: 'action name'
author: 'action authors' author: 'action authors'
description: | description: |
action description action ${{ env.SOMETHING }} description
inputs: inputs:
url: url:
description: 'url description' description: 'url description'
@ -143,7 +148,33 @@ runs:
echo "${{ github.action_path }}" echo "${{ github.action_path }}"
env: env:
MYVAR: ${{ vars.VARIABLE }} MYVAR: ${{ vars.VARIABLE }}
`), &node) `,
},
{
name: "NoInputs",
action: `
runs:
using: "composite"
steps:
- run: echo OK
`,
},
{
name: "NoMappingInputs",
action: `
inputs:
parameter1:
parameter2:
runs:
using: "composite"
steps:
- run: echo OK
`,
},
} {
t.Run(testCase.name, func(t *testing.T) {
var node yaml.Node
err := yaml.Unmarshal([]byte(testCase.action), &node)
if !assert.NoError(t, err) { if !assert.NoError(t, err) {
return return
} }
@ -152,4 +183,6 @@ runs:
Schema: GetActionSchema(), Schema: GetActionSchema(),
}).UnmarshalYAML(&node) }).UnmarshalYAML(&node)
assert.NoError(t, err) assert.NoError(t, err)
})
}
} }