Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ bin/
.secrets/
Taskfile.yml
go.work*
tags
6 changes: 4 additions & 2 deletions cmd/run/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,15 @@ func main() {
return err
}

rf, err2 := parser.ParseRunfile(types.NewContext(ctx, logger), runfilePath)
runfileCtx := types.NewContext(ctx, logger)

rf, err2 := parser.ParseRunfile(runfileCtx, runfilePath)
if err2 != nil {
slog.Error("parsing runfile, got", "err", err2)
panic(err2)
}

if err := runner.Run(types.NewContext(ctx, logger), rf, runner.RunArgs{
if err := runner.Run(runfileCtx, rf, runner.RunArgs{
Tasks: args,
ExecuteInParallel: parallel,
Watch: watch,
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
module github.com/nxtcoder17/runfile

go 1.24
go 1.24.1

toolchain go1.24.2

require (
github.com/alecthomas/chroma/v2 v2.15.0
github.com/charmbracelet/lipgloss v1.0.0
github.com/joho/godotenv v1.5.1
github.com/muesli/termenv v0.15.2
github.com/nxtcoder17/fastlog v0.0.0-20250416154215-c6aac24aebcb
github.com/nxtcoder17/fwatcher v1.2.2-0.20250318121757-bfc2065fa9f5
github.com/nxtcoder17/go.pkgs v0.0.0-20250216034729-39e2d2cd48da
github.com/urfave/cli/v3 v3.0.0-beta1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6T
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo=
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
github.com/nxtcoder17/fwatcher v1.2.0 h1:Nn5NQZrd6tnY0aFIUmpHCysLDbIsUYn4oyHaxEaVj60=
github.com/nxtcoder17/fwatcher v1.2.0/go.mod h1:SMwIdCpyi5fBygrkCX8hIIUeILzgoxJFaDSlhFBOWWQ=
github.com/nxtcoder17/fastlog v0.0.0-20250416154215-c6aac24aebcb h1:BHKArf9In3jINU2B3mTLQb75F5PMoJ5fnOlRD7dOq/w=
github.com/nxtcoder17/fastlog v0.0.0-20250416154215-c6aac24aebcb/go.mod h1:EWaIRNdsxHdqCv53XcNw9H9QMwhEV3LTWfsSQZCiiC4=
github.com/nxtcoder17/fwatcher v1.2.2-0.20250318121757-bfc2065fa9f5 h1:6BulIAQBv2FZqUFZcKtFEhc1vMOeOdeMS+S5d874FMY=
github.com/nxtcoder17/fwatcher v1.2.2-0.20250318121757-bfc2065fa9f5/go.mod h1:SMwIdCpyi5fBygrkCX8hIIUeILzgoxJFaDSlhFBOWWQ=
github.com/nxtcoder17/go.pkgs v0.0.0-20250216034729-39e2d2cd48da h1:Y6GILHFlrihVfDqDPQ98y2kdUeI0SQc8tnoXh2NbEIA=
Expand Down
4 changes: 4 additions & 0 deletions parser/parse-command.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ func parseCommand(ctx types.Context, prf *types.ParsedRunfile, taskEnv map[strin
switch {
case cj.Run != nil:
{
if ctx.TaskNamespace != "" {
*cj.Run = ctx.TaskNamespace + ":" + *cj.Run
}
pcj.Run = cj.Run

if _, ok := prf.Tasks[*cj.Run]; !ok {
err := errors.ErrTaskNotFound.Wrap(fmt.Errorf("run target, not found")).KV("command", command, "run-target", cj.Run)
return nil, err
Expand Down
1 change: 1 addition & 0 deletions parser/parse-task.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func ParseTask(ctx types.Context, prf *types.ParsedRunfile, task types.Task) (*t
}

return &types.ParsedTask{
Namespace: task.Metadata.Namespace,
Name: task.Name,
Shell: task.Shell,
WorkingDir: *task.Dir,
Expand Down
22 changes: 10 additions & 12 deletions parser/parser-runfile.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package parser

import (
"context"
"fmt"
"os"
"path/filepath"

"github.com/nxtcoder17/go.pkgs/log"
"github.com/nxtcoder17/runfile/errors"
fn "github.com/nxtcoder17/runfile/functions"
"github.com/nxtcoder17/runfile/types"
Expand All @@ -18,25 +16,28 @@ func parseRunfile(ctx types.Context, runfile *types.Runfile) (*types.ParsedRunfi
Env: make(map[string]string),
Tasks: make(map[string]types.Task),
}
prf.Metadata.RunfilePath = runfile.Filepath

for k, task := range runfile.Tasks {
task.Name = k
task.Metadata.RunfilePath = &prf.Metadata.RunfilePath
prf.Tasks[k] = task
}

m, err := parseIncludes(ctx, runfile.Includes)
includes, err := parseIncludes(ctx, runfile.Includes)
if err != nil {
return nil, err
}

for k, iprf := range m {
for taskName, task := range iprf.Tasks {
task.Name = k
task.Metadata.RunfilePath = &iprf.Metadata.RunfilePath
for k, included := range includes {
for taskName, task := range included.Tasks {
task.Name = taskName
task.Metadata.RunfilePath = &included.Metadata.RunfilePath
task.Metadata.Namespace = k
prf.Tasks[fmt.Sprintf("%s:%s", k, taskName)] = task
}

for k, v := range iprf.Env {
for k, v := range included.Env {
prf.Env[k] = v
}
}
Expand All @@ -58,7 +59,7 @@ func parseRunfile(ctx types.Context, runfile *types.Runfile) (*types.ParsedRunfi
return nil, err
}

envVars, err := parseEnvVars(types.Context{Context: context.TODO(), Logger: log.New()}, runfile.Env, evaluationParams{Env: dotenvVars})
envVars, err := parseEnvVars(ctx, runfile.Env, evaluationParams{Env: dotenvVars})
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -86,9 +87,6 @@ func parseRunfileFromFile(ctx types.Context, file string) (*types.ParsedRunfile,
if err != nil {
return nil, err
}

// prf.Metadata.RunfilePath = file
prf.Metadata.RunfilePath = fn.Must(filepath.Abs(file))
return prf, nil
}

Expand Down
16 changes: 5 additions & 11 deletions runner/run-task.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func isTTY() bool {

func hasANSISupport() bool {
term := os.Getenv("TERM")
return strings.Contains(term, "xterm") || strings.Contains(term, "screen") || strings.Contains(term, "vt100")
return strings.Contains(term, "xterm") || strings.Contains(term, "screen") || strings.Contains(term, "vt100") || strings.Contains(term, "tmux")
}

func printCommand(writer io.Writer, prefix, lang, cmd string) {
Expand Down Expand Up @@ -187,25 +187,19 @@ func createCommandGroups(ctx types.Context, args CreateCommandGroupArgs) ([]exec
}

func runTask(ctx types.Context, prf *types.ParsedRunfile, args runTaskArgs) error {
runfilePath := prf.Metadata.RunfilePath
task := prf.Tasks[args.taskName]

if task.Metadata.RunfilePath != nil {
runfilePath = *task.Metadata.RunfilePath
}

args.taskTrail = append(args.taskTrail, args.taskName)

logger := ctx.With("task", args.taskName, "runfile", fn.Must(filepath.Rel(fn.Must(os.Getwd()), runfilePath)))
logger.Debug("running task")
logger := ctx.With("task", args.taskName, "runfile", fn.Must(filepath.Rel(fn.Must(os.Getwd()), *task.Metadata.RunfilePath)), "namespace", task.Metadata.Namespace)
logger.Debug("running")

ctx.TaskNamespace = task.Metadata.Namespace

task, ok := prf.Tasks[args.taskName]
if !ok {
return errors.ErrTaskNotFound
}

task.Name = args.taskName

pt, err := parser.ParseTask(ctx, prf, task)
if err != nil {
return errors.WithErr(err)
Expand Down
62 changes: 31 additions & 31 deletions runner/run-task_test.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
package runner

import (
"context"
"log/slog"
"testing"
// import (
// "context"
// "testing"
//
// "github.com/nxtcoder17/fwatcher/pkg/executor"
// "github.com/nxtcoder17/go.pkgs/log"
// "github.com/nxtcoder17/runfile/types"
// )

"github.com/nxtcoder17/fwatcher/pkg/executor"
"github.com/nxtcoder17/runfile/types"
)

func TestCreateCommands(t *testing.T) {
tests := []struct {
prf types.ParsedRunfile
pt types.ParsedTask
rta runTaskArgs

want []executor.CommandGroup
}{
{
prf: types.ParsedRunfile{},
pt: types.ParsedTask{},
},
}

for _, tt := range tests {
cg, err := createCommandGroups(Context{Context: context.TODO(), Logger: slog.Default()}, &tt.prf, &tt.pt, tt.rta)
if err != nil {
t.Error(err)
}

_ = cg
}
}
// func TestCreateCommands(t *testing.T) {
// tests := []struct {
// prf types.ParsedRunfile
// pt types.ParsedTask
// rta runTaskArgs
//
// want []executor.CommandGroup
// }{
// {
// prf: types.ParsedRunfile{},
// pt: types.ParsedTask{},
// },
// }
//
// for _, tt := range tests {
// cg, err := createCommandGroups(types.Context{Context: context.TODO(), Logger: log.New()}, &tt.prf, &tt.pt, tt.rta)
// if err != nil {
// t.Error(err)
// }
//
// _ = cg
// }
// }
3 changes: 2 additions & 1 deletion types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
type Context struct {
context.Context
log.Logger
TaskName string
TaskName string
TaskNamespace string
}

func NewContext(ctx context.Context, logger log.Logger) Context {
Expand Down
10 changes: 7 additions & 3 deletions types/parsed-types.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package types

type ParsedRunfile struct {
Env map[string]string `json:"env,omitempty"`
Tasks map[string]Task `json:"tasks"`
Env map[string]string
Includes map[string]Task
Tasks map[string]Task

Metadata struct {
RunfilePath string
} `json:"-"`
}
}

type ParsedTask struct {
// Namespace for a task is auto set, when it is imported under a name
Namespace string `json:"-"`

// Name should be resolved from key itself
Name string `json:"-"`

Expand Down
3 changes: 2 additions & 1 deletion types/types.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package types

type Runfile struct {
Filepath string
Filepath string `json:"-"`
Version string `json:"version,omitempty"`
Includes map[string]IncludeSpec `json:"includes"`
Env EnvVar `json:"env,omitempty"`
Expand Down Expand Up @@ -51,6 +51,7 @@ type TaskWatch struct {
type Task struct {
Metadata struct {
RunfilePath *string
Namespace string
}

Name string `json:"-"`
Expand Down