successfully able to run simple workflows
Signed-off-by: Casey Lee <cplee@nektos.com>
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/nektos/act/pkg/common"
|
||||
@@ -21,7 +20,7 @@ func drawGraph(plan *model.Plan) error {
|
||||
|
||||
ids := make([]string, 0)
|
||||
for _, r := range stage.Runs {
|
||||
ids = append(ids, fmt.Sprintf("%s/%s", r.Workflow.Name, r.JobID))
|
||||
ids = append(ids, r.String())
|
||||
}
|
||||
drawings = append(drawings, jobPen.DrawBoxes(ids...))
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
// Input contains the input for the root command
|
||||
type Input struct {
|
||||
workingDir string
|
||||
workdir string
|
||||
workflowsPath string
|
||||
eventPath string
|
||||
reuseContainers bool
|
||||
@@ -16,7 +16,7 @@ type Input struct {
|
||||
}
|
||||
|
||||
func (i *Input) resolve(path string) string {
|
||||
basedir, err := filepath.Abs(i.workingDir)
|
||||
basedir, err := filepath.Abs(i.workdir)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@@ -29,6 +29,11 @@ func (i *Input) resolve(path string) string {
|
||||
return path
|
||||
}
|
||||
|
||||
// Workdir returns path to workdir
|
||||
func (i *Input) Workdir() string {
|
||||
return i.resolve(".")
|
||||
}
|
||||
|
||||
// WorkflowsPath returns path to workflows
|
||||
func (i *Input) WorkflowsPath() string {
|
||||
return i.resolve(i.workflowsPath)
|
||||
|
43
cmd/root.go
43
cmd/root.go
@@ -5,8 +5,11 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/nektos/act/pkg/common"
|
||||
|
||||
fswatch "github.com/andreaskoch/go-fswatch"
|
||||
"github.com/nektos/act/pkg/model"
|
||||
"github.com/nektos/act/pkg/runner"
|
||||
gitignore "github.com/sabhiram/go-gitignore"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -31,7 +34,7 @@ func Execute(ctx context.Context, version string) {
|
||||
rootCmd.Flags().BoolVarP(&input.forcePull, "pull", "p", false, "pull docker image(s) if already present")
|
||||
rootCmd.Flags().StringVarP(&input.eventPath, "event", "e", "", "path to event JSON file")
|
||||
rootCmd.PersistentFlags().StringVarP(&input.workflowsPath, "workflows", "W", "./.github/workflows/", "path to workflow files")
|
||||
rootCmd.PersistentFlags().StringVarP(&input.workingDir, "directory", "C", ".", "working directory")
|
||||
rootCmd.PersistentFlags().StringVarP(&input.workdir, "directory", "C", ".", "working directory")
|
||||
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "verbose output")
|
||||
rootCmd.PersistentFlags().BoolVarP(&input.dryrun, "dryrun", "n", false, "dryrun mode")
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
@@ -87,26 +90,30 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str
|
||||
}
|
||||
|
||||
// run the plan
|
||||
// runner, err := runner.New(config)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// defer runner.Close()
|
||||
config := &runner.Config{
|
||||
EventName: eventName,
|
||||
EventPath: input.EventPath(),
|
||||
ForcePull: input.forcePull,
|
||||
ReuseContainers: input.reuseContainers,
|
||||
Workdir: input.Workdir(),
|
||||
}
|
||||
runner, err := runner.New(config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// if watch, err := cmd.Flags().GetBool("watch"); err != nil {
|
||||
// return err
|
||||
// } else if watch {
|
||||
// return watchAndRun(ctx, func() error {
|
||||
// return runner.RunPlan(plan)
|
||||
// })
|
||||
// }
|
||||
ctx = common.WithDryrun(ctx, input.dryrun)
|
||||
if watch, err := cmd.Flags().GetBool("watch"); err != nil {
|
||||
return err
|
||||
} else if watch {
|
||||
return watchAndRun(ctx, runner.NewPlanExecutor(plan))
|
||||
}
|
||||
|
||||
// return runner.RunPlan(plan)
|
||||
return nil
|
||||
return runner.NewPlanExecutor(plan)(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
func watchAndRun(ctx context.Context, fn func() error) error {
|
||||
func watchAndRun(ctx context.Context, fn common.Executor) error {
|
||||
recurse := true
|
||||
checkIntervalInSeconds := 2
|
||||
dir, err := os.Getwd()
|
||||
@@ -132,13 +139,13 @@ func watchAndRun(ctx context.Context, fn func() error) error {
|
||||
|
||||
go func() {
|
||||
for folderWatcher.IsRunning() {
|
||||
if err = fn(); err != nil {
|
||||
if err = fn(ctx); err != nil {
|
||||
break
|
||||
}
|
||||
log.Debugf("Watching %s for changes", dir)
|
||||
for changes := range folderWatcher.ChangeDetails() {
|
||||
log.Debugf("%s", changes.String())
|
||||
if err = fn(); err != nil {
|
||||
if err = fn(ctx); err != nil {
|
||||
break
|
||||
}
|
||||
log.Debugf("Watching %s for changes", dir)
|
||||
|
Reference in New Issue
Block a user