Files
act_runner/act/runner/step_factory.go
bircni 7ad12038d1 feat(runner): add built-in actions framework with checkout (#871)
Adds built-in actions, native Go actions shipped with the runner and selected with `uses: builtin:<name>`. Jobs need no action download and no Node in their image.

The first one is `builtin:checkout`, a subset of `actions/checkout` with `repository`, `ref`, `token`, `path` and `fetch-depth`. Other inputs fail the step. The runner clones shallowly on its host and copies the tree into the job, while `gitea-runner exec` copies the local working directory for the workflow's own ref.

`actions/checkout` and other remote actions are unchanged. A clone ref of `HEAD` now shallow-clones the remote's default branch, which checkout uses for other repositories.

---------

Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: silverwind <2021+silverwind@noreply.gitea.com>
Reviewed-on: https://gitea.com/gitea/runner/pulls/871
Reviewed-by: silverwind <2021+silverwind@noreply.gitea.com>
Co-authored-by: bircni <bircni@icloud.com>
2026-09-24 15:47:58 +00:00

66 lines
1.6 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 (
"fmt"
"maps"
"slices"
"strings"
"gitea.dev/actionslib/pkg/model"
)
type stepFactory interface {
newStep(step *model.Step, rc *RunContext) (step, error)
}
type stepFactoryImpl struct{}
func (sf *stepFactoryImpl) newStep(stepModel *model.Step, rc *RunContext) (step, error) {
switch stepModel.Type() {
case model.StepTypeInvalid:
return nil, fmt.Errorf("invalid run/uses syntax for job:%s step:%+v", rc.Run, stepModel)
case model.StepTypeRun:
return &stepRun{
Step: stepModel,
RunContext: rc,
}, nil
case model.StepTypeUsesActionLocal:
return &stepActionLocal{
Step: stepModel,
RunContext: rc,
readAction: readActionImpl,
runAction: runActionImpl,
}, nil
case model.StepTypeUsesActionRemote:
if name, ok := strings.CutPrefix(stepModel.Uses, "builtin:"); ok {
run, ok := builtinActions[name]
if !ok {
return nil, fmt.Errorf("unknown built-in action %q (known: %v) for job:%s step:%+v",
name, slices.Sorted(maps.Keys(builtinActions)), rc.Run, stepModel)
}
return &stepActionBuiltin{
Step: stepModel,
RunContext: rc,
run: run,
}, nil
}
return &stepActionRemote{
Step: stepModel,
RunContext: rc,
readAction: readActionImpl,
runAction: runActionImpl,
}, nil
case model.StepTypeUsesDockerURL:
return &stepDocker{
Step: stepModel,
RunContext: rc,
}, nil
}
return nil, fmt.Errorf("unable to determine how to run job:%s step:%+v", rc.Run, stepModel)
}