Support go run on action (#12)

Reviewed-on: https://gitea.com/gitea/act/pulls/12
Reviewed-by: Jason Song <i@wolfogre.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
Lunny Xiao 2023-02-15 16:10:15 +08:00 committed by Jason Song
parent e46ede1b17
commit 4b99ed8916
2 changed files with 14 additions and 3 deletions

View file

@ -42,6 +42,8 @@ const (
ActionRunsUsingDocker = "docker" ActionRunsUsingDocker = "docker"
// ActionRunsUsingComposite for running composite // ActionRunsUsingComposite for running composite
ActionRunsUsingComposite = "composite" ActionRunsUsingComposite = "composite"
// ActionRunsUsingGo for running with go
ActionRunsUsingGo = "go"
) )
// ActionRuns are a field in Action // ActionRuns are a field in Action

View file

@ -29,8 +29,10 @@ type actionStep interface {
type readAction func(ctx context.Context, step *model.Step, actionDir string, actionPath string, readFile actionYamlReader, writeFile fileWriter) (*model.Action, error) type readAction func(ctx context.Context, step *model.Step, actionDir string, actionPath string, readFile actionYamlReader, writeFile fileWriter) (*model.Action, error)
type actionYamlReader func(filename string) (io.Reader, io.Closer, error) type (
type fileWriter func(filename string, data []byte, perm fs.FileMode) error actionYamlReader func(filename string) (io.Reader, io.Closer, error)
fileWriter func(filename string, data []byte, perm fs.FileMode) error
)
type runAction func(step actionStep, actionDir string, remoteAction *remoteAction) common.Executor type runAction func(step actionStep, actionDir string, remoteAction *remoteAction) common.Executor
@ -61,7 +63,7 @@ func readActionImpl(ctx context.Context, step *model.Step, actionDir string, act
if b, err = trampoline.ReadFile("res/trampoline.js"); err != nil { if b, err = trampoline.ReadFile("res/trampoline.js"); err != nil {
return nil, err return nil, err
} }
err2 := writeFile(filepath.Join(actionDir, actionPath, "trampoline.js"), b, 0400) err2 := writeFile(filepath.Join(actionDir, actionPath, "trampoline.js"), b, 0o400)
if err2 != nil { if err2 != nil {
return nil, err2 return nil, err2
} }
@ -167,6 +169,13 @@ func runActionImpl(step actionStep, actionDir string, remoteAction *remoteAction
} }
return execAsComposite(step)(ctx) return execAsComposite(step)(ctx)
case model.ActionRunsUsingGo:
if err := maybeCopyToActionDir(ctx, step, actionDir, actionPath, containerActionDir); err != nil {
return err
}
containerArgs := []string{"go", "run", path.Join(containerActionDir, action.Runs.Main)}
logger.Debugf("executing remote job container: %s", containerArgs)
return rc.execJobContainer(containerArgs, *step.getEnv(), "", "")(ctx)
default: default:
return fmt.Errorf(fmt.Sprintf("The runs.using key must be one of: %v, got %s", []string{ return fmt.Errorf(fmt.Sprintf("The runs.using key must be one of: %v, got %s", []string{
model.ActionRunsUsingDocker, model.ActionRunsUsingDocker,