mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-09-30 19:22:09 +00:00
- Changes `EvaluateConcurrency` to `EvaluateWorkflowConcurrency`, which has no job-related arguments - Changes gitContext to be sent as an object rather than a map - Allows `nil` to be returned for `cancelInProgress`, which indicates that the value wasn't specified in the input yaml -- required for distinguishing the `cancel-in-progress: false` case from not being specified at all. ReadWorkflowRawConcurrency & EvaluateWorkflowConcurrency were never used in forgejo yet, so this shouldn't break the forgejo build. Prerequisite for https://codeberg.org/forgejo/forgejo/pulls/9434. <!--start release-notes-assistant--> <!--URL:https://code.forgejo.org/forgejo/runner--> - features - [PR](https://code.forgejo.org/forgejo/runner/pulls/1026): <!--number 1026 --><!--line 0 --><!--description ZmVhdDogc3VwcG9ydCBldmFsdWF0aW5nIHdvcmtmbG93LWxldmVsIGNvbmN1cnJlbmN5IGJsb2NrcyBpbiBqb2JwYXJzZXI=-->feat: support evaluating workflow-level concurrency blocks in jobparser<!--description--> <!--end release-notes-assistant--> Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1026 Reviewed-by: earl-warren <earl-warren@noreply.code.forgejo.org> Co-authored-by: Mathieu Fenniak <mathieu@fenniak.net> Co-committed-by: Mathieu Fenniak <mathieu@fenniak.net>
114 lines
2.8 KiB
Go
114 lines
2.8 KiB
Go
package jobparser
|
|
|
|
import (
|
|
"code.forgejo.org/forgejo/runner/v11/act/exprparser"
|
|
"code.forgejo.org/forgejo/runner/v11/act/model"
|
|
"go.yaml.in/yaml/v3"
|
|
)
|
|
|
|
// NewInterpeter returns an interpeter used in the server,
|
|
// need github, needs, strategy, matrix, inputs context only,
|
|
// see https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability
|
|
func NewInterpeter(
|
|
jobID string,
|
|
job *model.Job,
|
|
matrix map[string]any,
|
|
gitCtx *model.GithubContext,
|
|
results map[string]*JobResult,
|
|
vars map[string]string,
|
|
inputs map[string]any,
|
|
) exprparser.Interpreter {
|
|
strategy := make(map[string]any)
|
|
if job.Strategy != nil {
|
|
strategy["fail-fast"] = job.Strategy.FailFast
|
|
strategy["max-parallel"] = job.Strategy.MaxParallel
|
|
}
|
|
|
|
run := &model.Run{
|
|
Workflow: &model.Workflow{
|
|
Jobs: map[string]*model.Job{},
|
|
},
|
|
JobID: jobID,
|
|
}
|
|
for id, result := range results {
|
|
need := yaml.Node{}
|
|
_ = need.Encode(result.Needs)
|
|
run.Workflow.Jobs[id] = &model.Job{
|
|
RawNeeds: need,
|
|
Result: result.Result,
|
|
Outputs: result.Outputs,
|
|
}
|
|
}
|
|
|
|
jobs := run.Workflow.Jobs
|
|
jobNeeds := run.Job().Needs()
|
|
|
|
using := map[string]exprparser.Needs{}
|
|
for _, need := range jobNeeds {
|
|
if v, ok := jobs[need]; ok {
|
|
using[need] = exprparser.Needs{
|
|
Outputs: v.Outputs,
|
|
Result: v.Result,
|
|
}
|
|
}
|
|
}
|
|
|
|
ee := &exprparser.EvaluationEnvironment{
|
|
Github: gitCtx,
|
|
Env: nil, // no need
|
|
Job: nil, // no need
|
|
Steps: nil, // no need
|
|
Runner: nil, // no need
|
|
Secrets: nil, // no need
|
|
Strategy: strategy,
|
|
Matrix: matrix,
|
|
Needs: using,
|
|
Inputs: inputs,
|
|
Vars: vars,
|
|
}
|
|
|
|
config := exprparser.Config{
|
|
Run: run,
|
|
WorkingDir: "", // WorkingDir is used for the function hashFiles, but it's not needed in the server
|
|
Context: "job",
|
|
}
|
|
|
|
return exprparser.NewInterpeter(ee, config)
|
|
}
|
|
|
|
// Returns an interpeter used in the server in the context of workflow-level templates. Needs github, inputs, and vars
|
|
// context only.
|
|
func NewWorkflowInterpeter(
|
|
gitCtx *model.GithubContext,
|
|
vars map[string]string,
|
|
inputs map[string]any,
|
|
) exprparser.Interpreter {
|
|
ee := &exprparser.EvaluationEnvironment{
|
|
Github: gitCtx,
|
|
Env: nil, // no need
|
|
Job: nil, // no need
|
|
Steps: nil, // no need
|
|
Runner: nil, // no need
|
|
Secrets: nil, // no need
|
|
Strategy: nil, // no need
|
|
Matrix: nil, // no need
|
|
Needs: nil, // no need
|
|
Inputs: inputs,
|
|
Vars: vars,
|
|
}
|
|
|
|
config := exprparser.Config{
|
|
Run: nil,
|
|
WorkingDir: "", // WorkingDir is used for the function hashFiles, but it's not needed in the server
|
|
Context: "workflow",
|
|
}
|
|
|
|
return exprparser.NewInterpeter(ee, config)
|
|
}
|
|
|
|
// JobResult is the minimum requirement of job results for Interpeter
|
|
type JobResult struct {
|
|
Needs []string
|
|
Result string
|
|
Outputs map[string]string
|
|
}
|