mirror of
https://gitea.com/gitea/runner.git
synced 2026-11-04 14:35:32 +00:00
Updates actionslib to https://gitea.com/gitea/actionslib/releases/tag/v1.2.1. 1. A job whose `if:` fails to evaluate, like `fromJSON` of an invalid job output, is skipped with the error in its log instead of failing, like on GitHub Actions. 1. Workflows the runner reads itself, like with `exec`, are rejected when an expression does not parse, like an unclosed `${{` or an unknown context, instead of failing later. 1. Task payloads from Gitea are read without that check, because they hold evaluated text that may contain `${{`. 1. `if: False`, `if: ~` and other boolean, null or number conditions work. Gitea PR: https://github.com/go-gitea/gitea/pull/39358 Reviewed-on: https://gitea.com/gitea/runner/pulls/1247 Reviewed-by: bircni <[email protected]> Co-authored-by: silverwind <[email protected]>
55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package run
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"sort"
|
|
"strings"
|
|
|
|
"gitea.dev/actionslib/pkg/model"
|
|
runnerv1 "gitea.dev/actionslib/runner/v1"
|
|
"go.yaml.in/yaml/v4"
|
|
)
|
|
|
|
func generateWorkflow(task *runnerv1.Task) (*model.Workflow, string, error) {
|
|
workflow, err := model.ReadWorkflowPayload(bytes.NewReader(task.WorkflowPayload))
|
|
if err != nil {
|
|
return nil, "", err
|
|
}
|
|
|
|
jobIDs := workflow.GetJobIDs()
|
|
if len(jobIDs) != 1 {
|
|
return nil, "", fmt.Errorf("multiple jobs found: %v", jobIDs)
|
|
}
|
|
jobID := jobIDs[0]
|
|
|
|
needJobIDs := make([]string, 0, len(task.Needs))
|
|
for id, need := range task.Needs {
|
|
needJobIDs = append(needJobIDs, id)
|
|
needJob := &model.Job{
|
|
Outputs: need.Outputs,
|
|
Result: strings.ToLower(strings.TrimPrefix(need.Result.String(), "RESULT_")),
|
|
}
|
|
workflow.Jobs[id] = needJob
|
|
}
|
|
sort.Strings(needJobIDs)
|
|
|
|
rawNeeds := yaml.Node{
|
|
Kind: yaml.SequenceNode,
|
|
Content: make([]*yaml.Node, 0, len(needJobIDs)),
|
|
}
|
|
for _, id := range needJobIDs {
|
|
rawNeeds.Content = append(rawNeeds.Content, &yaml.Node{
|
|
Kind: yaml.ScalarNode,
|
|
Value: id,
|
|
})
|
|
}
|
|
|
|
workflow.Jobs[jobID].RawNeeds = rawNeeds
|
|
|
|
return workflow, jobID, nil
|
|
}
|