From cbf360f543272423c1b27fc54393b5628c5ffd79 Mon Sep 17 00:00:00 2001 From: ChristopherHX Date: Mon, 6 Mar 2023 13:24:32 +0800 Subject: [PATCH 1/6] fix docker executor on windows and local actions (#34) If the Workdir field doesn't ends with the filepath seperator, bad things happen Fixes #33 Sample for host mode on windows, needs be adjusted for linux e.g. replace pwsh with bash Also fixes ```yaml on: push jobs: _: runs-on: self-hosted steps: - uses: actions/checkout@v3 with: path: subdir/action - uses: ./subdir/action ``` with an action.yml in the same repo ```yaml runs: using: composite steps: - run: | echo "Hello World" shell: pwsh ``` Co-authored-by: Christopher Homberger Reviewed-on: https://gitea.com/gitea/act_runner/pulls/34 Reviewed-by: Jason Song Reviewed-by: Lunny Xiao Co-authored-by: ChristopherHX Co-committed-by: ChristopherHX --- runtime/task.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/task.go b/runtime/task.go index dbff4ea..f9b4a14 100644 --- a/runtime/task.go +++ b/runtime/task.go @@ -206,7 +206,7 @@ func (t *Task) Run(ctx context.Context, task *runnerv1.Task) (lastErr error) { input := t.Input config := &runner.Config{ - Workdir: "/" + preset.Repository, + Workdir: "." + string(filepath.Separator), BindWorkdir: false, ReuseContainers: false, ForcePull: input.forcePull, From ba181d4a503e6c944c887c924c220279132582e9 Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Mon, 6 Mar 2023 18:42:07 +0800 Subject: [PATCH 2/6] Add runner name to log (#37) User can get the name of the runner that executed the specified job. ![image](/attachments/61328f68-7223-4345-85c7-ac08781e81db) Co-authored-by: Zettat123 Reviewed-on: https://gitea.com/gitea/act_runner/pulls/37 Reviewed-by: Jason Song Reviewed-by: Lunny Xiao Co-authored-by: Zettat123 Co-committed-by: Zettat123 --- .gitignore | 7 ++++++- config/config.go | 3 +++ runtime/runtime.go | 2 +- runtime/task.go | 4 ++-- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 82ec058..4e43895 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,9 @@ act_runner .env .runner -coverage.txt \ No newline at end of file +coverage.txt +/gitea-vet + +# MS VSCode +.vscode +__debug_bin diff --git a/config/config.go b/config/config.go index 607df95..5b2772e 100644 --- a/config/config.go +++ b/config/config.go @@ -65,6 +65,9 @@ func FromEnviron() (Config, error) { if runner.UUID != "" { cfg.Runner.UUID = runner.UUID } + if runner.Name != "" { + cfg.Runner.Name = runner.Name + } if runner.Token != "" { cfg.Runner.Token = runner.Token } diff --git a/runtime/runtime.go b/runtime/runtime.go index 5ab8c93..f23eed0 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -26,7 +26,7 @@ func (s *Runner) Run(ctx context.Context, task *runnerv1.Task) error { env[k] = v } env["ACTIONS_CACHE_URL"] = s.CacheHandler.ExternalURL() + "/" - return NewTask(s.ForgeInstance, task.Id, s.Client, env, s.platformPicker).Run(ctx, task) + return NewTask(s.ForgeInstance, task.Id, s.Client, env, s.platformPicker).Run(ctx, task, s.Machine) } func (s *Runner) platformPicker(labels []string) string { diff --git a/runtime/task.go b/runtime/task.go index f9b4a14..561fd9c 100644 --- a/runtime/task.go +++ b/runtime/task.go @@ -112,7 +112,7 @@ func getToken(task *runnerv1.Task) string { return token } -func (t *Task) Run(ctx context.Context, task *runnerv1.Task) (lastErr error) { +func (t *Task) Run(ctx context.Context, task *runnerv1.Task, runnerName string) (lastErr error) { ctx, cancel := context.WithCancel(ctx) defer cancel() _, exist := globalTaskMap.Load(task.Id) @@ -140,7 +140,7 @@ func (t *Task) Run(ctx context.Context, task *runnerv1.Task) (lastErr error) { }() reporter.RunDaemon() - reporter.Logf("received task %v of job %v", task.Id, task.Context.Fields["job"].GetStringValue()) + reporter.Logf("%s received task %v of job %v", runnerName, task.Id, task.Context.Fields["job"].GetStringValue()) workflowsPath, err := getWorkflowsPath(t.Input.repoDirectory) if err != nil { From 65d2485f58d56631403afa6baee7e12d77340ba6 Mon Sep 17 00:00:00 2001 From: a1012112796 <1012112796@qq.com> Date: Wed, 8 Mar 2023 10:55:31 +0800 Subject: [PATCH 3/6] Add `exec` subcommand for runner so that we can run the tasks locally(#39) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Most codes are copied from https://gitea.com/gitea/act/src/branch/main/cmd and do some small changes to make it run again examples: ```SHELL ./act_runner exec -l ./act_runner exec -j lint ./act_runner exec -j lint -n ``` some example result: ![屏幕截图 2023-03-06 135735](/attachments/547bd05c-ade2-41f7-ba60-c9937fa32d5f) ![屏幕截图 2023-03-06 140643](/attachments/e8f48dba-c7f3-4daa-a163-aa9b36b1dc32) Signed-off-by: a1012112796 <1012112796@qq.com> fix #32 Reviewed-on: https://gitea.com/gitea/act_runner/pulls/39 Reviewed-by: Lunny Xiao Reviewed-by: Jason Song Co-authored-by: a1012112796 <1012112796@qq.com> Co-committed-by: a1012112796 <1012112796@qq.com> --- cmd/cmd.go | 4 +- cmd/exec.go | 448 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 451 insertions(+), 1 deletion(-) create mode 100644 cmd/exec.go diff --git a/cmd/cmd.go b/cmd/cmd.go index 528aecb..b1242c7 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -51,9 +51,11 @@ func Execute(ctx context.Context) { Args: cobra.MaximumNArgs(1), RunE: runDaemon(ctx, gArgs.EnvFile), } - // add all command rootCmd.AddCommand(daemonCmd) + // ./act_runner exec + rootCmd.AddCommand(loadExecCmd(ctx)) + // hide completion command rootCmd.CompletionOptions.HiddenDefaultCmd = true diff --git a/cmd/exec.go b/cmd/exec.go new file mode 100644 index 0000000..2e98eca --- /dev/null +++ b/cmd/exec.go @@ -0,0 +1,448 @@ +// Copyright 2023 The Gitea Authors. All rights reserved. +// Copyright 2019 nektos +// SPDX-License-Identifier: MIT + +package cmd + +import ( + "context" + "fmt" + "os" + "path/filepath" + "strconv" + "strings" + "time" + + "gitea.com/gitea/act_runner/artifactcache" + "github.com/joho/godotenv" + "github.com/nektos/act/pkg/artifacts" + "github.com/nektos/act/pkg/common" + "github.com/nektos/act/pkg/model" + "github.com/nektos/act/pkg/runner" + log "github.com/sirupsen/logrus" + "github.com/spf13/cobra" + "golang.org/x/term" +) + +type executeArgs struct { + runList bool + job string + event string + workdir string + workflowsPath string + noWorkflowRecurse bool + autodetectEvent bool + forcePull bool + forceRebuild bool + jsonLogger bool + envs []string + envfile string + secrets []string + defaultActionsUrl string + insecureSecrets bool + privileged bool + usernsMode string + containerArchitecture string + containerDaemonSocket string + useGitIgnore bool + containerCapAdd []string + containerCapDrop []string + artifactServerPath string + artifactServerPort string + noSkipCheckout bool + debug bool + dryrun bool + cacheHandler *artifactcache.Handler +} + +// WorkflowsPath returns path to workflow file(s) +func (i *executeArgs) WorkflowsPath() string { + return i.resolve(i.workflowsPath) +} + +// Envfile returns path to .env +func (i *executeArgs) Envfile() string { + return i.resolve(i.envfile) +} + +func (i *executeArgs) LoadSecrets() map[string]string { + s := make(map[string]string) + for _, secretPair := range i.secrets { + secretPairParts := strings.SplitN(secretPair, "=", 2) + secretPairParts[0] = strings.ToUpper(secretPairParts[0]) + if strings.ToUpper(s[secretPairParts[0]]) == secretPairParts[0] { + log.Errorf("Secret %s is already defined (secrets are case insensitive)", secretPairParts[0]) + } + if len(secretPairParts) == 2 { + s[secretPairParts[0]] = secretPairParts[1] + } else if env, ok := os.LookupEnv(secretPairParts[0]); ok && env != "" { + s[secretPairParts[0]] = env + } else { + fmt.Printf("Provide value for '%s': ", secretPairParts[0]) + val, err := term.ReadPassword(int(os.Stdin.Fd())) + fmt.Println() + if err != nil { + log.Errorf("failed to read input: %v", err) + os.Exit(1) + } + s[secretPairParts[0]] = string(val) + } + } + return s +} + +func readEnvs(path string, envs map[string]string) bool { + if _, err := os.Stat(path); err == nil { + env, err := godotenv.Read(path) + if err != nil { + log.Fatalf("Error loading from %s: %v", path, err) + } + for k, v := range env { + envs[k] = v + } + return true + } + return false +} + +func (i *executeArgs) LoadEnvs() map[string]string { + envs := make(map[string]string) + if i.envs != nil { + for _, envVar := range i.envs { + e := strings.SplitN(envVar, `=`, 2) + if len(e) == 2 { + envs[e[0]] = e[1] + } else { + envs[e[0]] = "" + } + } + } + _ = readEnvs(i.Envfile(), envs) + + envs["ACTIONS_CACHE_URL"] = i.cacheHandler.ExternalURL() + "/" + + return envs +} + +// Workdir returns path to workdir +func (i *executeArgs) Workdir() string { + return i.resolve(".") +} + +func (i *executeArgs) resolve(path string) string { + basedir, err := filepath.Abs(i.workdir) + if err != nil { + log.Fatal(err) + } + if path == "" { + return path + } + if !filepath.IsAbs(path) { + path = filepath.Join(basedir, path) + } + return path +} + +func printList(plan *model.Plan) error { + type lineInfoDef struct { + jobID string + jobName string + stage string + wfName string + wfFile string + events string + } + lineInfos := []lineInfoDef{} + + header := lineInfoDef{ + jobID: "Job ID", + jobName: "Job name", + stage: "Stage", + wfName: "Workflow name", + wfFile: "Workflow file", + events: "Events", + } + + jobs := map[string]bool{} + duplicateJobIDs := false + + jobIDMaxWidth := len(header.jobID) + jobNameMaxWidth := len(header.jobName) + stageMaxWidth := len(header.stage) + wfNameMaxWidth := len(header.wfName) + wfFileMaxWidth := len(header.wfFile) + eventsMaxWidth := len(header.events) + + for i, stage := range plan.Stages { + for _, r := range stage.Runs { + jobID := r.JobID + line := lineInfoDef{ + jobID: jobID, + jobName: r.String(), + stage: strconv.Itoa(i), + wfName: r.Workflow.Name, + wfFile: r.Workflow.File, + events: strings.Join(r.Workflow.On(), `,`), + } + if _, ok := jobs[jobID]; ok { + duplicateJobIDs = true + } else { + jobs[jobID] = true + } + lineInfos = append(lineInfos, line) + if jobIDMaxWidth < len(line.jobID) { + jobIDMaxWidth = len(line.jobID) + } + if jobNameMaxWidth < len(line.jobName) { + jobNameMaxWidth = len(line.jobName) + } + if stageMaxWidth < len(line.stage) { + stageMaxWidth = len(line.stage) + } + if wfNameMaxWidth < len(line.wfName) { + wfNameMaxWidth = len(line.wfName) + } + if wfFileMaxWidth < len(line.wfFile) { + wfFileMaxWidth = len(line.wfFile) + } + if eventsMaxWidth < len(line.events) { + eventsMaxWidth = len(line.events) + } + } + } + + jobIDMaxWidth += 2 + jobNameMaxWidth += 2 + stageMaxWidth += 2 + wfNameMaxWidth += 2 + wfFileMaxWidth += 2 + + fmt.Printf("%*s%*s%*s%*s%*s%*s\n", + -stageMaxWidth, header.stage, + -jobIDMaxWidth, header.jobID, + -jobNameMaxWidth, header.jobName, + -wfNameMaxWidth, header.wfName, + -wfFileMaxWidth, header.wfFile, + -eventsMaxWidth, header.events, + ) + for _, line := range lineInfos { + fmt.Printf("%*s%*s%*s%*s%*s%*s\n", + -stageMaxWidth, line.stage, + -jobIDMaxWidth, line.jobID, + -jobNameMaxWidth, line.jobName, + -wfNameMaxWidth, line.wfName, + -wfFileMaxWidth, line.wfFile, + -eventsMaxWidth, line.events, + ) + } + if duplicateJobIDs { + fmt.Print("\nDetected multiple jobs with the same job name, use `-W` to specify the path to the specific workflow.\n") + } + return nil +} + +func runExecList(ctx context.Context, planner model.WorkflowPlanner, execArgs *executeArgs) error { + // plan with filtered jobs - to be used for filtering only + var filterPlan *model.Plan + + // Determine the event name to be filtered + var filterEventName string = "" + + if len(execArgs.event) > 0 { + log.Infof("Using chosed event for filtering: %s", execArgs.event) + filterEventName = execArgs.event + } else if execArgs.autodetectEvent { + // collect all events from loaded workflows + events := planner.GetEvents() + + // set default event type to first event from many available + // this way user dont have to specify the event. + log.Infof("Using first detected workflow event for filtering: %s", events[0]) + + filterEventName = events[0] + } + + if execArgs.job != "" { + log.Infof("Preparing plan with a job: %s", execArgs.job) + filterPlan = planner.PlanJob(execArgs.job) + } else if filterEventName != "" { + log.Infof("Preparing plan for a event: %s", filterEventName) + filterPlan = planner.PlanEvent(filterEventName) + } else { + log.Infof("Preparing plan with all jobs") + filterPlan = planner.PlanAll() + } + + printList(filterPlan) + + return nil +} + +func runExec(ctx context.Context, execArgs *executeArgs) func(cmd *cobra.Command, args []string) error { + return func(cmd *cobra.Command, args []string) error { + planner, err := model.NewWorkflowPlanner(execArgs.WorkflowsPath(), execArgs.noWorkflowRecurse) + if err != nil { + return err + } + + if execArgs.runList { + return runExecList(ctx, planner, execArgs) + } + + // plan with triggered jobs + var plan *model.Plan + + // Determine the event name to be triggered + var eventName string + + // collect all events from loaded workflows + events := planner.GetEvents() + + if len(execArgs.event) > 0 { + log.Infof("Using chosed event for filtering: %s", execArgs.event) + eventName = args[0] + } else if len(events) == 1 && len(events[0]) > 0 { + log.Infof("Using the only detected workflow event: %s", events[0]) + eventName = events[0] + } else if execArgs.autodetectEvent && len(events) > 0 && len(events[0]) > 0 { + // set default event type to first event from many available + // this way user dont have to specify the event. + log.Infof("Using first detected workflow event: %s", events[0]) + eventName = events[0] + } else { + log.Infof("Using default workflow event: push") + eventName = "push" + } + + // build the plan for this run + if execArgs.job != "" { + log.Infof("Planning job: %s", execArgs.job) + plan = planner.PlanJob(execArgs.job) + } else { + log.Infof("Planning jobs for event: %s", eventName) + plan = planner.PlanEvent(eventName) + } + + maxLifetime := 3 * time.Hour + if deadline, ok := ctx.Deadline(); ok { + maxLifetime = time.Until(deadline) + } + + // init a cache server + handler, err := artifactcache.NewHandler() + if err != nil { + return err + } + log.Infof("cache handler listens on: %v", handler.ExternalURL()) + execArgs.cacheHandler = handler + + // run the plan + config := &runner.Config{ + Workdir: execArgs.Workdir(), + BindWorkdir: false, + ReuseContainers: false, + ForcePull: execArgs.forcePull, + ForceRebuild: execArgs.forceRebuild, + LogOutput: true, + JSONLogger: execArgs.jsonLogger, + Env: execArgs.LoadEnvs(), + Secrets: execArgs.LoadSecrets(), + InsecureSecrets: execArgs.insecureSecrets, + Privileged: execArgs.privileged, + UsernsMode: execArgs.usernsMode, + ContainerArchitecture: execArgs.containerArchitecture, + ContainerDaemonSocket: execArgs.containerDaemonSocket, + UseGitIgnore: execArgs.useGitIgnore, + // GitHubInstance: t.client.Address(), + ContainerCapAdd: execArgs.containerCapAdd, + ContainerCapDrop: execArgs.containerCapDrop, + AutoRemove: true, + ArtifactServerPath: execArgs.artifactServerPath, + ArtifactServerPort: execArgs.artifactServerPort, + NoSkipCheckout: execArgs.noSkipCheckout, + // PresetGitHubContext: preset, + // EventJSON: string(eventJSON), + ContainerNamePrefix: fmt.Sprintf("GITEA-ACTIONS-TASK-%s", eventName), + ContainerMaxLifetime: maxLifetime, + ContainerNetworkMode: "bridge", + DefaultActionInstance: execArgs.defaultActionsUrl, + PlatformPicker: func(_ []string) string { + return "node:16-bullseye" + }, + } + + // TODO: handle log level config + // waiting https://gitea.com/gitea/act/pulls/19 + // if !execArgs.debug { + // logLevel := log.Level(log.InfoLevel) + // config.JobLoggerLevel = &logLevel + // } + + r, err := runner.New(config) + if err != nil { + return err + } + + if len(execArgs.artifactServerPath) == 0 { + tempDir, err := os.MkdirTemp("", "gitea-act-") + if err != nil { + fmt.Println(err) + } + defer os.RemoveAll(tempDir) + + execArgs.artifactServerPath = tempDir + } + + artifactCancel := artifacts.Serve(ctx, execArgs.artifactServerPath, execArgs.artifactServerPort) + log.Debugf("artifacts server started at %s:%s", execArgs.artifactServerPath, execArgs.artifactServerPort) + + ctx = common.WithDryrun(ctx, execArgs.dryrun) + executor := r.NewPlanExecutor(plan).Finally(func(ctx context.Context) error { + artifactCancel() + return nil + }) + + return executor(ctx) + } +} + +func loadExecCmd(ctx context.Context) *cobra.Command { + execArg := executeArgs{} + + execCmd := &cobra.Command{ + Use: "exec", + Short: "Run workflow locally.", + Args: cobra.MaximumNArgs(20), + RunE: runExec(ctx, &execArg), + } + + execCmd.Flags().BoolVarP(&execArg.runList, "list", "l", false, "list workflows") + execCmd.Flags().StringVarP(&execArg.job, "job", "j", "", "run a specific job ID") + execCmd.Flags().StringVarP(&execArg.event, "event", "E", "", "run a event name") + execCmd.PersistentFlags().StringVarP(&execArg.workflowsPath, "workflows", "W", "./.gitea/workflows/", "path to workflow file(s)") + execCmd.PersistentFlags().StringVarP(&execArg.workdir, "directory", "C", ".", "working directory") + execCmd.PersistentFlags().BoolVarP(&execArg.noWorkflowRecurse, "no-recurse", "", false, "Flag to disable running workflows from subdirectories of specified path in '--workflows'/'-W' flag") + execCmd.Flags().BoolVarP(&execArg.autodetectEvent, "detect-event", "", false, "Use first event type from workflow as event that triggered the workflow") + execCmd.Flags().BoolVarP(&execArg.forcePull, "pull", "p", false, "pull docker image(s) even if already present") + execCmd.Flags().BoolVarP(&execArg.forceRebuild, "rebuild", "", false, "rebuild local action docker image(s) even if already present") + execCmd.PersistentFlags().BoolVar(&execArg.jsonLogger, "json", false, "Output logs in json format") + execCmd.Flags().StringArrayVarP(&execArg.envs, "env", "", []string{}, "env to make available to actions with optional value (e.g. --env myenv=foo or --env myenv)") + execCmd.PersistentFlags().StringVarP(&execArg.envfile, "env-file", "", ".env", "environment file to read and use as env in the containers") + execCmd.Flags().StringArrayVarP(&execArg.secrets, "secret", "s", []string{}, "secret to make available to actions with optional value (e.g. -s mysecret=foo or -s mysecret)") + execCmd.PersistentFlags().BoolVarP(&execArg.insecureSecrets, "insecure-secrets", "", false, "NOT RECOMMENDED! Doesn't hide secrets while printing logs.") + execCmd.Flags().BoolVar(&execArg.privileged, "privileged", false, "use privileged mode") + execCmd.Flags().StringVar(&execArg.usernsMode, "userns", "", "user namespace to use") + execCmd.PersistentFlags().StringVarP(&execArg.containerArchitecture, "container-architecture", "", "", "Architecture which should be used to run containers, e.g.: linux/amd64. If not specified, will use host default architecture. Requires Docker server API Version 1.41+. Ignored on earlier Docker server platforms.") + execCmd.PersistentFlags().StringVarP(&execArg.containerDaemonSocket, "container-daemon-socket", "", "/var/run/docker.sock", "Path to Docker daemon socket which will be mounted to containers") + execCmd.Flags().BoolVar(&execArg.useGitIgnore, "use-gitignore", true, "Controls whether paths specified in .gitignore should be copied into container") + execCmd.Flags().StringArrayVarP(&execArg.containerCapAdd, "container-cap-add", "", []string{}, "kernel capabilities to add to the workflow containers (e.g. --container-cap-add SYS_PTRACE)") + execCmd.Flags().StringArrayVarP(&execArg.containerCapDrop, "container-cap-drop", "", []string{}, "kernel capabilities to remove from the workflow containers (e.g. --container-cap-drop SYS_PTRACE)") + execCmd.PersistentFlags().StringVarP(&execArg.artifactServerPath, "artifact-server-path", "", ".", "Defines the path where the artifact server stores uploads and retrieves downloads from. If not specified the artifact server will not start.") + execCmd.PersistentFlags().StringVarP(&execArg.artifactServerPort, "artifact-server-port", "", "34567", "Defines the port where the artifact server listens (will only bind to localhost).") + execCmd.PersistentFlags().StringVarP(&execArg.defaultActionsUrl, "default-actions-url", "", "https://gitea.com", "Defines the default url of action instance.") + execCmd.PersistentFlags().BoolVarP(&execArg.noSkipCheckout, "no-skip-checkout", "", false, "Do not skip actions/checkout") + execCmd.PersistentFlags().BoolVarP(&execArg.debug, "debug", "d", false, "enable debug log") + execCmd.PersistentFlags().BoolVarP(&execArg.dryrun, "dryrun", "n", false, "dryrun mode") + + return execCmd +} From 4d5007a3332c0daf6f600580f3dae226b5126fa3 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Wed, 8 Mar 2023 15:01:49 +0100 Subject: [PATCH 4/6] s/gitea/forgejo/ for exec --- cmd/exec.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/exec.go b/cmd/exec.go index 2e98eca..ee0c069 100644 --- a/cmd/exec.go +++ b/cmd/exec.go @@ -13,7 +13,7 @@ import ( "strings" "time" - "gitea.com/gitea/act_runner/artifactcache" + "codeberg.org/forgejo/runner/artifactcache" "github.com/joho/godotenv" "github.com/nektos/act/pkg/artifacts" "github.com/nektos/act/pkg/common" @@ -419,7 +419,7 @@ func loadExecCmd(ctx context.Context) *cobra.Command { execCmd.Flags().BoolVarP(&execArg.runList, "list", "l", false, "list workflows") execCmd.Flags().StringVarP(&execArg.job, "job", "j", "", "run a specific job ID") execCmd.Flags().StringVarP(&execArg.event, "event", "E", "", "run a event name") - execCmd.PersistentFlags().StringVarP(&execArg.workflowsPath, "workflows", "W", "./.gitea/workflows/", "path to workflow file(s)") + execCmd.PersistentFlags().StringVarP(&execArg.workflowsPath, "workflows", "W", "./.forgejo/workflows/", "path to workflow file(s)") execCmd.PersistentFlags().StringVarP(&execArg.workdir, "directory", "C", ".", "working directory") execCmd.PersistentFlags().BoolVarP(&execArg.noWorkflowRecurse, "no-recurse", "", false, "Flag to disable running workflows from subdirectories of specified path in '--workflows'/'-W' flag") execCmd.Flags().BoolVarP(&execArg.autodetectEvent, "detect-event", "", false, "Use first event type from workflow as event that triggered the workflow") @@ -439,7 +439,7 @@ func loadExecCmd(ctx context.Context) *cobra.Command { execCmd.Flags().StringArrayVarP(&execArg.containerCapDrop, "container-cap-drop", "", []string{}, "kernel capabilities to remove from the workflow containers (e.g. --container-cap-drop SYS_PTRACE)") execCmd.PersistentFlags().StringVarP(&execArg.artifactServerPath, "artifact-server-path", "", ".", "Defines the path where the artifact server stores uploads and retrieves downloads from. If not specified the artifact server will not start.") execCmd.PersistentFlags().StringVarP(&execArg.artifactServerPort, "artifact-server-port", "", "34567", "Defines the port where the artifact server listens (will only bind to localhost).") - execCmd.PersistentFlags().StringVarP(&execArg.defaultActionsUrl, "default-actions-url", "", "https://gitea.com", "Defines the default url of action instance.") + execCmd.PersistentFlags().StringVarP(&execArg.defaultActionsUrl, "default-actions-url", "", "https://codeberg.org", "Defines the default url of action instance.") execCmd.PersistentFlags().BoolVarP(&execArg.noSkipCheckout, "no-skip-checkout", "", false, "Do not skip actions/checkout") execCmd.PersistentFlags().BoolVarP(&execArg.debug, "debug", "d", false, "enable debug log") execCmd.PersistentFlags().BoolVarP(&execArg.dryrun, "dryrun", "n", false, "dryrun mode") From 40954c450dc11f3a48f08cf0b9ba902ba7fd7a19 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Wed, 8 Mar 2023 15:02:28 +0100 Subject: [PATCH 5/6] .gitignore forgejo-runner --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 4e43895..a77f656 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -act_runner +forgejo-runner .env .runner coverage.txt From 048b2e630fc4203816c4136bef929441aec2788e Mon Sep 17 00:00:00 2001 From: HesterG Date: Wed, 8 Mar 2023 21:32:54 +0800 Subject: [PATCH 6/6] Fix wrong last step duration when job failed (#41) This PR is to fix the wrong last step duration when job failed like shown in the screenshot. The reason is because when job failed, `Fire` function did not pass in Time, and `r.state.StoppedAt` is by default set to `0001-01-01 08:05:43 +0805 LMT`, which is later on reported to gitea by `UpdateTask`, which calls `UpdateTaskByState` to update the `task.Stopped`, and `task.Stopped` is used in `FullSteps`, resulting in wrong calcaulation of last step duration. Co-authored-by: nickname Co-authored-by: Lunny Xiao Reviewed-on: https://gitea.com/gitea/act_runner/pulls/41 Reviewed-by: Jason Song Reviewed-by: Lunny Xiao Co-authored-by: HesterG Co-committed-by: HesterG --- runtime/task.go | 1 + 1 file changed, 1 insertion(+) diff --git a/runtime/task.go b/runtime/task.go index 561fd9c..ac15323 100644 --- a/runtime/task.go +++ b/runtime/task.go @@ -134,6 +134,7 @@ func (t *Task) Run(ctx context.Context, task *runnerv1.Task, runnerName string) Data: log.Fields{ "jobResult": "failure", }, + Time: time.Now(), }) } _ = reporter.Close(lastWords)