From c9ec56172974b50191eed082d8e12ccc82cb4ab8 Mon Sep 17 00:00:00 2001 From: Srevin Saju Date: Wed, 21 Jun 2023 20:17:14 +0530 Subject: [PATCH 1/5] feat: add fmt command for formatting --- cmd/togomak/main.go | 17 +++++++++++++++++ pkg/orchestra/format.go | 38 ++++++++++++++++++++++++++++++++++++++ pkg/pipeline/parse.go | 9 +++++++-- togomak.hcl | 6 +++--- 4 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 pkg/orchestra/format.go diff --git a/cmd/togomak/main.go b/cmd/togomak/main.go index 5684555..e6da91f 100644 --- a/cmd/togomak/main.go +++ b/cmd/togomak/main.go @@ -44,6 +44,18 @@ func main() { Aliases: []string{"ls", "l"}, Action: list, }, + { + Name: "fmt", + Usage: "format a pipeline file", + Action: format, + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "check", + Usage: "check if the file is formatted", + Aliases: []string{"c"}, + }, + }, + }, { Name: "cache", Usage: "manage the cache", @@ -205,3 +217,8 @@ func list(ctx *cli.Context) error { cfg := newConfigFromCliContext(ctx) return orchestra.List(cfg) } + +func format(ctx *cli.Context) error { + cfg := newConfigFromCliContext(ctx) + return orchestra.Format(cfg, ctx.Bool("check")) +} diff --git a/pkg/orchestra/format.go b/pkg/orchestra/format.go new file mode 100644 index 0000000..c52300f --- /dev/null +++ b/pkg/orchestra/format.go @@ -0,0 +1,38 @@ +package orchestra + +import ( + "bytes" + "fmt" + "github.com/hashicorp/hcl/v2/hclwrite" + "github.com/srevinsaju/togomak/v1/pkg/pipeline" + "os" +) + +func Format(cfg Config, check bool) error { + _, ctx := NewContextWithTogomak(cfg) + fn := pipeline.ConfigFilePath(ctx) + + var err error + var hasLocalChanges bool = false + + data, err := os.ReadFile(fn) + if err != nil { + panic(err) + } + outSrc := hclwrite.Format(data) + + if !bytes.Equal(outSrc, data) { + hasLocalChanges = true + } + if check && hasLocalChanges { + fmt.Println(fn) + os.Exit(1) + } + + if hasLocalChanges { + fmt.Println(fn) + return os.WriteFile(fn, outSrc, 0644) + } + return nil + +} diff --git a/pkg/pipeline/parse.go b/pkg/pipeline/parse.go index 7251e86..5291942 100644 --- a/pkg/pipeline/parse.go +++ b/pkg/pipeline/parse.go @@ -11,8 +11,7 @@ import ( "path/filepath" ) -func Read(ctx context.Context, parser *hclparse.Parser) (*ci.Pipeline, hcl.Diagnostics) { - +func ConfigFilePath(ctx context.Context) string { filePath := ctx.Value(c.TogomakContextPipelineFilePath).(string) if filePath == "" { filePath = meta.ConfigFileName @@ -22,6 +21,12 @@ func Read(ctx context.Context, parser *hclparse.Parser) (*ci.Pipeline, hcl.Diagn if filepath.IsAbs(filePath) == false { filePath = filepath.Join(owd, filePath) } + return filePath +} + +func Read(ctx context.Context, parser *hclparse.Parser) (*ci.Pipeline, hcl.Diagnostics) { + filePath := ConfigFilePath(ctx) + f, diags := parser.ParseHCLFile(filePath) if diags.HasErrors() { diff --git a/togomak.hcl b/togomak.hcl index e61a3bc..7e26169 100644 --- a/togomak.hcl +++ b/togomak.hcl @@ -11,17 +11,17 @@ stage "vet" { } stage "build" { depends_on = [stage.fmt, stage.vet] - script = "go build -v -o ./cmd/togomak/togomak github.com/srevinsaju/togomak/v1/cmd/togomak" + script = "go build -v -o ./cmd/togomak/togomak github.com/srevinsaju/togomak/v1/cmd/togomak" } stage "install" { depends_on = [stage.build] - script = "go install github.com/srevinsaju/togomak/v1/cmd/togomak" + script = "go install github.com/srevinsaju/togomak/v1/cmd/togomak" } stage "docs_serve" { daemon { enabled = true } - if = false + if = false script = "cd docs && mdbook serve" } From d1e6002026a2db4d8f7b37f5fc2288a6ee8266ca Mon Sep 17 00:00:00 2001 From: Srevin Saju Date: Wed, 21 Jun 2023 20:27:01 +0530 Subject: [PATCH 2/5] feat: add -recursive formatting flag --- cmd/togomak/main.go | 7 ++++- pkg/orchestra/format.go | 69 +++++++++++++++++++++++++++++------------ 2 files changed, 55 insertions(+), 21 deletions(-) diff --git a/cmd/togomak/main.go b/cmd/togomak/main.go index e6da91f..e5de0d0 100644 --- a/cmd/togomak/main.go +++ b/cmd/togomak/main.go @@ -54,6 +54,11 @@ func main() { Usage: "check if the file is formatted", Aliases: []string{"c"}, }, + &cli.BoolFlag{ + Name: "recursive", + Usage: "format all the files named togomak.hcl in the current directory, and its children", + Aliases: []string{"r"}, + }, }, }, { @@ -220,5 +225,5 @@ func list(ctx *cli.Context) error { func format(ctx *cli.Context) error { cfg := newConfigFromCliContext(ctx) - return orchestra.Format(cfg, ctx.Bool("check")) + return orchestra.Format(cfg, ctx.Bool("check"), ctx.Bool("recursive")) } diff --git a/pkg/orchestra/format.go b/pkg/orchestra/format.go index c52300f..e796c79 100644 --- a/pkg/orchestra/format.go +++ b/pkg/orchestra/format.go @@ -4,34 +4,63 @@ import ( "bytes" "fmt" "github.com/hashicorp/hcl/v2/hclwrite" + "github.com/srevinsaju/togomak/v1/pkg/meta" "github.com/srevinsaju/togomak/v1/pkg/pipeline" "os" + "path/filepath" ) -func Format(cfg Config, check bool) error { - _, ctx := NewContextWithTogomak(cfg) - fn := pipeline.ConfigFilePath(ctx) +func Format(cfg Config, check bool, recursive bool) error { + t, ctx := NewContextWithTogomak(cfg) - var err error - var hasLocalChanges bool = false + var toFormat []string - data, err := os.ReadFile(fn) - if err != nil { - panic(err) + if recursive { + err := filepath.WalkDir(t.cwd, func(path string, d os.DirEntry, err error) error { + if filepath.Base(path) == meta.ConfigFileName { + t.logger.Tracef("Found %s", path) + data, err := os.ReadFile(path) + if err != nil { + return err + } + outSrc := hclwrite.Format(data) + if !bytes.Equal(outSrc, data) { + t.logger.Tracef("%s needs formatting", path) + toFormat = append(toFormat, path) + } + } else { + t.logger.Tracef("Skipping %s", path) + } + return nil + }) + if err != nil { + t.logger.Fatalf("Error while formatting: %s", err) + } + } else { + fn := pipeline.ConfigFilePath(ctx) + data, err := os.ReadFile(fn) + if err != nil { + return err + } + outSrc := hclwrite.Format(data) + if !bytes.Equal(outSrc, data) { + t.logger.Tracef("%s needs formatting", fn) + toFormat = append(toFormat, fn) + } } - outSrc := hclwrite.Format(data) - - if !bytes.Equal(outSrc, data) { - hasLocalChanges = true - } - if check && hasLocalChanges { - fmt.Println(fn) - os.Exit(1) - } - - if hasLocalChanges { + for _, fn := range toFormat { fmt.Println(fn) - return os.WriteFile(fn, outSrc, 0644) + if !check { + data, err := os.ReadFile(fn) + if err != nil { + panic(err) + } + outSrc := hclwrite.Format(data) + err = os.WriteFile(fn, outSrc, 0644) + if err != nil { + panic(err) + } + } } return nil From 7e8e02c13ecc0d741a64d4001d66aeee60912f55 Mon Sep 17 00:00:00 2001 From: Srevin Saju Date: Wed, 21 Jun 2023 20:56:21 +0530 Subject: [PATCH 3/5] feat: add recursive clean function --- cmd/togomak/main.go | 10 +++++++++- go.mod | 1 + go.sum | 2 ++ pkg/cache/clean.go | 26 ++++++++++++++++++++++++-- pkg/orchestra/format.go | 36 +++++++++++++++++------------------- togomak.hcl | 3 +++ 6 files changed, 56 insertions(+), 22 deletions(-) diff --git a/cmd/togomak/main.go b/cmd/togomak/main.go index e5de0d0..a9b503f 100644 --- a/cmd/togomak/main.go +++ b/cmd/togomak/main.go @@ -69,6 +69,13 @@ func main() { Name: "clean", Usage: "clean the cache", Action: cleanCache, + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "recursive", + Usage: "clean the cache recursively", + Aliases: []string{"r"}, + }, + }, }, }, }, @@ -206,6 +213,7 @@ func run(ctx *cli.Context) error { } func cleanCache(ctx *cli.Context) error { + recursive := ctx.Bool("recursive") owd, err := os.Getwd() if err != nil { panic(err) @@ -214,7 +222,7 @@ func cleanCache(ctx *cli.Context) error { if dir == "" { dir = owd } - cache.CleanCache(dir) + cache.CleanCache(dir, recursive) return nil } diff --git a/go.mod b/go.mod index 6b5a954..f3ad85e 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/alessio/shellescape v1.4.1 github.com/bcicen/jstream v1.0.1 github.com/bmatcuk/doublestar v1.1.5 + github.com/bmatcuk/doublestar/v4 v4.6.0 github.com/creack/pty v1.1.18 github.com/docker/docker v24.0.2+incompatible github.com/fatih/color v1.15.0 diff --git a/go.sum b/go.sum index bf572b0..075e9d1 100644 --- a/go.sum +++ b/go.sum @@ -62,6 +62,8 @@ github.com/bcicen/jstream v1.0.1 h1:BXY7Cu4rdmc0rhyTVyT3UkxAiX3bnLpKLas9btbH5ck= github.com/bcicen/jstream v1.0.1/go.mod h1:9ielPxqFry7Y4Tg3j4BfjPocfJ3TbsRtXOAYXYmRuAQ= github.com/bmatcuk/doublestar v1.1.5 h1:2bNwBOmhyFEFcoB3tGvTD5xanq+4kyOZlB8wFYbMjkk= github.com/bmatcuk/doublestar v1.1.5/go.mod h1:wiQtGV+rzVYxB7WIlirSN++5HPtPlXEo9MEoZQC/PmE= +github.com/bmatcuk/doublestar/v4 v4.6.0 h1:HTuxyug8GyFbRkrffIpzNCSK4luc0TY3wzXvzIZhEXc= +github.com/bmatcuk/doublestar/v4 v4.6.0/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc= github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= diff --git a/pkg/cache/clean.go b/pkg/cache/clean.go index 31360e6..12bcebd 100644 --- a/pkg/cache/clean.go +++ b/pkg/cache/clean.go @@ -6,11 +6,12 @@ import ( "github.com/srevinsaju/togomak/v1/pkg/x" "os" "path/filepath" + "sync" ) -func CleanCache(dir string) { +func CleanCache(dir string, recursive bool) { dirPath := filepath.Join(dir, meta.BuildDirPrefix, "pipelines", "tmp") - filepath.Walk(dirPath, func(path string, info os.FileInfo, err error) error { + err := filepath.Walk(dirPath, func(path string, info os.FileInfo, err error) error { if path == dirPath { return nil } @@ -20,5 +21,26 @@ func CleanCache(dir string) { } return nil }) + if err != nil { + panic(err) + } + var wg sync.WaitGroup + if recursive { + entries, err := os.ReadDir(dir) + if err != nil { + panic(err) + } + for _, entry := range entries { + + if entry.IsDir() { + wg.Add(1) + go func(entry os.DirEntry) { + defer wg.Done() + CleanCache(filepath.Join(dir, entry.Name()), recursive) + }(entry) + } + } + } + wg.Wait() } diff --git a/pkg/orchestra/format.go b/pkg/orchestra/format.go index e796c79..2b53070 100644 --- a/pkg/orchestra/format.go +++ b/pkg/orchestra/format.go @@ -3,11 +3,10 @@ package orchestra import ( "bytes" "fmt" + "github.com/bmatcuk/doublestar" "github.com/hashicorp/hcl/v2/hclwrite" - "github.com/srevinsaju/togomak/v1/pkg/meta" "github.com/srevinsaju/togomak/v1/pkg/pipeline" "os" - "path/filepath" ) func Format(cfg Config, check bool, recursive bool) error { @@ -16,25 +15,21 @@ func Format(cfg Config, check bool, recursive bool) error { var toFormat []string if recursive { - err := filepath.WalkDir(t.cwd, func(path string, d os.DirEntry, err error) error { - if filepath.Base(path) == meta.ConfigFileName { - t.logger.Tracef("Found %s", path) - data, err := os.ReadFile(path) - if err != nil { - return err - } - outSrc := hclwrite.Format(data) - if !bytes.Equal(outSrc, data) { - t.logger.Tracef("%s needs formatting", path) - toFormat = append(toFormat, path) - } - } else { - t.logger.Tracef("Skipping %s", path) + matches, err := doublestar.Glob("**/*.hcl") + for _, path := range matches { + t.logger.Tracef("Found %s", path) + data, err := os.ReadFile(path) + if err != nil { + return err + } + outSrc := hclwrite.Format(data) + if !bytes.Equal(outSrc, data) { + t.logger.Tracef("%s needs formatting", path) + toFormat = append(toFormat, path) } - return nil - }) + } if err != nil { - t.logger.Fatalf("Error while formatting: %s", err) + t.logger.Fatalf("Error while globbing for **/*.hcl: %s", err) } } else { fn := pipeline.ConfigFilePath(ctx) @@ -62,6 +57,9 @@ func Format(cfg Config, check bool, recursive bool) error { } } } + if check && len(toFormat) > 0 { + os.Exit(1) + } return nil } diff --git a/togomak.hcl b/togomak.hcl index 7e26169..545eff3 100644 --- a/togomak.hcl +++ b/togomak.hcl @@ -6,13 +6,16 @@ togomak { stage "fmt" { script = "go fmt github.com/srevinsaju/togomak/v1/..." } + stage "vet" { script = "go vet github.com/srevinsaju/togomak/v1/..." } + stage "build" { depends_on = [stage.fmt, stage.vet] script = "go build -v -o ./cmd/togomak/togomak github.com/srevinsaju/togomak/v1/cmd/togomak" } + stage "install" { depends_on = [stage.build] script = "go install github.com/srevinsaju/togomak/v1/cmd/togomak" From 545bc3813fb6723b422a8e1a750370d3aec63d31 Mon Sep 17 00:00:00 2001 From: Srevin Saju Date: Wed, 21 Jun 2023 20:57:05 +0530 Subject: [PATCH 4/5] chore: lint with 'togomak fmt' --- examples/conditions/togomak.hcl | 4 +-- examples/docker/togomak.hcl | 2 +- examples/files/togomak.hcl | 2 +- examples/git/togomak.hcl | 2 +- examples/locals/togomak.hcl | 2 +- examples/macros/togomak.hcl | 30 +++++++++---------- examples/output/togomak.hcl | 4 +-- examples/prompt/togomak.hcl | 6 ++-- examples/remote-stages/togomak.hcl | 6 ++-- tests/tests/failing/cant-run-fail/togomak.hcl | 2 +- .../failing/dependency-cycles/togomak.hcl | 4 +-- .../failing/invalid-block-id/togomak.hcl | 2 +- .../failing/invalid-env-output/togomak.hcl | 4 +-- tests/tests/failing/retry/togomak.hcl | 8 ++--- .../self-referenced-dependencies/togomak.hcl | 4 +-- tests/togomak.hcl | 22 +++++++------- 16 files changed, 52 insertions(+), 52 deletions(-) diff --git a/examples/conditions/togomak.hcl b/examples/conditions/togomak.hcl index 8827c71..9c3af6e 100644 --- a/examples/conditions/togomak.hcl +++ b/examples/conditions/togomak.hcl @@ -3,12 +3,12 @@ togomak { } data "env" "home" { - key = "HOME" + key = "HOME" default = "@" } stage "example" { - if = data.env.home.value != "@" + if = data.env.home.value != "@" name = "example" script = "echo hello world" } diff --git a/examples/docker/togomak.hcl b/examples/docker/togomak.hcl index fff048d..5c0dbc9 100644 --- a/examples/docker/togomak.hcl +++ b/examples/docker/togomak.hcl @@ -6,7 +6,7 @@ stage "example" { container { image = "ubuntu" volume { - source = "${cwd}/diary" + source = "${cwd}/diary" destination = "/newdiary" } } diff --git a/examples/files/togomak.hcl b/examples/files/togomak.hcl index 5ff0aa1..55ef18d 100644 --- a/examples/files/togomak.hcl +++ b/examples/files/togomak.hcl @@ -4,6 +4,6 @@ togomak { stage "list" { - name = "listing files" + name = "listing files" args = ["ls", "-al"] } diff --git a/examples/git/togomak.hcl b/examples/git/togomak.hcl index 3209bc3..3d8bbd2 100644 --- a/examples/git/togomak.hcl +++ b/examples/git/togomak.hcl @@ -3,7 +3,7 @@ togomak { } data "git" "repo" { - url = "https://github.com/srevinsaju/togomak" + url = "https://github.com/srevinsaju/togomak" files = ["togomak.hcl"] } diff --git a/examples/locals/togomak.hcl b/examples/locals/togomak.hcl index dd67195..a0d5576 100644 --- a/examples/locals/togomak.hcl +++ b/examples/locals/togomak.hcl @@ -4,7 +4,7 @@ togomak { locals { nerv_headquarters = "Tokyo-3" - pilot_name = "Shinji" + pilot_name = "Shinji" } stage "eva01_synchronization" { diff --git a/examples/macros/togomak.hcl b/examples/macros/togomak.hcl index 6df9447..61e24fc 100644 --- a/examples/macros/togomak.hcl +++ b/examples/macros/togomak.hcl @@ -3,8 +3,8 @@ togomak { } macro "explode" { - stage "explode" { - script = <<-EOT + stage "explode" { + script = <<-EOT for i in $(seq 1 10); do sleep 0.1 echo "${param.eva}: Loading $i..." @@ -12,28 +12,28 @@ macro "explode" { echo "${param.eva}: entry plug connected! pilot ${param.pilot} synchronized! 🤖" EOT - } + } } stage "entry_plug_eva01" { - use { - macro = macro.explode - parameters = { - pilot = "Shinji Ikari 🙅‍♂️" - eva = "01" - } + use { + macro = macro.explode + parameters = { + pilot = "Shinji Ikari 🙅‍♂️" + eva = "01" } + } } stage "entry_plug_eva02" { - use { - macro = macro.explode - parameters = { - pilot = "Asuka Langley Soryu 🙅‍♀️" - eva = "02" - } + use { + macro = macro.explode + parameters = { + pilot = "Asuka Langley Soryu 🙅‍♀️" + eva = "02" } + } } diff --git a/examples/output/togomak.hcl b/examples/output/togomak.hcl index b09b054..0a98b11 100644 --- a/examples/output/togomak.hcl +++ b/examples/output/togomak.hcl @@ -11,6 +11,6 @@ stage "agent" { stage "seele" { depends_on = [stage.agent] - name = "seele" - script = "echo The agent from Seele reporting! ${output.AGENT}" + name = "seele" + script = "echo The agent from Seele reporting! ${output.AGENT}" } diff --git a/examples/prompt/togomak.hcl b/examples/prompt/togomak.hcl index bbf914c..1511586 100644 --- a/examples/prompt/togomak.hcl +++ b/examples/prompt/togomak.hcl @@ -3,12 +3,12 @@ togomak { } data "env" "quit_if_not_shinji" { - key = "QUIT_IF_NOT_SHINJI" + key = "QUIT_IF_NOT_SHINJI" default = "false" } data "prompt" "name" { - prompt = "What is your name?" + prompt = "What is your name?" default = "Pen Pen" } @@ -18,7 +18,7 @@ stage "example" { } stage "quit" { - if = data.env.quit_if_not_shinji.value != "false" + if = data.env.quit_if_not_shinji.value != "false" script = <<-EOT #!/usr/bin/env bash set -eux diff --git a/examples/remote-stages/togomak.hcl b/examples/remote-stages/togomak.hcl index 1ed38ba..4b92cd8 100644 --- a/examples/remote-stages/togomak.hcl +++ b/examples/remote-stages/togomak.hcl @@ -3,16 +3,16 @@ togomak { } data "git" "eva01_source" { - url = "https://github.com/srevinsaju/togomak" + url = "https://github.com/srevinsaju/togomak" files = ["togomak.hcl"] } macro "gendo_brain" { - files = data.git.eva01_source.files + files = data.git.eva01_source.files } stage "build_eva01" { - name = "Building eva unit" + name = "Building eva unit" use { macro = macro.gendo_brain } diff --git a/tests/tests/failing/cant-run-fail/togomak.hcl b/tests/tests/failing/cant-run-fail/togomak.hcl index f6777df..d987877 100644 --- a/tests/tests/failing/cant-run-fail/togomak.hcl +++ b/tests/tests/failing/cant-run-fail/togomak.hcl @@ -2,7 +2,7 @@ togomak { version = 1 } stage "example" { - if = this.what + if = this.what name = "example" script = "echo hello world" } diff --git a/tests/tests/failing/dependency-cycles/togomak.hcl b/tests/tests/failing/dependency-cycles/togomak.hcl index 6041562..bab301d 100644 --- a/tests/tests/failing/dependency-cycles/togomak.hcl +++ b/tests/tests/failing/dependency-cycles/togomak.hcl @@ -4,10 +4,10 @@ togomak { stage "example_a" { depends_on = [stage.example_b] - script = "echo hello world" + script = "echo hello world" } stage "example_b" { depends_on = [stage.example_a] - script = "echo hello again" + script = "echo hello again" } diff --git a/tests/tests/failing/invalid-block-id/togomak.hcl b/tests/tests/failing/invalid-block-id/togomak.hcl index 443e9b8..4a1fa5e 100644 --- a/tests/tests/failing/invalid-block-id/togomak.hcl +++ b/tests/tests/failing/invalid-block-id/togomak.hcl @@ -3,7 +3,7 @@ togomak { } data "env" "hello_world" { - key = "HOME" + key = "HOME" default = "@" } diff --git a/tests/tests/failing/invalid-env-output/togomak.hcl b/tests/tests/failing/invalid-env-output/togomak.hcl index 66ffc57..139e848 100644 --- a/tests/tests/failing/invalid-env-output/togomak.hcl +++ b/tests/tests/failing/invalid-env-output/togomak.hcl @@ -11,6 +11,6 @@ stage "agent" { stage "seele" { depends_on = [stage.agent] - name = "seele" - script = "echo The agent from Seele reporting! ${output.AGENT}" + name = "seele" + script = "echo The agent from Seele reporting! ${output.AGENT}" } diff --git a/tests/tests/failing/retry/togomak.hcl b/tests/tests/failing/retry/togomak.hcl index 1f632d5..5752e41 100644 --- a/tests/tests/failing/retry/togomak.hcl +++ b/tests/tests/failing/retry/togomak.hcl @@ -5,11 +5,11 @@ togomak { stage "example" { retry { - enabled = true + enabled = true exponential_backoff = true - attempts = 3 - min_backoff = 1 - max_backoff = 3 + attempts = 3 + min_backoff = 1 + max_backoff = 3 } script = "echo hello world && exit 1" } diff --git a/tests/tests/failing/self-referenced-dependencies/togomak.hcl b/tests/tests/failing/self-referenced-dependencies/togomak.hcl index 069afe8..d41d257 100644 --- a/tests/tests/failing/self-referenced-dependencies/togomak.hcl +++ b/tests/tests/failing/self-referenced-dependencies/togomak.hcl @@ -3,6 +3,6 @@ togomak { } stage "example" { depends_on = [stage.example] - name = "example" - script = "echo hello world" + name = "example" + script = "echo hello world" } diff --git a/tests/togomak.hcl b/tests/togomak.hcl index ca9d16f..09c7170 100644 --- a/tests/togomak.hcl +++ b/tests/togomak.hcl @@ -5,13 +5,13 @@ togomak { stage "build" { name = "build" - dir = ".." + dir = ".." script = "go build -cover -o tests/togomak_coverage ./cmd/togomak" } locals { - coverage_data_dir = "${cwd}/coverage_data_files" - coverage_merge_dir = "${cwd}/coverage_merge_dir" + coverage_data_dir = "${cwd}/coverage_data_files" + coverage_merge_dir = "${cwd}/coverage_merge_dir" coverage_data_interactive_dir = "${cwd}/coverage_data_interactive_dir" } @@ -26,7 +26,7 @@ stage "coverage_prepare" { stage "integration_tests" { depends_on = [stage.build, stage.coverage_prepare] - script = <<-EOT + script = <<-EOT #!/usr/bin/env bash set -e ls ../examples @@ -49,29 +49,29 @@ stage "integration_tests" { EOT env { - name = "GOCOVERDIR" + name = "GOCOVERDIR" value = local.coverage_data_dir } } stage "coverage_raw" { depends_on = [stage.integration_tests] - script = "go tool covdata percent -i=${local.coverage_data_dir}" + script = "go tool covdata percent -i=${local.coverage_data_dir}" } stage "coverage_merge" { depends_on = [stage.coverage_raw, stage.coverage_unit_tests] - script = "go tool covdata merge -i=${local.coverage_data_dir},${local.coverage_data_interactive_dir} -o=${local.coverage_merge_dir}" + script = "go tool covdata merge -i=${local.coverage_data_dir},${local.coverage_data_interactive_dir} -o=${local.coverage_merge_dir}" } stage "coverage" { depends_on = [stage.coverage_merge] - script = "go tool covdata textfmt -i=${local.coverage_merge_dir} -o=coverage.out" + script = "go tool covdata textfmt -i=${local.coverage_merge_dir} -o=coverage.out" } stage "coverage_unit_tests" { depends_on = [stage.build] - dir = ".." - script = "go test ./... -coverprofile=coverage_unit_tests.out" + dir = ".." + script = "go test ./... -coverprofile=coverage_unit_tests.out" env { - name = "PROMPT_GOCOVERDIR" + name = "PROMPT_GOCOVERDIR" value = local.coverage_data_interactive_dir } } From 6e1715932e70bcb0c499ade5cd7f1d33d1313ab9 Mon Sep 17 00:00:00 2001 From: Srevin Saju Date: Wed, 21 Jun 2023 20:59:08 +0530 Subject: [PATCH 5/5] test: add i9n tests for cache clean, and fmt --- tests/togomak.hcl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/togomak.hcl b/tests/togomak.hcl index 09c7170..75edef0 100644 --- a/tests/togomak.hcl +++ b/tests/togomak.hcl @@ -35,6 +35,8 @@ stage "integration_tests" { ./togomak_coverage -C "$i" --ci -v root ./togomak_coverage -C "$i" --ci -v -n done + ./togomak_coverage cache clean --recursive + ./togomak_coverage fmt --check --recursive for i in tests/failing/*; do set +e