mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-09 05:38:54 +09:00
2087d4a1a5
Pairs with https://gitea.com/gitea/runner/pulls/1143. Gitea depends on `gitea.com/gitea/runner` for exactly two packages: `act/model` and `act/exprparser`, the workflow model and the expression evaluator it needs to parse workflows and to build the task payload the runner consumes. Pulling the whole runner module in for that is heavy and puts shared code in the repository of one of the two consumers. Both packages now live in `gitea.dev/actionslib` (`pkg/model`, `pkg/exprparser`), the module Gitea and the runner already share for the runner API, so the dependency on the runner repository is dropped here. ### Changes - `gitea.com/gitea/runner/act/model` -> `gitea.dev/actionslib/pkg/model`, `.../act/exprparser` -> `gitea.dev/actionslib/pkg/exprparser` (22 files, import paths only). - `routers/api/actions/runner/interceptor.go` takes the `x-runner-uuid` / `x-runner-token` names from `gitea.dev/actionslib/pkg/protocol` instead of repeating the literals the runner also has. - `go.mod`: `gitea.com/gitea/runner` removed. --------- Signed-off-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Zettat123 <zettat123@gmail.com>
92 lines
2.4 KiB
Go
92 lines
2.4 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package jobparser
|
|
|
|
import (
|
|
"gitea.dev/actionslib/pkg/exprparser"
|
|
"gitea.dev/actionslib/pkg/model"
|
|
|
|
"go.yaml.in/yaml/v4"
|
|
)
|
|
|
|
// 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
|
|
// TODO: The empty JobContext.Status is right for now because Gitea never checks `if` condition when the workflow run is cancelled.
|
|
// This is an implementation gap in Gitea Actions. When a workflow run is cancelled, Gitea should check the job's `if` condition,
|
|
// and if the condition is met (e.g. `if: ${{ cancelled() }}` ), the job should be executed rather than cancelled.
|
|
Job: &model.JobContext{},
|
|
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
|
|
}
|