diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4f189ff..f68ab26 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -115,7 +115,7 @@ jobs: gh release list -R ${{ github.repository }} | grep -i $IMAGE_TAG exit_code=$? if [ $exit_code -ne 0 ]; then - gh release create $IMAGE_TAG -R ${{ github.repository }} --generate-notes --prerelease + gh release create $IMAGE_TAG -R ${{ github.repository }} --generate-notes --prerelease --draft=false fi - name: upload to github release diff --git a/README.md b/README.md index cffc965..0280901 100644 --- a/README.md +++ b/README.md @@ -24,9 +24,11 @@ Create a `Runfile` in the root of your project, and add tasks to it. - [x] Run tasks with Key-Value environment variables - [x] Run tasks with dynamic environment variables (by shell execution) - [x] Run tasks with dotenv files as their environment variables -- [ ] Running tasks in different working directory [reference](https://taskfile.dev/reference/schema/#task) +- [x] Running tasks in different working directory [reference](https://taskfile.dev/reference/schema/#task) +- [x] Running tasks in parallel - [ ] Running tasks with watch mode -- [ ] Running tasks in parallel +- [x] Requirements prior to running a target +- [x] Environment validations and default value ### Example diff --git a/cmd/run/main.go b/cmd/run/main.go index c8a6c14..8f7249d 100644 --- a/cmd/run/main.go +++ b/cmd/run/main.go @@ -7,6 +7,7 @@ import ( "os" "os/signal" "path/filepath" + "strings" "syscall" "github.com/nxtcoder17/fwatcher/pkg/logging" @@ -70,7 +71,7 @@ func main() { watch := c.Bool("watch") debug := c.Bool("debug") - logging.NewSlogLogger(logging.SlogOptions{ + logger := logging.NewSlogLogger(logging.SlogOptions{ ShowCaller: debug, ShowDebugLogs: debug, SetAsDefaultLogger: true, @@ -90,6 +91,9 @@ func main() { panic(err) } + kv := make(map[string]string) + + // INFO: for supporting flags that have been suffixed post arguments args := make([]string, 0, len(c.Args().Slice())) for _, arg := range c.Args().Slice() { if arg == "-p" || arg == "--parallel" { @@ -107,6 +111,12 @@ func main() { continue } + sp := strings.SplitN(arg, "=", 2) + if len(sp) == 2 { + kv[sp[0]] = sp[1] + continue + } + args = append(args, arg) } @@ -114,11 +124,12 @@ func main() { return fmt.Errorf("parallel and watch can't be set together") } - return rf.Run(ctx, runfile.RunArgs{ + return rf.Run(runfile.NewContext(ctx, logger), runfile.RunArgs{ Tasks: args, ExecuteInParallel: parallel, Watch: watch, Debug: debug, + KVs: kv, }) }, } diff --git a/pkg/runfile/run.go b/pkg/runfile/run.go index ae96ded..385eeba 100644 --- a/pkg/runfile/run.go +++ b/pkg/runfile/run.go @@ -81,16 +81,23 @@ type RunArgs struct { ExecuteInParallel bool Watch bool Debug bool + KVs map[string]string } -func (rf *Runfile) Run(ctx context.Context, args RunArgs) error { - for _, v := range args.Tasks { - if _, ok := rf.Tasks[v]; !ok { +func (rf *Runfile) Run(ctx Context, args RunArgs) error { + for _, taskName := range args.Tasks { + task, ok := rf.Tasks[taskName] + if !ok { return errors.TaskNotFound{Context: errors.Context{ - Task: v, + Task: taskName, Runfile: rf.attrs.RunfilePath, }} } + + // INFO: adding parsed KVs as environments to the specified tasks + for k, v := range args.KVs { + task.Env[k] = v + } } if args.ExecuteInParallel { diff --git a/pkg/runfile/type.go b/pkg/runfile/type.go index 4333a64..8074e7a 100644 --- a/pkg/runfile/type.go +++ b/pkg/runfile/type.go @@ -5,6 +5,7 @@ import ( "context" "encoding/json" "fmt" + "log/slog" "os" "strings" "text/template" @@ -13,6 +14,20 @@ import ( fn "github.com/nxtcoder17/runfile/pkg/functions" ) +type Context struct { + context.Context + *slog.Logger +} + +func NewContext(ctx context.Context, logger *slog.Logger) Context { + lgr := logger + if lgr == nil { + lgr = slog.Default() + } + + return Context{Context: ctx, Logger: lgr} +} + type EvaluationArgs struct { Shell []string Env map[string]string