mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-08-13 22:41:54 +02:00
Gitea needs the workflow model and the expression evaluator to parse workflows and to build the task payload this runner consumes, so today it depends on `gitea.com/gitea/runner` just for `act/model` and `act/exprparser`. Both packages now live in `gitea.dev/actionslib` (`pkg/model`, `pkg/exprparser`), the module both sides already share, and this repository consumes them from there. ### Changes - `act/model` and `act/exprparser` are deleted, all imports point at `gitea.dev/actionslib/pkg/...`. - New `act/ghcontext` package: the `GithubContext` helpers that need a git checkout on disk (`SetRef`, `SetSha`, `SetRepositoryAndOwner`) are runner only and would drag a git client plus the act context logger into the shared module, so they stay here as functions, with their tests. Only caller is `RunContext.getGithubContext`. - `act/common.CartesianProduct` moved to the shared model package, `act/model` was its only user. - `act/model/testdata/container-volumes` moved to `act/runner/testdata/container-volumes`, its only user is `runner_test.go`. - `internal/pkg/client.UUIDHeader` / `TokenHeader` now alias `pkg/protocol`, so the header names cannot drift apart from Gitea. ### Notes - No behaviour change intended: the moved files are unchanged apart from the import paths and the split described above. - `go.mod` depends on the released `gitea.dev/actionslib v0.7.0`, which carries both https://gitea.com/gitea/actionslib/pulls/11 and the `model.UsesHash` port in https://gitea.com/gitea/actionslib/pulls/14 that `main` needs after https://gitea.com/gitea/runner/pulls/1150. - Verified with `go build ./...`, `go vet ./...` and `go test ./act/... ./internal/...`; the docker based `act/runner` integration tests (`TestRunEvent`, `TestRunMatrixWithUserDefinedInclusions`) fail identically with and without this change in my environment. Assisted-by: Codet:GPT-5.1-Codex Reviewed-on: https://gitea.com/gitea/runner/pulls/1143 Reviewed-by: silverwind <[email protected]>
144 lines
3.9 KiB
Go
144 lines
3.9 KiB
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// Copyright 2022 The nektos/act Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package runner
|
|
|
|
import (
|
|
"archive/tar"
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
"io/fs"
|
|
"os"
|
|
"path"
|
|
"path/filepath"
|
|
|
|
"gitea.com/gitea/runner/act/common"
|
|
|
|
"gitea.dev/actionslib/pkg/model"
|
|
)
|
|
|
|
type stepActionLocal struct {
|
|
Step *model.Step
|
|
RunContext *RunContext
|
|
compositeRunContext *RunContext
|
|
compositeSteps *compositeSteps
|
|
runAction runAction
|
|
readAction readAction
|
|
env map[string]string
|
|
action *model.Action
|
|
}
|
|
|
|
func (sal *stepActionLocal) pre() common.Executor {
|
|
sal.env = map[string]string{}
|
|
|
|
return func(ctx context.Context) error {
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func (sal *stepActionLocal) main() common.Executor {
|
|
return runStepExecutor(sal, stepStageMain, func(ctx context.Context) error {
|
|
if common.Dryrun(ctx) {
|
|
return nil
|
|
}
|
|
|
|
printRunActionHeader(ctx, sal.Step, sal.env, sal.getRunContext())
|
|
rawLogger := common.Logger(ctx).WithField(rawOutputField, true)
|
|
defer rawLogger.Infof("::endgroup::")
|
|
|
|
actionDir := filepath.Join(sal.getRunContext().Config.Workdir, sal.Step.Uses)
|
|
|
|
localReader := func(ctx context.Context) actionYamlReader {
|
|
_, cpath := getContainerActionPaths(sal.Step, path.Join(actionDir, ""), sal.RunContext)
|
|
return func(filename string) (io.Reader, io.Closer, error) {
|
|
spath := path.Join(cpath, filename)
|
|
for range maxSymlinkDepth {
|
|
tars, err := sal.RunContext.JobContainer.GetContainerArchive(ctx, spath)
|
|
if errors.Is(err, fs.ErrNotExist) {
|
|
return nil, nil, err
|
|
} else if err != nil {
|
|
return nil, nil, fs.ErrNotExist
|
|
}
|
|
treader := tar.NewReader(tars)
|
|
header, err := treader.Next()
|
|
if errors.Is(err, io.EOF) {
|
|
return nil, nil, os.ErrNotExist
|
|
} else if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
if header.FileInfo().Mode()&os.ModeSymlink == os.ModeSymlink {
|
|
spath, err = symlinkJoin(spath, header.Linkname, cpath)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
} else {
|
|
return treader, tars, nil
|
|
}
|
|
}
|
|
return nil, nil, fmt.Errorf("max depth %d of symlinks exceeded while reading %s", maxSymlinkDepth, spath)
|
|
}
|
|
}
|
|
|
|
actionModel, err := sal.readAction(ctx, sal.Step, actionDir, "", localReader(ctx), os.WriteFile)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
sal.action = actionModel
|
|
|
|
return sal.runAction(sal, actionDir, nil)(ctx)
|
|
})
|
|
}
|
|
|
|
func (sal *stepActionLocal) post() common.Executor {
|
|
return runStepExecutor(sal, stepStagePost, runPostStep(sal)).If(hasPostStep(sal)).If(shouldRunPostStep(sal))
|
|
}
|
|
|
|
func (sal *stepActionLocal) getRunContext() *RunContext {
|
|
return sal.RunContext
|
|
}
|
|
|
|
func (sal *stepActionLocal) getGithubContext(ctx context.Context) *model.GithubContext {
|
|
return sal.getRunContext().getGithubContext(ctx)
|
|
}
|
|
|
|
func (sal *stepActionLocal) getStepModel() *model.Step {
|
|
return sal.Step
|
|
}
|
|
|
|
func (sal *stepActionLocal) getEnv() *map[string]string {
|
|
return &sal.env
|
|
}
|
|
|
|
func (sal *stepActionLocal) getIfExpression(_ context.Context, stage stepStage) string {
|
|
switch stage {
|
|
case stepStageMain:
|
|
return sal.Step.If.Value
|
|
case stepStagePost:
|
|
return sal.action.Runs.PostIf
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func (sal *stepActionLocal) getActionModel() *model.Action {
|
|
return sal.action
|
|
}
|
|
|
|
func (sal *stepActionLocal) getCompositeRunContext(ctx context.Context) *RunContext {
|
|
if sal.compositeRunContext == nil {
|
|
actionDir := filepath.Join(sal.RunContext.Config.Workdir, sal.Step.Uses)
|
|
_, containerActionDir := getContainerActionPaths(sal.getStepModel(), actionDir, sal.RunContext)
|
|
|
|
sal.compositeRunContext = newCompositeRunContext(ctx, sal.RunContext, sal, containerActionDir)
|
|
sal.compositeSteps = sal.compositeRunContext.compositeExecutor(sal.action)
|
|
}
|
|
return sal.compositeRunContext
|
|
}
|
|
|
|
func (sal *stepActionLocal) getCompositeSteps() *compositeSteps {
|
|
return sal.compositeSteps
|
|
}
|