mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-08-16 18:01:34 +00:00
Pre-req for support `concurrency` clauses for Gitea Actions, later added to Gitea in PR: https://github.com/go-gitea/gitea/pull/32751. Unit tests added in this PR relative to upstream. Squashes PRs https://gitea.com/gitea/act/pulls/124 & https://gitea.com/gitea/act/pulls/139, as noted in https://code.forgejo.org/forgejo/runner/issues/678 Reviewed-on: https://gitea.com/gitea/act/pulls/124 Reviewed-by: Lunny Xiao <lunny@noreply.gitea.com> Co-authored-by: Zettat123 <zettat123@gmail.com> Co-committed-by: Zettat123 <zettat123@gmail.com> Reviewed-on: https://gitea.com/gitea/act/pulls/139 Reviewed-by: Zettat123 <zettat123@noreply.gitea.com> Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: ChristopherHX <christopher.homberger@web.de> Co-committed-by: ChristopherHX <christopher.homberger@web.de> <!--start release-notes-assistant--> <!--URL:https://code.forgejo.org/forgejo/runner--> - features - [PR](https://code.forgejo.org/forgejo/runner/pulls/827): <!--number 827 --><!--line 0 --><!--description ZmVhdDogc3VwcG9ydCBldmFsdWF0aW9uIG9mIGNvbmN1cnJlbmN5IGNsYXVzZXMgaW4gcnVubmVy-->feat: support evaluation of concurrency clauses in runner<!--description--> <!--end release-notes-assistant--> Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/827 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>
84 lines
2 KiB
Go
84 lines
2 KiB
Go
package jobparser
|
|
|
|
import (
|
|
"code.forgejo.org/forgejo/runner/v9/act/exprparser"
|
|
"code.forgejo.org/forgejo/runner/v9/act/model"
|
|
"gopkg.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]interface{},
|
|
gitCtx *model.GithubContext,
|
|
results map[string]*JobResult,
|
|
vars map[string]string,
|
|
inputs map[string]interface{},
|
|
) exprparser.Interpreter {
|
|
strategy := make(map[string]interface{})
|
|
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)
|
|
}
|
|
|
|
// JobResult is the minimum requirement of job results for Interpeter
|
|
type JobResult struct {
|
|
Needs []string
|
|
Result string
|
|
Outputs map[string]string
|
|
}
|