mirror of
https://gitea.com/gitea/act
synced 2026-05-11 13:51:18 +02:00
Fix yaml with prefixed newline broken setjob
This commit is contained in:
@@ -52,6 +52,11 @@ func TestParse(t *testing.T) {
|
|||||||
options: nil,
|
options: nil,
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "prefixed_newline",
|
||||||
|
options: nil,
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
|||||||
@@ -50,16 +50,18 @@ func (w *SingleWorkflow) SetJob(id string, job *Job) error {
|
|||||||
m := map[string]*Job{
|
m := map[string]*Job{
|
||||||
id: job,
|
id: job,
|
||||||
}
|
}
|
||||||
out, err := yaml.Marshal(m)
|
var buf bytes.Buffer
|
||||||
if err != nil {
|
encoder := yaml.NewEncoder(&buf)
|
||||||
return err
|
encoder.SetIndent(2)
|
||||||
}
|
encoder.Encode(m)
|
||||||
|
encoder.Close()
|
||||||
|
|
||||||
node := yaml.Node{}
|
node := yaml.Node{}
|
||||||
if err := yaml.Unmarshal(out, &node); err != nil {
|
if err := yaml.Unmarshal(buf.Bytes(), &node); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(node.Content) != 1 || node.Content[0].Kind != yaml.MappingNode {
|
if len(node.Content) != 1 || node.Content[0].Kind != yaml.MappingNode {
|
||||||
return fmt.Errorf("can not set job: %q", out)
|
return fmt.Errorf("can not set job: %s", buf.String())
|
||||||
}
|
}
|
||||||
w.RawJobs = *node.Content[0]
|
w.RawJobs = *node.Content[0]
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
14
pkg/jobparser/testdata/prefixed_newline.in.yaml
vendored
Normal file
14
pkg/jobparser/testdata/prefixed_newline.in.yaml
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
name: Step with leading new line
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: "\nExtract tag for variant"
|
||||||
|
id: extract_tag
|
||||||
|
run: |
|
||||||
|
|
||||||
|
echo Test
|
||||||
15
pkg/jobparser/testdata/prefixed_newline.out.yaml
vendored
Normal file
15
pkg/jobparser/testdata/prefixed_newline.out.yaml
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
name: Step with leading new line
|
||||||
|
"on":
|
||||||
|
push:
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
name: test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- id: extract_tag
|
||||||
|
name: |2-
|
||||||
|
|
||||||
|
Extract tag for variant
|
||||||
|
run: |2
|
||||||
|
|
||||||
|
echo Test
|
||||||
Reference in New Issue
Block a user