[FORGEJO] when a workflow decode error happen, log and do not crash

This commit is contained in:
Earl Warren 2024-09-15 15:46:01 +02:00
parent d301a5b66a
commit a7db265415
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
3 changed files with 21 additions and 2 deletions

View file

@ -44,5 +44,5 @@ jobs:
- name: build without docker
run: go build -tags WITHOUT_DOCKER -v ./...
- name: test
run: go test -v ./pkg/jobparser
run: go test -v ./pkg/jobparser ./pkg/model
# TODO test more packages

View file

@ -749,7 +749,7 @@ func (w *Workflow) GetJobIDs() []string {
}
var OnDecodeNodeError = func(node yaml.Node, out interface{}, err error) {
log.Fatalf("Failed to decode node %v into %T: %v", node, out, err)
log.Errorf("Failed to decode node %v into %T: %v", node, out, err)
}
func decodeNode(node yaml.Node, out interface{}) bool {

View file

@ -153,6 +153,25 @@ jobs:
assert.Contains(t, workflow.On(), "pull_request")
}
func TestReadWorkflow_DecodeNodeError(t *testing.T) {
yaml := `
on:
push:
jobs:
test:
runs-on: ubuntu-latest
steps:
- run: echo
env:
foo: {{ a }}
`
workflow, err := ReadWorkflow(strings.NewReader(yaml))
assert.NoError(t, err, "read workflow should succeed")
assert.Nil(t, workflow.GetJob("test").Steps[0].GetEnv())
}
func TestReadWorkflow_RunsOnLabels(t *testing.T) {
yaml := `
name: local-action-docker-url